From 0c73c7927a9cf01e202d07d78d5e7651fb701b41 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Fri, 7 Jun 2024 13:08:47 -0600 Subject: [PATCH] Remove the restriction on reading freespace while deleting using the more robust iteration --- dependencies/lmdb/libraries/liblmdb/mdb.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/dependencies/lmdb/libraries/liblmdb/mdb.c b/dependencies/lmdb/libraries/liblmdb/mdb.c index 808e0932a..a4f2b7b0a 100644 --- a/dependencies/lmdb/libraries/liblmdb/mdb.c +++ b/dependencies/lmdb/libraries/liblmdb/mdb.c @@ -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; @@ -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 */ @@ -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) @@ -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; @@ -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); @@ -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; @@ -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)); @@ -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 */