From 945e6903b32b1ea1e769da279a39669650dbbcad Mon Sep 17 00:00:00 2001 From: Scott Schurr Date: Mon, 2 May 2022 18:09:29 -0700 Subject: [PATCH] [FOLD] suggest renaming stopping() to handleHealth() --- src/ripple/app/misc/SHAMapStoreImp.cpp | 32 +++++++++++++------------- src/ripple/app/misc/SHAMapStoreImp.h | 16 ++++++------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 0ac8e0ad510..5ea041013f3 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -268,7 +268,7 @@ SHAMapStoreImp::copyNode(std::uint64_t& nodeCount, SHAMapTreeNode const& node) true); if (!(++nodeCount % checkHealthInterval_)) { - if (stopping()) + if (handleHealth() == stopping) return false; } @@ -326,7 +326,7 @@ SHAMapStoreImp::run() bool const readyToRotate = validatedSeq >= lastRotated + deleteInterval_ && - canDelete_ >= lastRotated - 1 && !stopping(); + canDelete_ >= lastRotated - 1 && handleHealth() == keepGoing; // Make sure we don't delete ledgers currently being // imported into the ShardStore @@ -358,7 +358,7 @@ SHAMapStoreImp::run() << ledgerMaster_->getValidatedLedgerAge().count() << 's'; clearPrior(lastRotated); - if (stopping()) + if (handleHealth() == stopping) return; JLOG(journal_.debug()) << "copying ledger " << validatedSeq; @@ -368,7 +368,7 @@ SHAMapStoreImp::run() this, std::ref(nodeCount), std::placeholders::_1)); - if (stopping()) + if (handleHealth() == stopping) return; // Only log if we completed without a "health" abort JLOG(journal_.debug()) << "copied ledger " << validatedSeq @@ -376,7 +376,7 @@ SHAMapStoreImp::run() JLOG(journal_.debug()) << "freshening caches"; freshenCaches(); - if (stopping()) + if (handleHealth() == stopping) return; // Only log if we completed without a "health" abort JLOG(journal_.debug()) << validatedSeq << " freshened caches"; @@ -387,7 +387,7 @@ SHAMapStoreImp::run() << validatedSeq << " new backend " << newBackend->getName(); clearCaches(validatedSeq); - if (stopping()) + if (handleHealth() == stopping) return; lastRotated = validatedSeq; @@ -552,7 +552,7 @@ SHAMapStoreImp::clearSql( min = *m; } - if (min > lastRotated || stopping()) + if (min > lastRotated || handleHealth() == stopping) return; if (min == lastRotated) { @@ -573,11 +573,11 @@ SHAMapStoreImp::clearSql( JLOG(journal_.trace()) << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < " << min << " from: " << TableName; - if (stopping()) + if (handleHealth() == stopping) return; if (min < lastRotated) std::this_thread::sleep_for(backOff_); - if (stopping()) + if (handleHealth() == stopping) return; } JLOG(journal_.debug()) << "finished deleting from: " << TableName; @@ -617,7 +617,7 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) ledgerMaster_->clearPriorLedgers(lastRotated); JLOG(journal_.trace()) << "End: Clear internal ledgers up to " << lastRotated; - if (stopping()) + if (handleHealth() == stopping) return; RelationalDBInterfaceSqlite* iface = @@ -633,7 +633,7 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) [&iface](LedgerIndex min) -> void { iface->deleteBeforeLedgerSeq(min); }); - if (stopping()) + if (handleHealth() == stopping) return; if (!app_.config().useTxTables()) @@ -648,7 +648,7 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) [&iface](LedgerIndex min) -> void { iface->deleteTransactionsBeforeLedgerSeq(min); }); - if (stopping()) + if (handleHealth() == stopping) return; clearSql( @@ -660,12 +660,12 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) [&iface](LedgerIndex min) -> void { iface->deleteAccountTransactionsBeforeLedgerSeq(min); }); - if (stopping()) + if (handleHealth() == stopping) return; } -bool -SHAMapStoreImp::stopping() +SHAMapStoreImp::HealthResult +SHAMapStoreImp::handleHealth() { auto age = ledgerMaster_->getValidatedLedgerAge(); OperatingMode mode = netOPs_->getOperatingMode(); @@ -683,7 +683,7 @@ SHAMapStoreImp::stopping() lock.lock(); } - return stop_; + return stop_ ? stopping : keepGoing; } void diff --git a/src/ripple/app/misc/SHAMapStoreImp.h b/src/ripple/app/misc/SHAMapStoreImp.h index c2b4476589e..150ed9cc3af 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.h +++ b/src/ripple/app/misc/SHAMapStoreImp.h @@ -104,9 +104,8 @@ class SHAMapStoreImp : public SHAMapStore std::uint32_t deleteBatch_ = 100; std::chrono::milliseconds backOff_{100}; std::chrono::seconds ageThreshold_{60}; - /// If the node is out of sync during an - /// online_delete health check, sleep the thread - /// for this time, and continue checking until + /// If the node is out of sync during an online_delete handleHealth() + /// call, sleep the thread for this time, and continue checking until /// recovery. /// See also: "recovery_wait_seconds" in rippled-example.cfg std::chrono::seconds recoveryWaitTime_{5}; @@ -199,7 +198,7 @@ class SHAMapStoreImp : public SHAMapStore { dbRotating_->fetchNodeObject( key, 0, NodeStore::FetchType::synchronous, true); - if (!(++check % checkHealthInterval_) && stopping()) + if (!(++check % checkHealthInterval_) && handleHealth() == stopping) return true; } @@ -225,13 +224,14 @@ class SHAMapStoreImp : public SHAMapStore /** * This is a health check for online deletion that waits until rippled is - * stable until returning. If the server is stopping, then it returns - * "true" to inform the caller to allow the server to stop. + * stable before returning. It returns an indication of whether the server + * is stopping. * * @return Whether the server is stopping. */ - bool - stopping(); + enum HealthResult { stopping, keepGoing }; + [[nodiscard]] HealthResult + handleHealth(); public: void