Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new freespace optional #322

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dependencies/lmdb/libraries/liblmdb/lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ typedef void (MDB_sum_func)(const MDB_val *src, MDB_val *dst, const MDB_val *key
#define MDB_SAFE_RESTORE 0x800
/** Track metrics for this env */
#define MDB_TRACK_METRICS 0x400
#define MDB_USE_NEW_FREESPACE 0x200
/** Use the overlapping sync strategy */
#define MDB_OVERLAPPINGSYNC_SYNC = 0x02
/** @} */
Expand Down
22 changes: 21 additions & 1 deletion dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,19 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
rc = mdb_cursor_get(&m2, &key, NULL, op);
op = MDB_NEXT; // now iterate forwards through the txns of free list
last = *(txnid_t *) key.mv_data;
} else {
} else if (!(MDB_USE_NEW_FREESPACE & env->me_flags)) {
if (env->me_freelist_end) { // if we are only reading forward, and we have already read the latest transactions, then nothing to do
break;
} else {
env->me_freelist_end = last = 1;
env->me_freelist_start = 1;
key.mv_data = &last; // start at the beginning of the freelist and read oldest txns first
key.mv_size = sizeof(last);
rc = mdb_cursor_get(&m2, &key, NULL, op);
op = MDB_NEXT; // now iterate forwards through the txns of free list
last = *(txnid_t *) key.mv_data;
}
} else {
// no more transactions to read going forward through newest, we are now going
// to switch to reading older transactions. However, first we set the op
// to forward to ensure that we fall into the switch into previous iterations below
Expand All @@ -2912,6 +2924,9 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
// iterating forward from the freelist range to find newer transactions
if (last >= oldest || rc == MDB_NOTFOUND) {
env->me_freelist_end = oldest;
if (!(MDB_USE_NEW_FREESPACE & env->me_flags)) {
break;
}
// no more newer transactions, go to the beginning of the range and look for older txns
op = MDB_SET_RANGE;
if (env->me_freelist_start <= 1) break; // should be no zero entry, break out
Expand Down Expand Up @@ -10357,6 +10372,11 @@ void
mdb_cursor_close(MDB_cursor *mc)
{
if (mc) {
if (!mc->mc_txn || !mc->mc_txn->mt_env) {
fprintf(stderr, "cursor_close: mc->mc_txn or mc->mc_txn->mt_env is NULL, ensure that cursors are closed before the transaction is closed\n");
free(mc);
return;
}
MDB_CURSOR_UNREF(mc, 0);
}
if (mc && !mc->mc_backup) {
Expand Down
Loading