This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Handle special case in trim_blocklog_front #10370
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8625701
Handle trim_blocklog_front special case
nickjjzhao 129b0b3
Update comments
nickjjzhao db07176
Simplify the while loop code
nickjjzhao 42935f1
Update code to avoid alignment issues
nickjjzhao a1cc6f9
Add test cases
nickjjzhao 879ff5b
Merge branch 'release/2.0.x' into jjz-epe895-trim-blocklog
nickjjzhao d4eb59c
Update the new test case
nickjjzhao 7baa80e
Move a method out of header file as the method is created for unit test
nickjjzhao 90499a4
Rename a function
nickjjzhao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ void remove_existing_blocks(controller::config& config) { | |||||||||||||||||
remove(block_index_path); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
void block_log_set_buff_len(uint64_t len); | ||||||||||||||||||
|
||||||||||||||||||
BOOST_AUTO_TEST_SUITE(restart_chain_tests) | ||||||||||||||||||
|
||||||||||||||||||
BOOST_AUTO_TEST_CASE(test_existing_state_without_block_log) | ||||||||||||||||||
|
@@ -78,4 +80,73 @@ BOOST_AUTO_TEST_CASE(test_restart_with_different_chain_id) | |||||||||||||||||
BOOST_REQUIRE_EXCEPTION(other.open(chain_id), chain_id_type_exception, fc_exception_message_starts_with("chain ID in state ")); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
namespace{ | ||||||||||||||||||
struct scoped_temp_path { | ||||||||||||||||||
boost::filesystem::path path; | ||||||||||||||||||
scoped_temp_path() { | ||||||||||||||||||
path = boost::filesystem::unique_path(); | ||||||||||||||||||
if (boost::unit_test::framework::master_test_suite().argc >= 2) { | ||||||||||||||||||
path += boost::unit_test::framework::master_test_suite().argv[1]; | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
~scoped_temp_path() { | ||||||||||||||||||
boost::filesystem::remove_all(path); | ||||||||||||||||||
} | ||||||||||||||||||
}; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
enum class buf_len_type { small, medium, large }; | ||||||||||||||||||
|
||||||||||||||||||
void trim_blocklog_front(uint32_t truncate_at_block, buf_len_type len_type) { | ||||||||||||||||||
tester chain; | ||||||||||||||||||
chain.produce_blocks(30); | ||||||||||||||||||
chain.close(); | ||||||||||||||||||
|
||||||||||||||||||
namespace bfs = boost::filesystem; | ||||||||||||||||||
|
||||||||||||||||||
auto blocks_dir = chain.get_config().blocks_dir; | ||||||||||||||||||
auto old_index_size = fc::file_size(blocks_dir / "blocks.index"); | ||||||||||||||||||
|
||||||||||||||||||
scoped_temp_path temp1, temp2; | ||||||||||||||||||
boost::filesystem::create_directory(temp1.path); | ||||||||||||||||||
bfs::copy(blocks_dir / "blocks.log", temp1.path / "blocks.log"); | ||||||||||||||||||
bfs::copy(blocks_dir / "blocks.index", temp1.path / "blocks.index"); | ||||||||||||||||||
|
||||||||||||||||||
trim_data old_log(temp1.path); | ||||||||||||||||||
uint64_t blk_size = old_log.block_pos(30) - old_log.block_pos(29); | ||||||||||||||||||
uint64_t log_size = old_log.block_pos(30) + blk_size; | ||||||||||||||||||
|
||||||||||||||||||
switch (len_type){ | ||||||||||||||||||
case buf_len_type::small: | ||||||||||||||||||
block_log_set_buff_len( blk_size + (sizeof(uint64_t) - 1)); | ||||||||||||||||||
break; | ||||||||||||||||||
case buf_len_type::medium: | ||||||||||||||||||
block_log_set_buff_len( log_size / 3); | ||||||||||||||||||
break; | ||||||||||||||||||
case buf_len_type::large: | ||||||||||||||||||
block_log_set_buff_len(log_size); | ||||||||||||||||||
break; | ||||||||||||||||||
default: | ||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
BOOST_CHECK( block_log::trim_blocklog_front(temp1.path, temp2.path, truncate_at_block) == true); | ||||||||||||||||||
trim_data new_log(temp1.path); | ||||||||||||||||||
BOOST_CHECK(new_log.first_block == truncate_at_block); | ||||||||||||||||||
BOOST_CHECK(new_log.last_block == old_log.last_block); | ||||||||||||||||||
BOOST_CHECK(old_log.version == new_log.version); | ||||||||||||||||||
|
||||||||||||||||||
int num_blocks_trimmed = truncate_at_block - 1; | ||||||||||||||||||
BOOST_CHECK(fc::file_size(temp1.path / "blocks.index") == old_index_size - sizeof(uint64_t) * num_blocks_trimmed); | ||||||||||||||||||
} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you follow the example in eos/unittests/restart_chain_tests.cpp Lines 651 to 658 in ce50319
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified. |
||||||||||||||||||
|
||||||||||||||||||
BOOST_AUTO_TEST_CASE(test_trim_blocklog_front) { | ||||||||||||||||||
trim_blocklog_front(5, buf_len_type::small); | ||||||||||||||||||
trim_blocklog_front(6, buf_len_type::small); | ||||||||||||||||||
trim_blocklog_front(10, buf_len_type::medium); | ||||||||||||||||||
trim_blocklog_front(11, buf_len_type::medium); | ||||||||||||||||||
trim_blocklog_front(15, buf_len_type::large); | ||||||||||||||||||
trim_blocklog_front(16, buf_len_type::large); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
BOOST_AUTO_TEST_SUITE_END() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop can be simplified to work within block boundaries only, for those doesn't fit into block boundaries, it should be re-read from the outer for-loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the while loop. Will make another update if it's not the way you expected. Thanks!