From cd93bd0de3ac7914021c61b0c02d813396a74d3d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:49:47 -0700 Subject: [PATCH] Make sure TaggedCaches get sweeped. --- src/Application.cpp | 13 ++++++++++++- src/Application.h | 3 +++ src/HashedObject.h | 1 + src/LedgerHistory.h | 1 + src/TaggedCache.h | 4 ++-- src/TransactionMaster.h | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 7c459fc129..8ec0b2bf3a 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -42,11 +42,13 @@ Application::Application() : mNetOps(mIOService, &mMasterLedger), mTempNodeCache(16384, 90), mHashedObjectStore(16384, 300), mSNTPClient(mAuxService), mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), - mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) + mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mSweepTimer(mAuxService) { RAND_bytes(mNonce256.begin(), mNonce256.size()); RAND_bytes(reinterpret_cast(&mNonceST), sizeof(mNonceST)); mJobQueue.setThreadCount(); + mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); + mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); } extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; @@ -183,6 +185,15 @@ void Application::run() std::cout << "Done." << std::endl; } +void Application::sweep() +{ + mMasterTransaction.sweep(); + mHashedObjectStore.sweep(); + mMasterLedger.sweep(); + mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); + mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); +} + Application::~Application() { delete mTxnDB; diff --git a/src/Application.h b/src/Application.h index ebb078492d..8193408327 100644 --- a/src/Application.h +++ b/src/Application.h @@ -66,6 +66,8 @@ class Application uint256 mNonce256; std::size_t mNonceST; + boost::asio::deadline_timer mSweepTimer; + std::map mPeerMap; boost::recursive_mutex mPeerMapLock; @@ -110,6 +112,7 @@ public: void run(); void stop(); + void sweep(); }; extern Application* theApp; diff --git a/src/HashedObject.h b/src/HashedObject.h index 5178af0896..a3fb8cbe0b 100644 --- a/src/HashedObject.h +++ b/src/HashedObject.h @@ -61,6 +61,7 @@ public: void bulkWrite(); void waitWrite(); + void sweep() { mCache.sweep(); } }; #endif diff --git a/src/LedgerHistory.h b/src/LedgerHistory.h index ed58f4fc98..51ecaf7143 100644 --- a/src/LedgerHistory.h +++ b/src/LedgerHistory.h @@ -18,6 +18,7 @@ public: Ledger::pointer getLedgerBySeq(uint32 index); Ledger::pointer getLedgerByHash(const uint256& hash); Ledger::pointer canonicalizeLedger(Ledger::pointer, bool cache); + void sweep() { mLedgersByHash.sweep(); } }; #endif diff --git a/src/TaggedCache.h b/src/TaggedCache.h index ece2b36631..a6c56efa42 100644 --- a/src/TaggedCache.h +++ b/src/TaggedCache.h @@ -96,7 +96,7 @@ template void TaggedCache::sweep typename boost::unordered_map::iterator cit = mCache.begin(); while (cit != mCache.end()) { - if (cit->second->second.first < target) + if (cit->second.first < target) mCache.erase(cit++); else ++cit; @@ -106,7 +106,7 @@ template void TaggedCache::sweep typename boost::unordered_map::iterator mit = mMap.begin(); while (mit != mMap.end()) { - if (mit->second->expired()) + if (mit->second.expired()) mMap.erase(mit++); else ++mit; diff --git a/src/TransactionMaster.h b/src/TransactionMaster.h index 19fd8b64da..138c05c9c0 100644 --- a/src/TransactionMaster.h +++ b/src/TransactionMaster.h @@ -20,6 +20,7 @@ public: // return value: true = we had the transaction already bool canonicalize(Transaction::pointer& txn, bool maybeNew); + void sweep(void) { mCache.sweep(); } }; #endif