Skip to content

Commit 46e3f46

Browse files
committed
ITS#8321 More cursor fixup
Based on page_touch fixup from ITS#7594 but expanded: make sure sub-cursors agree with main cursors.
1 parent 2b89f4b commit 46e3f46

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

libraries/liblmdb/mdb.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,13 @@ mdb_cursor_chk(MDB_cursor *mc)
16131613
}
16141614
if (mc->mc_ki[i] >= NUMKEYS(mc->mc_pg[i]))
16151615
printf("ack!\n");
1616+
if (mc->mc_xcursor && (mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
1617+
node = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
1618+
if (((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA) &&
1619+
mc->mc_xcursor->mx_cursor.mc_pg[0] != NODEDATA(node)) {
1620+
printf("blah!\n");
1621+
}
1622+
}
16161623
}
16171624
#endif
16181625

@@ -2423,10 +2430,10 @@ mdb_page_touch(MDB_cursor *mc)
24232430
m2->mc_pg[mc->mc_top] = np;
24242431
if ((mc->mc_db->md_flags & MDB_DUPSORT) &&
24252432
IS_LEAF(np) &&
2426-
m2->mc_ki[mc->mc_top] == mc->mc_ki[mc->mc_top])
2433+
(m2->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED))
24272434
{
2428-
MDB_node *leaf = NODEPTR(np, mc->mc_ki[mc->mc_top]);
2429-
if (!(leaf->mn_flags & F_SUBDATA))
2435+
MDB_node *leaf = NODEPTR(np, m2->mc_ki[mc->mc_top]);
2436+
if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
24302437
m2->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
24312438
}
24322439
}
@@ -7623,6 +7630,7 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
76237630
data.mv_size = NODEDSZ(srcnode);
76247631
data.mv_data = NODEDATA(srcnode);
76257632
}
7633+
mn.mc_xcursor = NULL;
76267634
if (IS_BRANCH(cdst->mc_pg[cdst->mc_top]) && cdst->mc_ki[cdst->mc_top] == 0) {
76277635
unsigned int snum = cdst->mc_snum;
76287636
MDB_node *s2;
@@ -7694,6 +7702,12 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
76947702
m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
76957703
m3->mc_ki[csrc->mc_top-1]++;
76967704
}
7705+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) &&
7706+
IS_LEAF(mps)) {
7707+
MDB_node *node = NODEPTR(m3->mc_pg[csrc->mc_top], m3->mc_ki[csrc->mc_top]);
7708+
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
7709+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
7710+
}
76977711
}
76987712
} else
76997713
/* Adding on the right, bump others down */
@@ -7714,6 +7728,12 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
77147728
} else {
77157729
m3->mc_ki[csrc->mc_top]--;
77167730
}
7731+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) &&
7732+
IS_LEAF(mps)) {
7733+
MDB_node *node = NODEPTR(m3->mc_pg[csrc->mc_top], m3->mc_ki[csrc->mc_top]);
7734+
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
7735+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
7736+
}
77177737
}
77187738
}
77197739
}
@@ -7838,6 +7858,7 @@ mdb_page_merge(MDB_cursor *csrc, MDB_cursor *cdst)
78387858
MDB_cursor mn;
78397859
MDB_node *s2;
78407860
mdb_cursor_copy(csrc, &mn);
7861+
mn.mc_xcursor = NULL;
78417862
/* must find the lowest key below src */
78427863
rc = mdb_page_search_lowest(&mn);
78437864
if (rc)
@@ -7913,6 +7934,12 @@ mdb_page_merge(MDB_cursor *csrc, MDB_cursor *cdst)
79137934
m3->mc_ki[top-1] > csrc->mc_ki[top-1]) {
79147935
m3->mc_ki[top-1]--;
79157936
}
7937+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) &&
7938+
IS_LEAF(psrc)) {
7939+
MDB_node *node = NODEPTR(m3->mc_pg[top], m3->mc_ki[top]);
7940+
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
7941+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
7942+
}
79167943
}
79177944
}
79187945
{
@@ -8171,6 +8198,11 @@ mdb_cursor_del0(MDB_cursor *mc)
81718198
else if (mc->mc_db->md_flags & MDB_DUPSORT)
81728199
m3->mc_xcursor->mx_cursor.mc_flags &= ~C_INITIALIZED;
81738200
}
8201+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
8202+
MDB_node *node = NODEPTR(m3->mc_pg[mc->mc_top], m3->mc_ki[mc->mc_top]);
8203+
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
8204+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
8205+
}
81748206
}
81758207
}
81768208
}
@@ -8353,6 +8385,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
83538385
}
83548386

83558387
mdb_cursor_copy(mc, &mn);
8388+
mn.mc_xcursor = NULL;
83568389
mn.mc_pg[mn.mc_top] = rp;
83578390
mn.mc_ki[ptop] = mc->mc_ki[ptop]+1;
83588391

@@ -8683,6 +8716,12 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
86838716
m3->mc_ki[ptop] >= mc->mc_ki[ptop]) {
86848717
m3->mc_ki[ptop]++;
86858718
}
8719+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) &&
8720+
IS_LEAF(mp)) {
8721+
MDB_node *node = NODEPTR(m3->mc_pg[mc->mc_top], m3->mc_ki[mc->mc_top]);
8722+
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) == F_DUPDATA)
8723+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
8724+
}
86868725
}
86878726
}
86888727
DPRINTF(("mp left: %d, rp left: %d", SIZELEFT(mp), SIZELEFT(rp)));

0 commit comments

Comments
 (0)