Refactor NodeStore

This commit is contained in:
Vinnie Falco
2013-07-20 07:17:47 -07:00
parent 1975d81153
commit db26c37156
37 changed files with 2075 additions and 1018 deletions

View File

@@ -48,8 +48,7 @@ void NetworkOPs::processNetTimer ()
// VFALCO NOTE This is for diagnosing a crash on exit
Application& app (getApp ());
ILoadManager& mgr (app.getLoadManager ());
getApp().getLoadManager ().resetDeadlockDetector ();
mgr.resetDeadlockDetector ();
std::size_t const numPeers = getApp().getPeers ().getPeerVector ().size ();

View File

@@ -16,6 +16,7 @@ class ApplicationImp
: public Application
, public SharedSingleton <ApplicationImp>
, public Validators::Listener
, public NodeStore::Scheduler
, LeakChecked <ApplicationImp>
{
public:
@@ -46,15 +47,14 @@ public:
, mNetOps (new NetworkOPs (&mLedgerMaster))
, m_rpcServerHandler (*mNetOps)
, mTempNodeCache ("NodeCache", 16384, 90)
, m_nodeStore (NodeStore::New (
theConfig.NODE_DB,
theConfig.FASTNODE_DB,
16384,
300))
, mSLECache ("LedgerEntryCache", 4096, 120)
, mSNTPClient (mAuxService)
, mJobQueue (mIOService)
// VFALCO New stuff
, m_nodeStore (NodeStore::New (
theConfig.NODE_DB,
theConfig.FASTNODE_DB,
*this))
, m_validators (Validators::New (this))
, mFeatures (IFeatures::New (2 * 7 * 24 * 60 * 60, 200)) // two weeks, 200/256
, mFeeVote (IFeeVote::New (10, 50 * SYSTEM_CURRENCY_PARTS, 12.5 * SYSTEM_CURRENCY_PARTS))
@@ -92,11 +92,28 @@ public:
delete mWalletDB;
}
//--------------------------------------------------------------------------
static void callScheduledTask (NodeStore::Scheduler::Task* task, Job&)
{
task->performScheduledTask ();
}
void scheduleTask (NodeStore::Scheduler::Task* task)
{
getJobQueue ().addJob (
jtWRITE,
"NodeObject::store",
BIND_TYPE (&ApplicationImp::callScheduledTask, task, P_1));
}
//--------------------------------------------------------------------------
LocalCredentials& getLocalCredentials ()
{
return m_localCredentials ;
}
NetworkOPs& getOPs ()
{
return *mNetOps;
@@ -106,62 +123,62 @@ public:
{
return mIOService;
}
LedgerMaster& getLedgerMaster ()
{
return mLedgerMaster;
}
InboundLedgers& getInboundLedgers ()
{
return m_inboundLedgers;
}
TransactionMaster& getMasterTransaction ()
{
return mMasterTransaction;
}
NodeCache& getTempNodeCache ()
{
return mTempNodeCache;
}
NodeStore& getNodeStore ()
{
return *m_nodeStore;
}
JobQueue& getJobQueue ()
{
return mJobQueue;
}
MasterLockType& getMasterLock ()
{
return mMasterLock;
}
ILoadManager& getLoadManager ()
{
return *m_loadManager;
}
TXQueue& getTxnQueue ()
{
return mTxnQueue;
}
PeerDoor& getPeerDoor ()
{
return *mPeerDoor;
}
OrderBookDB& getOrderBookDB ()
{
return mOrderBookDB;
}
SLECache& getSLECache ()
{
return mSLECache;
@@ -176,37 +193,37 @@ public:
{
return *mFeatures;
}
ILoadFeeTrack& getFeeTrack ()
{
return *mFeeTrack;
}
IFeeVote& getFeeVote ()
{
return *mFeeVote;
}
IHashRouter& getHashRouter ()
{
return *mHashRouter;
}
IValidations& getValidations ()
{
return *mValidations;
}
UniqueNodeList& getUNL ()
{
return *mUNL;
}
IProofOfWorkFactory& getProofOfWorkFactory ()
{
return *mProofOfWorkFactory;
}
IPeers& getPeers ()
{
return *mPeers;
@@ -272,7 +289,6 @@ private:
ScopedPointer <NetworkOPs> mNetOps;
RPCServerHandler m_rpcServerHandler;
NodeCache mTempNodeCache;
ScopedPointer <NodeStore> m_nodeStore;
SLECache mSLECache;
SNTPClient mSNTPClient;
JobQueue mJobQueue;
@@ -280,16 +296,17 @@ private:
OrderBookDB mOrderBookDB;
// VFALCO Clean stuff
beast::ScopedPointer <Validators> m_validators;
beast::ScopedPointer <IFeatures> mFeatures;
beast::ScopedPointer <IFeeVote> mFeeVote;
beast::ScopedPointer <ILoadFeeTrack> mFeeTrack;
beast::ScopedPointer <IHashRouter> mHashRouter;
beast::ScopedPointer <IValidations> mValidations;
beast::ScopedPointer <UniqueNodeList> mUNL;
beast::ScopedPointer <IProofOfWorkFactory> mProofOfWorkFactory;
beast::ScopedPointer <IPeers> mPeers;
beast::ScopedPointer <ILoadManager> m_loadManager;
ScopedPointer <NodeStore> m_nodeStore;
ScopedPointer <Validators> m_validators;
ScopedPointer <IFeatures> mFeatures;
ScopedPointer <IFeeVote> mFeeVote;
ScopedPointer <ILoadFeeTrack> mFeeTrack;
ScopedPointer <IHashRouter> mHashRouter;
ScopedPointer <IValidations> mValidations;
ScopedPointer <UniqueNodeList> mUNL;
ScopedPointer <IProofOfWorkFactory> mProofOfWorkFactory;
ScopedPointer <IPeers> mPeers;
ScopedPointer <ILoadManager> m_loadManager;
// VFALCO End Clean stuff
DatabaseCon* mRpcDB;
@@ -382,7 +399,7 @@ void ApplicationImp::setup ()
if (!theConfig.DEBUG_LOGFILE.empty ())
{
// Let BEAST_DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose)
// Let debug messages go to the file but only WARNING or higher to regular output (unless verbose)
Log::setLogFile (theConfig.DEBUG_LOGFILE);
if (Log::getMinSeverity () > lsDEBUG)
@@ -596,7 +613,7 @@ void ApplicationImp::run ()
// VFALCO NOTE This seems unnecessary. If we properly refactor the load
// manager then the deadlock detector can just always be "armed"
//
getApp().getLoadManager ().activateDeadlockDetector ();
getApp().getLoadManager ().activateDeadlockDetector ();
}
mIOService.run (); // This blocks
@@ -964,7 +981,7 @@ void ApplicationImp::updateTables ()
}
if (!theConfig.DB_IMPORT.empty())
getApp().getNodeStore().import(theConfig.DB_IMPORT);
getApp().getNodeStore().import(theConfig.DB_IMPORT);
}
//------------------------------------------------------------------------------

View File

@@ -65,12 +65,12 @@ public:
char const* getFileName () const noexcept
{
return m_fileName;
return m_fileName.get ();
}
int getLineNumber () const noexcept
{
return m_lineNumber;
return m_lineNumber.get ();
}
private:
@@ -78,19 +78,19 @@ public:
void setOwner (char const* fileName, int lineNumber)
{
m_fileName = fileName;
m_lineNumber = lineNumber;
m_fileName.set (fileName);
m_lineNumber.set (lineNumber);
}
void resetOwner ()
{
m_fileName = "";
m_lineNumber = 0;
m_fileName.set ("");
m_lineNumber.set (0);
}
boost::recursive_mutex m_mutex;
char const* m_fileName;
int m_lineNumber;
Atomic <char const*> m_fileName;
Atomic <int> m_lineNumber;
};
class ScopedLockType

