Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove representation table during v15 upgrade #2429

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ());
Expand Down
21 changes: 19 additions & 2 deletions nano/node/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,23 @@ 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;
accounts = accounts_v0;
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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions nano/node/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class mdb_store : public block_store_partial<MDB_val, mdb_store>
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;
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/blockstore_partial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ class block_store_partial : public block_store
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)
Expand Down