From ae61e9ebdf3946cfa70e8c3bb16d886f87bd1f0c Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 21 Nov 2016 21:01:15 +0300 Subject: [PATCH 1/3] mdbx: distinct signature of internal objects for LMDB/MDBX modes. --- mdb.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mdb.c b/mdb.c index edf088ec..408cebdb 100644 --- a/mdb.c +++ b/mdb.c @@ -805,11 +805,17 @@ typedef struct MDB_dbx { void *md_relctx; /**< user-provided context for md_rel */ } MDB_dbx; +#if MDBX_MODE_ENABLED +# define MDBX_MODE_SALT 0 +#else +# define MDBX_MODE_SALT 1115449266 +#endif + /** A database transaction. * Every operation requires a transaction handle. */ struct MDB_txn { -#define MDBX_MT_SIGNATURE 0x706C553B +#define MDBX_MT_SIGNATURE (0x706C553B^MDBX_MODE_SALT) unsigned mt_signature; MDB_txn *mt_parent; /**< parent of a nested txn */ /** Nested txn under this txn, set together with flag #MDB_TXN_HAS_CHILD */ @@ -914,7 +920,7 @@ struct MDB_xcursor; * (A node with #F_DUPDATA but no #F_SUBDATA contains a subpage). */ struct MDB_cursor { -#define MDBX_MC_SIGNATURE 0xFE05D5B1 +#define MDBX_MC_SIGNATURE (0xFE05D5B1^MDBX_MODE_SALT) unsigned mc_signature; /** Next cursor on this DB in this txn */ MDB_cursor *mc_next; @@ -980,7 +986,7 @@ struct MDB_rthc { }; /** The database environment. */ struct MDB_env { -#define MDBX_ME_SIGNATURE 0x9A899641 +#define MDBX_ME_SIGNATURE (0x9A899641^MDBX_MODE_SALT) unsigned me_signature; HANDLE me_fd; /**< The main data file */ HANDLE me_lfd; /**< The lock file */ From ff70f5feb0afc3b972bf040148450e87cc613ff6 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sat, 26 Nov 2016 23:54:38 +0300 Subject: [PATCH 2/3] mdbx: avoid large '.data' section in mdbx_chk. Initializes walk-array in runtime, for placing it in the '.bss' section instead of '.data'. Change-Id: I5bd1d9cabd2094f8ae517d91488840ce12844bfa --- mdb_chk.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mdb_chk.c b/mdb_chk.c index 1d800703..4fe83ff0 100644 --- a/mdb_chk.c +++ b/mdb_chk.c @@ -74,9 +74,13 @@ struct { short *pagemap; size_t total_payload_bytes; size_t pgcount; -} walk = { - .dbi_names = { "@gc" } -}; +} walk; + +static __attribute__((constructor)) +void init_walk(void) +{ + walk.dbi_names[0] = "@gc"; +} size_t total_unused_bytes; int exclusive = 2; From 7ea16c1daf962c04e791cdaa608c44d97f5d4a1b Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 27 Nov 2016 00:04:28 +0300 Subject: [PATCH 3/3] mdbx: fix build mtest1. Change-Id: I8d206bb45ee4b99b1e12b32897c5b5b31c4df760 --- mtest1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mtest1.c b/mtest1.c index 4923ac64..ff063198 100644 --- a/mtest1.c +++ b/mtest1.c @@ -74,7 +74,7 @@ int main(int argc,char * argv[]) env_oflags = 0; } /* LY: especially here we always needs MDB_NOSYNC - * for testing mdb_env_close_ex() and "redo-to-steady" on open. */ + * for testing mdbx_env_close_ex() and "redo-to-steady" on open. */ env_oflags |= MDB_NOSYNC; E(mdb_env_open(env, DBPATH, env_oflags, 0664)); @@ -159,7 +159,7 @@ int main(int argc,char * argv[]) mdb_dbi_close(env, dbi); /********************* LY: kept DB dirty ****************/ - mdb_env_close_ex(env, 1); + mdbx_env_close_ex(env, 1); E(mdb_env_create(&env)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, DBPATH, env_oflags, 0664)); @@ -194,7 +194,7 @@ int main(int argc,char * argv[]) mdb_txn_abort(txn); mdb_dbi_close(env, dbi); - mdb_env_close_ex(env, 0); + mdbx_env_close_ex(env, 0); return 0; }