2020-11-19 02:06:45 +00:00
|
|
|
|
|
|
|
|
#include <ruby.h>
|
|
|
|
|
#include "extconf.h"
|
|
|
|
|
|
|
|
|
|
#include "mdbx.h"
|
|
|
|
|
|
2021-06-28 23:39:46 +00:00
|
|
|
#ifndef RBMDBX_EXT
|
|
|
|
|
#define RBMDBX_EXT
|
2020-11-30 05:57:26 +00:00
|
|
|
|
2020-12-23 01:10:19 +00:00
|
|
|
#define RMDBX_TXN_ROLLBACK 0
|
|
|
|
|
#define RMDBX_TXN_COMMIT 1
|
|
|
|
|
|
2021-06-28 23:39:46 +00:00
|
|
|
/* Shortcut for fetching wrapped data structure.
|
|
|
|
|
*/
|
|
|
|
|
#define UNWRAP_DB( self, db ) \
|
|
|
|
|
rmdbx_db_t *db; \
|
|
|
|
|
TypedData_Get_Struct( self, rmdbx_db_t, &rmdbx_db_data, db )
|
|
|
|
|
|
|
|
|
|
/* Raise if current DB is not open. */
|
|
|
|
|
#define CHECK_HANDLE() \
|
|
|
|
|
if ( ! db->state.open ) rb_raise( rmdbx_eDatabaseError, "Closed database." )
|
|
|
|
|
|
|
|
|
|
|
2020-12-23 01:10:19 +00:00
|
|
|
/*
|
|
|
|
|
* A struct encapsulating an instance's DB
|
|
|
|
|
* state and settings.
|
|
|
|
|
*/
|
|
|
|
|
struct rmdbx_db {
|
|
|
|
|
MDBX_env *env;
|
|
|
|
|
MDBX_dbi dbi;
|
|
|
|
|
MDBX_txn *txn;
|
|
|
|
|
MDBX_cursor *cursor;
|
|
|
|
|
|
|
|
|
|
struct {
|
2021-06-28 23:39:46 +00:00
|
|
|
unsigned int env_flags;
|
|
|
|
|
unsigned int db_flags;
|
2020-12-23 01:10:19 +00:00
|
|
|
int mode;
|
|
|
|
|
int open;
|
|
|
|
|
int max_collections;
|
|
|
|
|
int max_readers;
|
|
|
|
|
uint64_t max_size;
|
|
|
|
|
} settings;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
int open;
|
2021-01-25 00:36:40 +00:00
|
|
|
int retain_txn;
|
2020-12-23 01:10:19 +00:00
|
|
|
} state;
|
|
|
|
|
|
|
|
|
|
char *path;
|
|
|
|
|
char *subdb;
|
|
|
|
|
};
|
|
|
|
|
typedef struct rmdbx_db rmdbx_db_t;
|
|
|
|
|
|
|
|
|
|
static const rb_data_type_t rmdbx_db_data;
|
2021-06-28 23:39:46 +00:00
|
|
|
|
2020-11-30 05:57:26 +00:00
|
|
|
|
2021-10-06 17:25:50 +00:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
|
* Logging
|
|
|
|
|
* ------------------------------------------------------------ */
|
|
|
|
|
#ifdef HAVE_STDARG_PROTOTYPES
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#define va_init_list(a,b) va_start(a,b)
|
|
|
|
|
void rmdbx_log_obj( VALUE, const char *, const char *, ... );
|
|
|
|
|
void rmdbx_log( const char *, const char *, ... );
|
|
|
|
|
#else
|
|
|
|
|
#include <varargs.h>
|
|
|
|
|
#define va_init_list(a,b) va_start(a)
|
|
|
|
|
void rmdbx_log_obj( VALUE, const char *, const char *, va_dcl );
|
|
|
|
|
void rmdbx_log( const char *, const char *, va_dcl );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2020-11-30 05:57:26 +00:00
|
|
|
/* ------------------------------------------------------------
|
|
|
|
|
* Globals
|
|
|
|
|
* ------------------------------------------------------------ */
|
2020-12-04 19:07:34 +00:00
|
|
|
extern VALUE rmdbx_mMDBX;
|
|
|
|
|
extern VALUE rmdbx_cDatabase;
|
|
|
|
|
extern VALUE rmdbx_eDatabaseError;
|
2020-12-22 06:24:18 +00:00
|
|
|
extern VALUE rmdbx_eRollback;
|
2020-11-30 05:57:26 +00:00
|
|
|
|
2020-11-19 02:06:45 +00:00
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------
|
2020-11-30 05:57:26 +00:00
|
|
|
* Functions
|
|
|
|
|
* ------------------------------------------------------------ */
|
2021-06-28 23:39:46 +00:00
|
|
|
extern void rmdbx_free( void *db ); /* forward declaration for the allocator */
|
2020-11-30 05:57:26 +00:00
|
|
|
extern void Init_rmdbx ( void );
|
|
|
|
|
extern void rmdbx_init_database ( void );
|
2021-06-28 23:39:46 +00:00
|
|
|
extern void rmdbx_close_all( rmdbx_db_t* );
|
2020-12-23 01:10:19 +00:00
|
|
|
extern void rmdbx_open_txn( rmdbx_db_t*, int );
|
|
|
|
|
extern void rmdbx_close_txn( rmdbx_db_t*, int );
|
2021-06-28 23:39:46 +00:00
|
|
|
extern void rmdbx_open_cursor( rmdbx_db_t* );
|
2020-12-23 01:10:19 +00:00
|
|
|
extern VALUE rmdbx_gather_stats( rmdbx_db_t* );
|
2020-11-30 05:57:26 +00:00
|
|
|
|
2020-11-19 02:06:45 +00:00
|
|
|
|
2021-06-28 23:39:46 +00:00
|
|
|
#endif /* define RBMDBX_EXT */
|
2020-11-19 02:06:45 +00:00
|
|
|
|