mdbx 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.md +14 -0
- data/ext/mdbx_ext/database.c +16 -27
- data/ext/mdbx_ext/mdbx_ext.c +54 -0
- data/ext/mdbx_ext/mdbx_ext.h +16 -0
- data/lib/mdbx/database.rb +31 -0
- data/lib/mdbx.rb +8 -1
- data.tar.gz.sig +0 -0
- metadata +17 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a961296e49a7e0e0fee9afbe7d2b92144a23b6295d68c3fc10d2296d5421666
|
4
|
+
data.tar.gz: 29fd9c1997cb4a6bd6d1f7ce99ccb8cb38651ddc78e34a1a93eb21d55a552505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d04ccf57c5cf613e930339c770acaa28c368eba2345e9b1255e0d2584f2271b9d166bdda8f55f2e27dc360315b00c41c4af7e59829f21611946fa2824975cc7
|
7
|
+
data.tar.gz: f6d39a0a124cd4bfbf189f439ae765c7aec0a99eb0bc7a8b2e4b7d29141faa99a294d50b4110e0d40ac13349b22b731b2df29f8b2b4a36eb199785c0dba22043
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Release History for MDBX
|
2
2
|
|
3
|
+
---
|
4
|
+
## v0.3.3 [2021-10-22] Mahlon E. Smith <mahlon@martini.nu>
|
5
|
+
|
6
|
+
Bugfixes:
|
7
|
+
|
8
|
+
- Close any open transactions if serialization functions fail.
|
9
|
+
- Don't use functions that assume NUL is the stream terminator.
|
10
|
+
|
11
|
+
|
12
|
+
Enhancements:
|
13
|
+
|
14
|
+
- Add Loggability for debug output.
|
15
|
+
|
16
|
+
|
3
17
|
---
|
4
18
|
## v0.3.2 [2021-07-13] Mahlon E. Smith <mahlon@martini.nu>
|
5
19
|
|
data/ext/mdbx_ext/database.c
CHANGED
@@ -123,7 +123,7 @@ rmdbx_key_for( VALUE key, MDBX_val *ckey )
|
|
123
123
|
VALUE key_str = rb_funcall( key, rb_intern("to_s"), 0 );
|
124
124
|
ckey->iov_len = RSTRING_LEN( key_str );
|
125
125
|
ckey->iov_base = malloc( ckey->iov_len );
|
126
|
-
|
126
|
+
memcpy( ckey->iov_base, StringValuePtr(key_str), ckey->iov_len );
|
127
127
|
}
|
128
128
|
|
129
129
|
|
@@ -135,30 +135,12 @@ rmdbx_key_for( VALUE key, MDBX_val *ckey )
|
|
135
135
|
void
|
136
136
|
rmdbx_val_for( VALUE self, VALUE val, MDBX_val *data )
|
137
137
|
{
|
138
|
-
|
139
|
-
|
140
|
-
if ( ! NIL_P( serialize_proc ) )
|
141
|
-
val = rb_funcall( serialize_proc, rb_intern("call"), 1, val );
|
142
|
-
|
138
|
+
val = rb_funcall( self, rb_intern("serialize"), 1, val );
|
143
139
|
Check_Type( val, T_STRING );
|
144
140
|
|
145
141
|
data->iov_len = RSTRING_LEN( val );
|
146
142
|
data->iov_base = malloc( data->iov_len );
|
147
|
-
|
148
|
-
}
|
149
|
-
|
150
|
-
|
151
|
-
/*
|
152
|
-
* Deserialize and return a value.
|
153
|
-
*/
|
154
|
-
VALUE
|
155
|
-
rmdbx_deserialize( VALUE self, VALUE val )
|
156
|
-
{
|
157
|
-
VALUE deserialize_proc = rb_iv_get( self, "@deserializer" );
|
158
|
-
if ( ! NIL_P( deserialize_proc ) )
|
159
|
-
val = rb_funcall( deserialize_proc, rb_intern("call"), 1, val );
|
160
|
-
|
161
|
-
return val;
|
143
|
+
memcpy( data->iov_base, StringValuePtr(val), data->iov_len );
|
162
144
|
}
|
163
145
|
|
164
146
|
|
@@ -355,7 +337,7 @@ rmdbx_get_val( VALUE self, VALUE key )
|
|
355
337
|
switch ( rc ) {
|
356
338
|
case MDBX_SUCCESS:
|
357
339
|
rv = rb_str_new( data.iov_base, data.iov_len );
|
358
|
-
return
|
340
|
+
return rb_funcall( self, rb_intern("deserialize"), 1, rv );
|
359
341
|
|
360
342
|
case MDBX_NOTFOUND:
|
361
343
|
return Qnil;
|
@@ -439,13 +421,17 @@ rmdbx_set_subdb( VALUE self, VALUE name )
|
|
439
421
|
if ( db->txn )
|
440
422
|
rb_raise( rmdbx_eDatabaseError, "Unable to change collection: transaction open" );
|
441
423
|
|
442
|
-
xfree( db->subdb );
|
424
|
+
xfree( db->subdb );
|
443
425
|
db->subdb = NULL;
|
444
426
|
|
445
427
|
if ( ! NIL_P(name) ) {
|
446
428
|
size_t len = RSTRING_LEN( name ) + 1;
|
447
429
|
db->subdb = malloc( len );
|
448
430
|
strlcpy( db->subdb, StringValuePtr(name), len );
|
431
|
+
rmdbx_log_obj( self, "debug", "setting subdb: %s", RSTRING_PTR(name) );
|
432
|
+
}
|
433
|
+
else {
|
434
|
+
rmdbx_log_obj( self, "debug", "clearing subdb" );
|
449
435
|
}
|
450
436
|
|
451
437
|
/* Reset the db handle and issue a single transaction to reify
|
@@ -644,11 +630,11 @@ rmdbx_each_value_i( VALUE self )
|
|
644
630
|
|
645
631
|
if ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_FIRST ) == MDBX_SUCCESS ) {
|
646
632
|
VALUE rv = rb_str_new( data.iov_base, data.iov_len );
|
647
|
-
rb_yield(
|
633
|
+
rb_yield( rb_funcall( self, rb_intern("deserialize"), 1, rv ) );
|
648
634
|
|
649
635
|
while ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_NEXT ) == MDBX_SUCCESS ) {
|
650
636
|
rv = rb_str_new( data.iov_base, data.iov_len );
|
651
|
-
rb_yield(
|
637
|
+
rb_yield( rb_funcall( self, rb_intern("deserialize"), 1, rv ) );
|
652
638
|
}
|
653
639
|
}
|
654
640
|
|
@@ -694,12 +680,15 @@ rmdbx_each_pair_i( VALUE self )
|
|
694
680
|
if ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_FIRST ) == MDBX_SUCCESS ) {
|
695
681
|
VALUE rkey = rb_str_new( key.iov_base, key.iov_len );
|
696
682
|
VALUE rval = rb_str_new( data.iov_base, data.iov_len );
|
697
|
-
|
683
|
+
rval = rb_funcall( self, rb_intern("deserialize"), 1, rval );
|
684
|
+
rb_yield( rb_assoc_new( rkey, rval ) );
|
698
685
|
|
699
686
|
while ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_NEXT ) == MDBX_SUCCESS ) {
|
700
687
|
rkey = rb_str_new( key.iov_base, key.iov_len );
|
701
688
|
rval = rb_str_new( data.iov_base, data.iov_len );
|
702
|
-
|
689
|
+
rval = rb_funcall( self, rb_intern("deserialize"), 1, rval );
|
690
|
+
|
691
|
+
rb_yield( rb_assoc_new( rkey, rval ) );
|
703
692
|
}
|
704
693
|
}
|
705
694
|
|
data/ext/mdbx_ext/mdbx_ext.c
CHANGED
@@ -6,6 +6,60 @@ VALUE rmdbx_mMDBX;
|
|
6
6
|
VALUE rmdbx_eDatabaseError;
|
7
7
|
VALUE rmdbx_eRollback;
|
8
8
|
|
9
|
+
/*
|
10
|
+
* Log a message to the given +context+ object's logger.
|
11
|
+
*/
|
12
|
+
void
|
13
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
14
|
+
rmdbx_log_obj( VALUE context, const char *level, const char *fmt, ... )
|
15
|
+
#else
|
16
|
+
rmdbx_log_obj( VALUE context, const char *level, const char *fmt, va_dcl )
|
17
|
+
#endif
|
18
|
+
{
|
19
|
+
char buf[BUFSIZ];
|
20
|
+
va_list args;
|
21
|
+
VALUE logger = Qnil;
|
22
|
+
VALUE message = Qnil;
|
23
|
+
|
24
|
+
va_init_list( args, fmt );
|
25
|
+
vsnprintf( buf, BUFSIZ, fmt, args );
|
26
|
+
message = rb_str_new2( buf );
|
27
|
+
|
28
|
+
logger = rb_funcall( context, rb_intern("log"), 0 );
|
29
|
+
rb_funcall( logger, rb_intern(level), 1, message );
|
30
|
+
|
31
|
+
va_end( args );
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
/*
|
36
|
+
* Log a message to the global logger.
|
37
|
+
*/
|
38
|
+
void
|
39
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
40
|
+
rmdbx_log( const char *level, const char *fmt, ... )
|
41
|
+
#else
|
42
|
+
rmdbx_log( const char *level, const char *fmt, va_dcl )
|
43
|
+
#endif
|
44
|
+
{
|
45
|
+
char buf[BUFSIZ];
|
46
|
+
va_list args;
|
47
|
+
VALUE logger = Qnil;
|
48
|
+
VALUE message = Qnil;
|
49
|
+
|
50
|
+
va_init_list( args, fmt );
|
51
|
+
vsnprintf( buf, BUFSIZ, fmt, args );
|
52
|
+
message = rb_str_new2( buf );
|
53
|
+
|
54
|
+
logger = rb_funcall( rmdbx_mMDBX, rb_intern("logger"), 0 );
|
55
|
+
rb_funcall( logger, rb_intern(level), 1, message );
|
56
|
+
|
57
|
+
va_end( args );
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
9
63
|
/*
|
10
64
|
* MDBX initialization
|
11
65
|
*/
|
data/ext/mdbx_ext/mdbx_ext.h
CHANGED
@@ -54,6 +54,22 @@ typedef struct rmdbx_db rmdbx_db_t;
|
|
54
54
|
static const rb_data_type_t rmdbx_db_data;
|
55
55
|
|
56
56
|
|
57
|
+
/* ------------------------------------------------------------
|
58
|
+
* Logging
|
59
|
+
* ------------------------------------------------------------ */
|
60
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
61
|
+
#include <stdarg.h>
|
62
|
+
#define va_init_list(a,b) va_start(a,b)
|
63
|
+
void rmdbx_log_obj( VALUE, const char *, const char *, ... );
|
64
|
+
void rmdbx_log( const char *, const char *, ... );
|
65
|
+
#else
|
66
|
+
#include <varargs.h>
|
67
|
+
#define va_init_list(a,b) va_start(a)
|
68
|
+
void rmdbx_log_obj( VALUE, const char *, const char *, va_dcl );
|
69
|
+
void rmdbx_log( const char *, const char *, va_dcl );
|
70
|
+
#endif
|
71
|
+
|
72
|
+
|
57
73
|
/* ------------------------------------------------------------
|
58
74
|
* Globals
|
59
75
|
* ------------------------------------------------------------ */
|
data/lib/mdbx/database.rb
CHANGED
@@ -8,6 +8,9 @@ require 'mdbx' unless defined?( MDBX )
|
|
8
8
|
# The primary class for interacting with an MDBX database.
|
9
9
|
#
|
10
10
|
class MDBX::Database
|
11
|
+
extend Loggability
|
12
|
+
|
13
|
+
log_to :mdbx
|
11
14
|
|
12
15
|
### call-seq:
|
13
16
|
### MDBX::Database.open( path ) => db
|
@@ -361,6 +364,34 @@ class MDBX::Database
|
|
361
364
|
protected
|
362
365
|
#########
|
363
366
|
|
367
|
+
|
368
|
+
### Safely serialize a value, closing any open transaction and re-raising
|
369
|
+
### if necessary.
|
370
|
+
###
|
371
|
+
def serialize( val )
|
372
|
+
return val unless self.serializer
|
373
|
+
return self.serializer.call( val )
|
374
|
+
|
375
|
+
rescue => err
|
376
|
+
self.close_transaction( false )
|
377
|
+
raise err
|
378
|
+
end
|
379
|
+
|
380
|
+
|
381
|
+
### Safely deserialize a value, closing any open transaction and re-raising
|
382
|
+
### if necessary.
|
383
|
+
###
|
384
|
+
def deserialize( val )
|
385
|
+
return val unless self.deserializer
|
386
|
+
return self.deserializer.call( val )
|
387
|
+
|
388
|
+
rescue => err
|
389
|
+
self.close_transaction( false )
|
390
|
+
raise err
|
391
|
+
end
|
392
|
+
|
393
|
+
|
394
|
+
|
364
395
|
### Yield and return the block, opening a snapshot first if
|
365
396
|
### there isn't already a transaction in progress. Closes
|
366
397
|
### the snapshot if this method opened it.
|
data/lib/mdbx.rb
CHANGED
@@ -2,15 +2,22 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4 ft=ruby:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
+
require 'loggability'
|
6
|
+
|
5
7
|
require 'mdbx_ext'
|
6
8
|
|
7
9
|
|
8
10
|
# Top level namespace for MDBX.
|
9
11
|
#
|
10
12
|
module MDBX
|
13
|
+
extend Loggability
|
11
14
|
|
12
15
|
# The version of this gem.
|
13
|
-
VERSION = '0.3.
|
16
|
+
VERSION = '0.3.3'
|
17
|
+
|
18
|
+
|
19
|
+
log_as :mdbx
|
20
|
+
|
14
21
|
|
15
22
|
end # module MDBX
|
16
23
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdbx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mahlon E. Smith
|
@@ -34,8 +34,22 @@ cert_chain:
|
|
34
34
|
49pOzX5KHZLTS9DKeaP/xcGPz6C8MiwQdYrZarr2SHRASX1zFa79rkItO8kE6RDr
|
35
35
|
b6WDF79UvZ55ajtE00TiwqjQL/ZPEtbd
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2021-
|
37
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: loggability
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - "~>"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.17'
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.17'
|
39
53
|
- !ruby/object:Gem::Dependency
|
40
54
|
name: pry
|
41
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
229
|
- !ruby/object:Gem::Version
|
216
230
|
version: '0'
|
217
231
|
requirements: []
|
218
|
-
rubygems_version: 3.
|
232
|
+
rubygems_version: 3.1.4
|
219
233
|
signing_key:
|
220
234
|
specification_version: 4
|
221
235
|
summary: A ruby binding to libmdbx, an improved version of the Lightning Memory Mapped
|
metadata.gz.sig
CHANGED
Binary file
|