fcmp++ lmdb: migration touchups

- If locked output migration step completes, then program exits
while migration step to grow the tree is in progress, make sure
the migration picks back up where it left off growing the tree.
- Make sure db cursor gets set in all cases when renaming
block infn table.
This commit is contained in:
j-berman 2024-09-11 18:34:42 -07:00
parent b055eb3f61
commit 043597426b

View File

@ -6900,6 +6900,12 @@ void BlockchainLMDB::migrate_5_6()
if (result != MDB_NOTFOUND)
{
cached_last_o = *(const tmp_output_cache*)v_last_output.mv_data;
if (n_outputs < cached_last_o.n_outputs_read)
throw0(DB_ERROR("Unexpected n_outputs_read on cached last output"));
if (n_outputs == cached_last_o.n_outputs_read)
break;
MDEBUG("Found cached output " << cached_last_o.ok.output_id
<< ", migrated " << cached_last_o.n_outputs_read << " outputs already");
found_cached_output = true;
@ -6910,8 +6916,6 @@ void BlockchainLMDB::migrate_5_6()
const std::size_t outkey_size = (cached_last_o.amount == 0) ? sizeof(outkey) : sizeof(pre_rct_outkey);
v = {outkey_size, (void *)&cached_last_o.ok};
if (n_outputs < cached_last_o.n_outputs_read)
throw0(DB_ERROR("Unexpected n_outputs_read on cached last output"));
i = cached_last_o.n_outputs_read;
op = MDB_NEXT;
}
@ -6931,6 +6935,13 @@ void BlockchainLMDB::migrate_5_6()
op = MDB_NEXT;
if (result == MDB_NOTFOUND)
{
// Indicate we've read all outputs so we know the migration step is complete
last_output.n_outputs_read = n_outputs;
MDB_val_set(v_last_output, last_output);
result = mdb_cursor_put(c_tmp_last_output, (MDB_val*)&zerokval, &v_last_output, 0);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to update max output id: ", result).c_str()));
batch_stop();
break;
}
@ -7126,7 +7137,10 @@ void BlockchainLMDB::migrate_5_6()
if (result)
throw0(DB_ERROR(lmdb_error("Failed to delete old block_info table: ", result).c_str()));
MDB_cursor *c_cur = c_new_block_info;
MDB_cursor *c_cur;
result = mdb_cursor_open(txn, m_block_info, &c_cur);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_infn: ", result).c_str()));
RENAME_DB("block_infn");
mdb_dbi_close(m_env, m_block_info);
@ -7137,6 +7151,7 @@ void BlockchainLMDB::migrate_5_6()
}
} while(0);
// Update db version
uint32_t version = 6;
v.mv_data = (void *)&version;
v.mv_size = sizeof(version);