If we start seeing acquire timeouts, don't start new acquires.

The link could be overloaded.
This commit is contained in:
JoelKatz
2013-02-20 13:30:57 -08:00
parent 25c52b1a4d
commit 52c378411d
3 changed files with 27 additions and 13 deletions

View File

@@ -920,15 +920,21 @@ void LedgerAcquireMaster::sweep()
}
}
int LedgerAcquireMaster::getFetchCount()
int LedgerAcquireMaster::getFetchCount(int& timeoutCount)
{
timeoutCount = 0;
int ret = 0;
{
typedef std::pair<uint256, LedgerAcquire::pointer> 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;
}

View File

@@ -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); }

View File

@@ -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<uint32, uint256> u_pair;
int fetchMax = theConfig.getSize(siLedgerFetch);
int timeoutCount;
int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount);
std::vector<u_pair> 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<uint32, uint256> u_pair;
std::vector<u_pair> 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);
}
}
}
}