View File

@@ -156,15 +156,6 @@ static void runBeastUnitTests (std::string const& individualTest = "")
{
tr.runTest (individualTest.c_str ());
}
// Report
for (int i = 0; i < tr.getNumResults (); ++i)
{
UnitTests::TestResult const& r (*tr.getResult (i));
for (int j = 0; j < r.messages.size (); ++j)
Log::out () << r.messages [j].toStdString ();
}
}
//------------------------------------------------------------------------------
@@ -257,16 +248,16 @@ int rippleMain (int argc, char** argv)
p.add ("parameters", -1);
// These must be added before the Application object is created
NodeStore::addBackendFactory (KeyvaDBBackendFactory::getInstance ());
NodeStore::addBackendFactory (LevelDBBackendFactory::getInstance ());
NodeStore::addBackendFactory (NullBackendFactory::getInstance ());
NodeStore::addBackendFactory (SqliteBackendFactory::getInstance ());
#if RIPPLE_HYPERLEVELDB_AVAILABLE
NodeStore::addBackendFactory (HyperLevelDBBackendFactory::getInstance ());
#endif
NodeStore::addBackendFactory (KeyvaDBBackendFactory::getInstance ());
NodeStore::addBackendFactory (LevelDBBackendFactory::getInstance ());
#if RIPPLE_MDB_AVAILABLE
NodeStore::addBackendFactory (MdbBackendFactory::getInstance ());
#endif
NodeStore::addBackendFactory (NullBackendFactory::getInstance ());
NodeStore::addBackendFactory (SqliteBackendFactory::getInstance ());
if (! RandomNumbers::getInstance ().initialize ())
{

View File

@@ -1554,7 +1554,7 @@ void PeerImp::recvGetObjectByHash (const boost::shared_ptr<protocol::TMGetObject
if (obj.has_hash () && (obj.hash ().size () == (256 / 8)))
{
memcpy (hash.begin (), obj.hash ().data (), 256 / 8);
NodeObject::pointer hObj = getApp().getNodeStore ().retrieve (hash);
NodeObject::pointer hObj = getApp().getNodeStore ().fetch (hash);
if (hObj)
{

View File

@@ -236,7 +236,7 @@ IProofOfWorkFactory* IProofOfWorkFactory::New ()
class ProofOfWorkTests : public UnitTest
{
public:
ProofOfWorkTests () : UnitTest ("ProofOfWork")
ProofOfWorkTests () : UnitTest ("ProofOfWork", "ripple")
{
}

View File

@@ -205,7 +205,7 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& id, uint256 const& ha
if (node)
{
#ifdef BEAST_DEBUG
#if BEAST_DEBUG
if (node->getNodeHash () != hash)
{
@@ -213,7 +213,7 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& id, uint256 const& ha
WriteLog (lsFATAL, SHAMap) << "ID: " << id;
WriteLog (lsFATAL, SHAMap) << "TgtHash " << hash;
WriteLog (lsFATAL, SHAMap) << "NodHash " << node->getNodeHash ();
throw std::runtime_error ("invalid node");
Throw (std::runtime_error ("invalid node"));
}
#endif
@@ -230,7 +230,7 @@ SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& has
SHAMapTreeNode* ret = getNodePointerNT (id, hash);
if (!ret)
throw SHAMapMissingNode (mType, id, hash);
Throw (SHAMapMissingNode (mType, id, hash));
return ret;
}
@@ -251,7 +251,7 @@ SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& id, uint256 const& has
SHAMapTreeNode* ret = getNodePointerNT (id, hash, filter);
if (!ret)
throw SHAMapMissingNode (mType, id, hash);
Throw (SHAMapMissingNode (mType, id, hash));
return ret;
}
@@ -493,7 +493,7 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT
firstNode = firstBelow (firstNode);
if (!firstNode || firstNode->isInner ())
throw std::runtime_error ("missing/corrupt node");
Throw (std::runtime_error ("missing/corrupt node"));
type = firstNode->getType ();
return firstNode->peekItem ();
@@ -531,7 +531,7 @@ SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id)
SHAMapTreeNode* item = firstBelow (node.get ());
if (!item)
throw std::runtime_error ("missing node");
Throw (std::runtime_error ("missing node"));
return item->peekItem ();
}
@@ -597,7 +597,7 @@ bool SHAMap::delItem (uint256 const& id)
std::stack<SHAMapTreeNode::pointer> stack = getStack (id, true);
if (stack.empty ())
throw std::runtime_error ("missing node");
Throw (std::runtime_error ("missing node"));
SHAMapTreeNode::pointer leaf = stack.top ();
stack.pop ();
@@ -678,7 +678,7 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta
std::stack<SHAMapTreeNode::pointer> stack = getStack (tag, true);
if (stack.empty ())
throw std::runtime_error ("missing node");
Throw (std::runtime_error ("missing node"));
SHAMapTreeNode::pointer node = stack.top ();
stack.pop ();
@@ -703,7 +703,7 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta
WriteLog (lsFATAL, SHAMap) << "NewNode: " << *newNode;
dump ();
assert (false);
throw std::runtime_error ("invalid inner node");
Throw (std::runtime_error ("invalid inner node"));
}
trackNewNode (newNode);
@@ -776,7 +776,7 @@ bool SHAMap::updateGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasM
std::stack<SHAMapTreeNode::pointer> stack = getStack (tag, true);
if (stack.empty ())
throw std::runtime_error ("missing node");
Throw (std::runtime_error ("missing node"));
SHAMapTreeNode::pointer node = stack.top ();
stack.pop ();
@@ -810,7 +810,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal (const SHAMapNode& id, uint256
SHAMapTreeNode::pointer ret = fetchNodeExternalNT (id, hash);
if (!ret)
throw SHAMapMissingNode (mType, id, hash);
Throw (SHAMapMissingNode (mType, id, hash));
return ret;
}
@@ -825,8 +825,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNode& id, uint2
// These are for diagnosing a crash on exit
Application& app (getApp ());
NodeStore& nodeStore (app.getNodeStore ());
NodeObject::pointer obj (getApp().getNodeStore ().retrieve (hash));
NodeObject::pointer obj (nodeStore.fetch (hash));
if (!obj)
{
@@ -889,8 +888,11 @@ bool SHAMap::fetchRoot (uint256 const& hash, SHAMapSyncFilter* filter)
}
SHAMapTreeNode::pointer newRoot = fetchNodeExternalNT(SHAMapNode(), hash);
if (newRoot)
{
root = newRoot;
}
else
{
Blob nodeData;
@@ -939,7 +941,7 @@ int SHAMap::flushDirty (DirtyMap& map, int maxNodes, NodeObjectType t, uint32 se
#endif
getApp().getNodeStore ().store (t, seq, s.peekData (), it->second->getNodeHash ());
getApp().getNodeStore ().store (t, seq, s.modData (), it->second->getNodeHash ());
if (flushed++ >= maxNodes)
return flushed;

View File

@@ -128,7 +128,7 @@ SHAMapNode SHAMapNode::getChildNodeID (int m) const
// Which branch would contain the specified hash
int SHAMapNode::selectBranch (uint256 const& hash) const
{
#ifdef PARANOID
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
if (mDepth >= 64)
{

View File

@@ -243,7 +243,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format,
{
Serializer s;
root->addRaw (s, snfPREFIX);
filter->gotNode (false, *root, root->getNodeHash (), s.peekData (), root->getType ());
filter->gotNode (false, *root, root->getNodeHash (), s.modData (), root->getType ());
}
return SHAMapAddNode::useful ();
@@ -281,7 +281,7 @@ SHAMapAddNode SHAMap::addRootNode (uint256 const& hash, Blob const& rootNode, SH
{
Serializer s;
root->addRaw (s, snfPREFIX);
filter->gotNode (false, *root, root->getNodeHash (), s.peekData (), root->getType ());
filter->gotNode (false, *root, root->getNodeHash (), s.modData (), root->getType ());
}
return SHAMapAddNode::useful ();
@@ -345,7 +345,7 @@ SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode,
{
Serializer s;
newNode->addRaw (s, snfPREFIX);
filter->gotNode (false, node, iNode->getChildHash (branch), s.peekData (), newNode->getType ());
filter->gotNode (false, node, iNode->getChildHash (branch), s.modData (), newNode->getType ());
}
mTNByID[node] = newNode;

View File

@@ -12,29 +12,18 @@
class SHAMapSyncFilter
{
public:
SHAMapSyncFilter ()
{
}
virtual ~SHAMapSyncFilter ()
{
}
virtual ~SHAMapSyncFilter () { }
// Note that the nodeData is overwritten by this call
virtual void gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
SHAMapTreeNode::TNType type)
{
}
Blob& nodeData,
SHAMapTreeNode::TNType type) = 0;
virtual bool haveNode (SHAMapNode const& id,
uint256 const& nodeHash,
Blob& nodeData)
{
return false;
}
Blob& nodeData) = 0;
};
#endif
// vim:ts=4

View File

@@ -9,7 +9,7 @@ ConsensusTransSetSF::ConsensusTransSetSF ()
}
void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNode& id, uint256 const& nodeHash,
Blob const& nodeData, SHAMapTreeNode::TNType type)
Blob& nodeData, SHAMapTreeNode::TNType type)
{
if (fromFilter)
return;
@@ -70,7 +70,7 @@ AccountStateSF::AccountStateSF (uint32 ledgerSeq)
void AccountStateSF::gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
Blob& nodeData,
SHAMapTreeNode::TNType)
{
getApp().getNodeStore ().store (hotACCOUNT_NODE, mLedgerSeq, nodeData, nodeHash);
@@ -93,7 +93,7 @@ TransactionStateSF::TransactionStateSF (uint32 ledgerSeq)
void TransactionStateSF::gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
Blob& nodeData,
SHAMapTreeNode::TNType type)
{
getApp().getNodeStore ().store (

View File

@@ -17,10 +17,11 @@ class ConsensusTransSetSF : public SHAMapSyncFilter
public:
ConsensusTransSetSF ();
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
Blob& nodeData,
SHAMapTreeNode::TNType);
bool haveNode (SHAMapNode const& id,
@@ -35,10 +36,11 @@ class AccountStateSF : public SHAMapSyncFilter
public:
explicit AccountStateSF (uint32 ledgerSeq);
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
Blob& nodeData,
SHAMapTreeNode::TNType);
bool haveNode (SHAMapNode const& id,
@@ -56,10 +58,11 @@ class TransactionStateSF : public SHAMapSyncFilter
public:
explicit TransactionStateSF (uint32 ledgerSeq);
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNode const& id,
uint256 const& nodeHash,
Blob const& nodeData,
Blob& nodeData,
SHAMapTreeNode::TNType);
bool haveNode (SHAMapNode const& id,

View File

@@ -207,7 +207,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, uint3
if (hashValid)
{
mHash = hash;
#ifdef PARANOID
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
updateHash ();
assert (mHash == hash);
#endif
@@ -225,7 +225,7 @@ bool SHAMapTreeNode::updateHash ()
if (mIsBranch != 0)
{
nh = Serializer::getPrefixHash (HashPrefix::innerNode, reinterpret_cast<unsigned char*> (mHashes), sizeof (mHashes));
#ifdef PARANOID
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
Serializer s;
s.add32 (HashPrefix::innerNode);