Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jnwatson/py-lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
jnwatson committed Feb 5, 2021
2 parents eae87cf + eb4c1e4 commit 5f60b41
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 118 deletions.
4 changes: 2 additions & 2 deletions lib/lmdb.h
Expand Up @@ -200,7 +200,7 @@ typedef int mdb_filehandle_t;
/** Library minor version */
#define MDB_VERSION_MINOR 9
/** Library patch version */
#define MDB_VERSION_PATCH 27
#define MDB_VERSION_PATCH 26

/** Combine args a,b,c into a single integer for easy version comparisons */
#define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
Expand All @@ -210,7 +210,7 @@ typedef int mdb_filehandle_t;
MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)

/** The release date of this library version */
#define MDB_VERSION_DATE "October 26, 2020"
#define MDB_VERSION_DATE "August 11, 2020"

/** A stringifier for the version info */
#define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
Expand Down
210 changes: 102 additions & 108 deletions lib/mdb.c
Expand Up @@ -5942,12 +5942,16 @@ mdb_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc != MDB_SUCCESS)
return rc;
} else if (data) {
}
if (data) {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc != MDB_SUCCESS)
return rc;
}
}

MDB_GET_KEY(leaf, key);
Expand All @@ -5971,8 +5975,7 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)

mp = mc->mc_pg[mc->mc_top];

if ((mc->mc_db->md_flags & MDB_DUPSORT) &&
mc->mc_ki[mc->mc_top] < NUMKEYS(mp)) {
if (mc->mc_db->md_flags & MDB_DUPSORT) {
leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
if (op == MDB_PREV || op == MDB_PREV_DUP) {
Expand Down Expand Up @@ -6011,25 +6014,27 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
DPRINTF(("==> cursor points to page %"Z"u with %u keys, key index %u",
mdb_dbg_pgno(mp), NUMKEYS(mp), mc->mc_ki[mc->mc_top]));

if (!IS_LEAF(mp))
return MDB_CORRUPTED;

if (IS_LEAF2(mp)) {
key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mp, mc->mc_ki[mc->mc_top], key->mv_size);
return MDB_SUCCESS;
}

mdb_cassert(mc, IS_LEAF(mp));
leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_last(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc != MDB_SUCCESS)
return rc;
} else if (data) {
}
if (data) {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
rc = mdb_cursor_last(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc != MDB_SUCCESS)
return rc;
}
}

MDB_GET_KEY(leaf, key);
Expand Down Expand Up @@ -6185,22 +6190,24 @@ mdb_cursor_set(MDB_cursor *mc, MDB_val *key, MDB_val *data,

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
if (op == MDB_SET || op == MDB_SET_KEY || op == MDB_SET_RANGE) {
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
} else {
int ex2, *ex2p;
if (op == MDB_GET_BOTH) {
ex2p = &ex2;
ex2 = 0;
}
if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
if (op == MDB_SET || op == MDB_SET_KEY || op == MDB_SET_RANGE) {
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
} else {
ex2p = NULL;
int ex2, *ex2p;
if (op == MDB_GET_BOTH) {
ex2p = &ex2;
ex2 = 0;
} else {
ex2p = NULL;
}
rc = mdb_cursor_set(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_SET_RANGE, ex2p);
if (rc != MDB_SUCCESS)
return rc;
}
rc = mdb_cursor_set(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_SET_RANGE, ex2p);
if (rc != MDB_SUCCESS)
return rc;
}
} else if (data) {
if (op == MDB_GET_BOTH || op == MDB_GET_BOTH_RANGE) {
} else if (op == MDB_GET_BOTH || op == MDB_GET_BOTH_RANGE) {
MDB_val olddata;
MDB_cmp_func *dcmp;
if ((rc = mdb_node_read(mc, leaf, &olddata)) != MDB_SUCCESS)
Expand Down Expand Up @@ -6258,23 +6265,22 @@ mdb_cursor_first(MDB_cursor *mc, MDB_val *key, MDB_val *data)
mc->mc_ki[mc->mc_top] = 0;

if (IS_LEAF2(mc->mc_pg[mc->mc_top])) {
if ( key ) {
key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mc->mc_pg[mc->mc_top], 0, key->mv_size);
}
key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mc->mc_pg[mc->mc_top], 0, key->mv_size);
return MDB_SUCCESS;
}

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc)
return rc;
} else if (data) {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;
if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc)
return rc;
} else {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;
}
}

