#ifndef __HASHEDOBJECT__ #define __HASHEDOBJECT__ #include #include #include #include "types.h" #include "uint256.h" #include "ScopedLock.h" #include "TaggedCache.h" #include "KeyCache.h" #include "InstanceCounter.h" DEFINE_INSTANCE(HashedObject); enum HashedObjectType { hotUNKNOWN = 0, hotLEDGER = 1, hotTRANSACTION = 2, hotACCOUNT_NODE = 3, hotTRANSACTION_NODE = 4 }; class HashedObject : private IS_INSTANCE(HashedObject) { public: typedef boost::shared_ptr pointer; HashedObjectType mType; uint256 mHash; uint32 mLedgerIndex; std::vector mData; HashedObject(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash) : mType(type), mHash(hash), mLedgerIndex(index), mData(data) { ; } HashedObject(HashedObjectType type, uint32 index, const unsigned char *data, int dlen, const uint256& hash) : mType(type), mHash(hash), mLedgerIndex(index), mData(data, data + dlen) { ; } const std::vector& getData() const { return mData; } const uint256& getHash() const { return mHash; } HashedObjectType getType() const { return mType; } uint32 getIndex() const { return mLedgerIndex; } }; class HashedObjectStore { protected: TaggedCache mCache; KeyCache mNegativeCache; boost::mutex mWriteMutex; boost::condition_variable mWriteCondition; int mWriteGeneration; std::vector< boost::shared_ptr > mWriteSet; bool mWritePending; bool mLevelDB; public: HashedObjectStore(int cacheSize, int cacheAge); bool isLevelDB() { return mLevelDB; } bool store(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash) { #ifdef USE_LEVELDB if (mLevelDB) return storeLevelDB(type, index, data, hash); #endif return storeSQLite(type, index, data, hash); } HashedObject::pointer retrieve(const uint256& hash) { #ifdef USE_LEVELDB if (mLevelDB) return retrieveLevelDB(hash); #endif return retrieveSQLite(hash); } bool storeSQLite(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash); HashedObject::pointer retrieveSQLite(const uint256& hash); #ifdef USE_LEVELDB bool storeLevelDB(HashedObjectType type, uint32 index, const std::vector& data, const uint256& hash); HashedObject::pointer retrieveLevelDB(const uint256& hash); #endif void bulkWrite(); void waitWrite(); void tune(int size, int age); void sweep() { mCache.sweep(); mNegativeCache.sweep(); } int import(const std::string& fileName, bool checkHashes); }; #endif // vim:ts=4