mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
mdbx: fix mdb_cursor_last (ITS#8557).
This is a port of http://www.openldap.org/devel/gitweb.cgi?p=openldap.git;a=commit;h=d84dee516fa4cca41b5234e95c2105eb4737dfb3 HYC: Optimize mdb_page_search_root(PS_LAST) when cursor is already near last position, ignoring C_EOF flag for now. LY: Fixed C_EOF check. Don't ignore it, otherwise in some cases we got a "MDB_PAGE_NOTFOUND", instead of just "MDB_NOTFOUND". Change-Id: I2edbf6b64403abfa830a2fcb84162125634a85d0
This commit is contained in:
parent
c96cc9c567
commit
97e1d9b685
1
CHANGES
1
CHANGES
@ -4,6 +4,7 @@ MDBX
|
||||
|
||||
LMDB 0.9.20 Release Engineering
|
||||
Fix mdb_load with escaped plaintext (ITS#8558)
|
||||
Fix mdb_cursor_last / mdb_put interaction (ITS#8557)
|
||||
|
||||
LMDB 0.9.19 Release (2016/12/28)
|
||||
Fix mdb_env_cwalk cursor init (ITS#8424)
|
||||
|
15
mdb.c
15
mdb.c
@ -5636,8 +5636,17 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
|
||||
|
||||
if (flags & (MDB_PS_FIRST|MDB_PS_LAST)) {
|
||||
i = 0;
|
||||
if (flags & MDB_PS_LAST)
|
||||
if (flags & MDB_PS_LAST) {
|
||||
i = NUMKEYS(mp) - 1;
|
||||
/* if already init'd, see if we're already in right place */
|
||||
if (mc->mc_flags & C_INITIALIZED) {
|
||||
if (mc->mc_ki[mc->mc_top] == i) {
|
||||
mp = mc->mc_pg[mc->mc_top];
|
||||
mc->mc_top = mc->mc_snum++;
|
||||
goto ready;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int exact;
|
||||
node = mdb_node_search(mc, key, &exact);
|
||||
@ -5663,6 +5672,7 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
|
||||
if (unlikely(rc = mdb_cursor_push(mc, mp)))
|
||||
return rc;
|
||||
|
||||
ready:
|
||||
if (flags & MDB_PS_MODIFY) {
|
||||
if (unlikely((rc = mdb_page_touch(mc)) != 0))
|
||||
return rc;
|
||||
@ -6405,15 +6415,14 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data)
|
||||
mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
|
||||
|
||||
if (likely(!(mc->mc_flags & C_EOF))) {
|
||||
|
||||
if (!(mc->mc_flags & C_INITIALIZED) || mc->mc_top) {
|
||||
rc = mdb_page_search(mc, NULL, MDB_PS_LAST);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
return rc;
|
||||
}
|
||||
mdb_cassert(mc, IS_LEAF(mc->mc_pg[mc->mc_top]));
|
||||
|
||||
}
|
||||
|
||||
mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]) - 1;
|
||||
mc->mc_flags |= C_INITIALIZED|C_EOF;
|
||||
leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user