Moved the final_vote LMDB table handler to its store class
This commit is contained in:
parent
96c4bfc988
commit
79c695167d
4 changed files with 41 additions and 32 deletions
|
@ -1869,33 +1869,39 @@ namespace lmdb
|
|||
}
|
||||
}
|
||||
|
||||
TEST (mdb_block_store, upgrade_v20_v21)
|
||||
namespace nano
|
||||
{
|
||||
if (nano::rocksdb_config::using_rocksdb_in_tests ())
|
||||
{
|
||||
// Don't test this in rocksdb mode
|
||||
return;
|
||||
}
|
||||
auto path (nano::unique_path ());
|
||||
nano::logger_mt logger;
|
||||
nano::stat stats;
|
||||
namespace lmdb
|
||||
{
|
||||
TEST (mdb_block_store, upgrade_v20_v21)
|
||||
{
|
||||
if (nano::rocksdb_config::using_rocksdb_in_tests ())
|
||||
{
|
||||
// Don't test this in rocksdb mode
|
||||
return;
|
||||
}
|
||||
auto path (nano::unique_path ());
|
||||
nano::logger_mt logger;
|
||||
nano::stat stats;
|
||||
{
|
||||
nano::lmdb::store store (logger, path, nano::dev::constants);
|
||||
nano::ledger ledger (store, stats, nano::dev::constants);
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.initialize (transaction, ledger.cache, ledger.constants);
|
||||
// Delete pruned table
|
||||
ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.final_vote_store.final_votes_handle, 1));
|
||||
store.version.put (transaction, 20);
|
||||
}
|
||||
// Upgrading should create the table
|
||||
nano::lmdb::store store (logger, path, nano::dev::constants);
|
||||
nano::ledger ledger (store, stats, nano::dev::constants);
|
||||
auto transaction (store.tx_begin_write ());
|
||||
store.initialize (transaction, ledger.cache, ledger.constants);
|
||||
// Delete pruned table
|
||||
ASSERT_FALSE (mdb_drop (store.env.tx (transaction), store.final_votes_handle, 1));
|
||||
store.version.put (transaction, 20);
|
||||
}
|
||||
// Upgrading should create the table
|
||||
nano::lmdb::store store (logger, path, nano::dev::constants);
|
||||
ASSERT_FALSE (store.init_error ());
|
||||
ASSERT_NE (store.final_votes_handle, 0);
|
||||
ASSERT_FALSE (store.init_error ());
|
||||
ASSERT_NE (store.final_vote_store.final_votes_handle, 0);
|
||||
|
||||
// Version should be correct
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_LT (19, store.version.get (transaction));
|
||||
// Version should be correct
|
||||
auto transaction (store.tx_begin_read ());
|
||||
ASSERT_LT (19, store.version.get (transaction));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST (mdb_block_store, upgrade_backup)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <nano/secure/store.hpp>
|
||||
|
||||
#include <lmdb/libraries/liblmdb/lmdb.h>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
namespace lmdb
|
||||
|
@ -24,6 +26,12 @@ namespace lmdb
|
|||
nano::store_iterator<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a) const override;
|
||||
nano::store_iterator<nano::qualified_root, nano::block_hash> end () const override;
|
||||
void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::qualified_root, nano::block_hash>, nano::store_iterator<nano::qualified_root, nano::block_hash>)> const & action_a) const override;
|
||||
|
||||
/**
|
||||
* Maps root to block hash for generated final votes.
|
||||
* nano::qualified_root -> nano::block_hash
|
||||
*/
|
||||
MDB_dbi final_votes_handle{ 0 };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ void nano::lmdb::store::open_databases (bool & error_a, nano::transaction const
|
|||
account_store.accounts_handle = account_store.accounts_v0_handle;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "pending", flags, &pending_store.pending_v0_handle) != 0;
|
||||
pending_store.pending_handle = pending_store.pending_v0_handle;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "final_votes", flags, &final_votes_handle) != 0;
|
||||
error_a |= mdb_dbi_open (env.tx (transaction_a), "final_votes", flags, &final_vote_store.final_votes_handle) != 0;
|
||||
|
||||
auto version_l = version.get (transaction_a);
|
||||
if (version_l < 19)
|
||||
|
@ -774,7 +774,7 @@ void nano::lmdb::store::upgrade_v19_to_v20 (nano::write_transaction const & tran
|
|||
void nano::lmdb::store::upgrade_v20_to_v21 (nano::write_transaction const & transaction_a)
|
||||
{
|
||||
logger.always_log ("Preparing v20 to v21 database upgrade...");
|
||||
mdb_dbi_open (env.tx (transaction_a), "final_votes", MDB_CREATE, &final_votes_handle);
|
||||
mdb_dbi_open (env.tx (transaction_a), "final_votes", MDB_CREATE, &final_vote_store.final_votes_handle);
|
||||
version.put (transaction_a, 21);
|
||||
logger.always_log ("Finished creating new final_vote table");
|
||||
}
|
||||
|
@ -881,7 +881,7 @@ MDB_dbi nano::lmdb::store::table_to_dbi (tables table_a) const
|
|||
case tables::confirmation_height:
|
||||
return confirmation_height_store.confirmation_height_handle;
|
||||
case tables::final_votes:
|
||||
return final_votes_handle;
|
||||
return final_vote_store.final_votes_handle;
|
||||
default:
|
||||
release_assert (false);
|
||||
return peer_store.peers_handle;
|
||||
|
|
|
@ -154,12 +154,6 @@ namespace lmdb
|
|||
*/
|
||||
MDB_dbi blocks_handle{ 0 };
|
||||
|
||||
/**
|
||||
* Maps root to block hash for generated final votes.
|
||||
* nano::qualified_root -> nano::block_hash
|
||||
*/
|
||||
MDB_dbi final_votes_handle{ 0 };
|
||||
|
||||
bool exists (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a) const;
|
||||
|
||||
int get (nano::transaction const & transaction_a, tables table_a, nano::mdb_val const & key_a, nano::mdb_val & value_a) const;
|
||||
|
@ -250,6 +244,7 @@ namespace lmdb
|
|||
friend class mdb_block_store_upgrade_v14_v15_Test;
|
||||
friend class mdb_block_store_upgrade_v15_v16_Test;
|
||||
friend class mdb_block_store_upgrade_v19_v20_Test;
|
||||
friend class mdb_block_store_upgrade_v20_v21_Test;
|
||||
friend void modify_account_info_to_v14 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t, nano::block_hash const &);
|
||||
friend void modify_confirmation_height_to_v15 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue