Put the threading in the correct owner node for unthreaded nodes.

Add some additional debug to threading.
This commit is contained in:
JoelKatz
2012-09-20 00:15:48 -07:00
parent 8c354f46b7
commit 02b3bcb089
5 changed files with 34 additions and 22 deletions

View File

@@ -291,7 +291,7 @@ SLE::pointer LedgerEntrySet::getForMod(const uint256& node, Ledger::ref ledger,
}
bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, const NewcoinAddress& threadTo, Ledger::ref ledger,
bool LedgerEntrySet::threadTx(const NewcoinAddress& threadTo, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods)
{
Log(lsTRACE) << "Thread to " << threadTo.getAccountID();
@@ -301,32 +301,36 @@ bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, const NewcoinAddres
assert(false);
return false;
}
return threadTx(metaNode, sle, ledger, newMods);
return threadTx(sle, ledger, newMods);
}
bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, SLE::ref threadTo, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods)
bool LedgerEntrySet::threadTx(SLE::ref threadTo, Ledger::ref ledger, boost::unordered_map<uint256, SLE::pointer>& newMods)
{ // node = the node that was modified/deleted/created
// threadTo = the node that needs to know
uint256 prevTxID;
uint32 prevLgrID;
if (!threadTo->thread(mSet.getTxID(), mSet.getLgrSeq(), prevTxID, prevLgrID))
return false;
if (metaNode.thread(prevTxID, prevLgrID))
if (mSet.getAffectedNode(threadTo->getIndex(), TMNModifiedNode, false).thread(prevTxID, prevLgrID))
return true;
assert(false);
return false;
}
bool LedgerEntrySet::threadOwners(TransactionMetaNode& metaNode, SLE::ref node, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods)
bool LedgerEntrySet::threadOwners(SLE::ref node, Ledger::ref ledger, boost::unordered_map<uint256, SLE::pointer>& newMods)
{ // thread new or modified node to owner or owners
if (node->hasOneOwner()) // thread to owner's account
return threadTx(metaNode, node->getOwner(), ledger, newMods);
else if (node->hasTwoOwners()) // thread to owner's accounts
{
Log(lsTRACE) << "Thread to single owner";
return threadTx(node->getOwner(), ledger, newMods);
}
else if (node->hasTwoOwners()) // thread to owner's accounts]
{
Log(lsTRACE) << "Thread to two owners";
return
threadTx(metaNode, node->getFirstOwner(), ledger, newMods) ||
threadTx(metaNode, node->getSecondOwner(), ledger, newMods);
threadTx(node->getFirstOwner(), ledger, newMods) &&
threadTx(node->getSecondOwner(), ledger, newMods);
}
else
return false;
}
@@ -369,12 +373,12 @@ void LedgerEntrySet::calcRawMeta(Serializer& s)
continue;
SLE::pointer curNode = it->second.mEntry;
TransactionMetaNode &metaNode = mSet.getAffectedNode(it->first, nType);
TransactionMetaNode &metaNode = mSet.getAffectedNode(it->first, nType, true);
if (nType == TMNDeletedNode)
{
assert(origNode);
threadOwners(metaNode, origNode, mLedger, newMod);
threadOwners(origNode, mLedger, newMod);
if (origNode->getIFieldPresent(sfAmount))
{ // node has an amount, covers ripple state nodes
@@ -408,13 +412,16 @@ void LedgerEntrySet::calcRawMeta(Serializer& s)
if (nType == TMNCreatedNode) // if created, thread to owner(s)
{
assert(!origNode);
threadOwners(metaNode, curNode, mLedger, newMod);
threadOwners(curNode, mLedger, newMod);
}
if ((nType == TMNCreatedNode) || (nType == TMNModifiedNode))
{
if (curNode->isThreadedType()) // always thread to self
threadTx(metaNode, curNode, mLedger, newMod);
{
Log(lsTRACE) << "Thread to self";
threadTx(curNode, mLedger, newMod);
}
}
if (nType == TMNModifiedNode)

View File

@@ -42,14 +42,12 @@ protected:
SLE::pointer getForMod(const uint256& node, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods);
bool threadTx(TransactionMetaNode& metaNode, const NewcoinAddress& threadTo, Ledger::ref ledger,
bool threadTx(const NewcoinAddress& threadTo, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods);
bool threadTx(TransactionMetaNode& metaNode, SLE::ref threadTo, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods);
bool threadTx(SLE::ref threadTo, Ledger::ref ledger, boost::unordered_map<uint256, SLE::pointer>& newMods);
bool threadOwners(TransactionMetaNode& metaNode, SLE::ref node, Ledger::ref ledger,
boost::unordered_map<uint256, SLE::pointer>& newMods);
bool threadOwners(SLE::ref node, Ledger::ref ledger, boost::unordered_map<uint256, SLE::pointer>& newMods);
public:

View File

@@ -3,6 +3,7 @@
#include <boost/format.hpp>
#include "Ledger.h"
#include "Log.h"
SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index)
: SerializedType("LedgerEntry"), mIndex(index)
@@ -99,6 +100,7 @@ uint32 SerializedLedgerEntry::getThreadedLedger()
bool SerializedLedgerEntry::thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID)
{
uint256 oldPrevTxID = getIFieldH256(sfLastTxnID);
Log(lsTRACE) << "Thread Tx:" << txID << " prev:" << oldPrevTxID;
if (oldPrevTxID == txID)
return false;
prevTxID = oldPrevTxID;

View File

@@ -294,11 +294,15 @@ bool TransactionMetaSet::isNodeAffected(const uint256& node) const
return mNodes.find(node) != mNodes.end();
}
TransactionMetaNode& TransactionMetaSet::getAffectedNode(const uint256& node, int type)
TransactionMetaNode& TransactionMetaSet::getAffectedNode(const uint256& node, int type, bool overrideType)
{
std::map<uint256, TransactionMetaNode>::iterator it = mNodes.find(node);
if (it != mNodes.end())
{
if (overrideType)
it->second.setType(type);
return it->second;
}
return mNodes.insert(std::make_pair(node, TransactionMetaNode(node, type))).first->second;
}

View File

@@ -158,6 +158,7 @@ public:
TransactionMetaNode(int type, const uint256& node, SerializerIterator&);
void addRaw(Serializer&);
void setType(int t) { mType = t; }
Json::Value getJson(int) const;
bool addAmount(int nodeType, const STAmount& amount);
@@ -189,7 +190,7 @@ public:
uint32 getLgrSeq() { return mLedger; }
bool isNodeAffected(const uint256&) const;
TransactionMetaNode& getAffectedNode(const uint256&, int type);
TransactionMetaNode& getAffectedNode(const uint256&, int type, bool overrideType);
const TransactionMetaNode& peekAffectedNode(const uint256&) const;
Json::Value getJson(int) const;