mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 00:15:51 +00:00
Rewrite InboundLedgers to mLedgers is unordered.
This commit is contained in:
@@ -7,33 +7,38 @@
|
|||||||
InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq)
|
InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq)
|
||||||
{
|
{
|
||||||
assert (hash.isNonZero ());
|
assert (hash.isNonZero ());
|
||||||
boost::mutex::scoped_lock sl (mLock);
|
InboundLedger::pointer ret;
|
||||||
InboundLedger::pointer& ptr = mLedgers[hash];
|
|
||||||
|
|
||||||
if (ptr)
|
|
||||||
{ // FIXME: Should set the sequence if it's not set
|
|
||||||
ptr->touch ();
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = boost::make_shared<InboundLedger> (hash, seq);
|
|
||||||
|
|
||||||
if (!ptr->isDone ())
|
|
||||||
{
|
{
|
||||||
ptr->addPeers ();
|
boost::mutex::scoped_lock sl (mLock);
|
||||||
ptr->setTimer (); // Cannot call in constructor
|
InboundLedger::pointer& ptr = mLedgers[hash];
|
||||||
}
|
|
||||||
else if (ptr->isComplete ())
|
if (ptr)
|
||||||
{
|
{ // FIXME: Should set the sequence if it's not set
|
||||||
Ledger::pointer ledger = ptr->getLedger ();
|
ptr->touch ();
|
||||||
ledger->setClosed ();
|
ret = ptr;
|
||||||
ledger->setImmutable ();
|
}
|
||||||
getApp().getLedgerMaster ().storeLedger (ledger);
|
else
|
||||||
WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have: " << hash;
|
{
|
||||||
|
ptr = ret = boost::make_shared<InboundLedger> (hash, seq);
|
||||||
|
|
||||||
|
if (!ret->isDone ())
|
||||||
|
{
|
||||||
|
ret->addPeers ();
|
||||||
|
ret->setTimer (); // Cannot call in constructor
|
||||||
|
}
|
||||||
|
else if (ret->isComplete ())
|
||||||
|
{
|
||||||
|
Ledger::pointer ledger = ret->getLedger ();
|
||||||
|
ledger->setClosed ();
|
||||||
|
ledger->setImmutable ();
|
||||||
|
getApp().getLedgerMaster ().storeLedger (ledger);
|
||||||
|
WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have locally: " << hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (mLedgers[hash]);
|
return ret;
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InboundLedger::pointer InboundLedgers::find (uint256 const& hash)
|
InboundLedger::pointer InboundLedgers::find (uint256 const& hash)
|
||||||
@@ -45,7 +50,7 @@ InboundLedger::pointer InboundLedgers::find (uint256 const& hash)
|
|||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl (mLock);
|
boost::mutex::scoped_lock sl (mLock);
|
||||||
|
|
||||||
std::map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
|
boost::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
|
||||||
if (it != mLedgers.end ())
|
if (it != mLedgers.end ())
|
||||||
{
|
{
|
||||||
it->second->touch ();
|
it->second->touch ();
|
||||||
@@ -213,7 +218,7 @@ void InboundLedgers::sweep ()
|
|||||||
int now = UptimeTimer::getInstance ().getElapsedSeconds ();
|
int now = UptimeTimer::getInstance ().getElapsedSeconds ();
|
||||||
boost::mutex::scoped_lock sl (mLock);
|
boost::mutex::scoped_lock sl (mLock);
|
||||||
|
|
||||||
std::map<uint256, InboundLedger::pointer>::iterator it = mLedgers.begin ();
|
boost::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.begin ();
|
||||||
|
|
||||||
while (it != mLedgers.end ())
|
while (it != mLedgers.end ())
|
||||||
{
|
{
|
||||||
@@ -223,7 +228,7 @@ void InboundLedgers::sweep ()
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
else if ((it->second->getLastAction () + 60) < now)
|
else if ((it->second->getLastAction () + 60) < now)
|
||||||
mLedgers.erase (it++);
|
it = mLedgers.erase (it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@@ -234,14 +239,19 @@ int InboundLedgers::getFetchCount (int& timeoutCount)
|
|||||||
timeoutCount = 0;
|
timeoutCount = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
std::map<uint256, InboundLedger::pointer> inboundLedgers;
|
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
|
||||||
|
std::vector<u256_acq_pair> inboundLedgers;
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl (mLock);
|
boost::mutex::scoped_lock sl (mLock);
|
||||||
inboundLedgers = mLedgers;
|
|
||||||
|
inboundLedgers.reserve(mLedgers.size());
|
||||||
|
BOOST_FOREACH (const u256_acq_pair & it, mLedgers)
|
||||||
|
{
|
||||||
|
inboundLedgers.push_back(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
|
|
||||||
BOOST_FOREACH (const u256_acq_pair & it, inboundLedgers)
|
BOOST_FOREACH (const u256_acq_pair & it, inboundLedgers)
|
||||||
{
|
{
|
||||||
if (it.second->isActive ())
|
if (it.second->isActive ())
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
boost::mutex mLock;
|
boost::mutex mLock;
|
||||||
std::map <uint256, InboundLedger::pointer> mLedgers;
|
boost::unordered_map <uint256, InboundLedger::pointer> mLedgers;
|
||||||
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
|
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user