Moving resizing outside of creating a transaction.
This commit is contained in:
parent
1d61de104f
commit
d3c4e9e2ff
5 changed files with 58 additions and 34 deletions
|
|
@ -15,6 +15,6 @@ enum class rai_networks
|
||||||
rai_live_network
|
rai_live_network
|
||||||
};
|
};
|
||||||
rai::rai_networks const rai_network = rai_networks::ACTIVE_NETWORK;
|
rai::rai_networks const rai_network = rai_networks::ACTIVE_NETWORK;
|
||||||
int const database_check_interval = rai_network == rai::rai_networks::rai_test_network ? 4 : 1024;
|
int const database_check_interval = rai_network == rai::rai_networks::rai_test_network ? 64 : 4096;
|
||||||
size_t const database_size_increment = rai_network == rai::rai_networks::rai_test_network ? 2 * 1024 * 1024 : 256 * 1024 * 1024;
|
size_t const database_size_increment = rai_network == rai::rai_networks::rai_test_network ? 2 * 1024 * 1024 : 256 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
@ -1043,6 +1043,14 @@ port_mapping (*this),
|
||||||
vote_processor (*this),
|
vote_processor (*this),
|
||||||
warmed_up (0)
|
warmed_up (0)
|
||||||
{
|
{
|
||||||
|
store.environment.sizing_action = [this] ()
|
||||||
|
{
|
||||||
|
auto this_l (shared_from_this ());
|
||||||
|
background ([this_l] ()
|
||||||
|
{
|
||||||
|
this_l->store.environment.handle_environment_sizing ();
|
||||||
|
});
|
||||||
|
};
|
||||||
wallets.observer = [this] (rai::account const & account_a, bool active)
|
wallets.observer = [this] (rai::account const & account_a, bool active)
|
||||||
{
|
{
|
||||||
observers.wallet (account_a, active);
|
observers.wallet (account_a, active);
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,8 @@ void rai::system::generate_rollback (rai::node & node_a, std::vector <rai::accou
|
||||||
}
|
}
|
||||||
|
|
||||||
void rai::system::generate_receive (rai::node & node_a)
|
void rai::system::generate_receive (rai::node & node_a)
|
||||||
|
{
|
||||||
|
std::unique_ptr <rai::block> send_block;
|
||||||
{
|
{
|
||||||
rai::transaction transaction (node_a.store.environment, nullptr, false);
|
rai::transaction transaction (node_a.store.environment, nullptr, false);
|
||||||
rai::uint256_union random_block;
|
rai::uint256_union random_block;
|
||||||
|
|
@ -169,8 +171,12 @@ void rai::system::generate_receive (rai::node & node_a)
|
||||||
{
|
{
|
||||||
rai::pending_key send_hash (i->first);
|
rai::pending_key send_hash (i->first);
|
||||||
rai::pending_info info (i->second);
|
rai::pending_info info (i->second);
|
||||||
auto send_block (node_a.store.block_get (transaction, send_hash.hash));
|
send_block = node_a.store.block_get (transaction, send_hash.hash);
|
||||||
assert (send_block != nullptr);
|
assert (send_block != nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (send_block != nullptr)
|
||||||
|
{
|
||||||
auto receive_error (wallet (0)->receive_sync (static_cast <rai::send_block &> (*send_block), rai::genesis_account, std::numeric_limits<rai::uint128_t>::max ()));
|
auto receive_error (wallet (0)->receive_sync (static_cast <rai::send_block &> (*send_block), rai::genesis_account, std::numeric_limits<rai::uint128_t>::max ()));
|
||||||
(void) receive_error;
|
(void) receive_error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ bool rai::from_string_hex (std::string const & value_a, uint64_t & target_a)
|
||||||
rai::mdb_env::mdb_env (bool & error_a, boost::filesystem::path const & path_a) :
|
rai::mdb_env::mdb_env (bool & error_a, boost::filesystem::path const & path_a) :
|
||||||
open_transactions (0),
|
open_transactions (0),
|
||||||
transaction_iteration (0),
|
transaction_iteration (0),
|
||||||
resizing (false)
|
resizing (false),
|
||||||
|
sizing_action ([this] () { handle_environment_sizing (); })
|
||||||
{
|
{
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
if (path_a.has_parent_path ())
|
if (path_a.has_parent_path ())
|
||||||
|
|
@ -57,7 +58,7 @@ resizing (false)
|
||||||
assert (status1 == 0);
|
assert (status1 == 0);
|
||||||
auto status2 (mdb_env_set_maxdbs (environment, 128));
|
auto status2 (mdb_env_set_maxdbs (environment, 128));
|
||||||
assert (status2 == 0);
|
assert (status2 == 0);
|
||||||
auto status3 (mdb_env_set_mapsize (environment, 2 * database_size_increment));
|
auto status3 (mdb_env_set_mapsize (environment, 0));
|
||||||
assert (status3 == 0);
|
assert (status3 == 0);
|
||||||
auto status4 (mdb_env_open (environment, path_a.string ().c_str (), MDB_NOSUBDIR, 00600));
|
auto status4 (mdb_env_open (environment, path_a.string ().c_str (), MDB_NOSUBDIR, 00600));
|
||||||
error_a = status4 != 0;
|
error_a = status4 != 0;
|
||||||
|
|
@ -90,12 +91,23 @@ rai::mdb_env::operator MDB_env * () const
|
||||||
|
|
||||||
void rai::mdb_env::add_transaction ()
|
void rai::mdb_env::add_transaction ()
|
||||||
{
|
{
|
||||||
|
// Minimize I/O from checking if we need to resive
|
||||||
|
// Too high and the enviroment might overflow
|
||||||
|
// Too low and we're making lots of trips to the disk
|
||||||
|
if ((transaction_iteration++ % rai::database_check_interval) == 0)
|
||||||
|
{
|
||||||
|
sizing_action ();
|
||||||
|
}
|
||||||
std::unique_lock <std::mutex> lock_l (lock);
|
std::unique_lock <std::mutex> lock_l (lock);
|
||||||
|
// Wait for any resizing operations to complete
|
||||||
while (resizing)
|
while (resizing)
|
||||||
{
|
{
|
||||||
resize_notify.wait (lock_l);
|
resize_notify.wait (lock_l);
|
||||||
}
|
}
|
||||||
if ((transaction_iteration % rai::database_check_interval) == 0)
|
++open_transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rai::mdb_env::handle_environment_sizing ()
|
||||||
{
|
{
|
||||||
MDB_stat stats;
|
MDB_stat stats;
|
||||||
mdb_env_stat (environment, &stats);
|
mdb_env_stat (environment, &stats);
|
||||||
|
|
@ -105,23 +117,19 @@ void rai::mdb_env::add_transaction ()
|
||||||
auto slack (info.me_mapsize - load);
|
auto slack (info.me_mapsize - load);
|
||||||
if (slack < (rai::database_size_increment / 4))
|
if (slack < (rai::database_size_increment / 4))
|
||||||
{
|
{
|
||||||
resizing = true;
|
if (!resizing.exchange (true))
|
||||||
auto done (std::chrono::system_clock::now () + std::chrono::milliseconds (500));
|
|
||||||
while (std::chrono::system_clock::now () < done && open_transactions > 0)
|
|
||||||
{
|
{
|
||||||
open_notify.wait_for (lock_l, std::chrono::milliseconds (50));
|
std::unique_lock <std::mutex> lock_l (lock);
|
||||||
|
while (open_transactions > 0)
|
||||||
|
{
|
||||||
|
open_notify.wait (lock_l);
|
||||||
}
|
}
|
||||||
if (open_transactions == 0)
|
|
||||||
{
|
|
||||||
auto next_size (((info.me_mapsize / database_size_increment) + 1) * database_size_increment);
|
auto next_size (((info.me_mapsize / database_size_increment) + 1) * database_size_increment);
|
||||||
mdb_env_set_mapsize (environment, next_size);
|
mdb_env_set_mapsize (environment, next_size);
|
||||||
}
|
|
||||||
resizing = false;
|
resizing = false;
|
||||||
resize_notify.notify_all ();
|
resize_notify.notify_all ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++transaction_iteration;
|
|
||||||
++open_transactions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rai::mdb_env::remove_transaction ()
|
void rai::mdb_env::remove_transaction ()
|
||||||
|
|
|
||||||
|
|
@ -138,13 +138,15 @@ public:
|
||||||
operator MDB_env * () const;
|
operator MDB_env * () const;
|
||||||
void add_transaction ();
|
void add_transaction ();
|
||||||
void remove_transaction ();
|
void remove_transaction ();
|
||||||
|
void handle_environment_sizing ();
|
||||||
MDB_env * environment;
|
MDB_env * environment;
|
||||||
std::mutex lock;
|
std::mutex lock;
|
||||||
std::condition_variable open_notify;
|
std::condition_variable open_notify;
|
||||||
unsigned open_transactions;
|
unsigned open_transactions;
|
||||||
unsigned transaction_iteration;
|
std::atomic_uint transaction_iteration;
|
||||||
std::condition_variable resize_notify;
|
std::condition_variable resize_notify;
|
||||||
bool resizing;
|
std::atomic_bool resizing;
|
||||||
|
std::function <void ()> sizing_action;
|
||||||
};
|
};
|
||||||
class mdb_val
|
class mdb_val
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue