Checkpoint work trying to make transactions thread safe.

FossilOrigin-Name: 3d7c96d03c58839bc6402ca0c69f8405edbdfde24c2cefdf8caa2bfdc8136625
This commit is contained in:
Mahlon E. Smith 2025-04-30 23:51:45 +00:00
parent 39f472cd10
commit 48e2184570
2 changed files with 38 additions and 1 deletions

View file

@ -465,6 +465,32 @@ rmdbx_in_transaction_p( VALUE self )
} }
struct txn_open_args_s {
rmdbx_db_t *db;
int rwflag;
};
/* Opens a transaction outside of th GVL. */
void *
rmdbx_open_txn_without_gvl( void *ptr )
{
// struct query_call *qcall = (struct query_call *)ptr;
struct txn_open_args_s *txn_open_args = (struct txn_open_args_s *)ptr;
rmdbx_db_t *db = txn_open_args->db;
int rc = mdbx_txn_begin(
db->env,
NULL,
txn_open_args->rwflag,
&db->txn
);
return (void *)rc;
}
/* /*
* Open a new database transaction. If a transaction is already * Open a new database transaction. If a transaction is already
* open, this is a no-op. * open, this is a no-op.
@ -476,7 +502,17 @@ rmdbx_open_txn( rmdbx_db_t *db, int rwflag )
{ {
if ( db->txn ) return; if ( db->txn ) return;
int rc = mdbx_txn_begin( db->env, NULL, rwflag, &db->txn ); struct txn_open_args_s txn_open_args;
txn_open_args.db = db;
txn_open_args.rwflag = rwflag;
void *result_ptr = rb_thread_call_without_gvl(
rmdbx_open_txn_without_gvl, (void *)&txn_open_args,
NULL, NULL
);
int rc = (int)result_ptr;
if ( rc != MDBX_SUCCESS ) { if ( rc != MDBX_SUCCESS ) {
rmdbx_close_all( db ); rmdbx_close_all( db );
rb_raise( rmdbx_eDatabaseError, "mdbx_txn_begin: (%d) %s", rc, mdbx_strerror(rc) ); rb_raise( rmdbx_eDatabaseError, "mdbx_txn_begin: (%d) %s", rc, mdbx_strerror(rc) );

View file

@ -3,6 +3,7 @@
#include "extconf.h" #include "extconf.h"
#include "mdbx.h" #include "mdbx.h"
#include "ruby/thread.h"
#ifndef RBMDBX_EXT #ifndef RBMDBX_EXT
#define RBMDBX_EXT #define RBMDBX_EXT