Remove representation table during upgrade (#2429)
This commit is contained in:
parent
198b311d01
commit
14a90d0ceb
4 changed files with 57 additions and 8 deletions
|
@ -1698,11 +1698,6 @@ TEST (mdb_block_store, upgrade_v14_v15)
|
|||
ASSERT_FALSE (store.confirmation_height_get (transaction, nano::genesis_account, confirmation_height));
|
||||
ASSERT_EQ (confirmation_height, 1);
|
||||
|
||||
// The representation table should be deleted
|
||||
auto error_get_representation (mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
|
||||
ASSERT_NE (error_get_representation, MDB_SUCCESS);
|
||||
ASSERT_EQ (store.representation, 0);
|
||||
|
||||
// accounts_v1, state_blocks_v1 & pending_v1 tables should be deleted
|
||||
auto error_get_accounts_v1 (mdb_get (store.env.tx (transaction), store.accounts_v1, nano::mdb_val (nano::genesis_account), value));
|
||||
ASSERT_NE (error_get_accounts_v1, MDB_SUCCESS);
|
||||
|
@ -1731,6 +1726,42 @@ TEST (mdb_block_store, upgrade_v14_v15)
|
|||
ASSERT_LT (14, store.version_get (transaction));
|
||||
}
|
||||
|
||||
TEST (mdb_block_store, upgrade_v15_v16)
|
||||
{
|
||||
auto path (nano::unique_path ());
|
||||
nano::mdb_val value;
|
||||
{
|
||||
nano::genesis genesis;
|
||||
nano::logger_mt logger;
|
||||
nano::mdb_store store (logger, path);
|
||||
nano::stat stats;
|
||||
nano::ledger ledger (store, stats);
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
|
||||
// The representation table should get removed after, so readd it so that we can later confirm this actually happens
|
||||
auto txn = store.env.tx (transaction);
|
||||
ASSERT_FALSE (mdb_dbi_open (txn, "representation", MDB_CREATE, &store.representation));
|
||||
auto weight = ledger.rep_weights.representation_get (nano::genesis_account);
|
||||
ASSERT_EQ (MDB_SUCCESS, mdb_put (txn, store.representation, nano::mdb_val (nano::genesis_account), nano::mdb_val (nano::uint128_union (weight)), 0));
|
||||
// Lower the database to the previous version
|
||||
store.version_put (transaction, 15);
|
||||
// Confirm the rep weight exists in the database
|
||||
ASSERT_EQ (MDB_SUCCESS, mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
|
||||
}
|
||||
|
||||
// Now do the upgrade
|
||||
nano::logger_mt logger;
|
||||
auto error (false);
|
||||
nano::mdb_store store (logger, path);
|
||||
ASSERT_FALSE (error);
|
||||
auto transaction (store.tx_begin_read ());
|
||||
|
||||
// The representation table should now be deleted
|
||||
auto error_get_representation (mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
|
||||
ASSERT_NE (MDB_SUCCESS, error_get_representation);
|
||||
ASSERT_EQ (store.representation, 0);
|
||||
}
|
||||
|
||||
TEST (mdb_block_store, upgrade_backup)
|
||||
{
|
||||
auto dir (nano::unique_path ());
|
||||
|
|
|
@ -176,6 +176,7 @@ void nano::mdb_store::open_databases (bool & error_a, nano::transaction const &
|
|||
error_a |= mdb_dbi_open (env.tx (transaction_a), "confirmation_height", flags, &confirmation_height) != 0;
|
||||
if (!full_sideband (transaction_a))
|
||||
{
|
||||
// The blocks_info database is no longer used, but need opening so that it can be deleted during an upgrade
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "blocks_info", flags, &blocks_info) != 0;
|
||||
}
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "accounts", flags, &accounts_v0) != 0;
|
||||
|
@ -183,8 +184,15 @@ void nano::mdb_store::open_databases (bool & error_a, nano::transaction const &
|
|||
error_a |= mdb_dbi_open (env.tx (transaction_a), "pending", flags, &pending_v0) != 0;
|
||||
pending = pending_v0;
|
||||
|
||||
if (version_get (transaction_a) < 16)
|
||||
{
|
||||
// The representation database is no longer used, but need opening so that it can be deleted during an upgrade
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "representation", flags, &representation) != 0;
|
||||
}
|
||||
|
||||
if (version_get (transaction_a) < 15)
|
||||
{
|
||||
// These databases are no longer used, but need opening so they can be deleted during an upgrade
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "state", flags, &state_blocks_v0) != 0;
|
||||
state_blocks = state_blocks_v0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "accounts_v1", flags, &accounts_v1) != 0;
|
||||
|
@ -233,6 +241,8 @@ bool nano::mdb_store::do_upgrades (nano::write_transaction & transaction_a, bool
|
|||
upgrade_v14_to_v15 (transaction_a);
|
||||
needs_vacuuming = true;
|
||||
case 15:
|
||||
upgrade_v15_to_v16 (transaction_a);
|
||||
case 16:
|
||||
break;
|
||||
default:
|
||||
logger.always_log (boost::str (boost::format ("The version of the ledger (%1%) is too high for this node") % version_l));
|
||||
|
@ -662,15 +672,22 @@ void nano::mdb_store::upgrade_v14_to_v15 (nano::write_transaction & transaction_
|
|||
mdb_put (env.tx (transaction_a), pending, nano::mdb_val (pending_key_pending_info_pair.first), nano::mdb_val (pending_key_pending_info_pair.second), MDB_APPEND);
|
||||
}
|
||||
|
||||
version_put (transaction_a, 15);
|
||||
logger.always_log ("Finished epoch merge upgrade. Preparing vacuum...");
|
||||
}
|
||||
|
||||
void nano::mdb_store::upgrade_v15_to_v16 (nano::write_transaction & transaction_a)
|
||||
{
|
||||
// Representation table is no longer used
|
||||
assert (representation != 0);
|
||||
if (representation != 0)
|
||||
{
|
||||
auto status (mdb_drop (env.tx (transaction_a), representation, 1));
|
||||
release_assert (status == MDB_SUCCESS);
|
||||
representation = 0;
|
||||
}
|
||||
version_put (transaction_a, 15);
|
||||
logger.always_log ("Finished epoch merge upgrade. Preparing vacuum...");
|
||||
|
||||
version_put (transaction_a, 16);
|
||||
}
|
||||
|
||||
/** Takes a filepath, appends '_backup_<timestamp>' to the end (but before any extension) and saves that file in the same directory */
|
||||
|
|
|
@ -239,6 +239,7 @@ private:
|
|||
void upgrade_v12_to_v13 (nano::write_transaction &, size_t);
|
||||
void upgrade_v13_to_v14 (nano::write_transaction const &);
|
||||
void upgrade_v14_to_v15 (nano::write_transaction &);
|
||||
void upgrade_v15_to_v16 (nano::write_transaction &);
|
||||
void open_databases (bool &, nano::transaction const &, unsigned);
|
||||
|
||||
int drop (nano::write_transaction const & transaction_a, tables table_a) override;
|
||||
|
|
|
@ -770,7 +770,7 @@ protected:
|
|||
nano::network_params network_params;
|
||||
std::unordered_map<nano::account, std::shared_ptr<nano::vote>> vote_cache_l1;
|
||||
std::unordered_map<nano::account, std::shared_ptr<nano::vote>> vote_cache_l2;
|
||||
static int constexpr version{ 15 };
|
||||
static int constexpr version{ 16 };
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<nano::block> block_random (nano::transaction const & transaction_a, tables table_a)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue