From 837872c3f39fcdf55007eb1a6408193fa5356fe5 Mon Sep 17 00:00:00 2001 From: Scott Schurr Date: Thu, 19 Jun 2014 16:09:24 -0700 Subject: [PATCH] Move static treeNodeCache from SHAMap to the Application These changes address two JIRA issues: - 291 unittest reported leaked objects - 292 SHAMap::treeNodeCache should be a dependency injection The treeNodeCache was a static member of SHAMap. It's now a non-static member of the Application accessed through getTreeNodeCache(). That addressed JIRA 291 The SHAMap constructors were adjusted so the treeNodeCache is passed in to the constructor. That addresses JIRA 292, It required that any code constructing a SHAMap needed to be edited to pass the new parameter to the constructed SHAMap. In the mean time, SHAMap was examined for dead/unused code and interfaces that could be made private. Dead and unused interfaces were removed and methods that could be private were made private. --- .../module/app/consensus/LedgerConsensus.cpp | 17 +-- src/ripple/module/app/ledger/Ledger.cpp | 35 +++--- src/ripple/module/app/main/Application.cpp | 18 +++- src/ripple/module/app/main/Application.h | 5 +- .../module/app/shamap/FetchPackTests.cpp | 21 ++-- src/ripple/module/app/shamap/SHAMap.cpp | 45 ++++---- src/ripple/module/app/shamap/SHAMap.h | 102 +++++------------- src/ripple/module/app/shamap/SHAMapSync.cpp | 21 ++-- src/ripple/module/app/shamap/SHAMapTreeNode.h | 2 + .../module/app/tx/TransactionAcquire.cpp | 3 +- src/ripple/module/rpc/handlers/GetCounts.cpp | 21 ++-- 11 files changed, 139 insertions(+), 151 deletions(-) diff --git a/src/ripple/module/app/consensus/LedgerConsensus.cpp b/src/ripple/module/app/consensus/LedgerConsensus.cpp index 6d420831e..b2ff907c5 100644 --- a/src/ripple/module/app/consensus/LedgerConsensus.cpp +++ b/src/ripple/module/app/consensus/LedgerConsensus.cpp @@ -270,13 +270,16 @@ public: { if (hash.isZero ()) { + Application& app = getApp(); SHAMap::pointer empty = std::make_shared ( - smtTRANSACTION, std::ref (getApp().getFullBelowCache())); + smtTRANSACTION, + app.getFullBelowCache(), + app.getTreeNodeCache()); mapComplete (hash, empty, false); return empty; } - acquiring = std::make_shared (hash, std::ref (m_clock)); + acquiring = std::make_shared (hash, m_clock); startAcquiring (acquiring); } } @@ -870,7 +873,7 @@ private: Ledger::pointer newLCL = std::make_shared (false - , std::ref (*mPreviousLedger)); + , *mPreviousLedger); // Set up to write SHAMap changes to our database, // perform updates, extract changes @@ -963,7 +966,7 @@ private: getApp().getLedgerMaster().consensusBuilt (newLCL); Ledger::pointer newOL = std::make_shared - (true, std::ref (*newLCL)); + (true, *newLCL); LedgerMaster::ScopedLockType sl (getApp().getLedgerMaster ().peekMutex ()); @@ -981,8 +984,7 @@ private: << " not get in"; SerializerIterator sit (it.second->peekTransaction ()); SerializedTransaction::pointer txn - = std::make_shared - (std::ref (sit)); + = std::make_shared(sit); if (applyTransaction (engine, txn, newOL, true, false)) { @@ -1263,8 +1265,7 @@ private: #endif SerializerIterator sit (item->peekSerializer ()); SerializedTransaction::pointer txn - = std::make_shared - (std::ref (sit)); + = std::make_shared(sit); if (applyTransaction (engine, txn, applyLedger, openLgr, true) == resultRetry) diff --git a/src/ripple/module/app/ledger/Ledger.cpp b/src/ripple/module/app/ledger/Ledger.cpp index 2ee9f574e..bfb15ef5c 100644 --- a/src/ripple/module/app/ledger/Ledger.cpp +++ b/src/ripple/module/app/ledger/Ledger.cpp @@ -41,9 +41,11 @@ Ledger::Ledger (const RippleAddress& masterID, std::uint64_t startAmount) , mAccepted (false) , mImmutable (false) , mTransactionMap (std::make_shared (smtTRANSACTION, - std::ref (getApp().getFullBelowCache()))) + getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) , mAccountStateMap (std::make_shared (smtSTATE, - std::ref (getApp().getFullBelowCache()))) + getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) { // special case: put coins in root account auto startAccount = std::make_shared (masterID); @@ -91,9 +93,12 @@ Ledger::Ledger (uint256 const& parentHash, , mAccepted (false) , mImmutable (true) , mTransactionMap (std::make_shared ( - smtTRANSACTION, transHash, std::ref (getApp().getFullBelowCache()))) + smtTRANSACTION, transHash, + getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) , mAccountStateMap (std::make_shared (smtSTATE, accountHash, - std::ref (getApp().getFullBelowCache()))) + getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) { updateHash (); loaded = true; @@ -154,7 +159,8 @@ Ledger::Ledger (bool /* dummy */, , mAccepted (false) , mImmutable (false) , mTransactionMap (std::make_shared (smtTRANSACTION, - std::ref (getApp().getFullBelowCache()))) + getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) , mAccountStateMap (prevLedger.mAccountStateMap->snapShot (true)) { prevLedger.updateHash (); @@ -222,9 +228,11 @@ Ledger::Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime) mAccepted (false), mImmutable (false), mTransactionMap (std::make_shared ( - smtTRANSACTION, std::ref (getApp().getFullBelowCache()))), + smtTRANSACTION, getApp().getFullBelowCache(), + getApp().getTreeNodeCache())), mAccountStateMap (std::make_shared ( - smtSTATE, std::ref (getApp().getFullBelowCache()))) + smtSTATE, getApp().getFullBelowCache(), + getApp().getTreeNodeCache())) { initializeFees (); } @@ -304,10 +312,13 @@ void Ledger::setRaw (Serializer& s, bool hasPrefix) if (mValidHash) { + Application& app = getApp(); mTransactionMap = std::make_shared (smtTRANSACTION, mTransHash, - std::ref (getApp().getFullBelowCache())); + app.getFullBelowCache(), + app.getTreeNodeCache()); mAccountStateMap = std::make_shared (smtSTATE, mAccountHash, - std::ref (getApp().getFullBelowCache())); + app.getFullBelowCache(), + app.getTreeNodeCache()); } } @@ -476,13 +487,13 @@ SerializedTransaction::pointer Ledger::getSTransaction ( SerializerIterator sit (item->peekSerializer ()); if (type == SHAMapTreeNode::tnTRANSACTION_NM) - return std::make_shared (std::ref (sit)); + return std::make_shared (sit); if (type == SHAMapTreeNode::tnTRANSACTION_MD) { Serializer sTxn (sit.getVL ()); SerializerIterator tSit (sTxn); - return std::make_shared (std::ref (tSit)); + return std::make_shared (tSit); } return SerializedTransaction::pointer (); @@ -497,7 +508,7 @@ SerializedTransaction::pointer Ledger::getSMTransaction ( if (type == SHAMapTreeNode::tnTRANSACTION_NM) { txMeta.reset (); - return std::make_shared (std::ref (sit)); + return std::make_shared (sit); } else if (type == SHAMapTreeNode::tnTRANSACTION_MD) { diff --git a/src/ripple/module/app/main/Application.cpp b/src/ripple/module/app/main/Application.cpp index fca1bd7b6..e455924eb 100644 --- a/src/ripple/module/app/main/Application.cpp +++ b/src/ripple/module/app/main/Application.cpp @@ -30,7 +30,7 @@ #include #include #include - + namespace ripple { // VFALCO TODO Clean this global up @@ -147,6 +147,7 @@ public: std::unique_ptr m_nodeStoreManager; NodeCache m_tempNodeCache; + TreeNodeCache m_treeNodeCache; SLECache m_sleCache; LocalCredentials m_localCredentials; TransactionMaster m_txMaster; @@ -230,6 +231,9 @@ public: , m_tempNodeCache ("NodeCache", 16384, 90, get_seconds_clock (), m_logs.journal("TaggedCache")) + , m_treeNodeCache ("TreeNodeCache", 65536, 60, get_seconds_clock (), + deprecatedLogs().journal("TaggedCache")) + , m_sleCache ("LedgerEntryCache", 4096, 120, get_seconds_clock (), m_logs.journal("TaggedCache")) @@ -421,6 +425,11 @@ public: return m_tempNodeCache; } + TreeNodeCache& getTreeNodeCache () + { + return m_treeNodeCache; + } + NodeStore::Database& getNodeStore () { return *m_nodeStore; @@ -679,7 +688,8 @@ public: m_ledgerMaster->tune (getConfig ().getSize (siLedgerSize), getConfig ().getSize (siLedgerAge)); m_sleCache.setTargetSize (getConfig ().getSize (siSLECacheSize)); m_sleCache.setTargetAge (getConfig ().getSize (siSLECacheAge)); - SHAMap::setTreeCache (getConfig ().getSize (siTreeCacheSize), getConfig ().getSize (siTreeCacheAge)); + m_treeNodeCache.setTargetSize (getConfig ().getSize (siTreeCacheSize)); + m_treeNodeCache.setTargetAge (getConfig ().getSize (siTreeCacheAge)); //---------------------------------------------------------------------- @@ -1050,8 +1060,8 @@ public: logTimedCall (m_journal.warning, "AcceptedLedger::sweep", __FILE__, __LINE__, &AcceptedLedger::sweep); - logTimedCall (m_journal.warning, "SHAMap::sweep", __FILE__, __LINE__, - &SHAMap::sweep); + logTimedCall (m_journal.warning, "SHAMap::sweep", __FILE__, __LINE__,std::bind ( + &TreeNodeCache::sweep, &m_treeNodeCache)); logTimedCall (m_journal.warning, "NetworkOPs::sweepFetchPack", __FILE__, __LINE__, std::bind ( &NetworkOPs::sweepFetchPack, m_networkOPs.get ())); diff --git a/src/ripple/module/app/main/Application.h b/src/ripple/module/app/main/Application.h index b4d59ae40..470946412 100644 --- a/src/ripple/module/app/main/Application.h +++ b/src/ripple/module/app/main/Application.h @@ -53,8 +53,8 @@ class PathRequests; class DatabaseCon; -typedef TaggedCache NodeCache; -typedef TaggedCache SLECache; +using NodeCache = TaggedCache ; +using SLECache = TaggedCache ; class Application : public beast::PropertyStream::Source { @@ -87,6 +87,7 @@ public: virtual RPC::Manager& getRPCManager () = 0; virtual SiteFiles::Manager& getSiteFiles () = 0; virtual NodeCache& getTempNodeCache () = 0; + virtual TreeNodeCache& getTreeNodeCache () = 0; virtual SLECache& getSLECache () = 0; virtual Validators::Manager& getValidators () = 0; virtual AmendmentTable& getAmendmentTable() = 0; diff --git a/src/ripple/module/app/shamap/FetchPackTests.cpp b/src/ripple/module/app/shamap/FetchPackTests.cpp index a2552be40..e45d2b682 100644 --- a/src/ripple/module/app/shamap/FetchPackTests.cpp +++ b/src/ripple/module/app/shamap/FetchPackTests.cpp @@ -75,18 +75,21 @@ public: { using namespace RadixMap; - FullBelowCache fullBelowCache ("test.full_below", - get_seconds_clock ()); + beast::manual_clock clock; // manual advance clock + beast::Journal const j; // debug journal + + FullBelowCache fullBelowCache ("test.full_below", clock); + TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j); std::shared_ptr t1 (std::make_shared
( - smtFREE, fullBelowCache)); - + smtFREE, fullBelowCache, treeNodeCache)); + pass (); // beast::Random r; // add_random_items (tableItems, *t1, r); // std::shared_ptr
t2 (t1->snapShot (true)); -// +// // add_random_items (tableItemsExtra, *t1, r); // add_random_items (tableItemsExtra, *t2, r); @@ -102,16 +105,16 @@ public: // try // { // TestFilter filter (map, beast::Journal()); -// +// // t3 = std::make_shared
(smtFREE, t2->getHash (), // fullBelowCache); -// +// // expect (t3->fetchRoot (t2->getHash (), &filter), "unable to get root"); -// +// // // everything should be in the pack, no hashes should be needed // std::vector hashes = t3->getNeededHashes(1, &filter); // expect (hashes.empty(), "missing hashes"); -// +// // expect (t3->getHash () == t2->getHash (), "root hashes do not match"); // expect (t3->deepCompare (*t2), "failed compare"); // } diff --git a/src/ripple/module/app/shamap/SHAMap.cpp b/src/ripple/module/app/shamap/SHAMap.cpp index 99d448b11..2f219e001 100644 --- a/src/ripple/module/app/shamap/SHAMap.cpp +++ b/src/ripple/module/app/shamap/SHAMap.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace ripple { @@ -29,11 +30,16 @@ void SHAMap::DefaultMissingNodeHandler::operator() (std::uint32_t refNUm) //------------------------------------------------------------------------------ -SHAMap::SHAMap (SHAMapType t, FullBelowCache& fullBelowCache, std::uint32_t seq, +SHAMap::SHAMap ( + SHAMapType t, + FullBelowCache& fullBelowCache, + TreeNodeCache& treeNodeCache, + std::uint32_t seq, MissingNodeHandler missing_node_handler) : m_fullBelowCache (fullBelowCache) , mSeq (seq) , mLedgerSeq (0) + , mTreeNodeCache (treeNodeCache) , mState (smsModifying) , mType (t) , mTXMap (false) @@ -48,11 +54,16 @@ SHAMap::SHAMap (SHAMapType t, FullBelowCache& fullBelowCache, std::uint32_t seq, mTNByID.replace(root->getID(), root); } -SHAMap::SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCache, +SHAMap::SHAMap ( + SHAMapType t, + uint256 const& hash, + FullBelowCache& fullBelowCache, + TreeNodeCache& treeNodeCache, MissingNodeHandler missing_node_handler) : m_fullBelowCache (fullBelowCache) , mSeq (1) , mLedgerSeq (0) + , mTreeNodeCache (treeNodeCache) , mState (smsSynching) , mType (t) , mTXMap (false) @@ -66,11 +77,6 @@ SHAMap::SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCach mTNByID.replace(root->getID(), root); } -TaggedCache - SHAMap::treeNodeCache ("TreeNodeCache", 65536, 60, - get_seconds_clock (), - deprecatedLogs().journal("TaggedCache")); - SHAMap::~SHAMap () { mState = smsInvalid; @@ -116,7 +122,7 @@ std::size_t hash_value (const SHAMapNodeID& mn) SHAMap::pointer SHAMap::snapShot (bool isMutable) { SHAMap::pointer ret = std::make_shared (mType, - std::ref (m_fullBelowCache)); + m_fullBelowCache, mTreeNodeCache); SHAMap& newMap = *ret; // Return a new SHAMap that is a snapshot of this one @@ -346,7 +352,7 @@ SHAMapTreeNode* SHAMap::getNodePointerNT (const SHAMapNodeID& id, uint256 const& if (filter->haveNode (id, hash, nodeData)) { SHAMapTreeNode::pointer node = std::make_shared ( - std::cref (id), std::cref (nodeData), 0, snfPREFIX, std::cref (hash), true); + id, nodeData, 0, snfPREFIX, hash, true); canonicalize (hash, node); // Canonicalize the node with mTNByID to make sure all threads gets the same node @@ -944,7 +950,7 @@ SHAMapTreeNode* SHAMap::getNodeAsync ( if (filter->haveNode (id, hash, nodeData)) { ptr = std::make_shared ( - std::cref (id), std::cref (nodeData), 0, snfPREFIX, std::cref (hash), true); + id, nodeData, 0, snfPREFIX, hash, true); filter->gotNode (true, id, hash, nodeData, ptr->getType ()); } } @@ -1083,7 +1089,7 @@ bool SHAMap::fetchRoot (uint256 const& hash, SHAMapSyncFilter* filter) } SHAMapTreeNode::pointer newRoot = fetchNodeExternalNT(SHAMapNodeID(), hash); - + if (newRoot) { root = newRoot; @@ -1302,7 +1308,7 @@ void SHAMap::dump (bool hash) SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash, SHAMapNodeID const& id) { - SHAMapTreeNode::pointer ret = treeNodeCache.fetch (hash); + SHAMapTreeNode::pointer ret = mTreeNodeCache.fetch (hash); assert (!ret || !ret->getSeq()); if (ret && (ret->getID() != id)) @@ -1313,7 +1319,7 @@ SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash, SHAMapNodeID cons ret->setID(id); // Future fetches are likely to use the "new" ID - treeNodeCache.canonicalize (hash, ret, true); + mTreeNodeCache.canonicalize (hash, ret, true); assert (ret->getID() == id); assert (ret->getNodeHash() == hash); } @@ -1327,7 +1333,7 @@ void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node) SHAMapNodeID id = node->getID(); - treeNodeCache.canonicalize (hash, node); + mTreeNodeCache.canonicalize (hash, node); if (id != node->getID()) { @@ -1336,7 +1342,7 @@ void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node) node->setID(id); // Future fetches are likely to use the newer ID - treeNodeCache.canonicalize (hash, node, true); + mTreeNodeCache.canonicalize (hash, node, true); assert (id == node->getID()); } } @@ -1362,8 +1368,11 @@ public: { testcase ("add/traverse"); - FullBelowCache fullBelowCache ("test.full_below", - get_seconds_clock ()); + beast::manual_clock clock; // manual advance clock + beast::Journal const j; // debug journal + + FullBelowCache fullBelowCache ("test.full_below", clock); + TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j); // h3 and h4 differ only in the leaf, same terminal node (level 19) uint256 h1, h2, h3, h4, h5; @@ -1373,7 +1382,7 @@ public: h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8"); h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); - SHAMap sMap (smtFREE, fullBelowCache); + SHAMap sMap (smtFREE, fullBelowCache, treeNodeCache); SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5)); unexpected (!sMap.addItem (i2, true, false), "no add"); diff --git a/src/ripple/module/app/shamap/SHAMap.h b/src/ripple/module/app/shamap/SHAMap.h index bfa3e360f..fce83e1a8 100644 --- a/src/ripple/module/app/shamap/SHAMap.h +++ b/src/ripple/module/app/shamap/SHAMap.h @@ -89,7 +89,6 @@ enum SHAMapState See https://en.wikipedia.org/wiki/Merkle_tree */ class SHAMap -// : public CountedObject { private: /** Function object which handles missing nodes. */ @@ -124,10 +123,18 @@ public: public: // build new map - explicit SHAMap (SHAMapType t, FullBelowCache& fullBelowCache, - std::uint32_t seq = 1, MissingNodeHandler missing_node_handler = DefaultMissingNodeHandler()); + SHAMap ( + SHAMapType t, + FullBelowCache& fullBelowCache, + TreeNodeCache& treeNodeCache, + std::uint32_t seq = 1, + MissingNodeHandler missing_node_handler = DefaultMissingNodeHandler()); - SHAMap (SHAMapType t, uint256 const& hash, FullBelowCache& fullBelowCache, + SHAMap ( + SHAMapType t, + uint256 const& hash, + FullBelowCache& fullBelowCache, + TreeNodeCache& treeNodeCache, MissingNodeHandler missing_node_handler = DefaultMissingNodeHandler()); ~SHAMap (); @@ -148,22 +155,17 @@ public: mLedgerSeq = lseq; } - bool hasNode (const SHAMapNodeID & id); bool fetchRoot (uint256 const & hash, SHAMapSyncFilter * filter); // normal hash access functions bool hasItem (uint256 const & id); bool delItem (uint256 const & id); bool addItem (const SHAMapItem & i, bool isTransaction, bool hasMeta); - bool updateItem (const SHAMapItem & i, bool isTransaction, bool hasMeta); + uint256 getHash () const { return root->getNodeHash (); } - uint256 getHash () - { - return root->getNodeHash (); - } // save a copy if you have a temporary anyway bool updateGiveItem (SHAMapItem::ref, bool isTransaction, bool hasMeta); @@ -203,10 +205,6 @@ public: assert (mState != smsInvalid); mState = smsImmutable; } - bool isImmutable () - { - return mState == smsImmutable; - } bool isSynching () const { return (mState == smsFloating) || (mState == smsSynching); @@ -215,10 +213,6 @@ public: { mState = smsSynching; } - void setFloating () - { - mState = smsFloating; - } void clearSynching () { mState = smsModifying; @@ -234,78 +228,37 @@ public: int armDirty (); int flushDirty (DirtySet & dirtySet, int maxNodes, NodeObjectType t, - std::uint32_t seq); + std::uint32_t seq); std::shared_ptr disarmDirty (); - void setSeq (std::uint32_t seq) - { - mSeq = seq; - assert (seq != 0); - } - std::uint32_t getSeq () - { - return mSeq; - } - - // overloads for backed maps - SHAMapTreeNode::pointer fetchNodeExternal (const SHAMapNodeID & id, uint256 const & hash); // throws - SHAMapTreeNode::pointer fetchNodeExternalNT (const SHAMapNodeID & id, uint256 const & hash); // no throw - - bool operator== (const SHAMap & s) - { - return getHash () == s.getHash (); - } - - // trusted path operations - prove a particular node is in a particular ledger - std::list getTrustedPath (uint256 const & index); - static Blob checkTrustedPath (uint256 const & ledgerHash, uint256 const & leafIndex, - const std::list& path); - void walkMap (std::vector& missingNodes, int maxMissing); - bool getPath (uint256 const & index, std::vector< Blob >& nodes, SHANodeFormat format); - bool deepCompare (SHAMap & other); - virtual void dump (bool withHashes = false); - typedef std::pair fetchPackEntry_t; - std::list getFetchPack (SHAMap * have, bool includeLeaves, int max); void getFetchPack (SHAMap * have, bool includeLeaves, int max, std::function); - // VFALCO NOTE These static members should be moved into a - // new Application singleton class. - // - // tree node cache operations - static SHAMapTreeNode::pointer getCache (uint256 const& hash, SHAMapNodeID const& id); - static void canonicalize (uint256 const& hash, SHAMapTreeNode::pointer&); - - static int getTreeNodeSize () - { - return treeNodeCache.getCacheSize (); - } - - static void sweep () - { - treeNodeCache.sweep (); - } - - static void setTreeCache (int size, int age) - { - treeNodeCache.setTargetSize (size); - treeNodeCache.setTargetAge (age); - } - void setTXMap () { mTXMap = true; } - typedef std::pair TNIndex; - private: - static TaggedCache treeNodeCache; + // trusted path operations - prove a particular node is in a particular ledger + std::list getTrustedPath (uint256 const & index); + + SHAMapTreeNode::pointer fetchNodeExternal (const SHAMapNodeID & id, + uint256 const & hash); // throws + SHAMapTreeNode::pointer fetchNodeExternalNT (const SHAMapNodeID & id, + uint256 const & hash); // no throw + + bool getPath (uint256 const & index, std::vector< Blob >& nodes, SHANodeFormat format); + void dump (bool withHashes = false); + + // tree node cache operations + SHAMapTreeNode::pointer getCache (uint256 const& hash, SHAMapNodeID const& id); + void canonicalize (uint256 const& hash, SHAMapTreeNode::pointer&); void dirtyUp (std::stack& stack, uint256 const & target, uint256 prevHash); std::stack getStack (uint256 const & id, bool include_nonmatching_leaf); @@ -352,6 +305,7 @@ private: std::uint32_t mLedgerSeq; // sequence number of ledger this is part of SyncUnorderedMapType< SHAMapNodeID, SHAMapTreeNode::pointer, SHAMapNode_hash > mTNByID; std::shared_ptr mDirtyNodes; + TreeNodeCache& mTreeNodeCache; SHAMapTreeNode::pointer root; SHAMapState mState; SHAMapType mType; diff --git a/src/ripple/module/app/shamap/SHAMapSync.cpp b/src/ripple/module/app/shamap/SHAMapSync.cpp index 7ed6c4456..f365b2e3e 100644 --- a/src/ripple/module/app/shamap/SHAMapSync.cpp +++ b/src/ripple/module/app/shamap/SHAMapSync.cpp @@ -634,15 +634,6 @@ static void addFPtoList (std::list& list, const uint25 list.push_back (SHAMap::fetchPackEntry_t (hash, blob)); } -std::list SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max) -{ - std::list ret; - getFetchPack (have, includeLeaves, max, - std::bind (addFPtoList, std::ref (ret), - std::placeholders::_1, std::placeholders::_2)); - return ret; -} - void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max, std::function func) { @@ -811,11 +802,14 @@ public: RAND_pseudo_bytes (reinterpret_cast (&seed), sizeof (seed)); srand (seed); - FullBelowCache fullBelowCache ("test.full_below", - get_seconds_clock ()); + beast::manual_clock clock; // manual advance clock + beast::Journal const j; // debug journal - SHAMap source (smtFREE, fullBelowCache); - SHAMap destination (smtFREE, fullBelowCache); + FullBelowCache fullBelowCache ("test.full_below", clock); + TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j); + + SHAMap source (smtFREE, fullBelowCache, treeNodeCache); + SHAMap destination (smtFREE, fullBelowCache, treeNodeCache); int items = 10000; for (int i = 0; i < items; ++i) @@ -853,6 +847,7 @@ public: do { + ++clock; ++passes; hashes.clear (); diff --git a/src/ripple/module/app/shamap/SHAMapTreeNode.h b/src/ripple/module/app/shamap/SHAMapTreeNode.h index 5933e60e3..f8d6809fa 100644 --- a/src/ripple/module/app/shamap/SHAMapTreeNode.h +++ b/src/ripple/module/app/shamap/SHAMapTreeNode.h @@ -196,6 +196,8 @@ private: bool updateHash (); }; +using TreeNodeCache = TaggedCache ; + } // ripple #endif diff --git a/src/ripple/module/app/tx/TransactionAcquire.cpp b/src/ripple/module/app/tx/TransactionAcquire.cpp index 657b71493..523000139 100644 --- a/src/ripple/module/app/tx/TransactionAcquire.cpp +++ b/src/ripple/module/app/tx/TransactionAcquire.cpp @@ -33,8 +33,9 @@ TransactionAcquire::TransactionAcquire (uint256 const& hash, clock_type& clock) deprecatedLogs().journal("TransactionAcquire")) , mHaveRoot (false) { + Application& app = getApp(); mMap = std::make_shared (smtTRANSACTION, hash, - std::ref (getApp().getFullBelowCache ())); + app.getFullBelowCache (), app.getTreeNodeCache()); mMap->setTXMap (); } diff --git a/src/ripple/module/rpc/handlers/GetCounts.cpp b/src/ripple/module/rpc/handlers/GetCounts.cpp index 4fc4ccc07..774c2af38 100644 --- a/src/ripple/module/rpc/handlers/GetCounts.cpp +++ b/src/ripple/module/rpc/handlers/GetCounts.cpp @@ -40,36 +40,37 @@ Json::Value doGetCounts (RPC::Context& context) ret [it.first] = it.second; } - int dbKB = getApp().getLedgerDB ()->getDB ()->getKBUsedAll (); + Application& app = getApp(); + int dbKB = app.getLedgerDB ()->getDB ()->getKBUsedAll (); if (dbKB > 0) ret["dbKBTotal"] = dbKB; - dbKB = getApp().getLedgerDB ()->getDB ()->getKBUsedDB (); + dbKB = app.getLedgerDB ()->getDB ()->getKBUsedDB (); if (dbKB > 0) ret["dbKBLedger"] = dbKB; - dbKB = getApp().getTxnDB ()->getDB ()->getKBUsedDB (); + dbKB = app.getTxnDB ()->getDB ()->getKBUsedDB (); if (dbKB > 0) ret["dbKBTransaction"] = dbKB; { - std::size_t c = getApp().getOPs().getLocalTxCount (); + std::size_t c = app.getOPs().getLocalTxCount (); if (c > 0) ret["local_txs"] = static_cast (c); } - ret["write_load"] = getApp().getNodeStore ().getWriteLoad (); + ret["write_load"] = app.getNodeStore ().getWriteLoad (); - ret["SLE_hit_rate"] = getApp().getSLECache ().getHitRate (); - ret["node_hit_rate"] = getApp().getNodeStore ().getCacheHitRate (); - ret["ledger_hit_rate"] = getApp().getLedgerMaster ().getCacheHitRate (); + ret["SLE_hit_rate"] = app.getSLECache ().getHitRate (); + ret["node_hit_rate"] = app.getNodeStore ().getCacheHitRate (); + ret["ledger_hit_rate"] = app.getLedgerMaster ().getCacheHitRate (); ret["AL_hit_rate"] = AcceptedLedger::getCacheHitRate (); - ret["fullbelow_size"] = int(getApp().getFullBelowCache().size()); - ret["treenode_size"] = SHAMap::getTreeNodeSize (); + ret["fullbelow_size"] = static_cast(app.getFullBelowCache().size()); + ret["treenode_size"] = app.getTreeNodeCache().getCacheSize(); std::string uptime; int s = UptimeTimer::getInstance ().getElapsedSeconds ();