Skip to content

Commit

Permalink
Remove the restriction on reading freespace while deleting using the …
Browse files Browse the repository at this point in the history
…more robust iteration
  • Loading branch information
kriszyp committed Jun 7, 2024
1 parent 2f0dc8f commit 0c73c79
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,6 @@ struct MDB_env {
# define me_freelist_written_end me_pgstate.mf_written_end
unsigned int me_maxfreepgs_to_load; /**< max freelist entries to load into memory */
unsigned int me_maxfreepgs_to_retain; /**< max freelist entries to load into memory */
int me_freelist_state; /**< state of writing freelist (if it is being deleted) */
MDB_page *me_dpages; /**< list of malloc'd blocks for re-use */
/** IDL of pages that became unused in a write txn */
MDB_IDL me_free_pgs;
Expand Down Expand Up @@ -2902,7 +2901,6 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
load_more:
if (op == MDB_SET_RANGE) { /* 1st iteration */
/* Prepare to fetch more and coalesce */
if (env->me_freelist_state & MDB_FREELIST_DELETING) break;
oldest = env->me_pgoldest;
mdb_cursor_init(&m2, txn, FREE_DBI, NULL);
#if (MDB_DEVEL) & 2 /* "& 2" so MDB_DEVEL=1 won't hide bugs breaking freeDB */
Expand Down Expand Up @@ -2943,11 +2941,6 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
}
} else {
// we are now iterating through the free list entries
// first, we need to check if we are in free-list deletion mode, in which case it is not safe to iterate backwards and we have to bail out
/*if (op == MDB_PREV && (env->me_freelist_state & MDB_FREELIST_DELETING)) {
//fprintf(stderr, "Skipping unsafe backwards iteration 1\n");
break;
}*/
// now iterate
rc = mdb_cursor_get(&m2, &key, NULL, op);
if (rc && rc != MDB_NOTFOUND)
Expand All @@ -2962,7 +2955,6 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
if (last >= oldest || rc == MDB_NOTFOUND) {
env->me_freelist_end = oldest;
// no more newer transactions, go to the beginning of the range and look for older txns
//if (env->me_freelist_state & MDB_FREELIST_DELETING) break;
op = MDB_SET_RANGE;
if (env->me_freelist_start <= 1) break; // should be no zero entry, break out
last = env->me_freelist_start - 1;
Expand Down Expand Up @@ -2995,9 +2987,11 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
env->me_freelist_start = 1;
break;
}
env->me_freelist_start = last;
}
if (op == MDB_PREV) {
// move to previous entry until we are before the last start time.
// note that occasionally this might take multiple iterations if we are in the middle of a
// rebalance and a node being moved
while (last >= env->me_freelist_start) {
// go to previous entry, through prev iteration
rc = mdb_cursor_get(&m2, &key, NULL, MDB_PREV);
Expand Down Expand Up @@ -4322,9 +4316,7 @@ mdb_freelist_save(MDB_txn *txn)
total_room = head_room = 0;
mdb_tassert(txn, head_id >= env->me_freelist_start);
//fprintf(stderr, "Deleting free list record %u\n", head_id);
//env->me_freelist_state = MDB_FREELIST_DELETING; // signal that we are deleting from the freelist, which means we can't iterate backwards
rc = mdb_cursor_del(&mc, 0);
env->me_freelist_state = 0;
if (rc) {
last_error = "Attempting to delete free-space record";
return rc;
Expand Down Expand Up @@ -9983,10 +9975,6 @@ mdb_node_add(MDB_cursor *mc, indx_t indx,
node_size = EVEN(node_size + sizeof(MDB_ovpage));
if ((ssize_t)node_size > room)
goto full;
if (mc->mc_dbi == 0) {
fprintf(stderr,"added new key %i ", *((txnid_t *) key->mv_data));
test_reversal(mc);
}
if ((rc = mdb_page_new(mc, P_OVERFLOW, ovpages, &ofp)))
return rc;
DPRINTF(("allocated overflow page %"Yu, ofp->mp_pgno));
Expand Down Expand Up @@ -10618,16 +10606,13 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)

/* Add the node to the destination page.
*/
test_reversal(cdst);
rc = mdb_node_add(cdst, cdst->mc_ki[cdst->mc_top], &key, &data, srcpg, flags);
test_reversal(cdst);
if (rc != MDB_SUCCESS)
return rc;

/* Delete the node from the source page.
*/
mdb_node_del(csrc, key.mv_size);
test_reversal(cdst);

{
/* Adjust other cursors pointing to mp */
Expand Down

0 comments on commit 0c73c79

Please sign in to comment.