CLI to clear online_weight & peers (#1689)

* CLI to clear online_weight & peers

* Fix

* Proper transactions environments
This commit is contained in:
Sergey Kroshnin 2019-02-04 20:53:57 +03:00 committed by GitHub
commit f42c3d8496
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 5 deletions

View file

@ -29,10 +29,12 @@ void nano::add_node_options (boost::program_options::options_description & descr
("account_key", "Get the public key for <account>")
("vacuum", "Compact database. If data_path is missing, the database in data directory is compacted.")
("snapshot", "Compact database and create snapshot, functions similar to vacuum but does not replace the existing database")
("unchecked_clear", "Clear unchecked blocks")
("data_path", boost::program_options::value<std::string> (), "Use the supplied path as the data directory")
("delete_node_id", "Delete the node ID in the database")
("clear_send_ids", "Remove all send IDs from the database (dangerous: not intended for production use)")
("delete_node_id", "Delete the node ID in the database")
("online_weight_clear", "Clear online weight history records")
("peer_clear", "Clear online peers database dump")
("unchecked_clear", "Clear unchecked blocks")
("diagnostics", "Run internal diagnostics")
("key_create", "Generates a adhoc random keypair and prints it to stdout")
("key_expand", "Derive public key and account number from <key>")
@ -163,9 +165,19 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
}
if (vm.count ("clear_send_ids"))
{
auto transaction (node.node->store.tx_begin_write ());
auto transaction (node.node->wallets.tx_begin_write ());
node.node->wallets.clear_send_ids (transaction);
}
if (vm.count ("online_weight_clear"))
{
auto transaction (node.node->store.tx_begin_write ());
node.node->store.online_weight_clear (transaction);
}
if (vm.count ("peer_clear"))
{
auto transaction (node.node->store.tx_begin_write ());
node.node->store.peer_clear (transaction);
}
success = node.node->copy_with_compaction (vacuum_path);
}
@ -219,9 +231,19 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
}
if (vm.count ("clear_send_ids"))
{
auto transaction (node.node->store.tx_begin_write ());
auto transaction (node.node->wallets.tx_begin_write ());
node.node->wallets.clear_send_ids (transaction);
}
if (vm.count ("online_weight_clear"))
{
auto transaction (node.node->store.tx_begin_write ());
node.node->store.online_weight_clear (transaction);
}
if (vm.count ("peer_clear"))
{
auto transaction (node.node->store.tx_begin_write ());
node.node->store.peer_clear (transaction);
}
success = node.node->copy_with_compaction (snapshot_path);
}
if (success)
@ -262,10 +284,26 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
{
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
inactive_node node (data_path);
auto transaction (node.node->store.tx_begin_write ());
auto transaction (node.node->wallets.tx_begin_write ());
node.node->wallets.clear_send_ids (transaction);
std::cerr << "Send IDs deleted" << std::endl;
}
else if (vm.count ("online_weight_clear"))
{
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
inactive_node node (data_path);
auto transaction (node.node->store.tx_begin_write ());
node.node->store.online_weight_clear (transaction);
std::cerr << "Onine weight records are removed" << std::endl;
}
else if (vm.count ("peer_clear"))
{
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
inactive_node node (data_path);
auto transaction (node.node->store.tx_begin_write ());
node.node->store.peer_clear (transaction);
std::cerr << "Database peers are removed" << std::endl;
}
else if (vm.count ("diagnostics"))
{
inactive_node node (data_path);

View file

@ -2180,6 +2180,12 @@ size_t nano::mdb_store::online_weight_count (nano::transaction const & transacti
return online_weight_stats.ms_entries;
}
void nano::mdb_store::online_weight_clear (nano::transaction const & transaction_a)
{
auto status (mdb_drop (env.tx (transaction_a), online_weight, 0));
release_assert (status == 0);
}
void nano::mdb_store::flush (nano::transaction const & transaction_a)
{
{

View file

@ -244,6 +244,7 @@ public:
nano::store_iterator<uint64_t, nano::amount> online_weight_begin (nano::transaction const &) override;
nano::store_iterator<uint64_t, nano::amount> online_weight_end () override;
size_t online_weight_count (nano::transaction const &) const override;
void online_weight_clear (nano::transaction const &) override;
std::mutex cache_mutex;
std::unordered_map<nano::account, std::shared_ptr<nano::vote>> vote_cache_l1;

View file

@ -293,6 +293,7 @@ public:
virtual nano::store_iterator<uint64_t, nano::amount> online_weight_begin (nano::transaction const &) = 0;
virtual nano::store_iterator<uint64_t, nano::amount> online_weight_end () = 0;
virtual size_t online_weight_count (nano::transaction const &) const = 0;
virtual void online_weight_clear (nano::transaction const &) = 0;
virtual void version_put (nano::transaction const &, int) = 0;
virtual int version_get (nano::transaction const &) = 0;