Skip to content

Commit

Permalink
Hid head-or-not block raw data access in block_log class
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucius committed Dec 17, 2024
1 parent bec4daf commit 8d5912e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
14 changes: 14 additions & 0 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ namespace hive { namespace chain {
return std::make_tuple(std::move(serialized_data), serialized_data_size, std::move(this_block_artifacts));
}

std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::block_attributes_t> block_log::read_common_raw_block_data_by_num(uint32_t block_num) const
{
if( block_num == my->_artifacts->read_head_block_num() )
{
return read_raw_head_block();
}
else
{
std::tuple<std::unique_ptr<char[]>, size_t, hive::chain::block_log_artifacts::artifacts_t> data_with_artifacts =
read_raw_block_data_by_num(block_num);
return std::make_tuple(std::get<0>(std::move(data_with_artifacts)), std::get<1>(data_with_artifacts), std::get<2>(data_with_artifacts).attributes);
}
}

// threading guarantees:
// - this function may only be called by one thread at a time
// - It is safe to call `append` while any number of other threads
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/block_log_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ std::tuple<std::unique_ptr<char[]>, size_t, block_attributes_t> block_log_wrappe
return get_head_log()->read_raw_head_block();
}

std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::artifacts_t> block_log_wrapper::read_raw_block_data_by_num(uint32_t block_num) const
std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::block_attributes_t> block_log_wrapper::read_common_raw_block_data_by_num(uint32_t block_num) const
{
const block_log_ptr_t log = get_block_log_corresponding_to( block_num );
FC_ASSERT( log,
"Unable to find block log corresponding to block number ${block_num}", (block_num));
return log->read_raw_block_data_by_num( block_num );
return log->read_common_raw_block_data_by_num( block_num );
}

void block_log_wrapper::append( const std::shared_ptr<full_block_type>& full_block, const bool is_at_live_sync )
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/hive/chain/block_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace hive { namespace chain {
block_log_artifacts::artifact_container_t& plural_of_artifacts);

void flush();
std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::block_attributes_t> read_common_raw_block_data_by_num(uint32_t block_num) const;
std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::artifacts_t> read_raw_block_data_by_num(uint32_t block_num) const;
void multi_read_raw_block_data(uint32_t first_block_num, uint32_t last_block_num_from_disk,
block_log_artifacts::artifact_container_t& plural_of_block_artifacts,
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/hive/chain/block_log_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace hive { namespace chain {

// Methods wrapping safely block_log ones.
std::tuple<std::unique_ptr<char[]>, size_t, block_attributes_t> read_raw_head_block() const;
std::tuple<std::unique_ptr<char[]>, size_t, block_log_artifacts::artifacts_t>
read_raw_block_data_by_num(uint32_t block_num) const;
std::tuple<std::unique_ptr<char[]>, size_t, block_attributes_t>
read_common_raw_block_data_by_num(uint32_t block_num) const;
void multi_read_raw_block_data(uint32_t first_block_num, uint32_t last_block_num_from_disk,
block_log_artifacts::artifact_container_t& plural_of_block_artifacts,
std::unique_ptr<char[]>& block_data_buffer, size_t& block_data_buffer_size ) const;
Expand Down
11 changes: 2 additions & 9 deletions programs/util/compress_block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,8 @@ void fill_pending_queue(const fc::path &input_path, const bool read_only, uint32
block_to_compress *uncompressed_block = new block_to_compress;
uncompressed_block->block_number = current_block_number;

std::tuple<std::unique_ptr<char[]>, size_t, hive::chain::block_log::block_attributes_t> raw_compressed_block_data;
if (current_block_number == head_block_num)
raw_compressed_block_data = log_reader->read_raw_head_block();
else
{
std::tuple<std::unique_ptr<char[]>, size_t, hive::chain::block_log_artifacts::artifacts_t> data_with_artifacts =
log_reader->read_raw_block_data_by_num(current_block_number);
raw_compressed_block_data = std::make_tuple(std::get<0>(std::move(data_with_artifacts)), std::get<1>(data_with_artifacts), std::get<2>(data_with_artifacts).attributes);
}
std::tuple<std::unique_ptr<char[]>, size_t, hive::chain::block_log::block_attributes_t> raw_compressed_block_data =
log_reader->read_common_raw_block_data_by_num(current_block_number);
std::tuple<std::unique_ptr<char[]>, size_t> raw_block_data =
hive::chain::block_log_compression::decompress_raw_block(std::move(raw_compressed_block_data));

Expand Down

0 comments on commit 8d5912e

Please sign in to comment.