Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Block log util#6884 #6913

Merged
merged 10 commits into from
May 2, 2019
Merged

Block log util#6884 #6913

merged 10 commits into from
May 2, 2019

Conversation

snstrand
Copy link
Contributor

@snstrand snstrand commented Mar 11, 2019

Added two new options to program eosio-blocklog:

  1. --trim-block-log --last 'blkNum'
    This truncates the files blocks.log and blocks.index so last block is 'blkNum'.
    Runtime is < 1 second. Nodeos trim block log option can take over 1 hour.

  2. --make-index
    This creates blocks.index from blocks.log. Can specify output file if do not want to
    overwrite existing blocks.index. Runtime for a recent test with 42e6 blocks in blocks.log
    was 80 seconds. Nodeos took 90 minutes to create the same blocks.index file.

I also added BOOST_AUTO_TEST_CASE(reverse_endian_tests) to unittests/misc_tests.cpp. I wrote a slightly smaller and faster implementation of endian_reverse_u64 and endian_reverse_u32 and initially updated fc/bitutil.hpp with this code and added the test to go with it. In the end I decided to not change the endian_reverse code because it was being done the most common way and future compilers might recognize what the intention was and provide highly optimized code. So I removed my slightly faster implementation (for one compiler at one point in time) but left the test in place.

In the future it might be a good idea to rename eosio-blocklog to eosio-nodeos-utils so additional new functions can be added.

@spoonincode spoonincode changed the base branch from master to develop March 11, 2019 22:56
Copy link
Contributor

@spoonincode spoonincode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to consider the comments in #6839 as well

uint64_t lastIndBufLen= indFileLen & (fposListLen-1); //fposListLen is a power of 2 so -1 creates low bits all 1
if (!lastIndBufLen) //will write integral number of bufLen and lastIndBufLen one time to index file
lastIndBufLen= bufLen;
uint64_t indPos= lseek(fout,indFileLen-lastIndBufLen,ios::beg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be SEEK_SET not ios::beg

programs/eosio-blocklog/main.cpp Show resolved Hide resolved
@@ -145,9 +149,12 @@ void blocklog::set_program_options(options_description& cli)
"Do not pretty print the output. Useful if piping to jq to improve performance.")
("as-json-array", bpo::bool_switch(&as_json_array)->default_value(false),
"Print out json blocks wrapped in json array (otherwise the output is free-standing json objects).")
("make-index", bpo::bool_switch(&make_index)->default_value(false),
"Create blocks.index from blocks.log. Must give 'blocks-dir'. Give 'output-file' relative to blocks-dir (default is blocks.index).")
("trim-block-log", bpo::bool_switch(&make_index)->default_value(false),
Copy link
Contributor

@spoonincode spoonincode Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim_block

programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
//struct used by truncBlockLog() and makeIndex() to read first 18 bytes of a block from blocks.log
struct __attribute__((packed)) BlockStart { //first 18 bytes of each block
block_timestamp_type timestamp;
account_name prodname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be producer to match block_header.
Add static_assert( sizeof(block_header) == whatever_it_currently_is, "Update when block_header updated");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we really not just use eosio::chain::block_header here? Does the deserialization markedly slow things down or something?

libraries/chain/include/eosio/chain/exceptions.hpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Outdated Show resolved Hide resolved
@snstrand
Copy link
Contributor Author

snstrand commented Mar 14, 2019 via email

bool make_index;
bool trim_log;
bool smoke_test;
bool help;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize uint32_t and bool members.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

FILE* ind_in; //C style files for reading blocks.log and blocks.index
//we use low level file IO because it is distinctly faster than C++ filebuf or iostream
uint64_t index_pos; //filepos in blocks.index for block n, +8 for block n+1
uint64_t fpos0, fpos1; //filepos in blocks.log for block n and block n+1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize all these data members.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

programs/eosio-blocklog/main.cpp Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Show resolved Hide resolved
programs/eosio-blocklog/main.cpp Show resolved Hide resolved
@spoonincode
Copy link
Contributor

Should this be included in binary packages? Seems like it probably should. But I guess we can address that in a separate pr

@brianjohnson5972 brianjohnson5972 merged commit 0c15515 into develop May 2, 2019
@brianjohnson5972
Copy link
Contributor

#7253

@heifner heifner deleted the blockLogUtil#6884 branch May 6, 2019 13:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants