Skip to content

Commit

Permalink
optimize snapshot user experience (FISCO-BCOS#4589)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust authored Aug 22, 2024
1 parent 163a03a commit b5cb345
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 80 deletions.
4 changes: 3 additions & 1 deletion bcos-ledger/src/libledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ bcos::Error::Ptr Ledger::storeTransactionsAndReceipts(
{
return BCOS_ERROR_PTR(LedgerError::ErrorArgument, "empty block");
}
auto blockNumber = block->blockHeaderConst()->number();
LEDGER_LOG(INFO) << LOG_DESC("storeTransactionsAndReceipts")
<< LOG_KV("blockNumber", blockNumber);
auto start = utcTime();
bcos::Error::Ptr error = nullptr;
auto txSize = std::max(block->transactionsSize(), block->transactionsMetaDataSize());
Expand Down Expand Up @@ -467,7 +470,6 @@ bcos::Error::Ptr Ledger::storeTransactionsAndReceipts(
keys.reserve(txSize);
std::vector<std::string_view> values;
values.reserve(txSize);
auto blockNumber = block->blockHeaderConst()->number();

RecursiveGuard guard(m_mutex);
size_t unstoredTxs = 0;
Expand Down
11 changes: 7 additions & 4 deletions bcos-storage/bcos-storage/RocksDBStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ void RocksDBStorage::asyncPrepare(const TwoPCParams& param, const TraverseStorag
void RocksDBStorage::asyncCommit(
const TwoPCParams& params, std::function<void(Error::Ptr, uint64_t)> callback)
{
STORAGE_ROCKSDB_LOG(DEBUG) << LOG_DESC("asyncCommit") << LOG_KV("blockNumber", params.number)
<< LOG_KV("startTS", params.timestamp);
__itt_task_begin(ittapi::ITT_DOMAINS::instance().ITT_DOMAIN_STORAGE, __itt_null, __itt_null,
const_cast<__itt_string_handle*>(ITT_STRING_STORAGE_COMMIT));

Expand Down Expand Up @@ -472,10 +474,11 @@ void RocksDBStorage::asyncCommit(
m_db->GetProperty("rocksdb.cur-size-all-mem-tables", &current);
STORAGE_ROCKSDB_LOG(INFO) << LOG_DESC("RocksDB statistics")
<< LOG_KV("blockNumber", params.number)
// << LOG_KV(
// "block_cache_usage", tableOptions->block_cache->GetUsage())
// << LOG_KV("block_cache_pinned_usage",
// tableOptions->block_cache->GetPinnedUsage())
// << LOG_KV(
// "block_cache_usage",
// tableOptions->block_cache->GetUsage())
// << LOG_KV("block_cache_pinned_usage",
// tableOptions->block_cache->GetPinnedUsage())
<< LOG_KV("estimate-table-readers-mem", out)
<< LOG_KV("cur-size-all-mem-tables", current);
}
Expand Down
4 changes: 2 additions & 2 deletions fisco-bcos-air/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ExitHandler
static void exit() { exitHandler(0); }
static void exitHandler(int signal)
{
std::cout << "[" << bcos::getCurrentDateTime() << "] " << "exit because receive signal "
<< signal << std::endl;
std::cout << "[" << bcos::getCurrentDateTime() << "] "
<< "exit because receive signal " << signal << std::endl;
ExitHandler::c_shouldExit.store(true);
ExitHandler::c_shouldExit.notify_all();
}
Expand Down
23 changes: 19 additions & 4 deletions fisco-bcos-air/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "AirNodeInitializer.h"
#include "Common.h"
#include "libinitializer/CommandHelper.h"
#include <bcos-crypto/signature/key/KeyFactoryImpl.h>
#include <bcos-tool/NodeConfig.h>
#include <bcos-utilities/BoostLogInitializer.h>
#include <execinfo.h>

using namespace bcos::node;
Expand Down Expand Up @@ -54,25 +57,34 @@ int main(int argc, const char* argv[])
try
{
auto param = bcos::initializer::initAirNodeCommandLine(argc, argv, false);
initializer->init(param.configFilePath, param.genesisFilePath);
if (param.op != bcos::initializer::Params::operation::None)
{
if (param.hasOp(bcos::initializer::Params::operation::Prune))
{
initializer->init(param.configFilePath, param.genesisFilePath);
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "prune the node data..." << std::endl;
initializer->nodeInitializer()->prune();
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "prune the node data success." << std::endl;
return 0;
}
auto logInitializer = std::make_shared<bcos::BoostLogInitializer>();
logInitializer->initLog(param.configFilePath);
auto nodeConfig = std::make_shared<bcos::tool::NodeConfig>(
std::make_shared<bcos::crypto::KeyFactoryImpl>());
nodeConfig->loadGenesisConfig(param.genesisFilePath);
nodeConfig->loadConfig(param.configFilePath);
auto nodeInitializer = std::make_shared<bcos::initializer::Initializer>();
nodeInitializer->initConfig(param.configFilePath, param.genesisFilePath, "", true);
if (param.hasOp(bcos::initializer::Params::operation::Snapshot) ||
param.hasOp(bcos::initializer::Params::operation::SnapshotWithoutTxAndReceipt))
{
bool withTxAndReceipt = param.hasOp(bcos::initializer::Params::operation::Snapshot);
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "generating snapshot to " << param.snapshotPath << " ..." << std::endl;
auto error = initializer->nodeInitializer()->generateSnapshot(
param.snapshotPath, withTxAndReceipt);
auto error = nodeInitializer->generateSnapshot(
param.snapshotPath, withTxAndReceipt, nodeConfig);
if (error)
{
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
Expand All @@ -82,13 +94,15 @@ int main(int argc, const char* argv[])
}
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "generate snapshot success." << std::endl;
return 0;
}
if (param.hasOp(bcos::initializer::Params::operation::ImportSnapshot))
{
// initializer->init(param.configFilePath, param.genesisFilePath);
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
std::cout << "importing snapshot from " << param.snapshotPath << " ..."
<< std::endl;
auto error = initializer->nodeInitializer()->importSnapshot(param.snapshotPath);
auto error = nodeInitializer->importSnapshot(param.snapshotPath, nodeConfig);
if (error)
{
std::cout << "[" << bcos::getCurrentDateTime() << "] ";
Expand All @@ -101,6 +115,7 @@ int main(int argc, const char* argv[])
}
return 0;
}
initializer->init(param.configFilePath, param.genesisFilePath);
bcos::initializer::showNodeVersionMetric();

bcos::initializer::printVersion();
Expand Down
Loading

0 comments on commit b5cb345

Please sign in to comment.