Rename NodeStore and add backend abstractions

This commit is contained in:
Vinnie Falco
2013-07-10 10:42:01 -07:00
parent d6fb686426
commit 8f0d65f099
11 changed files with 93 additions and 73 deletions

View File

@@ -31,7 +31,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HashedObjectStore.cpp">
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStore.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -1343,7 +1343,7 @@
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_RPCServerHandler.h" />
<ClInclude Include="..\..\modules\ripple_app\basics\ripple_Version.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeObject.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HashedObjectStore.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStore.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HashStoreBE.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBELevelDB.h" />
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.h" />

View File

@@ -855,10 +855,10 @@
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.cpp">
<Filter>[1] Ripple\ripple_app\node</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HashedObjectStore.cpp">
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeObject.cpp">
<Filter>[1] Ripple\ripple_app\node</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeObject.cpp">
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStore.cpp">
<Filter>[1] Ripple\ripple_app\node</Filter>
</ClCompile>
</ItemGroup>
@@ -1605,10 +1605,10 @@
<ClInclude Include="..\..\src\cpp\ripple\ripple_DBInit.h">
<Filter>[1] Ripple\ripple_app\_data</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HashedObjectStore.h">
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeObject.h">
<Filter>[1] Ripple\ripple_app\node</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeObject.h">
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStore.h">
<Filter>[1] Ripple\ripple_app\node</Filter>
</ClInclude>
</ItemGroup>

View File

