Pathfinding improvements.

This commit is contained in:
JoelKatz
2013-11-12 13:18:55 -08:00
committed by Vinnie Falco
parent 58f07a573f
commit a3024352ba
5 changed files with 38 additions and 3 deletions

View File

@@ -924,9 +924,17 @@ void LedgerMaster::updatePaths (Job& job)
{
Ledger::pointer lastLedger;
if (getApp().getOPs().isNeedNetworkLedger ())
{
ScopedLockType ml (mLock, __FILE__, __LINE__);
mPathFindThread = false;
return;
}
while (! job.shouldCancel())
{
bool newOnly = true;
bool hasNew = mPathFindNewRequest;
{
ScopedLockType ml (mLock, __FILE__, __LINE__);
@@ -952,7 +960,7 @@ void LedgerMaster::updatePaths (Job& job)
}
// VFALCO TODO Fix this global variable
PathRequest::updateAll (lastLedger, newOnly, job.getCancelCallback ());
PathRequest::updateAll (lastLedger, newOnly, hasNew, job.getCancelCallback ());
}
}
@@ -968,3 +976,17 @@ void LedgerMaster::newPathRequest ()
BIND_TYPE (&LedgerMaster::updatePaths, this, P_1));
}
}
// If the order book is radically updated, we need to reprocess all pathfinding requests
void LedgerMaster::newOrderBookDB ()
{
ScopedLockType ml (mLock, __FILE__, __LINE__);
mPathLedger.reset();
if (!mPathFindThread)
{
mPathFindThread = true;
getApp().getJobQueue ().addJob (jtUPDATE_PF, "updatePaths",
BIND_TYPE (&LedgerMaster::updatePaths, this, P_1));
}
}

View File

@@ -213,6 +213,7 @@ public:
void tryAdvance ();
void newPathRequest ();
void newOrderBookDB ();
static bool shouldAcquire (uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger);

View File

@@ -116,6 +116,7 @@ void OrderBookDB::update (Ledger::pointer ledger)
mSourceMap.swap(sourceMap);
mDestMap.swap(destMap);
}
getApp().getLedgerMaster().newOrderBookDB();
}
void OrderBookDB::addOrderBook(const uint160& ci, const uint160& co,

View File

@@ -256,6 +256,12 @@ Json::Value PathRequest::doStatus (const Json::Value&)
return jvStatus;
}
void PathRequest::resetLevel (int l)
{
if (iLastLevel > l)
iLastLevel = l;
}
bool PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
{
WriteLog (lsDEBUG, PathRequest) << iIdentifier << " update " << (fast ? "fast" : "normal");
@@ -403,7 +409,7 @@ bool PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
return true;
}
void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, CancelCallback shouldCancel)
void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, bool hasNew, CancelCallback shouldCancel)
{
std::set<wptr> requests;
@@ -433,6 +439,10 @@ void PathRequest::updateAll (Ledger::ref ledger, bool newOnly, CancelCallback sh
if (pRequest)
{
// Drop old requests level to get new ones done faster
if (hasNew)
pRequest->resetLevel(getConfig().PATH_SEARCH);
if (newOnly && !pRequest->isNew ())
remove = false;
else

View File

@@ -58,10 +58,11 @@ public:
bool doUpdate (const boost::shared_ptr<RippleLineCache>&, bool fast); // update jvStatus
static void updateAll (const boost::shared_ptr<Ledger>& ledger, bool newOnly, CancelCallback shouldCancel);
static void updateAll (const boost::shared_ptr<Ledger>& ledger, bool newOnly, bool hasNew, CancelCallback shouldCancel);
private:
void setValid ();
void resetLevel (int level);
int parseJson (const Json::Value&, bool complete);
typedef RippleRecursiveMutex LockType;