From e9a02882f1431356daf7bf4ed37abbc1fc29cf24 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 12 Mar 2013 15:17:26 -0700 Subject: [PATCH] Don't let ledger fetching go too fast. --- src/cpp/ripple/JobQueue.cpp | 8 ++++++++ src/cpp/ripple/JobQueue.h | 5 +++-- src/cpp/ripple/Ledger.cpp | 2 +- src/cpp/ripple/LedgerMaster.cpp | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index d5cd438fa..904af7e8e 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -118,6 +118,14 @@ int JobQueue::getJobCount(JobType t) return (c == mJobCounts.end()) ? 0 : c->second.first; } +int JobQueue::getJobCountTotal(JobType t) +{ + boost::mutex::scoped_lock sl(mJobLock); + + std::map< JobType, std::pair >::iterator c = mJobCounts.find(t); + return (c == mJobCounts.end()) ? 0 : (c->second.first + c->second.second); +} + int JobQueue::getJobCountGE(JobType t) { // return the number of jobs at this priority level or greater int ret = 0; diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index 159b7dfa6..bf439cc6e 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -103,8 +103,9 @@ public: void addJob(JobType type, const std::string& name, const boost::function& job); - int getJobCount(JobType t); // Jobs at this priority - int getJobCountGE(JobType t); // All jobs at or greater than this priority + int getJobCount(JobType t); // Jobs waiting at this priority + int getJobCountTotal(JobType t); // Jobs waiting plus running at this priority + int getJobCountGE(JobType t); // All waiting jobs at or greater than this priority std::vector< std::pair > > getJobCounts(); // jobs waiting, threads doing void shutdown(); diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 2fbf26eb1..52ce07c50 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -512,7 +512,7 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus) if (!fromConsensus) dropCache(); - if (theApp->getJobQueue().getJobCount(jtPUBOLDLEDGER) == 0) + if (theApp->getJobQueue().getJobCountTotal(jtPUBOLDLEDGER) == 0) theApp->getLedgerMaster().resumeAcquiring(); } diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 4d79e5166..892d70822 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -388,7 +388,7 @@ void LedgerMaster::setFullLedger(Ledger::pointer ledger) return; } - if (theApp->getJobQueue().getJobCount(jtPUBOLDLEDGER) > 2) + if (theApp->getJobQueue().getJobCountTotal(jtPUBOLDLEDGER) > 1) { cLog(lsDEBUG) << "Too many pending ledger saves"; return;