Skip to content

Commit

Permalink
If mapped mode was requested, revert to it after loading snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Oct 2, 2023
1 parent 797f045 commit ca9b6a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
13 changes: 8 additions & 5 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <new>
#include <shared_mutex>
#include <utility>

namespace eosio { namespace chain {

Expand Down Expand Up @@ -605,7 +606,9 @@ struct controller_impl {
}
ilog( "Snapshot loaded, lib: ${lib}", ("lib", head->block_num) );

init(check_shutdown);
init(std::move(check_shutdown));
if (conf.revert_to_mapped_mode)
db.revert_to_mapped_mode();
ilog( "Finished initialization from snapshot" );
} catch (boost::interprocess::bad_alloc& e) {
elog( "Failed initialization from snapshot - db storage not configured to have enough storage for the provided snapshot, please increase and retry snapshot" );
Expand All @@ -621,7 +624,7 @@ struct controller_impl {
("genesis_chain_id", genesis_chain_id)("controller_chain_id", chain_id)
);

this->shutdown = shutdown;
this->shutdown = std::move(shutdown);
if( fork_db.head() ) {
if( read_mode == db_read_mode::IRREVERSIBLE && fork_db.head()->id != fork_db.root()->id ) {
fork_db.rollback_head_to_root();
Expand All @@ -643,14 +646,14 @@ struct controller_impl {
} else {
blog.reset( genesis, head->block );
}
init(check_shutdown);
init(std::move(check_shutdown));
}

void startup(std::function<void()> shutdown, std::function<bool()> check_shutdown) {
EOS_ASSERT( db.revision() >= 1, database_exception, "This version of controller::startup does not work with a fresh state database." );
EOS_ASSERT( fork_db.head(), fork_database_exception, "No existing fork database despite existing chain state. Replay required." );

this->shutdown = shutdown;
this->shutdown = std::move(shutdown);
uint32_t lib_num = fork_db.root()->block_num;
auto first_block_num = blog.first_block_num();
if( auto blog_head = blog.head() ) {
Expand All @@ -673,7 +676,7 @@ struct controller_impl {
}
head = fork_db.head();

init(check_shutdown);
init(std::move(check_shutdown));
}


Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace eosio { namespace chain {
bool disable_replay_opts = false;
bool contracts_console = false;
bool allow_ram_billing_in_notify = false;
bool revert_to_mapped_mode = false;
uint32_t maximum_variable_signature_length = chain::config::default_max_variable_signature_length;
bool disable_all_subjective_mitigations = false; //< for developer & testing purposes, can be configured using `disable-all-subjective-mitigations` when `EOSIO_DEVELOPER` build option is provided
uint32_t terminate_at_block = 0;
Expand Down
4 changes: 3 additions & 1 deletion plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,10 @@ void chain_plugin_impl::plugin_initialize(const variables_map& options) {

// when loading a snapshot, all the state will be modified, so use the `shared` mode instead
// of `copy_on_write` to lower memory requirements
if (snapshot_path && chain_config->db_map_mode == pinnable_mapped_file::mapped)
if (snapshot_path && chain_config->db_map_mode == pinnable_mapped_file::mapped) {
chain_config->db_map_mode = pinnable_mapped_file::mapped_shared;
chain_config->revert_to_mapped_mode = true; // revert to `mapped` mode after loading snapshot.
}

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if( options.count("eos-vm-oc-cache-size-mb") )
Expand Down

0 comments on commit ca9b6a9

Please sign in to comment.