Skip to content

Commit 6ceab4a

Browse files
ABWvogel76
authored andcommitted
flush block log/artifacts when it becomes full and new part is opened
Previously files could remain not flushed until they were closed at the end, which could cause them to be broken in case of node crash.
1 parent b33a208 commit 6ceab4a

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

libraries/chain/block_log.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ namespace hive { namespace chain {
460460
// no restrictions
461461
void block_log::flush()
462462
{
463+
my->_artifacts->flush();
463464
// writes to file descriptors are flushed automatically
464465
}
465466

libraries/chain/block_log_artifacts.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ void block_log_artifacts::truncate(uint32_t new_head_block_num)
10441044
_impl->truncate_file(new_head_block_num);
10451045
}
10461046

1047+
void block_log_artifacts::flush()
1048+
{
1049+
dlog( "flushing artifacts" );
1050+
_impl->flush_header();
1051+
}
1052+
10471053
std::string block_log_artifacts::get_artifacts_contents(const fc::optional<uint32_t>& starting_block_number, const fc::optional<uint32_t>& ending_block_number, bool header_only) const
10481054
{
10491055
return _impl->get_artifacts_contents(starting_block_number, ending_block_number, header_only);

libraries/chain/block_log_wrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,12 @@ void block_log_wrapper::internal_append( uint32_t first_block_num, size_t block_
770770
// Is it time to switch to a new file & append there?
771771
if( is_last_number_of_the_file( first_block_num -1 ) && ( block_part_number > _logs.size() ) )
772772
{
773+
if( not _logs.empty() )
774+
{
775+
auto current_part_log = get_head_log();
776+
if( current_part_log )
777+
current_part_log->flush();
778+
}
773779
fc::path new_path = _open_args.data_dir / block_log_file_name_info::get_nth_part_file_name( block_part_number ).c_str();
774780
const auto new_part_log = std::make_shared<block_log>( _app );
775781
internal_open_and_init( new_part_log, new_path, false /*read_only*/ );

libraries/chain/include/hive/chain/block_log_artifacts.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class block_log_artifacts final
110110
void store_block_artifacts(artifact_data_container_t& artifacts_data, const bool is_at_live_sync);
111111

112112
void truncate(uint32_t new_head_block_num);
113+
void flush();
113114

114115
// for block_log_util
115116
std::string get_artifacts_contents(const fc::optional<uint32_t>& starting_block_number, const fc::optional<uint32_t>& ending_block_number, bool header_only) const;

0 commit comments

Comments
 (0)