From 52c378411de5862d822d276aa5fcf75d14645bc9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 20 Feb 2013 13:30:57 -0800 Subject: [PATCH] If we start seeing acquire timeouts, don't start new acquires. The link could be overloaded. --- src/cpp/ripple/LedgerAcquire.cpp | 8 +++++++- src/cpp/ripple/LedgerAcquire.h | 2 +- src/cpp/ripple/LedgerMaster.cpp | 30 +++++++++++++++++++----------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/cpp/ripple/LedgerAcquire.cpp b/src/cpp/ripple/LedgerAcquire.cpp index 84b3a5a85e..352b1d2206 100644 --- a/src/cpp/ripple/LedgerAcquire.cpp +++ b/src/cpp/ripple/LedgerAcquire.cpp @@ -920,15 +920,21 @@ void LedgerAcquireMaster::sweep() } } -int LedgerAcquireMaster::getFetchCount() +int LedgerAcquireMaster::getFetchCount(int& timeoutCount) { + timeoutCount = 0; int ret = 0; { typedef std::pair u256_acq_pair; boost::mutex::scoped_lock sl(mLock); BOOST_FOREACH(const u256_acq_pair& it, mLedgers) + { if (it.second->isActive()) + { ++ret; + timeoutCount += it.second->getTimeouts(); + } + } } return ret; } diff --git a/src/cpp/ripple/LedgerAcquire.h b/src/cpp/ripple/LedgerAcquire.h index b6d60f0f37..28c8434a02 100644 --- a/src/cpp/ripple/LedgerAcquire.h +++ b/src/cpp/ripple/LedgerAcquire.h @@ -149,7 +149,7 @@ public: void dropLedger(const uint256& ledgerHash); SMAddNode gotLedgerData(ripple::TMLedgerData& packet, Peer::ref); - int getFetchCount(); + int getFetchCount(int& timeoutCount); void logFailure(const uint256& h) { mRecentFailures.add(h); } bool isFailure(const uint256& h) { return mRecentFailures.isPresent(h, false); } diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 5176d58795..e505172eee 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -203,20 +203,28 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l theApp->getIOService().post(boost::bind(&LedgerMaster::missingAcquireComplete, this, mMissingLedger)); } - int fetch = theConfig.getSize(siLedgerFetch); - if (theApp->getMasterLedgerAcquire().getFetchCount() < fetch) - { - int count = 0; - typedef std::pair u_pair; + int fetchMax = theConfig.getSize(siLedgerFetch); + int timeoutCount; + int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount); - std::vector vec = origLedger->getLedgerHashes(); - BOOST_REVERSE_FOREACH(const u_pair& it, vec) + if (fetchCount < fetchMax) + { + if (timeoutCount > 4) { - if ((count < fetch) && (it.first < ledgerSeq) && - !mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second)) + cLog(lsDEBUG) << "Not acquiring due to timeouts"; + } + else + { + typedef std::pair u_pair; + std::vector vec = origLedger->getLedgerHashes(); + BOOST_REVERSE_FOREACH(const u_pair& it, vec) { - ++count; - theApp->getMasterLedgerAcquire().findCreate(it.second); + if ((fetchCount < fetchMax) && (it.first < ledgerSeq) && + !mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second)) + { + ++fetchCount; + theApp->getMasterLedgerAcquire().findCreate(it.second); + } } } }