Skip to content

Commit 94e8009

Browse files
committed
ITS#8300 more for prev commit
Just tell explicitly which direction we moved/merged from
1 parent ba85adb commit 94e8009

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libraries/liblmdb/mdb.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ static int mdb_node_add(MDB_cursor *mc, indx_t indx,
13271327
MDB_val *key, MDB_val *data, pgno_t pgno, unsigned int flags);
13281328
static void mdb_node_del(MDB_cursor *mc, int ksize);
13291329
static void mdb_node_shrink(MDB_page *mp, indx_t indx);
1330-
static int mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst);
1330+
static int mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft);
13311331
static int mdb_node_read(MDB_txn *txn, MDB_node *leaf, MDB_val *data);
13321332
static size_t mdb_leaf_size(MDB_env *env, MDB_val *key, MDB_val *data);
13331333
static size_t mdb_branch_size(MDB_env *env, MDB_val *key);
@@ -7526,7 +7526,7 @@ mdb_cursor_copy(const MDB_cursor *csrc, MDB_cursor *cdst);
75267526
/** Move a node from csrc to cdst.
75277527
*/
75287528
static int
7529-
mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst)
7529+
mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
75307530
{
75317531
MDB_node *srcnode;
75327532
MDB_val key, data;
@@ -7628,7 +7628,7 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst)
76287628

76297629
mps = csrc->mc_pg[csrc->mc_top];
76307630
/* If we're adding on the left, bump others up */
7631-
if (!cdst->mc_ki[csrc->mc_top]) {
7631+
if (fromleft) {
76327632
mpd = cdst->mc_pg[csrc->mc_top];
76337633
for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
76347634
if (csrc->mc_flags & C_SUB)
@@ -7910,7 +7910,7 @@ static int
79107910
mdb_rebalance(MDB_cursor *mc)
79117911
{
79127912
MDB_node *node;
7913-
int rc;
7913+
int rc, fromleft;
79147914
unsigned int ptop, minkeys, thresh;
79157915
MDB_cursor mn;
79167916
indx_t oldki;
@@ -8043,6 +8043,7 @@ mdb_rebalance(MDB_cursor *mc)
80438043
return rc;
80448044
mn.mc_ki[mn.mc_top] = 0;
80458045
mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]);
8046+
fromleft = 0;
80468047
} else {
80478048
/* There is at least one neighbor to the left.
80488049
*/
@@ -8054,6 +8055,7 @@ mdb_rebalance(MDB_cursor *mc)
80548055
return rc;
80558056
mn.mc_ki[mn.mc_top] = NUMKEYS(mn.mc_pg[mn.mc_top]) - 1;
80568057
mc->mc_ki[mc->mc_top] = 0;
8058+
fromleft = 1;
80578059
}
80588060

80598061
DPRINTF(("found neighbor page %"Z"u (%u keys, %.1f%% full)",
@@ -8065,13 +8067,13 @@ mdb_rebalance(MDB_cursor *mc)
80658067
* (A branch page must never have less than 2 keys.)
80668068
*/
80678069
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= thresh && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
8068-
rc = mdb_node_move(&mn, mc);
8069-
if (!mc->mc_ki[mc->mc_top]) {
8070+
rc = mdb_node_move(&mn, mc, fromleft);
8071+
if (fromleft) {
80708072
/* if we inserted on left, bump position up */
80718073
oldki++;
80728074
}
80738075
} else {
8074-
if (mc->mc_ki[ptop] == 0) {
8076+
if (!fromleft) {
80758077
rc = mdb_page_merge(&mn, mc);
80768078
} else {
80778079
MDB_cursor dummy;

0 commit comments

Comments
 (0)