ITS#7229 more mdb_page_split tweaks

Also add mdb_debug/mdb_debug_start to toggle debug output at runtime
vmware
Howard Chu 13 years ago
parent a66f9e9292
commit d793594173
  1. 74
      libraries/libmdb/mdb.c

@ -259,9 +259,12 @@ typedef ID txnid_t;
#if !(__STDC_VERSION__ >= 199901L || defined(__GNUC__)) #if !(__STDC_VERSION__ >= 199901L || defined(__GNUC__))
# define DPRINTF (void) /* Vararg macros may be unsupported */ # define DPRINTF (void) /* Vararg macros may be unsupported */
#elif MDB_DEBUG #elif MDB_DEBUG
static int mdb_debug;
static int mdb_debug_start;
/** Print a debug message with printf formatting. */ /** Print a debug message with printf formatting. */
# define DPRINTF(fmt, ...) /**< Requires 2 or more args */ \ # define DPRINTF(fmt, ...) /**< Requires 2 or more args */ \
fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, __VA_ARGS__) if (mdb_debug) fprintf(stderr, "%s:%d " fmt "\n", __func__, __LINE__, __VA_ARGS__)
#else #else
# define DPRINTF(fmt, ...) ((void) 0) # define DPRINTF(fmt, ...) ((void) 0)
#endif #endif
@ -1576,6 +1579,10 @@ mdb_txn_renew0(MDB_txn *txn)
if (env->me_wtxnid < txn->mt_txnid) if (env->me_wtxnid < txn->mt_txnid)
mt_dbflag = DB_STALE; mt_dbflag = DB_STALE;
txn->mt_txnid++; txn->mt_txnid++;
#if MDB_DEBUG
if (txn->mt_txnid == mdb_debug_start)
mdb_debug = 1;
#endif
txn->mt_toggle = env->me_txns->mti_me_toggle; txn->mt_toggle = env->me_txns->mti_me_toggle;
txn->mt_u.dirty_list = env->me_dirty_list; txn->mt_u.dirty_list = env->me_dirty_list;
txn->mt_u.dirty_list[0].mid = 0; txn->mt_u.dirty_list[0].mid = 0;
@ -5765,43 +5772,45 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
* When the size of the data items is much smaller than * When the size of the data items is much smaller than
* one-half of a page, this check is irrelevant. * one-half of a page, this check is irrelevant.
*/ */
if (IS_LEAF(mp) && nkeys < 16) { if (IS_LEAF(mp)) {
unsigned int psize, nsize; unsigned int psize, nsize;
/* Maximum free space in an empty page */ /* Maximum free space in an empty page */
pmax = mc->mc_txn->mt_env->me_psize - PAGEHDRSZ; pmax = mc->mc_txn->mt_env->me_psize - PAGEHDRSZ;
nsize = mdb_leaf_size(mc->mc_txn->mt_env, newkey, newdata); nsize = mdb_leaf_size(mc->mc_txn->mt_env, newkey, newdata);
if (newindx <= split_indx) { if ((nkeys < 20) || (nsize > pmax/4)) {
psize = nsize; if (newindx <= split_indx) {
newpos = 0; psize = nsize;
for (i=0; i<split_indx; i++) { newpos = 0;
node = NODEPTR(mp, i); for (i=0; i<split_indx; i++) {
psize += NODESIZE + NODEKSZ(node) + sizeof(indx_t); node = NODEPTR(mp, i);
if (F_ISSET(node->mn_flags, F_BIGDATA)) psize += NODESIZE + NODEKSZ(node) + sizeof(indx_t);
psize += sizeof(pgno_t); if (F_ISSET(node->mn_flags, F_BIGDATA))
else psize += sizeof(pgno_t);
psize += NODEDSZ(node);
psize += psize & 1;
if (psize > pmax) {
if (i == split_indx - 1 && newindx == split_indx)
newpos = 1;
else else
split_indx = i; psize += NODEDSZ(node);
break; psize += psize & 1;
if (psize > pmax) {
if (i == split_indx - 1 && newindx == split_indx)
newpos = 1;
else
split_indx = i;
break;
}
} }
} } else {
} else { psize = nsize;
psize = nsize; for (i=nkeys-1; i>=split_indx; i--) {
for (i=nkeys-1; i>=split_indx; i--) { node = NODEPTR(mp, i);
node = NODEPTR(mp, i); psize += NODESIZE + NODEKSZ(node) + sizeof(indx_t);
psize += NODESIZE + NODEKSZ(node) + sizeof(indx_t); if (F_ISSET(node->mn_flags, F_BIGDATA))
if (F_ISSET(node->mn_flags, F_BIGDATA)) psize += sizeof(pgno_t);
psize += sizeof(pgno_t); else
else psize += NODEDSZ(node);
psize += NODEDSZ(node); psize += psize & 1;
psize += psize & 1; if (psize > pmax) {
if (psize > pmax) { split_indx = i+1;
split_indx = i+1; break;
break; }
} }
} }
} }
@ -5918,6 +5927,7 @@ newsep:
} }
rc = mdb_node_add(mc, j, &rkey, rdata, pgno, flags); rc = mdb_node_add(mc, j, &rkey, rdata, pgno, flags);
if (rc) break;
} }
nkeys = NUMKEYS(copy); nkeys = NUMKEYS(copy);

Loading…
Cancel
Save