Skip to content

Commit

Permalink
[FOLD] suggest renaming stopping() to handleHealth()
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed May 3, 2022
1 parent f2143de commit 945e690
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions src/ripple/app/misc/SHAMapStoreImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ SHAMapStoreImp::copyNode(std::uint64_t& nodeCount, SHAMapTreeNode const& node)
true);
if (!(++nodeCount % checkHealthInterval_))
{
if (stopping())
if (handleHealth() == stopping)
return false;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -358,7 +358,7 @@ SHAMapStoreImp::run()
<< ledgerMaster_->getValidatedLedgerAge().count() << 's';

clearPrior(lastRotated);
if (stopping())
if (handleHealth() == stopping)
return;

JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
Expand All @@ -368,15 +368,15 @@ 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
<< " nodecount " << nodeCount;

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";
Expand All @@ -387,7 +387,7 @@ SHAMapStoreImp::run()
<< validatedSeq << " new backend " << newBackend->getName();

clearCaches(validatedSeq);
if (stopping())
if (handleHealth() == stopping)
return;

lastRotated = validatedSeq;
Expand Down Expand Up @@ -552,7 +552,7 @@ SHAMapStoreImp::clearSql(
min = *m;
}

if (min > lastRotated || stopping())
if (min > lastRotated || handleHealth() == stopping)
return;
if (min == lastRotated)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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 =
Expand All @@ -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())
Expand All @@ -648,7 +648,7 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
[&iface](LedgerIndex min) -> void {
iface->deleteTransactionsBeforeLedgerSeq(min);
});
if (stopping())
if (handleHealth() == stopping)
return;

clearSql(
Expand All @@ -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();
Expand All @@ -683,7 +683,7 @@ SHAMapStoreImp::stopping()
lock.lock();
}

return stop_;
return stop_ ? stopping : keepGoing;
}

void
Expand Down
16 changes: 8 additions & 8 deletions src/ripple/app/misc/SHAMapStoreImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 945e690

Please sign in to comment.