Skip to content

Commit

Permalink
Remove blockchain_worker_thread_pool::get_instance function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela authored and vogel76 committed Oct 24, 2023
1 parent 1cc7c53 commit a2bfcd2
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 32 deletions.
16 changes: 7 additions & 9 deletions libraries/chain/blockchain_worker_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ void blockchain_worker_thread_pool::impl::thread_function()
}
}

void blockchain_worker_thread_pool::impl_deleter::operator()(blockchain_worker_thread_pool::impl* ptr) const
{
delete ptr;
}

//std::shared_ptr<std::thread> fill_queue_thread = std::make_shared<std::thread>([&](){ fill_pending_queue(input_block_log_path / "block_log"); });
blockchain_worker_thread_pool::blockchain_worker_thread_pool( appbase::application& app ) :
my(std::make_unique<impl>( app, [this]( const std::vector<std::shared_ptr<full_transaction_type>>& full_transactions, data_source_type data_source,
std::optional<uint32_t> block_number ){ this->enqueue_work( full_transactions, data_source, block_number ); } ))
my(std::unique_ptr<impl, impl_deleter>( new impl( app, [this]( const std::vector<std::shared_ptr<full_transaction_type>>& full_transactions, data_source_type data_source,
std::optional<uint32_t> block_number ){ this->enqueue_work( full_transactions, data_source, block_number ); } ) ) )
{
lazy_init();
}
Expand Down Expand Up @@ -510,12 +515,5 @@ void blockchain_worker_thread_pool::shutdown()
thread_pool_size = new_thread_pool_size;
}

/* static */ blockchain_worker_thread_pool& blockchain_worker_thread_pool::get_instance( appbase::application& app )
{
static blockchain_worker_thread_pool thread_pool( app );
thread_pool.lazy_init();
return thread_pool;
}

} } // end namespace hive::chain

6 changes: 3 additions & 3 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ database::~database()
clear_pending();
}

void database::open( const open_args& args, hive::chain::blockchain_worker_thread_pool& thread_pool )
void database::open( const open_args& args )
{
try
{
Expand All @@ -169,14 +169,14 @@ void database::open( const open_args& args, hive::chain::blockchain_worker_threa
);
const bool wipe_shared_file = args.force_replay || args.load_snapshot;
chainbase::database::open( args.shared_mem_dir, args.chainbase_flags, args.shared_file_size, args.database_cfg, &environment_extension, wipe_shared_file );
initialize_state_independent_data(args, thread_pool);
initialize_state_independent_data(args);
load_state_initial_data(args);

}
FC_CAPTURE_LOG_AND_RETHROW( (args.data_dir)(args.shared_mem_dir)(args.shared_file_size) )
}

