mdbx 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 678369c278e65d4faf56eb814e2cb7eba22da57fb5c07c6e4f9dc4e6edd7f09f
4
- data.tar.gz: 0fc4b455b4556bb932f867fa40e7c240f555a5a6bbb7d09cb55c68ed7745bfd0
3
+ metadata.gz: a6ce9c7c96bb8e8857f7a6150df3ded621f5eca3d40848f52999fbe8192f72de
4
+ data.tar.gz: 8445320bae46524ae7dac00dfb9b1bc6d38c9401607a5d2d983380fa73c8d2b4
5
5
  SHA512:
6
- metadata.gz: b9844be65fc6e46df8dbaee242ce9bf185c4330559d2a5d8c803eca43f4d09a783276c3d2a20258ef84be099a133031acf0f0b36ff0c2af1f69d0882a0dd4335
7
- data.tar.gz: 22fd3c418db16d2a58100ad6bd8f3ae7b7ddce2172075713a798065440e59f6a2fd4cea47bd37d3585781dbeaebc0421f483e20375a5e652fe3a81ee76e0da2f
6
+ metadata.gz: 0d062355ba32667ac5f4f1d2e6a26a977823d2b0cf841d2f0131509bd2b96f7e36eeb981e96c343a3d960ba77f23996a57f0d1dad4210c99cce9cf870d7a36ee
7
+ data.tar.gz: 2e517e62946e3005da7d5e20190c5362106253fb925c1bd97e15fc4d7fdf5a0e7c536553babb5ef9b704043f7646dbc1dc46873d9939dd85c64a665562fe0de5
checksums.yaml.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Release History for MDBX
2
2
 
3
+ ---
4
+ ## v0.3.4 [2022-12-21] Mahlon E. Smith <mahlon@martini.nu>
5
+
6
+ Bugfixes:
7
+
8
+ - Don't use mdbx_replace() when not using the original value(s)
9
+
10
+
11
+ ---
12
+ ## v0.3.3 [2021-10-22] Mahlon E. Smith <mahlon@martini.nu>
13
+
14
+ Bugfixes:
15
+
16
+ - Close any open transactions if serialization functions fail.
17
+ - Don't use functions that assume NUL is the stream terminator.
18
+
19
+
20
+ Enhancements:
21
+
22
+ - Add Loggability for debug output.
23
+
24
+
3
25
  ---
4
26
  ## v0.3.2 [2021-07-13] Mahlon E. Smith <mahlon@martini.nu>
5
27
 
data/README.md CHANGED
@@ -2,22 +2,13 @@
2
2
  # Ruby::MDBX
3
3
 
4
4
  home
5
- : https://code.martini.nu/ruby-mdbx
6
-
7
- code
8
- : https://code.martini.nu/ruby-mdbx
5
+ : https://code.martini.nu/fossil/ruby-mdbx
9
6
 
10
7
  docs
11
8
  : https://martini.nu/docs/ruby-mdbx
12
9
 
13
- github
14
- : https://github.com/mahlon/ruby-mdbx
15
-
16
- gitlab
17
- : https://gitlab.com/mahlon/ruby-mdbx
18
-
19
- sourcehut:
20
- : https://hg.sr.ht/~mahlon/ruby-mdbx
10
+ github mirror
11
+ : https://github.com/mahlonsmith/ruby-mdbx
21
12
 
22
13
 
23
14
  ## Description
@@ -30,13 +21,13 @@ of properties and capabilities, focused on creating unique lightweight
30
21
  solutions.
31
22
 
32
23
  For more information about libmdbx (features, limitations, etc), see the
