More fetch pack work.

This commit is contained in:
JoelKatz
2013-04-22 12:45:37 -07:00
parent 905bc84c94
commit d5535dbdfd
3 changed files with 39 additions and 28 deletions

View File

@@ -118,7 +118,7 @@ bool LedgerAcquire::tryLocal()
std::vector<unsigned char> data;
if (!theApp->getOPs().getFetchPack(mHash, data))
return false;
cLog(lsINFO) << "Ledger base found in fetch pack";
cLog(lsTRACE) << "Ledger base found in fetch pack";
mLedger = boost::make_shared<Ledger>(data, true);
theApp->getHashedObjectStore().store(hotLEDGER, mLedger->getLedgerSeq(), data, mHash);
}
@@ -792,7 +792,13 @@ LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
ptr->setTimer(); // Cannot call in constructor
}
else
{
Ledger::pointer ledger = ptr->getLedger();
ledger->setClosed();
ledger->setImmutable();
theApp->getLedgerMaster().storeLedger(ledger);
cLog(lsDEBUG) << "Acquiring ledger we already have: " << hash;
}
return ptr;
}

View File

@@ -251,6 +251,38 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
theApp->getIOService().post(boost::bind(&LedgerMaster::missingAcquireComplete, this, mMissingLedger));
}
int fetchMax = theConfig.getSize(siLedgerFetch);
int timeoutCount;
int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount);
if ((fetchCount < fetchMax) && theApp->getOPs().isFull())
{
if (timeoutCount > 2)
{
cLog(lsDEBUG) << "Not acquiring due to timeouts";
}
else
{
typedef std::pair<uint32, uint256> u_pair;
std::vector<u_pair> vec = origLedger->getLedgerHashes();
BOOST_FOREACH(const u_pair& it, vec)
{
if ((fetchCount < fetchMax) && (it.first < ledgerSeq) &&
!mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second))
{
LedgerAcquire::pointer acq = theApp->getMasterLedgerAcquire().findCreate(it.second);
if (acq && acq->isComplete())
{
acq->getLedger()->setAccepted();
setFullLedger(acq->getLedger());
mLedgerHistory.addAcceptedLedger(acq->getLedger(), false);
}
else ++fetchCount;
}
}
}
}
if (theApp->getOPs().shouldFetchPack())
{ // refill our fetch pack
Ledger::pointer nextLedger = mLedgerHistory.getLedgerBySeq(ledgerSeq + 1);
@@ -286,32 +318,6 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
}
}
int fetchMax = theConfig.getSize(siLedgerFetch);
int timeoutCount;
int fetchCount = theApp->getMasterLedgerAcquire().getFetchCount(timeoutCount);
if ((fetchCount < fetchMax) && theApp->getOPs().isFull())
{
if (timeoutCount > 2)
{
cLog(lsDEBUG) << "Not acquiring due to timeouts";
}
else
{
typedef std::pair<uint32, uint256> u_pair;
std::vector<u_pair> vec = origLedger->getLedgerHashes();
BOOST_FOREACH(const u_pair& it, vec)
{
if ((fetchCount < fetchMax) && (it.first < ledgerSeq) &&
!mCompleteLedgers.hasValue(it.first) && !theApp->getMasterLedgerAcquire().find(it.second))
{
++fetchCount;
theApp->getMasterLedgerAcquire().findCreate(it.second);
}
}
}
}
return true;
}

View File

@@ -2088,7 +2088,6 @@ bool NetworkOPs::getFetchPack(const uint256& hash, std::vector<unsigned char>& d
cLog(lsWARNING) << "Bad entry in fetch pack";
return false;
}
cLog(lsINFO) << hash << " found in fetch pack";
return true;
}