Stop etl when crash (#708)

Fixes #706
This commit is contained in:
cyan317
2023-06-21 13:10:24 +01:00
committed by GitHub
parent 557ea5d7f6
commit d9e89746a4
2 changed files with 46 additions and 25 deletions

View File

@@ -83,31 +83,41 @@ ETLService::monitor()
"from the network.";
std::optional<ripple::LedgerInfo> ledger;
if (startSequence_)
try
{
log_.info() << "ledger sequence specified in config. "
<< "Will begin ETL process starting with ledger " << *startSequence_;
ledger = ledgerLoader_.loadInitialLedger(*startSequence_);
}
else
{
log_.info() << "Waiting for next ledger to be validated by network...";
std::optional<uint32_t> mostRecentValidated = networkValidatedLedgers_->getMostRecent();
if (mostRecentValidated)
if (startSequence_)
{
log_.info() << "Ledger " << *mostRecentValidated << " has been validated. "
<< "Downloading...";
ledger = ledgerLoader_.loadInitialLedger(*mostRecentValidated);
log_.info() << "ledger sequence specified in config. "
<< "Will begin ETL process starting with ledger " << *startSequence_;
ledger = ledgerLoader_.loadInitialLedger(*startSequence_);
}
else
{
log_.info() << "The wait for the next validated "
<< "ledger has been aborted. "
<< "Exiting monitor loop";
return;
log_.info() << "Waiting for next ledger to be validated by network...";
std::optional<uint32_t> mostRecentValidated = networkValidatedLedgers_->getMostRecent();
if (mostRecentValidated)
{
log_.info() << "Ledger " << *mostRecentValidated << " has been validated. "
<< "Downloading...";
ledger = ledgerLoader_.loadInitialLedger(*mostRecentValidated);
}
else
{
log_.info() << "The wait for the next validated "
<< "ledger has been aborted. "
<< "Exiting monitor loop";
return;
}
}
}
catch (std::runtime_error const& e)
{
log_.fatal()
<< "Failed to load initial ledger, Exiting monitor loop : " << e.what()
<< " Possible cause: The ETL node is not compatible with the version of the rippled lib Clio is using.";
return;
}
if (ledger)
{

View File

@@ -174,19 +174,30 @@ private:
backend_->writeLedger(lgrInfo, std::move(*rawData.mutable_ledger_header()));
writeSuccessors(lgrInfo, rawData);
updateCache(lgrInfo, rawData);
std::optional<FormattedTransactionsData> insertTxResultOp;
try
{
updateCache(lgrInfo, rawData);
log_.debug() << "Inserted/modified/deleted all objects. Number of objects = "
<< rawData.ledger_objects().objects_size();
log_.debug() << "Inserted/modified/deleted all objects. Number of objects = "
<< rawData.ledger_objects().objects_size();
auto insertTxResult = loader_.get().insertTransactions(lgrInfo, rawData);
insertTxResultOp.emplace(loader_.get().insertTransactions(lgrInfo, rawData));
}
catch (std::runtime_error const& e)
{
log_.fatal()
<< "Failed to build next ledger : " << e.what()
<< " Possible cause: The ETL node is not compatible with the version of the rippled lib Clio is using.";
return {ripple::LedgerInfo{}, false};
}
log_.debug() << "Inserted all transactions. Number of transactions = "
<< rawData.transactions_list().transactions_size();
backend_->writeAccountTransactions(std::move(insertTxResult.accountTxData));
backend_->writeNFTs(std::move(insertTxResult.nfTokensData));
backend_->writeNFTTransactions(std::move(insertTxResult.nfTokenTxData));
backend_->writeAccountTransactions(std::move(insertTxResultOp->accountTxData));
backend_->writeNFTs(std::move(insertTxResultOp->nfTokensData));
backend_->writeNFTTransactions(std::move(insertTxResultOp->nfTokenTxData));
auto [success, duration] =
util::timed<std::chrono::duration<double>>([&]() { return backend_->finishWrites(lgrInfo.seq); });