33
- [introduction](https://erthink.github.io/libmdbx/intro.html).
24
+ [introduction](https://libmdbx.dqdkfa.ru).
34
25
 
35
26
 
36
27
  ## Prerequisites
37
28
 
38
29
  * Ruby 2.6+
39
- * [libmdbx](https://github.com/erthink/libmdbx)
30
+ * [libmdbx](https://gitflic.ru/project/erthink/libmdbx)
40
31
 
41
32
 
42
33
  ## Installation
@@ -342,8 +333,8 @@ the currently connected clients.
342
333
 
343
334
  ## Contributing
344
335
 
345
- You can check out the current development source with Mercurial via its
346
- [home repo](https://code.martini.nu/ruby-mdbx), or with Git at its
336
+ You can check out the current development source with Fossil via its
337
+ [home repo](https://code.martini.nu/fossil/ruby-mdbx), or with Git at its
347
338
  [project mirror](https://gitlab.com/mahlon/ruby-mdbx).
348
339
 
349
340
  After checking out the source, run:
@@ -362,7 +353,7 @@ development.
362
353
 
363
354
  ## License
364
355
 
365
- Copyright (c) 2020-2021 Mahlon E. Smith
356
+ Copyright (c) 2020-2022 Mahlon E. Smith
366
357
  All rights reserved.
367
358
 
368
359
  Redistribution and use in source and binary forms, with or without
@@ -101,16 +101,6 @@ rmdbx_closed_p( VALUE self )
101
101
  }
102
102
 
103
103
 
104
- /*
105
- * Check if a given +flag+ is enabled for flag +val+.
106
- */
107
- int
108
- rmdbx_flag_enabled( val, flag )
109
- {
110
- return ( val & flag ) == flag;
111
- }
112
-
113
-
114
104
  /*
115
105
  * Given a ruby string +key+ and a pointer to an MDBX_val, prepare the
116
106
  * key for usage within mdbx. All keys are explicitly converted to
@@ -123,7 +113,7 @@ rmdbx_key_for( VALUE key, MDBX_val *ckey )
123
113
  VALUE key_str = rb_funcall( key, rb_intern("to_s"), 0 );
124
114
  ckey->iov_len = RSTRING_LEN( key_str );
125
115
  ckey->iov_base = malloc( ckey->iov_len );
126
- strlcpy( ckey->iov_base, StringValuePtr(key_str), ckey->iov_len + 1 );
116
+ memcpy( ckey->iov_base, StringValuePtr(key_str), ckey->iov_len );
127
117
  }
128
118
 
129
119
 
@@ -135,30 +125,12 @@ rmdbx_key_for( VALUE key, MDBX_val *ckey )
135
125
  void
136
126
  rmdbx_val_for( VALUE self, VALUE val, MDBX_val *data )
137
127
  {
138
- VALUE serialize_proc = rb_iv_get( self, "@serializer" );
139
-
140
- if ( ! NIL_P( serialize_proc ) )
141
- val = rb_funcall( serialize_proc, rb_intern("call"), 1, val );
142
-
128
+ val = rb_funcall( self, rb_intern("serialize"), 1, val );
143
129
  Check_Type( val, T_STRING );
144
130
 
145
131
  data->iov_len = RSTRING_LEN( val );
146
132
  data->iov_base = malloc( data->iov_len );
147
- strlcpy( data->iov_base, StringValuePtr(val), data->iov_len + 1 );
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;
133
+ memcpy( data->iov_base, StringValuePtr(val), data->iov_len );
162
134
  }
163
135
 
164
136
 
@@ -355,7 +327,7 @@ rmdbx_get_val( VALUE self, VALUE key )
355
327
  switch ( rc ) {
356
328
  case MDBX_SUCCESS:
357
329
  rv = rb_str_new( data.iov_base, data.iov_len );
358
- return rmdbx_deserialize( self, rv );
330
+ return rb_funcall( self, rb_intern("deserialize"), 1, rv );
359
331
 
360
332
  case MDBX_NOTFOUND:
361
333
  return Qnil;
@@ -389,10 +361,9 @@ rmdbx_put_val( VALUE self, VALUE key, VALUE val )
389
361
  rc = mdbx_del( db->txn, db->dbi, &ckey, NULL );
390
362
  }
391
363
  else {
392
- MDBX_val old;
393
364
  MDBX_val data;
394
365
  rmdbx_val_for( self, val, &data );
395
- rc = mdbx_replace( db->txn, db->dbi, &ckey, &data, &old, 0 );
366
+ rc = mdbx_put( db->txn, db->dbi, &ckey, &data, 0 );
396
367
  xfree( data.iov_base );
397
368
  }
398
369
 
@@ -439,13 +410,17 @@ rmdbx_set_subdb( VALUE self, VALUE name )
439
410
  if ( db->txn )
440
411
  rb_raise( rmdbx_eDatabaseError, "Unable to change collection: transaction open" );
441
412
 
442
- xfree( db->subdb );
413
+ xfree( db->subdb );
443
414
  db->subdb = NULL;
444
415
 
445
416
  if ( ! NIL_P(name) ) {
446
417
  size_t len = RSTRING_LEN( name ) + 1;
447
418
  db->subdb = malloc( len );
448
419
  strlcpy( db->subdb, StringValuePtr(name), len );
420
+ rmdbx_log_obj( self, "debug", "setting subdb: %s", RSTRING_PTR(name) );
421
+ }
422
+ else {
423
+ rmdbx_log_obj( self, "debug", "clearing subdb" );
449
424
  }
450
425
 
451
426
  /* Reset the db handle and issue a single transaction to reify
@@ -644,11 +619,11 @@ rmdbx_each_value_i( VALUE self )
644
619
 
645
620
  if ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_FIRST ) == MDBX_SUCCESS ) {
646
621
  VALUE rv = rb_str_new( data.iov_base, data.iov_len );
647
- rb_yield( rmdbx_deserialize( self, rv ) );
622
+ rb_yield( rb_funcall( self, rb_intern("deserialize"), 1, rv ) );
648
623
 
649
624
  while ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_NEXT ) == MDBX_SUCCESS ) {
650
625
  rv = rb_str_new( data.iov_base, data.iov_len );
651
- rb_yield( rmdbx_deserialize( self, rv ) );
626
+ rb_yield( rb_funcall( self, rb_intern("deserialize"), 1, rv ) );
652
627
  }
653
628
  }
654
629
 
@@ -694,12 +669,15 @@ rmdbx_each_pair_i( VALUE self )
694
669
  if ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_FIRST ) == MDBX_SUCCESS ) {
695
670
  VALUE rkey = rb_str_new( key.iov_base, key.iov_len );
696
671
  VALUE rval = rb_str_new( data.iov_base, data.iov_len );
697
- rb_yield( rb_assoc_new( rkey, rmdbx_deserialize( self, rval ) ) );
672
+ rval = rb_funcall( self, rb_intern("deserialize"), 1, rval );
673
+ rb_yield( rb_assoc_new( rkey, rval ) );
698
674
 
699
675
  while ( mdbx_cursor_get( db->cursor, &key, &data, MDBX_NEXT ) == MDBX_SUCCESS ) {
700
676
  rkey = rb_str_new( key.iov_base, key.iov_len );
701
677
  rval = rb_str_new( data.iov_base, data.iov_len );
702
- rb_yield( rb_assoc_new( rkey, rmdbx_deserialize( self, rval ) ) );
678
+ rval = rb_funcall( self, rb_intern("deserialize"), 1, rval );
679
+
680
+ rb_yield( rb_assoc_new( rkey, rval ) );
703
681
  }
704
682
  }
705
683
 
@@ -881,7 +859,7 @@ static VALUE rmdbx_init_copy( VALUE copy, VALUE orig )
881
859
  void
882
860
  rmdbx_init_database()
883
861
  {
884
- rmdbx_cDatabase = rb_define_class_under( rmdbx_mMDBX, "Database", rb_cData );
862
+ rmdbx_cDatabase = rb_define_class_under( rmdbx_mMDBX, "Database", rb_cObject );
885
863
 
886
864
  #ifdef FOR_RDOC
887
865
  rmdbx_mMDBX = rb_define_module( "MDBX" );
@@ -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
  */
@@ -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
@@ -82,7 +85,7 @@ class MDBX::Database
82
85
  ###
83
86
  ### [:no_threadlocal]
84
87
  ### Parallelize read-only transactions across threads. Writes are
85
- ### always thread local. (See MDBX documentatoin for details.)
88
+ ### always thread local. (See MDBX documentation for details.)
86
89
  ###
87
90
  ### [:readonly]
88
91
  ### Reject any write attempts while using this database handle.
@@ -361,6 +364,32 @@ class MDBX::Database
361
364
  protected
362
365
  #########
363
366
 
367
+ ### Safely serialize a value, closing any open transaction and re-raising
368
+ ### if necessary.
369
+ ###
370
+ def serialize( val )
371
+ return val unless self.serializer
372
+ return self.serializer.call( val )
373
+
374
+ rescue => err
375
+ self.close_transaction( false )
376
+ raise err
377
+ end
378
+
379
+
380
+ ### Safely deserialize a value, closing any open transaction and re-raising
381
+ ### if necessary.
382
+ ###
383
+ def deserialize( val )
384
+ return val unless self.deserializer
385
+ return self.deserializer.call( val )
386
+
387
+ rescue => err
388
+ self.close_transaction( false )
389
+ raise err
390
+ end
391
+
392
+
364
393
  ### Yield and return the block, opening a snapshot first if
365
394
  ### there isn't already a transaction in progress. Closes
366
395
  ### 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.2'
16
+ VERSION = '0.3.4'
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.2
4
+ version: 0.3.4
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-07-13 00:00:00.000000000 Z
37
+ date: 2022-12-21 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
@@ -192,14 +206,13 @@ files:
192
206
  - ext/mdbx_ext/stats.c
193
207
  - lib/mdbx.rb
194
208
  - lib/mdbx/database.rb
195
- homepage: https://code.martini.nu/ruby-mdbx
209
+ homepage: https://code.martini.nu/fossil/ruby-mdbx
196
210
  licenses:
197
211
  - BSD-3-Clause
198
212
  metadata:
199
- homepage_uri: https://code.martini.nu/ruby-mdbx
213
+ homepage_uri: https://code.martini.nu/fossil/ruby-mdbx
200
214
  documentation_uri: https://martini.nu/docs/ruby-mdbx
201
215
  changelog_uri: https://martini.nu/docs/ruby-mdbx/History_md.html
202
- source_uri: https://code.martini.nu/ruby-mdbx
203
216
  post_install_message:
204
217
  rdoc_options: []
205
218
  require_paths:
@@ -215,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
228
  - !ruby/object:Gem::Version
216
229
  version: '0'
217
230
  requirements: []
218
- rubygems_version: 3.2.11
231
+ rubygems_version: 3.3.7
219
232
  signing_key:
220
233
  specification_version: 4
221
234
  summary: A ruby binding to libmdbx, an improved version of the Lightning Memory Mapped
metadata.gz.sig CHANGED
Binary file