@@ -1,7 +1,7 @@
#ifndef HSBELEVELDB_H
#define HSBELEVELDB_H
class HSBELevelDB : public HashStoreBE
class HSBELevelDB : public NodeStore::Backend
{
public:
HSBELevelDB(std::string const& path);

View File

@@ -1,7 +1,7 @@
#ifndef HSBESQLITE_H
#define HSBESQLITE_H
class HSBESQLite : public HashStoreBE
class HSBESQLite : public NodeStore::Backend
{
public:
HSBESQLite(std::string const& path);

View File

@@ -1,31 +1,10 @@
//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
#ifndef RIPPLE_HASHSTOREBE_H
#define RIPPLE_HASHSTOREBE_H
/** Back end for storing objects indexed by 256-bit hash
*/
class HashStoreBE
{
public:
typedef boost::shared_ptr<HashStoreBE> pointer;
HashStoreBE() { ; }
virtual ~HashStoreBE() { ; }
virtual std::string getBackEndName() = 0;
virtual std::string getDataBaseName() = 0;
// Store/retrieve a single object
// These functions must be thread safe
virtual bool store(NodeObject::ref) = 0;
virtual NodeObject::pointer retrieve(uint256 const &hash) = 0;
// Store a group of objects
// This function will only be called from a single thread
virtual bool bulkStore(const std::vector< NodeObject::pointer >&) = 0;
// Visit every object in the database
// This function will only be called during an import operation
virtual void visitAll(FUNCTION_TYPE<void (NodeObject::pointer)>) = 0;
};
#endif

View File

@@ -4,10 +4,10 @@
*/
//==============================================================================
#ifndef RIPPLE_HASHEDOBJECT_H
#define RIPPLE_HASHEDOBJECT_H
#ifndef RIPPLE_NODEOBJECT_H_INCLUDED
#define RIPPLE_NODEOBJECT_H_INCLUDED
/** The types of hashed objects.
/** The types of node objects.
*/
enum NodeObjectType
{
@@ -29,11 +29,7 @@ enum NodeObjectType
@note No checking is performed to make sure the hash matches the data.
@see SHAMap
*/
// VFALCO TODO consider making the instance a private member of SHAMap
// since its the primary user.
//
class NodeObject
: public CountedObject <NodeObject>
class NodeObject : public CountedObject <NodeObject>
{
public:
static char const* getCountedObjectName () { return "NodeObject"; }
@@ -85,4 +81,3 @@ private:
};
#endif
// vim:ts=4

View File

@@ -4,8 +4,8 @@
*/
//==============================================================================
HashedObjectStore::HashedObjectStore (int cacheSize, int cacheAge) :
mCache ("HashedObjectStore", cacheSize, cacheAge), mNegativeCache ("HashedObjectNegativeCache", 0, 120),
NodeStore::NodeStore (int cacheSize, int cacheAge) :
mCache ("NodeStore", cacheSize, cacheAge), mNegativeCache ("HashedObjectNegativeCache", 0, 120),
mWriteGeneration (0), mWriteLoad (0), mWritePending (false), mLevelDB (false), mEphemeralDB (false)
{
mWriteSet.reserve (128);
@@ -24,13 +24,13 @@ HashedObjectStore::HashedObjectStore (int cacheSize, int cacheAge) :
mEphemeralDB = true;
}
void HashedObjectStore::tune (int size, int age)
void NodeStore::tune (int size, int age)
{
mCache.setTargetSize (size);
mCache.setTargetAge (age);
}
void HashedObjectStore::waitWrite ()
void NodeStore::waitWrite ()
{
boost::mutex::scoped_lock sl (mWriteMutex);
int gen = mWriteGeneration;
@@ -39,14 +39,14 @@ void HashedObjectStore::waitWrite ()
mWriteCondition.wait (sl);
}
int HashedObjectStore::getWriteLoad ()
int NodeStore::getWriteLoad ()
{
boost::mutex::scoped_lock sl (mWriteMutex);
return std::max (mWriteLoad, static_cast<int> (mWriteSet.size ()));
}
// low-level retrieve
NodeObject::pointer HashedObjectStore::LLRetrieve (uint256 const& hash, leveldb::DB* db)
NodeObject::pointer NodeStore::LLRetrieve (uint256 const& hash, leveldb::DB* db)
{
std::string sData;
@@ -68,7 +68,7 @@ NodeObject::pointer HashedObjectStore::LLRetrieve (uint256 const& hash, leveldb:
}
// low-level write single
void HashedObjectStore::LLWrite (boost::shared_ptr<NodeObject> ptr, leveldb::DB* db)
void NodeStore::LLWrite (boost::shared_ptr<NodeObject> ptr, leveldb::DB* db)
{
NodeObject& obj = *ptr;
Blob rawData (9 + obj.getData ().size ());
@@ -91,7 +91,7 @@ void HashedObjectStore::LLWrite (boost::shared_ptr<NodeObject> ptr, leveldb::DB*
}
// low-level write set
void HashedObjectStore::LLWrite (const std::vector< boost::shared_ptr<NodeObject> >& set, leveldb::DB* db)
void NodeStore::LLWrite (const std::vector< boost::shared_ptr<NodeObject> >& set, leveldb::DB* db)
{
leveldb::WriteBatch batch;
@@ -119,7 +119,7 @@ void HashedObjectStore::LLWrite (const std::vector< boost::shared_ptr<NodeObject
}
}
bool HashedObjectStore::storeLevelDB (NodeObjectType type, uint32 index,
bool NodeStore::storeLevelDB (NodeObjectType type, uint32 index,
Blob const& data, uint256 const& hash)
{
// return: false = already in cache, true = added to cache
@@ -144,7 +144,7 @@ bool HashedObjectStore::storeLevelDB (NodeObjectType type, uint32 index,
{
mWritePending = true;
getApp().getJobQueue ().addJob (jtWRITE, "NodeObject::store",
BIND_TYPE (&HashedObjectStore::bulkWriteLevelDB, this, P_1));
BIND_TYPE (&NodeStore::bulkWriteLevelDB, this, P_1));
}
}
@@ -152,7 +152,7 @@ bool HashedObjectStore::storeLevelDB (NodeObjectType type, uint32 index,
return true;
}
void HashedObjectStore::bulkWriteLevelDB (Job&)
void NodeStore::bulkWriteLevelDB (Job&)
{
assert (mLevelDB);
int setSize = 0;
@@ -188,7 +188,7 @@ void HashedObjectStore::bulkWriteLevelDB (Job&)
}
}
NodeObject::pointer HashedObjectStore::retrieveLevelDB (uint256 const& hash)
NodeObject::pointer NodeStore::retrieveLevelDB (uint256 const& hash)
{
NodeObject::pointer obj = mCache.fetch (hash);
@@ -226,7 +226,7 @@ NodeObject::pointer HashedObjectStore::retrieveLevelDB (uint256 const& hash)
return obj;
}
bool HashedObjectStore::storeSQLite (NodeObjectType type, uint32 index,
bool NodeStore::storeSQLite (NodeObjectType type, uint32 index,
Blob const& data, uint256 const& hash)
{
// return: false = already in cache, true = added to cache
@@ -256,7 +256,7 @@ bool HashedObjectStore::storeSQLite (NodeObjectType type, uint32 index,
{
mWritePending = true;
getApp().getJobQueue ().addJob (jtWRITE, "NodeObject::store",
BIND_TYPE (&HashedObjectStore::bulkWriteSQLite, this, P_1));
BIND_TYPE (&NodeStore::bulkWriteSQLite, this, P_1));
}
}
@@ -267,7 +267,7 @@ bool HashedObjectStore::storeSQLite (NodeObjectType type, uint32 index,
return true;
}
void HashedObjectStore::bulkWriteSQLite (Job&)
void NodeStore::bulkWriteSQLite (Job&)
{
assert (!mLevelDB);
int setSize = 0;
@@ -410,7 +410,7 @@ void HashedObjectStore::bulkWriteSQLite (Job&)
}
}
NodeObject::pointer HashedObjectStore::retrieveSQLite (uint256 const& hash)
NodeObject::pointer NodeStore::retrieveSQLite (uint256 const& hash)
{
NodeObject::pointer obj = mCache.fetch (hash);
@@ -531,7 +531,7 @@ NodeObject::pointer HashedObjectStore::retrieveSQLite (uint256 const& hash)
return obj;
}
int HashedObjectStore::import (const std::string& file)
int NodeStore::import (const std::string& file)
{
WriteLog (lsWARNING, NodeObject) << "Hashed object import from \"" << file << "\".";
UPTR_T<Database> importDB (new SqliteDatabase (file.c_str ()));

View File

@@ -4,16 +4,63 @@
*/
//==============================================================================
#ifndef RIPPLE_HASHEDOBJECTSTORE_H
#define RIPPLE_HASHEDOBJECTSTORE_H
#ifndef RIPPLE_NODESTORE_H_INCLUDED
#define RIPPLE_NODESTORE_H_INCLUDED
/** Persistency layer for hashed objects.
/** Persistency layer for NodeObject
*/
// VFALCO TODO Move all definitions to the .cpp
class HashedObjectStore : LeakChecked <HashedObjectStore>
class NodeStore : LeakChecked <NodeStore>
{
public:
HashedObjectStore (int cacheSize, int cacheAge);
/** Back end used for the store.
*/
class Backend
{
public:
// VFALCO TODO Remove this, the backend should not be a shared
// object it should be ScopedPointer owned.
//
typedef boost::shared_ptr <Backend> pointer;
Backend() { ; }
virtual ~Backend() { ; }
virtual std::string getDataBaseName() = 0;
// Store/retrieve a single object
// These functions must be thread safe
virtual bool store(NodeObject::ref) = 0;
virtual NodeObject::pointer retrieve(uint256 const &hash) = 0;
// Store a group of objects
// This function will only be called from a single thread
virtual bool bulkStore(const std::vector< NodeObject::pointer >&) = 0;
// Visit every object in the database
// This function will only be called during an import operation
virtual void visitAll(FUNCTION_TYPE<void (NodeObject::pointer)>) = 0;
};
public:
/** Factory to produce backends.
*/
class BackendFactory
{
public:
virtual ~BackendFactory () { }
/** Retrieve the name of this factory.
*/
virtual String getName () const = 0;
/** Create an instance of this factory's backend.
*/
virtual Backend* createInstance (HashMap <String, String> const& keyValueParameters);
};
public:
NodeStore (int cacheSize, int cacheAge);
bool isLevelDB ()
{
@@ -85,4 +132,3 @@ private:
};
#endif
// vim:ts=4

View File

@@ -95,7 +95,7 @@ namespace ripple
#include "src/cpp/ripple/ripple_DBInit.h"
#include "node/ripple_NodeObject.h"
#include "node/ripple_HashedObjectStore.h"
#include "node/ripple_NodeStore.h"
#include "node/ripple_HashStoreBE.h"
#include "node/ripple_HSBELevelDB.h"
#include "node/ripple_HSBESqlite.h"
@@ -236,7 +236,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
#include "basics/ripple_RPCServerHandler.cpp"
#include "node/ripple_NodeObject.cpp"
#include "node/ripple_HashedObjectStore.cpp"
#include "node/ripple_NodeStore.cpp"
#include "node/ripple_HSBELevelDB.cpp"
#include "node/ripple_HSBESqlite.cpp"

View File

@@ -63,7 +63,7 @@ public:
return mTempNodeCache;
}
HashedObjectStore& getHashedObjectStore ()
NodeStore& getHashedObjectStore ()
{
return mHashedObjectStore;
}
@@ -223,7 +223,7 @@ private:
NetworkOPs mNetOps;
RPCServerHandler m_rpcServerHandler;
NodeCache mTempNodeCache;
HashedObjectStore mHashedObjectStore;
NodeStore mHashedObjectStore;
SLECache mSLECache;
SNTPClient mSNTPClient;
JobQueue mJobQueue;

View File

@@ -17,7 +17,7 @@ class IProofOfWorkFactory;
class UniqueNodeList;
class IValidations;
class HashedObjectStore;
class NodeStore;
class JobQueue;
class InboundLedgers;
class LedgerMaster;
@@ -68,7 +68,7 @@ public:
virtual UniqueNodeList& getUNL () = 0;
virtual IValidations& getValidations () = 0;
virtual HashedObjectStore& getHashedObjectStore () = 0;
virtual NodeStore& getHashedObjectStore () = 0;
virtual JobQueue& getJobQueue () = 0;
virtual InboundLedgers& getInboundLedgers () = 0;
virtual LedgerMaster& getLedgerMaster () = 0;