blockchain_export: show progress during export

This commit is contained in:
warptangent 2015-03-22 10:57:21 -07:00
parent 4bedd68d2c
commit 7476d2e253
No known key found for this signature in database
GPG key ID: 0E490BEBFBE4E92D

View file

@ -239,14 +239,16 @@ bool BlockchainExport::BlockchainExport::close()
#if SOURCE_DB == DB_MEMORY #if SOURCE_DB == DB_MEMORY
bool BlockchainExport::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t use_block_height) bool BlockchainExport::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_height)
#else #else
bool BlockchainExport::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t use_block_height) bool BlockchainExport::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_height)
#endif #endif
{ {
uint64_t use_block_height2 = 0; uint64_t block_height = 0;
m_blockchain_storage = _blockchain_storage; m_blockchain_storage = _blockchain_storage;
m_tx_pool = _tx_pool; m_tx_pool = _tx_pool;
uint64_t progress_interval = 100;
std::string refresh_string = "\r \r";
LOG_PRINT_L0("Storing blocks raw data..."); LOG_PRINT_L0("Storing blocks raw data...");
if (!BlockchainExport::open(output_dir)) if (!BlockchainExport::open(output_dir))
{ {
@ -255,15 +257,15 @@ bool BlockchainExport::store_blockchain_raw(Blockchain* _blockchain_storage, tx_
} }
block b; block b;
LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()); LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height());
LOG_PRINT_L0("requested block height: " << use_block_height); LOG_PRINT_L0("requested block height: " << requested_block_height);
if ((use_block_height > 0) && (use_block_height < m_blockchain_storage->get_current_blockchain_height())) if ((requested_block_height > 0) && (requested_block_height < m_blockchain_storage->get_current_blockchain_height()))
use_block_height2 = use_block_height; block_height = requested_block_height;
else else
{ {
use_block_height2 = m_blockchain_storage->get_current_blockchain_height(); block_height = m_blockchain_storage->get_current_blockchain_height();
LOG_PRINT_L0("using block height: " << use_block_height2); LOG_PRINT_L0("Using block height of source blockchain: " << block_height);
} }
for (height=0; height < use_block_height2; ++height) for (height=0; height < block_height; ++height)
{ {
crypto::hash hash = m_blockchain_storage->get_block_id_by_height(height); crypto::hash hash = m_blockchain_storage->get_block_id_by_height(height);
m_blockchain_storage->get_block_by_hash(hash, b); m_blockchain_storage->get_block_by_hash(hash, b);
@ -271,11 +273,17 @@ bool BlockchainExport::store_blockchain_raw(Blockchain* _blockchain_storage, tx_
if (height % NUM_BLOCKS_PER_CHUNK == 0) { if (height % NUM_BLOCKS_PER_CHUNK == 0) {
flush_chunk(); flush_chunk();
} }
if (height % progress_interval == 0) {
std::cout << refresh_string;
std::cout << "height " << height << "/" << block_height << std::flush;
}
} }
if (height % NUM_BLOCKS_PER_CHUNK != 0) if (height % NUM_BLOCKS_PER_CHUNK != 0)
{ {
flush_chunk(); flush_chunk();
} }
std::cout << refresh_string;
std::cout << "height " << height << "/" << block_height << ENDL;
LOG_PRINT_L0("longest chunk was " << max_chunk << " bytes"); LOG_PRINT_L0("longest chunk was " << max_chunk << " bytes");
return BlockchainExport::close(); return BlockchainExport::close();