void database::initialize_state_independent_data(const open_args& args, hive::chain::blockchain_worker_thread_pool& thread_pool)
void database::initialize_state_independent_data(const open_args& args)
{
_my->create_new_decoded_types_data_storage();
_my->_decoded_types_data_storage->register_new_type<irreversible_object_type>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class blockchain_worker_thread_pool
public:
struct impl;
private:
blockchain_worker_thread_pool( appbase::application& app );
class impl_deleter
{
public:
void operator()(blockchain_worker_thread_pool::impl* ptr) const;
};

void lazy_init();
std::unique_ptr<impl> my;
public:
std::unique_ptr<impl, impl_deleter> my;
public:

blockchain_worker_thread_pool( appbase::application& app );

// when we process a block/transaction, we need to know where it came from in
// order to know what processing it needs. e.g., transactions that arrived
// in blocks usually won't have their signatures validated, while stand-alone
Expand Down Expand Up @@ -66,7 +74,6 @@ class blockchain_worker_thread_pool

void shutdown();
static void set_thread_pool_size(uint32_t thread_pool_size);
static blockchain_worker_thread_pool& get_instance( appbase::application& app );
};

} } // end namespace hive::chain
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/hive/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace chain {
*
* @param data_dir Path to open or create database in
*/
void open( const open_args& args, hive::chain::blockchain_worker_thread_pool& thread_pool );
void open( const open_args& args );

private:

Expand All @@ -204,7 +204,7 @@ namespace chain {
void remove_proposal_votes_for_accounts_without_voting_rights();

/// Allows to load all data being independent to the persistent storage held in shared memory file.
void initialize_state_independent_data(const open_args& args, hive::chain::blockchain_worker_thread_pool& thread_pool);
void initialize_state_independent_data(const open_args& args);

void begin_type_register_process(util::abstract_type_registrar& r);

Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void chain_plugin_impl::open()
db_open_args.block_log_compression_level,
db_open_args.enable_block_log_auto_fixing,
thread_pool );
db.open( db_open_args, thread_pool );
db.open( db_open_args );

if( dump_memory_details )
{
Expand Down
2 changes: 1 addition & 1 deletion programs/util/block_log_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char** argv)
try
{
appbase::application theApp;
hive::chain::blockchain_worker_thread_pool& thread_pool = hive::chain::blockchain_worker_thread_pool::get_instance( theApp );
hive::chain::blockchain_worker_thread_pool thread_pool = hive::chain::blockchain_worker_thread_pool( theApp );

boost::program_options::options_description options("Allowed options");
options.add_options()("input-block-log,i", boost::program_options::value<std::string>()->required(), "The path pointing the input block log file");
Expand Down
2 changes: 1 addition & 1 deletion programs/util/block_log_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ bool get_block_artifacts(const fc::path& block_log_path, const std::optional<uin
int main(int argc, char** argv)
{
appbase::application theApp;
hive::chain::blockchain_worker_thread_pool& thread_pool = hive::chain::blockchain_worker_thread_pool::get_instance( theApp );
hive::chain::blockchain_worker_thread_pool thread_pool = hive::chain::blockchain_worker_thread_pool( theApp );

boost::program_options::options_description global_options("Global options");
global_options.add_options()("jobs,j", boost::program_options::value<int>()->default_value(4), "The number of worker threads to spawn");
Expand Down
2 changes: 1 addition & 1 deletion programs/util/compress_block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ int main(int argc, char** argv)
try
{
appbase::application theApp;
hive::chain::blockchain_worker_thread_pool& thread_pool = hive::chain::blockchain_worker_thread_pool::get_instance( theApp );
hive::chain::blockchain_worker_thread_pool thread_pool = hive::chain::blockchain_worker_thread_pool( theApp );
// zstd doesn't have well-defined levels, so we get these at runtime
std::ostringstream zstd_levels_description_stream;
zstd_levels_description_stream << "The zstd compression level to use";
Expand Down
4 changes: 2 additions & 2 deletions programs/util/dump_hive_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FC_REFLECT( hive_schema, (schema_map)(chain_object_types) )
int main( int argc, char** argv, char** envp )
{
appbase::application app;
hive::chain::blockchain_worker_thread_pool& thread_pool = hive::chain::blockchain_worker_thread_pool::get_instance( app );
hive::chain::blockchain_worker_thread_pool thread_pool = hive::chain::blockchain_worker_thread_pool( app );

hive::chain::database db( app );
hive::chain::sync_block_writer block_writer( db, app );
Expand All @@ -96,7 +96,7 @@ int main( int argc, char** argv, char** envp )
db_args.block_log_compression_level,
db_args.enable_block_log_auto_fixing,
thread_pool );
db.open( db_args, thread_pool );
db.open( db_args );

hive_schema ss;

Expand Down
2 changes: 1 addition & 1 deletion programs/util/test_block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main( int argc, char** argv, char** envp )
try
{
appbase::application theApp;
hive::chain::blockchain_worker_thread_pool& thread_pool = hive::chain::blockchain_worker_thread_pool::get_instance( theApp );
hive::chain::blockchain_worker_thread_pool thread_pool = hive::chain::blockchain_worker_thread_pool( theApp );
//hive::chain::database db;
hive::chain::block_log log( theApp );

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/db_fixture/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ fc::path common_init( appbase::application& app, const std::function< void( appb
return _data_dir;
}

database_fixture::database_fixture(): thread_pool( hive::chain::blockchain_worker_thread_pool::get_instance( theApp ) )
{
}

fc::ecc::private_key database_fixture::generate_private_key(string seed)
{
static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate( fc::sha256::hash( string( "init_key" ) ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/db_fixture/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ struct database_fixture {
bool skip_key_index_test = false;

appbase::application theApp;
hive::chain::blockchain_worker_thread_pool& thread_pool;
hive::chain::blockchain_worker_thread_pool* thread_pool = nullptr;

database_fixture();
database_fixture() {}
virtual ~database_fixture() {}

static fc::ecc::private_key generate_private_key( string seed = "init_key" );
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/db_fixture/hived_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ void hived_fixture::postponed_init_impl( const config_arg_override_t& config_arg
BOOST_REQUIRE( db );
db->_log_hardforks = false;

thread_pool = &chain.get_thread_pool();
BOOST_REQUIRE( thread_pool );

// Load configuration file into logging config structure, used to create loggers & appenders.
// Store the structure for further examination (in tests).
_logging_config = app.load_logging_config();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void open_test_database( database& db, sync_block_writer& sbw,
args.block_log_compression_level,
args.enable_block_log_auto_fixing,
thread_pool );
db.open( args, thread_pool );
db.open( args );
}

#define SET_UP_DATABASE( NAME, APP, DATA_DIR_PATH, LOG_HARDFORKS ) \
Expand Down

0 comments on commit a2bfcd2

Please sign in to comment.