Skip to content

Commit

Permalink
add signals for on-reindex-start and on-reindex-done events
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Feb 6, 2018
1 parent 46b1682 commit ce5699f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 13 additions & 1 deletion libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include <fc/io/fstream.hpp>

#include <boost/scope_exit.hpp>

#include <cstdint>
#include <deque>
#include <fstream>
Expand Down Expand Up @@ -153,9 +155,17 @@ void database::open( const open_args& args )

uint32_t database::reindex( const open_args& args )
{
bool reindex_success = false;
uint32_t last_block_number = 0; // result

BOOST_SCOPE_EXIT(this_,&reindex_success,&last_block_number) {
STEEM_TRY_NOTIFY(this_->_on_reindex_done, reindex_success, last_block_number);
} BOOST_SCOPE_EXIT_END

try
{
uint32_t last_block_number = 0; // result
STEEM_TRY_NOTIFY(_on_reindex_start);

ilog( "Reindexing Blockchain" );
wipe( args.data_dir, args.shared_mem_dir, false );
open( args );
Expand Down Expand Up @@ -217,6 +227,8 @@ uint32_t database::reindex( const open_args& args )
auto end = fc::time_point::now();
ilog( "Done reindexing, elapsed time: ${t} sec", ("t",double((end-start).count())/1000000.0 ) );

reindex_success = true;

return last_block_number;
}
FC_CAPTURE_AND_RETHROW( (args.data_dir)(args.shared_mem_dir) )
Expand Down
12 changes: 11 additions & 1 deletion libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ namespace steem { namespace chain {

///@}
#endif
typedef void on_reindex_start_t();
typedef void on_reindex_done_t(bool,uint32_t);

void on_reindex_start_connect(on_reindex_start_t functor)
{ _on_reindex_start.connect(functor); }
void on_reindex_done_connect(on_reindex_done_t functor)
{ _on_reindex_done.connect(functor); }

protected:
//Mark pop_undo() as protected -- we do not want outside calling pop_undo(); it should call pop_block() instead
Expand Down Expand Up @@ -521,7 +528,10 @@ namespace steem { namespace chain {
uint32_t _next_available_nai = 4;

flat_map< std::string, std::shared_ptr< custom_operation_interpreter > > _custom_operation_interpreters;
std::string _json_schema;
std::string _json_schema;

fc::signal<on_reindex_start_t> _on_reindex_start;
fc::signal<on_reindex_done_t> _on_reindex_done;
};

} }

0 comments on commit ce5699f

Please sign in to comment.