MDB_GET_KEY(leaf, key);
return MDB_SUCCESS;
}
Expand All @@ -6301,21 +6307,21 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data)
leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);

if (IS_LEAF2(mc->mc_pg[mc->mc_top])) {
if (key) {
key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top], key->mv_size);
}
key->mv_size = mc->mc_db->md_pad;
key->mv_data = LEAF2KEY(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top], key->mv_size);
return MDB_SUCCESS;
}

if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_last(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc)
return rc;
} else if (data) {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;
if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(mc, leaf);
rc = mdb_cursor_last(&mc->mc_xcursor->mx_cursor, data, NULL);
if (rc)
return rc;
} else {
if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc;
}
}

MDB_GET_KEY(leaf, key);
Expand Down Expand Up @@ -7096,8 +7102,6 @@ mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
return rc;

mp = mc->mc_pg[mc->mc_top];
if (!IS_LEAF(mp))
return MDB_CORRUPTED;
if (IS_LEAF2(mp))
goto del_key;
leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
Expand Down Expand Up @@ -8469,70 +8473,60 @@ mdb_cursor_del0(MDB_cursor *mc)
}
}
rc = mdb_rebalance(mc);
if (rc)
goto fail;

/* DB is totally empty now, just bail out.
* Other cursors adjustments were already done
* by mdb_rebalance and aren't needed here.
*/
if (!mc->mc_snum) {
mc->mc_flags |= C_EOF;
return rc;
}
if (rc == MDB_SUCCESS) {
/* DB is totally empty now, just bail out.
* Other cursors adjustments were already done
* by mdb_rebalance and aren't needed here.
*/
if (!mc->mc_snum)
return rc;

ki = mc->mc_ki[mc->mc_top];
mp = mc->mc_pg[mc->mc_top];
nkeys = NUMKEYS(mp);
mp = mc->mc_pg[mc->mc_top];
nkeys = NUMKEYS(mp);

/* Adjust other cursors pointing to mp */
for (m2 = mc->mc_txn->mt_cursors[dbi]; !rc && m2; m2=m2->mc_next) {
m3 = (mc->mc_flags & C_SUB) ? &m2->mc_xcursor->mx_cursor : m2;
if (!(m2->mc_flags & m3->mc_flags & C_INITIALIZED))
continue;
if (m3->mc_snum < mc->mc_snum)
continue;
if (m3->mc_pg[mc->mc_top] == mp) {
/* if m3 points past last node in page, find next sibling */
if (m3->mc_ki[mc->mc_top] >= nkeys) {
rc = mdb_cursor_sibling(m3, 1);
if (rc == MDB_NOTFOUND) {
m3->mc_flags |= C_EOF;
rc = MDB_SUCCESS;
continue;
}
if (rc)
goto fail;
}
if (m3->mc_ki[mc->mc_top] >= ki ||
/* moved to right sibling */ m3->mc_pg[mc->mc_top] != mp) {
if (m3->mc_xcursor && !(m3->mc_flags & C_EOF)) {
MDB_node *node = NODEPTR(m3->mc_pg[m3->mc_top], m3->mc_ki[m3->mc_top]);
/* If this node has dupdata, it may need to be reinited
* because its data has moved.
* If the xcursor was not initd it must be reinited.
* Else if node points to a subDB, nothing is needed.
* Else (xcursor was initd, not a subDB) needs mc_pg[0] reset.
*/
if (node->mn_flags & F_DUPDATA) {
if (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) {
if (!(node->mn_flags & F_SUBDATA))
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
} else {
mdb_xcursor_init1(m3, node);
rc = mdb_cursor_first(&m3->mc_xcursor->mx_cursor, NULL, NULL);
if (rc)
goto fail;
/* Adjust other cursors pointing to mp */
for (m2 = mc->mc_txn->mt_cursors[dbi]; !rc && m2; m2=m2->mc_next) {
m3 = (mc->mc_flags & C_SUB) ? &m2->mc_xcursor->mx_cursor : m2;
if (! (m2->mc_flags & m3->mc_flags & C_INITIALIZED))
continue;
if (m3->mc_snum < mc->mc_snum)
continue;
if (m3->mc_pg[mc->mc_top] == mp) {
/* if m3 points past last node in page, find next sibling */
if (m3->mc_ki[mc->mc_top] >= mc->mc_ki[mc->mc_top]) {
if (m3->mc_ki[mc->mc_top] >= nkeys) {
rc = mdb_cursor_sibling(m3, 1);
if (rc == MDB_NOTFOUND) {
m3->mc_flags |= C_EOF;
rc = MDB_SUCCESS;
continue;
}
}
if (mc->mc_db->md_flags & MDB_DUPSORT) {
MDB_node *node = NODEPTR(m3->mc_pg[m3->mc_top], m3->mc_ki[m3->mc_top]);
/* If this node has dupdata, it may need to be reinited
* because its data has moved.
* If the xcursor was not initd it must be reinited.
* Else if node points to a subDB, nothing is needed.
* Else (xcursor was initd, not a subDB) needs mc_pg[0] reset.
*/
if (node->mn_flags & F_DUPDATA) {
if (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) {
if (!(node->mn_flags & F_SUBDATA))
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(node);
} else {
mdb_xcursor_init1(m3, node);
m3->mc_xcursor->mx_cursor.mc_flags |= C_DEL;
}
}
}
m3->mc_xcursor->mx_cursor.mc_flags |= C_DEL;
}
m3->mc_flags |= C_DEL;
}
}
mc->mc_flags |= C_DEL;
}

fail:
if (rc)
mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
return rc;
Expand Down
16 changes: 8 additions & 8 deletions lib/py-lmdb/env-copy-txn.patch
@@ -1,5 +1,5 @@
diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h
index 361c93010..da6254819 100644
index 1461ee564..23a20cb7b 100644
--- a/libraries/liblmdb/lmdb.h
+++ b/libraries/liblmdb/lmdb.h
@@ -682,9 +682,14 @@ int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
Expand Down Expand Up @@ -32,10 +32,10 @@ index 361c93010..da6254819 100644
/** @brief Return statistics about the LMDB environment.
*
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index b70a6a54d..0b382a721 100644
index f09441052..ffb8f92bc 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -9334,12 +9334,12 @@ done:
@@ -9328,12 +9328,12 @@ done:

/** Copy environment with compaction. */
static int ESECT
Expand All @@ -50,7 +50,7 @@ index b70a6a54d..0b382a721 100644
pthread_t thr;
pgno_t root, new_root;
int rc = MDB_SUCCESS;
@@ -9385,9 +9385,11 @@ mdb_env_copyfd1(MDB_env *env, HANDLE fd)
@@ -9379,9 +9379,11 @@ mdb_env_copyfd1(MDB_env *env, HANDLE fd)
if (rc)
goto done;

Expand All @@ -65,7 +65,7 @@ index b70a6a54d..0b382a721 100644

mp = (MDB_page *)my.mc_wbuf[0];
memset(mp, 0, NUM_METAS * env->me_psize);
@@ -9447,7 +9449,8 @@ finish:
@@ -9441,7 +9443,8 @@ finish:
my.mc_error = rc;
mdb_env_cthr_toggle(&my, 1 | MDB_EOF);
rc = THREAD_FINISH(thr);
Expand All @@ -75,7 +75,7 @@ index b70a6a54d..0b382a721 100644

done:
#ifdef _WIN32
@@ -9564,12 +9567,22 @@ leave:
@@ -9558,12 +9561,22 @@ leave:
}

int ESECT
Expand All @@ -100,7 +100,7 @@ index b70a6a54d..0b382a721 100644
}

int ESECT
@@ -9580,6 +9593,12 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)
@@ -9574,6 +9587,12 @@ mdb_env_copyfd(MDB_env *env, HANDLE fd)

int ESECT
mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
Expand All @@ -113,7 +113,7 @@ index b70a6a54d..0b382a721 100644
{
int rc;
MDB_name fname;
@@ -9591,7 +9610,7 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
@@ -9585,7 +9604,7 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
mdb_fname_destroy(fname);
}
if (rc == MDB_SUCCESS) {
Expand Down

0 comments on commit 5f60b41

Please sign in to comment.