From 7fc1ebb408ae627f139cdabbbc5403b038e7a0e8 Mon Sep 17 00:00:00 2001 From: mahlon Date: Mon, 25 Mar 2024 01:58:15 +0000 Subject: [PATCH] Updates to support libmdbx 0.12.x. Also, close some hanging open transactions in some error states. FossilOrigin-Name: 9582fff0788d3f78e9b33f292a2c48afeac32587c89496a5a7d5e97a98085683 --- .solargraph.yml | 22 ++++++++++++++++++++++ README.md | 2 +- ext/mdbx_ext/database.c | 22 +++++++++++++++++++--- ext/mdbx_ext/mdbx_ext.c | 2 -- 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 .solargraph.yml diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..a8ef410 --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,22 @@ +--- +include: +- "**/*.rb" +exclude: +- spec/**/* +- test/**/* +- vendor/**/* +- ".bundle/**/*" +require: [] +domains: [] +reporters: +- rubocop +- require_not_found +formatter: + rubocop: + cops: safe + except: [] + only: [] + extra_args: [] +require_paths: [] +plugins: [] +max_files: 5000 diff --git a/README.md b/README.md index 2cbbcae..a050cd5 100644 --- a/README.md +++ b/README.md @@ -423,7 +423,7 @@ development. ## Reporting Issues Tests are performed against the latest stable MRI Ruby, and I endeavor to test -against the latest stable libmdbx (as of this writing, the 0.11.x versioning), +against the latest stable libmdbx (as of this writing, the 0.12.x versioning), on both x86 and ARM chipsets. Things may work for you in other environments - I'm just not matrix testing diff --git a/ext/mdbx_ext/database.c b/ext/mdbx_ext/database.c index 980eaa9..126d262 100644 --- a/ext/mdbx_ext/database.c +++ b/ext/mdbx_ext/database.c @@ -168,6 +168,12 @@ rmdbx_open_env( VALUE self ) rb_raise( rmdbx_eDatabaseError, "mdbx_env_open: (%d) %s", rc, mdbx_strerror(rc) ); } + /* Force populate the db->dbi handle. Under 0.12.x, getting a + * 'permission denied' doing this for the first access with a RDONLY + * for some reason. */ + rmdbx_open_txn( db, MDBX_TXN_READWRITE ); + rmdbx_close_txn( db, RMDBX_TXN_ROLLBACK ); + db->state.open = 1; return Qtrue; } @@ -189,8 +195,10 @@ rmdbx_clear( VALUE self ) rmdbx_open_txn( db, MDBX_TXN_READWRITE ); int rc = mdbx_drop( db->txn, db->dbi, false ); - if ( rc != MDBX_SUCCESS ) + if ( rc != MDBX_SUCCESS ) { + rmdbx_close_txn( db, RMDBX_TXN_ROLLBACK ); rb_raise( rmdbx_eDatabaseError, "mdbx_drop: (%d) %s", rc, mdbx_strerror(rc) ); + } rmdbx_close_txn( db, RMDBX_TXN_COMMIT ); @@ -229,8 +237,10 @@ rmdbx_drop( VALUE self, VALUE name ) rmdbx_open_txn( db, MDBX_TXN_READWRITE ); int rc = mdbx_drop( db->txn, db->dbi, true ); - if ( rc != MDBX_SUCCESS ) + if ( rc != MDBX_SUCCESS ) { + rmdbx_close_txn( db, RMDBX_TXN_ROLLBACK ); rb_raise( rmdbx_eDatabaseError, "mdbx_drop: (%d) %s", rc, mdbx_strerror(rc) ); + } rmdbx_close_txn( db, RMDBX_TXN_COMMIT ); @@ -238,6 +248,12 @@ rmdbx_drop( VALUE self, VALUE name ) db->subdb = NULL; rmdbx_close_dbi( db ); /* ensure next access is not in the defunct subdb */ + /* Force populate the new db->dbi handle. Under 0.12.x, getting a + * 'permission denied' doing this for the first access with a RDONLY + * for some reason. */ + rmdbx_open_txn( db, MDBX_TXN_READWRITE ); + rmdbx_close_txn( db, RMDBX_TXN_ROLLBACK ); + return self; } @@ -830,7 +846,7 @@ rmdbx_stats( VALUE self ) * db.clone => [copy of db] * * Copy the object (clone/dup). The returned copy is closed and needs - * to be reopened before use. This function likely has limited use, + * to be reopened before use. This function likely has limited use, * considering you can't open two handles within the same process. */ static VALUE rmdbx_init_copy( VALUE copy, VALUE orig ) diff --git a/ext/mdbx_ext/mdbx_ext.c b/ext/mdbx_ext/mdbx_ext.c index 8bd7eeb..fbf8d8a 100644 --- a/ext/mdbx_ext/mdbx_ext.c +++ b/ext/mdbx_ext/mdbx_ext.c @@ -58,8 +58,6 @@ rmdbx_log( const char *level, const char *fmt, va_dcl ) } - - /* * MDBX initialization */