Multiple changes.
- Raise an error if invalid options are passed to the constructor. - Bugfix: Ensure drop() only removes the specified collection. - Fix initializer double memory allocation. - Fix key/data object allocation: make garbage collection safe. - Move common macros to the global header file. FossilOrigin-Name: 98d3016bd25921dead39d9c5474712766b56519d575bc8cd960932b3fbc16b69
This commit is contained in:
parent
b7e515d51e
commit
e9b476a4d7
10 changed files with 605 additions and 517 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -4,12 +4,23 @@
|
|||
|
||||
#include "mdbx.h"
|
||||
|
||||
#ifndef MDBX_EXT_0_9_3
|
||||
#define MDBX_EXT_0_9_3
|
||||
#ifndef RBMDBX_EXT
|
||||
#define RBMDBX_EXT
|
||||
|
||||
#define RMDBX_TXN_ROLLBACK 0
|
||||
#define RMDBX_TXN_COMMIT 1
|
||||
|
||||
/* 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." )
|
||||
|
||||
|
||||
/*
|
||||
* A struct encapsulating an instance's DB
|
||||
* state and settings.
|
||||
|
|
@ -21,7 +32,8 @@ struct rmdbx_db {
|
|||
MDBX_cursor *cursor;
|
||||
|
||||
struct {
|
||||
int env_flags;
|
||||
unsigned int env_flags;
|
||||
unsigned int db_flags;
|
||||
int mode;
|
||||
int open;
|
||||
int max_collections;
|
||||
|
|
@ -40,12 +52,11 @@ struct rmdbx_db {
|
|||
typedef struct rmdbx_db rmdbx_db_t;
|
||||
|
||||
static const rb_data_type_t rmdbx_db_data;
|
||||
extern void rmdbx_free( void *db ); /* forward declaration for the allocator */
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Globals
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
extern VALUE rmdbx_mMDBX;
|
||||
extern VALUE rmdbx_cDatabase;
|
||||
extern VALUE rmdbx_eDatabaseError;
|
||||
|
|
@ -55,13 +66,15 @@ extern VALUE rmdbx_eRollback;
|
|||
/* ------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------ */
|
||||
extern void rmdbx_free( void *db ); /* forward declaration for the allocator */
|
||||
extern void Init_rmdbx ( void );
|
||||
extern void rmdbx_init_database ( void );
|
||||
extern void rmdbx_close_all( rmdbx_db_t* );
|
||||
extern void rmdbx_open_txn( rmdbx_db_t*, int );
|
||||
extern void rmdbx_close_txn( rmdbx_db_t*, int );
|
||||
|
||||
extern void rmdbx_open_cursor( rmdbx_db_t* );
|
||||
extern VALUE rmdbx_gather_stats( rmdbx_db_t* );
|
||||
|
||||
|
||||
#endif /* define MDBX_EXT_0_9_3 */
|
||||
#endif /* define RBMDBX_EXT */
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
* Expose a bunch of mdbx internals to ruby.
|
||||
* This is all largely stolen from mdbx_stat.c.
|
||||
*
|
||||
* Entry point is rmdbx_stats() in database.c.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mdbx_ext.h"
|
||||
|
|
@ -28,6 +26,32 @@ rmdbx_gather_build_stats( VALUE stat )
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Grab current memory usage. (Available since MDBX 0.10.0).
|
||||
*/
|
||||
void
|
||||
rmdbx_gather_memory_stats( VALUE stat )
|
||||
{
|
||||
if (! ( MDBX_VERSION_MAJOR >= 0 && MDBX_VERSION_MINOR >= 10 ) )
|
||||
return;
|
||||
|
||||
VALUE mem = rb_hash_new();
|
||||
rb_hash_aset( stat, ID2SYM(rb_intern("system_memory")), mem );
|
||||
|
||||
intptr_t page_size;
|
||||
intptr_t total_pages;
|
||||
intptr_t avail_pages;
|
||||
|
||||
mdbx_get_sysraminfo( &page_size, &total_pages, &avail_pages );
|
||||
|
||||
rb_hash_aset( mem, ID2SYM(rb_intern("pagesize")), LONG2FIX( page_size ) );
|
||||
rb_hash_aset( mem, ID2SYM(rb_intern("total_pages")), LONG2FIX( total_pages ) );
|
||||
rb_hash_aset( mem, ID2SYM(rb_intern("avail_pages")), LONG2FIX( avail_pages ) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Metadata for the database file.
|
||||
*/
|
||||
|
|
@ -80,6 +104,16 @@ rmdbx_gather_environment_stats(
|
|||
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("pagesize")),
|
||||
INT2NUM(mstat.ms_psize) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("branch_pages")),
|
||||
LONG2NUM(mstat.ms_branch_pages) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("leaf_pages")),
|
||||
LONG2NUM(mstat.ms_leaf_pages) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("overflow_pages")),
|
||||
LONG2NUM(mstat.ms_overflow_pages) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("btree_depth")),
|
||||
INT2NUM(mstat.ms_depth) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("entries")),
|
||||
LONG2NUM(mstat.ms_entries) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("last_txnid")),
|
||||
INT2NUM(menvinfo.mi_recent_txnid) );
|
||||
rb_hash_aset( environ, ID2SYM(rb_intern("last_reader_txnid")),
|
||||
|
|
@ -101,7 +135,7 @@ rmdbx_gather_environment_stats(
|
|||
*
|
||||
*/
|
||||
int
|
||||
reader_list_callback(
|
||||
rmdbx_reader_list_cb(
|
||||
void *ctx,
|
||||
int num,
|
||||
int slot,
|
||||
|
|
@ -148,7 +182,7 @@ rmdbx_gather_reader_stats(
|
|||
{
|
||||
VALUE readers = rb_ary_new();
|
||||
|
||||
mdbx_reader_list( db->env, reader_list_callback, (void*)readers );
|
||||
mdbx_reader_list( db->env, rmdbx_reader_list_cb, (void*)readers );
|
||||
rb_hash_aset( stat, ID2SYM(rb_intern("readers")), readers );
|
||||
|
||||
return;
|
||||
|
|
@ -168,6 +202,7 @@ rmdbx_gather_stats( rmdbx_db_t *db )
|
|||
MDBX_stat mstat;
|
||||
MDBX_envinfo menvinfo;
|
||||
|
||||
rmdbx_gather_memory_stats( stat );
|
||||
rmdbx_gather_build_stats( stat );
|
||||
|
||||
rmdbx_open_txn( db, MDBX_TXN_RDONLY );
|
||||
|
|
@ -183,9 +218,6 @@ rmdbx_gather_stats( rmdbx_db_t *db )
|
|||
rmdbx_gather_environment_stats( stat, mstat, menvinfo );
|
||||
rmdbx_gather_reader_stats( db, stat, mstat, menvinfo );
|
||||
|
||||
/* TODO: database and subdatabase stats */
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue