mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-01 23:54:12 +08:00
mdbx: backpost - ITS#8300 fix rebalance after node_move.
ITS#8258, ITS#7829 fixes checked parent index to see if we were moving from a left neighbor. Should have just checked to see if current index was 0, meaning we added on the left. (Parent index may not tell us anything meaningful after a nested rebalance.) Includes: - ITS#8300 fix node_move Don't adjust other cursors when we added a node on the right. - ITS#8300 more for node_move fixups When moving a node from the right neighbor, a different adjustment is needed. - ITS#8300 simplify - ITS#8300 more for node_move When moving a node from one page to another, make sure other cursors' parent index gets adjusted too.
This commit is contained in:
parent
7890eb8a8e
commit
ee26517b5d
1
CHANGES
1
CHANGES
@ -9,6 +9,7 @@ LMDB 0.9.17 Release Engineering
|
||||
Fix ITS#8263 cursor_put cursor tracking
|
||||
Fix ITS#8264 cursor_del cursor tracking
|
||||
Fix ITS#8299 mdb_del cursor tracking
|
||||
Fix ITS#8300 mdb_del cursor tracking
|
||||
Fix ITS#7771 fakepage cursor tracking
|
||||
Fix ITS#7789 ensure mapsize >= pages in use
|
||||
Fix ITS#7971 mdb_txn_renew0() new reader slots
|
||||
|
67
mdb.c
67
mdb.c
@ -7738,32 +7738,48 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst)
|
||||
/* Adjust other cursors pointing to mp */
|
||||
MDB_cursor *m2, *m3;
|
||||
MDB_dbi dbi = csrc->mc_dbi;
|
||||
MDB_page *mp;
|
||||
MDB_page *mpd, *mps;
|
||||
|
||||
mp = cdst->mc_pg[csrc->mc_top];
|
||||
for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
|
||||
if (csrc->mc_flags & C_SUB)
|
||||
m3 = &m2->mc_xcursor->mx_cursor;
|
||||
else
|
||||
m3 = m2;
|
||||
if (m3 == cdst) continue;
|
||||
if (m3->mc_pg[csrc->mc_top] == mp && m3->mc_ki[csrc->mc_top] >=
|
||||
cdst->mc_ki[csrc->mc_top]) {
|
||||
m3->mc_ki[csrc->mc_top]++;
|
||||
mps = csrc->mc_pg[csrc->mc_top];
|
||||
/* If we're adding on the left, bump others up */
|
||||
if (!cdst->mc_ki[csrc->mc_top]) {
|
||||
mpd = cdst->mc_pg[csrc->mc_top];
|
||||
for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
|
||||
if (csrc->mc_flags & C_SUB)
|
||||
m3 = &m2->mc_xcursor->mx_cursor;
|
||||
else
|
||||
m3 = m2;
|
||||
if (m3 != cdst &&
|
||||
m3->mc_pg[csrc->mc_top] == mpd &&
|
||||
m3->mc_ki[csrc->mc_top] >= cdst->mc_ki[csrc->mc_top]) {
|
||||
m3->mc_ki[csrc->mc_top]++;
|
||||
}
|
||||
if (m3 !=csrc &&
|
||||
m3->mc_pg[csrc->mc_top] == mps &&
|
||||
m3->mc_ki[csrc->mc_top] == csrc->mc_ki[csrc->mc_top]) {
|
||||
m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
|
||||
m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
|
||||
m3->mc_ki[csrc->mc_top-1]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp = csrc->mc_pg[csrc->mc_top];
|
||||
for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
|
||||
if (csrc->mc_flags & C_SUB)
|
||||
m3 = &m2->mc_xcursor->mx_cursor;
|
||||
else
|
||||
m3 = m2;
|
||||
if (m3 == csrc) continue;
|
||||
if (m3->mc_pg[csrc->mc_top] == mp && m3->mc_ki[csrc->mc_top] ==
|
||||
csrc->mc_ki[csrc->mc_top]) {
|
||||
m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
|
||||
m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
|
||||
} else
|
||||
/* Adding on the right, bump others down */
|
||||
{
|
||||
for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
|
||||
if (csrc->mc_flags & C_SUB)
|
||||
m3 = &m2->mc_xcursor->mx_cursor;
|
||||
else
|
||||
m3 = m2;
|
||||
if (m3 == csrc) continue;
|
||||
if (m3->mc_pg[csrc->mc_top] == mps) {
|
||||
if (!m3->mc_ki[csrc->mc_top]) {
|
||||
m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
|
||||
m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
|
||||
m3->mc_ki[csrc->mc_top-1]--;
|
||||
} else {
|
||||
m3->mc_ki[csrc->mc_top]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8151,7 +8167,8 @@ mdb_rebalance(MDB_cursor *mc)
|
||||
*/
|
||||
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= thresh && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
|
||||
rc = mdb_node_move(&mn, mc);
|
||||
if (mc->mc_ki[mc->mc_top-1]) {
|
||||
if (!mc->mc_ki[mc->mc_top]) {
|
||||
/* if we inserted on left, bump position up */
|
||||
oldki++;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user