Skip to content

Commit

Permalink
Make using newer freespace and iterating backwards optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jan 22, 2025
1 parent e764d2c commit 22bf368
Show file tree
Hide file tree
Showing 3 changed files with 330 additions and 152 deletions.
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
17 changes: 16 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
Loading

0 comments on commit 22bf368

Please sign in to comment.