Renumber MDB_TXN_* flags, simplify flag code

vl32b
Hallvard Furuseth 10 years ago
parent 49bb9e82e8
commit 54516639ac
  1. 46
      libraries/liblmdb/mdb.c

@ -1080,12 +1080,16 @@ struct MDB_txn {
* @ingroup internal * @ingroup internal
* @{ * @{
*/ */
#define MDB_TXN_RDONLY 0x01 /**< read-only transaction */ /** #mdb_txn_begin() flags */
#define MDB_TXN_BEGIN_FLAGS (MDB_NOMETASYNC|MDB_NOSYNC|MDB_RDONLY)
#define MDB_TXN_NOMETASYNC MDB_NOMETASYNC /**< don't sync meta for this txn on commit */
#define MDB_TXN_NOSYNC MDB_NOSYNC /**< don't sync this txn on commit */
#define MDB_TXN_RDONLY MDB_RDONLY /**< read-only transaction */
/* internal txn flags */
#define MDB_TXN_WRITEMAP MDB_WRITEMAP /**< copy of #MDB_env flag in writers */
#define MDB_TXN_ERROR 0x02 /**< txn is unusable after an error */ #define MDB_TXN_ERROR 0x02 /**< txn is unusable after an error */
#define MDB_TXN_DIRTY 0x04 /**< must write, even if dirty list is empty */ #define MDB_TXN_DIRTY 0x04 /**< must write, even if dirty list is empty */
#define MDB_TXN_SPILLS 0x08 /**< txn or a parent has spilled pages */ #define MDB_TXN_SPILLS 0x08 /**< txn or a parent has spilled pages */
#define MDB_TXN_NOSYNC 0x10 /**< don't sync this txn on commit */
#define MDB_TXN_NOMETASYNC 0x20 /**< don't sync meta for this txn on commit */
/** @} */ /** @} */
unsigned int mt_flags; /**< @ref mdb_txn */ unsigned int mt_flags; /**< @ref mdb_txn */
/** #dirty_list room: Array size - \#dirty pages visible to this txn. /** #dirty_list room: Array size - \#dirty pages visible to this txn.
@ -1996,7 +2000,7 @@ mdb_page_dirty(MDB_txn *txn, MDB_page *mp)
MDB_ID2 mid; MDB_ID2 mid;
int rc, (*insert)(MDB_ID2L, MDB_ID2 *); int rc, (*insert)(MDB_ID2L, MDB_ID2 *);
if (txn->mt_env->me_flags & MDB_WRITEMAP) { if (txn->mt_flags & MDB_TXN_WRITEMAP) {
insert = mdb_mid2l_append; insert = mdb_mid2l_append;
} else { } else {
insert = mdb_mid2l_insert; insert = mdb_mid2l_insert;
@ -2570,7 +2574,7 @@ mdb_txn_renew0(MDB_txn *txn)
int rc, new_notls = 0; int rc, new_notls = 0;
if (txn->mt_flags & MDB_TXN_RDONLY) { if (txn->mt_flags & MDB_TXN_RDONLY) {
txn->mt_flags = MDB_TXN_RDONLY; txn->mt_flags &= MDB_TXN_BEGIN_FLAGS;
/* Setup db info */ /* Setup db info */
txn->mt_numdbs = env->me_numdbs; txn->mt_numdbs = env->me_numdbs;
txn->mt_dbxs = env->me_dbxs; /* mostly static anyway */ txn->mt_dbxs = env->me_dbxs; /* mostly static anyway */
@ -2720,18 +2724,20 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
MDB_ntxn *ntxn; MDB_ntxn *ntxn;
int rc, size, tsize = sizeof(MDB_txn); int rc, size, tsize = sizeof(MDB_txn);
flags &= MDB_TXN_BEGIN_FLAGS;
flags |= env->me_flags & MDB_WRITEMAP;
if (env->me_flags & MDB_FATAL_ERROR) { if (env->me_flags & MDB_FATAL_ERROR) {
DPUTS("environment had fatal error, must shutdown!"); DPUTS("environment had fatal error, must shutdown!");
return MDB_PANIC; return MDB_PANIC;
} }
if ((env->me_flags & MDB_RDONLY) && !(flags & MDB_RDONLY)) if (env->me_flags & MDB_RDONLY & ~flags) /* write txn in RDONLY env */
return EACCES; return EACCES;
if (parent) { if (parent) {
/* Nested transactions: Max 1 child, write txns only, no writemap */ /* Nested transactions: Max 1 child, write txns only, no writemap */
if (parent->mt_child || if (parent->mt_child ||
(flags & MDB_RDONLY) || ((flags | parent->mt_flags) &
(parent->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_ERROR)) || (MDB_RDONLY|MDB_WRITEMAP|MDB_TXN_ERROR)))
(env->me_flags & MDB_WRITEMAP))
{ {
return (parent->mt_flags & MDB_TXN_RDONLY) ? EINVAL : MDB_BAD_TXN; return (parent->mt_flags & MDB_TXN_RDONLY) ? EINVAL : MDB_BAD_TXN;
} }
@ -2754,14 +2760,9 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
} }
txn->mt_dbs = (MDB_db *) ((char *)txn + tsize); txn->mt_dbs = (MDB_db *) ((char *)txn + tsize);
if (flags & MDB_RDONLY) { if (flags & MDB_RDONLY) {
txn->mt_flags |= MDB_TXN_RDONLY;
txn->mt_dbflags = (unsigned char *)(txn->mt_dbs + env->me_maxdbs); txn->mt_dbflags = (unsigned char *)(txn->mt_dbs + env->me_maxdbs);
txn->mt_dbiseqs = env->me_dbiseqs; txn->mt_dbiseqs = env->me_dbiseqs;
} else { } else {
if (flags & MDB_NOSYNC)
txn->mt_flags |= MDB_TXN_NOSYNC;
if (flags & MDB_NOMETASYNC)
txn->mt_flags |= MDB_TXN_NOMETASYNC;
txn->mt_cursors = (MDB_cursor **)(txn->mt_dbs + env->me_maxdbs); txn->mt_cursors = (MDB_cursor **)(txn->mt_dbs + env->me_maxdbs);
if (parent) { if (parent) {
txn->mt_dbiseqs = parent->mt_dbiseqs; txn->mt_dbiseqs = parent->mt_dbiseqs;
@ -2771,6 +2772,7 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
txn->mt_dbflags = (unsigned char *)(txn->mt_dbiseqs + env->me_maxdbs); txn->mt_dbflags = (unsigned char *)(txn->mt_dbiseqs + env->me_maxdbs);
} }
} }
txn->mt_flags = flags;
txn->mt_env = env; txn->mt_env = env;
ok: ok:
@ -2822,7 +2824,7 @@ ok:
} else { } else {
*ret = txn; *ret = txn;
DPRINTF(("begin txn %"Z"u%c %p on mdbenv %p, root page %"Z"u", DPRINTF(("begin txn %"Z"u%c %p on mdbenv %p, root page %"Z"u",
txn->mt_txnid, (txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w', txn->mt_txnid, (flags & MDB_RDONLY) ? 'r' : 'w',
(void *) txn, (void *) env, txn->mt_dbs[MAIN_DBI].md_root)); (void *) txn, (void *) env, txn->mt_dbs[MAIN_DBI].md_root));
} }
@ -3660,6 +3662,7 @@ mdb_env_write_meta(MDB_txn *txn)
{ {
MDB_env *env; MDB_env *env;
MDB_meta meta, metab, *mp; MDB_meta meta, metab, *mp;
unsigned flags;
size_t mapsize; size_t mapsize;
off_t off; off_t off;
int rc, len, toggle; int rc, len, toggle;
@ -3676,13 +3679,14 @@ mdb_env_write_meta(MDB_txn *txn)
toggle, txn->mt_dbs[MAIN_DBI].md_root)); toggle, txn->mt_dbs[MAIN_DBI].md_root));
env = txn->mt_env; env = txn->mt_env;
flags = txn->mt_flags & env->me_flags;
mp = env->me_metas[toggle]; mp = env->me_metas[toggle];
mapsize = env->me_metas[toggle ^ 1]->mm_mapsize; mapsize = env->me_metas[toggle ^ 1]->mm_mapsize;
/* Persist any increases of mapsize config */ /* Persist any increases of mapsize config */
if (mapsize < env->me_mapsize) if (mapsize < env->me_mapsize)
mapsize = env->me_mapsize; mapsize = env->me_mapsize;
if (env->me_flags & MDB_WRITEMAP) { if (flags & MDB_WRITEMAP) {
mp->mm_mapsize = mapsize; mp->mm_mapsize = mapsize;
mp->mm_dbs[0] = txn->mt_dbs[0]; mp->mm_dbs[0] = txn->mt_dbs[0];
mp->mm_dbs[1] = txn->mt_dbs[1]; mp->mm_dbs[1] = txn->mt_dbs[1];
@ -3692,9 +3696,7 @@ mdb_env_write_meta(MDB_txn *txn)
__sync_synchronize(); __sync_synchronize();
#endif #endif
mp->mm_txnid = txn->mt_txnid; mp->mm_txnid = txn->mt_txnid;
if (txn->mt_flags & (MDB_TXN_NOSYNC|MDB_TXN_NOMETASYNC)) if (!(flags & (MDB_NOMETASYNC|MDB_NOSYNC))) {
goto done;
if (!(env->me_flags & (MDB_NOMETASYNC|MDB_NOSYNC))) {
unsigned meta_size = env->me_psize; unsigned meta_size = env->me_psize;
rc = (env->me_flags & MDB_MAPASYNC) ? MS_ASYNC : MS_SYNC; rc = (env->me_flags & MDB_MAPASYNC) ? MS_ASYNC : MS_SYNC;
ptr = env->me_map; ptr = env->me_map;
@ -3730,9 +3732,7 @@ mdb_env_write_meta(MDB_txn *txn)
off += PAGEHDRSZ; off += PAGEHDRSZ;
/* Write to the SYNC fd */ /* Write to the SYNC fd */
mfd = ((env->me_flags & (MDB_NOSYNC|MDB_NOMETASYNC)) || mfd = (flags & (MDB_NOSYNC|MDB_NOMETASYNC)) ? env->me_fd : env->me_mfd;
(txn->mt_flags & (MDB_TXN_NOSYNC|MDB_TXN_NOMETASYNC))) ?
env->me_fd : env->me_mfd;
#ifdef _WIN32 #ifdef _WIN32
{ {
memset(&ov, 0, sizeof(ov)); memset(&ov, 0, sizeof(ov));
@ -5133,7 +5133,7 @@ mdb_page_get(MDB_txn *txn, pgno_t pgno, MDB_page **ret, int *lvl)
MDB_page *p = NULL; MDB_page *p = NULL;
int level; int level;
if (!((txn->mt_flags & MDB_TXN_RDONLY) | (env->me_flags & MDB_WRITEMAP))) { if (! (txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_WRITEMAP))) {
MDB_txn *tx2 = txn; MDB_txn *tx2 = txn;
level = 1; level = 1;
do { do {

Loading…
Cancel
Save