mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Refactor backends to new interfaces
This commit is contained in:
@@ -37,13 +37,13 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HSBELevelDB.cpp">
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStoreLevelDB.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>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.cpp">
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStoreSqlite.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>
|
||||
@@ -1344,8 +1344,8 @@
|
||||
<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_NodeStore.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBELevelDB.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStoreLevelDB.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStoreSqlite.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\ripple_app.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\containers\ripple_KeyCache.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_basics\containers\ripple_RangeSet.h" />
|
||||
|
||||
@@ -849,18 +849,18 @@
|
||||
<ClCompile Include="..\..\modules\ripple_basio\boost\ripple_SslContext.cpp">
|
||||
<Filter>[1] Ripple\ripple_basio\boost</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HSBELevelDB.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeObject.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStore.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStoreLevelDB.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeStoreSqlite.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\Subtrees\sqlite\sqlite3.h">
|
||||
@@ -1593,12 +1593,6 @@
|
||||
<ClInclude Include="..\..\modules\ripple_basio\boost\ripple_SslContext.h">
|
||||
<Filter>[1] Ripple\ripple_basio\boost</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBELevelDB.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HSBESqlite.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\cpp\ripple\ripple_DBInit.h">
|
||||
<Filter>[1] Ripple\ripple_app\_data</Filter>
|
||||
</ClInclude>
|
||||
@@ -1608,6 +1602,12 @@
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStore.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStoreLevelDB.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_NodeStoreSqlite.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\cpp\ripple\ripple.proto" />
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
|
||||
HSBELevelDB::HSBELevelDB(std::string const& path) : mName(path), mDB(NULL)
|
||||
{
|
||||
leveldb::Options options;
|
||||
options.create_if_missing = true;
|
||||
options.block_cache = leveldb::NewLRUCache (theConfig.getSize (siHashNodeDBCache) * 1024 * 1024);
|
||||
|
||||
if (theConfig.NODE_SIZE >= 2)
|
||||
options.filter_policy = leveldb::NewBloomFilterPolicy (10);
|
||||
|
||||
leveldb::Status status = leveldb::DB::Open (options, path, &mDB);
|
||||
if (!status.ok () || mDB)
|
||||
throw (std::runtime_error (std::string("Unable to open/create leveldb: ") + status.ToString()));
|
||||
}
|
||||
|
||||
HSBELevelDB::~HSBELevelDB()
|
||||
{
|
||||
delete mDB;
|
||||
}
|
||||
|
||||
std::string HSBELevelDB::getDataBaseName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool HSBELevelDB::store(NodeObject::ref obj)
|
||||
{
|
||||
Blob blob (toBlob (obj));
|
||||
return mDB->Put (leveldb::WriteOptions (),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(obj->getHash ().begin ()), 256 / 8),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(&blob.front ()), blob.size ())).ok ();
|
||||
}
|
||||
|
||||
bool HSBELevelDB::bulkStore(const std::vector< NodeObject::pointer >& objs)
|
||||
{
|
||||
leveldb::WriteBatch batch;
|
||||
|
||||
BOOST_FOREACH (NodeObject::ref obj, objs)
|
||||
{
|
||||
Blob blob (toBlob (obj));
|
||||
batch.Put (
|
||||
leveldb::Slice (reinterpret_cast<char const*>(obj->getHash ().begin ()), 256 / 8),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(&blob.front ()), blob.size ()));
|
||||
}
|
||||
return mDB->Write (leveldb::WriteOptions (), &batch).ok ();
|
||||
}
|
||||
|
||||
NodeObject::pointer HSBELevelDB::retrieve(uint256 const& hash)
|
||||
{
|
||||
std::string sData;
|
||||
if (!mDB->Get (leveldb::ReadOptions (),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(hash.begin ()), 256 / 8), &sData).ok ())
|
||||
{
|
||||
return NodeObject::pointer();
|
||||
}
|
||||
return fromBinary(hash, &sData[0], sData.size ());
|
||||
}
|
||||
|
||||
void HSBELevelDB::visitAll(FUNCTION_TYPE<void (NodeObject::pointer)> func)
|
||||
{
|
||||
leveldb::Iterator* it = mDB->NewIterator (leveldb::ReadOptions ());
|
||||
for (it->SeekToFirst (); it->Valid (); it->Next ())
|
||||
{
|
||||
if (it->key ().size () == 256 / 8)
|
||||
{
|
||||
uint256 hash;
|
||||
memcpy(hash.begin(), it->key ().data(), 256 / 8);
|
||||
func (fromBinary (hash, it->value ().data (), it->value ().size ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Blob HSBELevelDB::toBlob(NodeObject::ref obj)
|
||||
{
|
||||
Blob rawData (9 + obj->getData ().size ());
|
||||
unsigned char* bufPtr = &rawData.front();
|
||||
|
||||
*reinterpret_cast<uint32*> (bufPtr + 0) = ntohl (obj->getIndex ());
|
||||
*reinterpret_cast<uint32*> (bufPtr + 4) = ntohl (obj->getIndex ());
|
||||
* (bufPtr + 8) = static_cast<unsigned char> (obj->getType ());
|
||||
memcpy (bufPtr + 9, &obj->getData ().front (), obj->getData ().size ());
|
||||
|
||||
return rawData;
|
||||
}
|
||||
|
||||
NodeObject::pointer HSBELevelDB::fromBinary(uint256 const& hash,
|
||||
char const* data, int size)
|
||||
{
|
||||
if (size < 9)
|
||||
throw std::runtime_error ("undersized object");
|
||||
|
||||
uint32 index = htonl (*reinterpret_cast<const uint32*> (data));
|
||||
int htype = data[8];
|
||||
|
||||
return boost::make_shared<NodeObject> (static_cast<NodeObjectType> (htype), index,
|
||||
data + 9, size - 9, hash);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef HSBELEVELDB_H
|
||||
#define HSBELEVELDB_H
|
||||
|
||||
class HSBELevelDB : public NodeStore::Backend
|
||||
{
|
||||
public:
|
||||
HSBELevelDB(std::string const& path);
|
||||
~HSBELevelDB();
|
||||
|
||||
std::string getBackEndName()
|
||||
{
|
||||
return "LevelDB";
|
||||
}
|
||||
|
||||
std::string getDataBaseName();
|
||||
|
||||
bool store(NodeObject::ref);
|
||||
bool bulkStore(const std::vector< NodeObject::pointer >&);
|
||||
|
||||
NodeObject::pointer retrieve(uint256 const& hash);
|
||||
|
||||
void visitAll(FUNCTION_TYPE<void (NodeObject::pointer)>);
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
leveldb::DB* mDB;
|
||||
|
||||
Blob toBlob(NodeObject::ref);
|
||||
NodeObject::pointer fromBinary(uint256 const& hash, char const* data, int size);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
|
||||
HSBESQLite::HSBESQLite(std::string const& path) : mName(path)
|
||||
{
|
||||
mDb = new DatabaseCon(path, HashNodeDBInit, HashNodeDBCount);
|
||||
mDb->getDB()->executeSQL(boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
(theConfig.getSize(siHashNodeDBCache) * 1024)));
|
||||
}
|
||||
|
||||
HSBESQLite::~HSBESQLite()
|
||||
{
|
||||
delete mDb;
|
||||
}
|
||||
|
||||
std::string HSBESQLite::getDataBaseName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool HSBESQLite::store(NodeObject::ref object)
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"INSERT OR IGNORE INTO CommittedObjects "
|
||||
"(Hash,ObjType,LedgerIndex,Object) VALUES (?, ?, ?, ?);");
|
||||
bind(pSt, object);
|
||||
pSt.step();
|
||||
pSt.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HSBESQLite::bulkStore(const std::vector< NodeObject::pointer >& objects)
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pStB(mDb->getDB()->getSqliteDB(), "BEGIN TRANSACTION;");
|
||||
static SqliteStatement pStE(mDb->getDB()->getSqliteDB(), "END TRANSACTION;");
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"INSERT OR IGNORE INTO CommittedObjects "
|
||||
"(Hash,ObjType,LedgerIndex,Object) VALUES (?, ?, ?, ?);");
|
||||
|
||||
pStB.step();
|
||||
pStB.reset();
|
||||
|
||||
BOOST_FOREACH(NodeObject::ref object, objects)
|
||||
{
|
||||
bind(pSt, object);
|
||||
pSt.step();
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
pStE.step();
|
||||
pStE.reset();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
NodeObject::pointer HSBESQLite::retrieve(uint256 const& hash)
|
||||
{
|
||||
NodeObject::pointer ret;
|
||||
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = ?;");
|
||||
|
||||
pSt.bind(1, hash.GetHex());
|
||||
|
||||
if (pSt.isRow(pSt.step()))
|
||||
ret = boost::make_shared<NodeObject>(getType(pSt.peekString(0)), pSt.getUInt32(1), pSt.getBlob(2), hash);
|
||||
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void HSBESQLite::visitAll(FUNCTION_TYPE<void (NodeObject::pointer)> func)
|
||||
{
|
||||
uint256 hash;
|
||||
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"SELECT ObjType,LedgerIndex,Object,Hash FROM CommittedObjects;");
|
||||
|
||||
while (pSt.isRow(pSt.step()))
|
||||
{
|
||||
hash.SetHexExact(pSt.getString(3));
|
||||
func(boost::make_shared<NodeObject>(getType(pSt.peekString(0)), pSt.getUInt32(1), pSt.getBlob(2), hash));
|
||||
}
|
||||
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
void HSBESQLite::bind(SqliteStatement& statement, NodeObject::ref object)
|
||||
{
|
||||
char const* type;
|
||||
switch (object->getType())
|
||||
{
|
||||
case hotLEDGER: type = "L"; break;
|
||||
case hotTRANSACTION: type = "T"; break;
|
||||
case hotACCOUNT_NODE: type = "A"; break;
|
||||
case hotTRANSACTION_NODE: type = "N"; break;
|
||||
default: type = "U";
|
||||
}
|
||||
|
||||
statement.bind(1, object->getHash().GetHex());
|
||||
statement.bind(2, type);
|
||||
statement.bind(3, object->getIndex());
|
||||
statement.bindStatic(4, object->getData());
|
||||
}
|
||||
|
||||
NodeObjectType HSBESQLite::getType(std::string const& type)
|
||||
{
|
||||
NodeObjectType htype = hotUNKNOWN;
|
||||
if (!type.empty())
|
||||
{
|
||||
switch (type[0])
|
||||
{
|
||||
case 'L': htype = hotLEDGER; break;
|
||||
case 'T': htype = hotTRANSACTION; break;
|
||||
case 'A': htype = hotACCOUNT_NODE; break;
|
||||
case 'N': htype = hotTRANSACTION_NODE; break;
|
||||
}
|
||||
}
|
||||
return htype;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef HSBESQLITE_H
|
||||
#define HSBESQLITE_H
|
||||
|
||||
class HSBESQLite : public NodeStore::Backend
|
||||
{
|
||||
public:
|
||||
HSBESQLite(std::string const& path);
|
||||
~HSBESQLite();
|
||||
|
||||
std::string getBackEndName()
|
||||
{
|
||||
return "SQLite";
|
||||
}
|
||||
|
||||
std::string getDataBaseName();
|
||||
|
||||
bool store(NodeObject::ref);
|
||||
bool bulkStore(const std::vector< NodeObject::pointer >&);
|
||||
|
||||
NodeObject::pointer retrieve(uint256 const& hash);
|
||||
|
||||
void visitAll(FUNCTION_TYPE<void (NodeObject::pointer)>);
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
DatabaseCon* mDb;
|
||||
|
||||
void bind(SqliteStatement& statement, NodeObject::ref object);
|
||||
NodeObjectType getType(std::string const&);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
/** Create an instance of this factory's backend.
|
||||
*/
|
||||
virtual Backend* createInstance (HashMap <String, String> const& keyValueParameters);
|
||||
virtual Backend* createInstance (HashMap <String, String> const& keyValueParameters) = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
142
modules/ripple_app/node/ripple_NodeStoreLevelDB.cpp
Normal file
142
modules/ripple_app/node/ripple_NodeStoreLevelDB.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class LevelDBBackendFactory::Backend : public NodeStore::Backend
|
||||
{
|
||||
public:
|
||||
Backend (std::string const& path)
|
||||
: mName(path)
|
||||
, mDB(NULL)
|
||||
{
|
||||
leveldb::Options options;
|
||||
options.create_if_missing = true;
|
||||
options.block_cache = leveldb::NewLRUCache (theConfig.getSize (siHashNodeDBCache) * 1024 * 1024);
|
||||
|
||||
if (theConfig.NODE_SIZE >= 2)
|
||||
options.filter_policy = leveldb::NewBloomFilterPolicy (10);
|
||||
|
||||
leveldb::Status status = leveldb::DB::Open (options, path, &mDB);
|
||||
if (!status.ok () || mDB)
|
||||
throw (std::runtime_error (std::string("Unable to open/create leveldb: ") + status.ToString()));
|
||||
}
|
||||
|
||||
~Backend ()
|
||||
{
|
||||
delete mDB;
|
||||
}
|
||||
|
||||
std::string getDataBaseName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool store (NodeObject::ref obj)
|
||||
{
|
||||
Blob blob (toBlob (obj));
|
||||
return mDB->Put (leveldb::WriteOptions (),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(obj->getHash ().begin ()), 256 / 8),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(&blob.front ()), blob.size ())).ok ();
|
||||
}
|
||||
|
||||
bool bulkStore (const std::vector< NodeObject::pointer >& objs)
|
||||
{
|
||||
leveldb::WriteBatch batch;
|
||||
|
||||
BOOST_FOREACH (NodeObject::ref obj, objs)
|
||||
{
|
||||
Blob blob (toBlob (obj));
|
||||
batch.Put (
|
||||
leveldb::Slice (reinterpret_cast<char const*>(obj->getHash ().begin ()), 256 / 8),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(&blob.front ()), blob.size ()));
|
||||
}
|
||||
return mDB->Write (leveldb::WriteOptions (), &batch).ok ();
|
||||
}
|
||||
|
||||
NodeObject::pointer retrieve (uint256 const& hash)
|
||||
{
|
||||
std::string sData;
|
||||
if (!mDB->Get (leveldb::ReadOptions (),
|
||||
leveldb::Slice (reinterpret_cast<char const*>(hash.begin ()), 256 / 8), &sData).ok ())
|
||||
{
|
||||
return NodeObject::pointer();
|
||||
}
|
||||
return fromBinary(hash, &sData[0], sData.size ());
|
||||
}
|
||||
|
||||
void visitAll (FUNCTION_TYPE<void (NodeObject::pointer)> func)
|
||||
{
|
||||
leveldb::Iterator* it = mDB->NewIterator (leveldb::ReadOptions ());
|
||||
for (it->SeekToFirst (); it->Valid (); it->Next ())
|
||||
{
|
||||
if (it->key ().size () == 256 / 8)
|
||||
{
|
||||
uint256 hash;
|
||||
memcpy(hash.begin(), it->key ().data(), 256 / 8);
|
||||
func (fromBinary (hash, it->value ().data (), it->value ().size ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Blob toBlob(NodeObject::ref obj)
|
||||
{
|
||||
Blob rawData (9 + obj->getData ().size ());
|
||||
unsigned char* bufPtr = &rawData.front();
|
||||
|
||||
*reinterpret_cast<uint32*> (bufPtr + 0) = ntohl (obj->getIndex ());
|
||||
*reinterpret_cast<uint32*> (bufPtr + 4) = ntohl (obj->getIndex ());
|
||||
* (bufPtr + 8) = static_cast<unsigned char> (obj->getType ());
|
||||
memcpy (bufPtr + 9, &obj->getData ().front (), obj->getData ().size ());
|
||||
|
||||
return rawData;
|
||||
}
|
||||
|
||||
NodeObject::pointer fromBinary(uint256 const& hash,
|
||||
char const* data, int size)
|
||||
{
|
||||
if (size < 9)
|
||||
throw std::runtime_error ("undersized object");
|
||||
|
||||
uint32 index = htonl (*reinterpret_cast<const uint32*> (data));
|
||||
int htype = data[8];
|
||||
|
||||
return boost::make_shared<NodeObject> (static_cast<NodeObjectType> (htype), index,
|
||||
data + 9, size - 9, hash);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
leveldb::DB* mDB;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
LevelDBBackendFactory::LevelDBBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
LevelDBBackendFactory::~LevelDBBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
LevelDBBackendFactory& LevelDBBackendFactory::getInstance ()
|
||||
{
|
||||
static LevelDBBackendFactory instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
String LevelDBBackendFactory::getName () const
|
||||
{
|
||||
return "LevelDB";
|
||||
}
|
||||
|
||||
NodeStore::Backend* LevelDBBackendFactory::createInstance (HashMap <String, String> const& keyValueParameters)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
27
modules/ripple_app/node/ripple_NodeStoreLevelDB.h
Normal file
27
modules/ripple_app/node/ripple_NodeStoreLevelDB.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_NODESTORELEVELDB_H_INCLUDED
|
||||
#define RIPPLE_NODESTORELEVELDB_H_INCLUDED
|
||||
|
||||
/** Factory to produce LevelDB backends for the NodeStore.
|
||||
*/
|
||||
class LevelDBBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
private:
|
||||
class Backend;
|
||||
|
||||
LevelDBBackendFactory ();
|
||||
~LevelDBBackendFactory ();
|
||||
|
||||
public:
|
||||
static LevelDBBackendFactory& getInstance ();
|
||||
|
||||
String getName () const;
|
||||
NodeStore::Backend* createInstance (HashMap <String, String> const& keyValueParameters);
|
||||
};
|
||||
|
||||
#endif
|
||||
165
modules/ripple_app/node/ripple_NodeStoreSqlite.cpp
Normal file
165
modules/ripple_app/node/ripple_NodeStoreSqlite.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class SqliteBackendFactory::Backend : public NodeStore::Backend
|
||||
{
|
||||
public:
|
||||
Backend(std::string const& path) : mName(path)
|
||||
{
|
||||
mDb = new DatabaseCon(path, HashNodeDBInit, HashNodeDBCount);
|
||||
mDb->getDB()->executeSQL(boost::str(boost::format("PRAGMA cache_size=-%d;") %
|
||||
(theConfig.getSize(siHashNodeDBCache) * 1024)));
|
||||
}
|
||||
|
||||
Backend()
|
||||
{
|
||||
delete mDb;
|
||||
}
|
||||
|
||||
std::string getDataBaseName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
bool store(NodeObject::ref object)
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"INSERT OR IGNORE INTO CommittedObjects "
|
||||
"(Hash,ObjType,LedgerIndex,Object) VALUES (?, ?, ?, ?);");
|
||||
bind(pSt, object);
|
||||
pSt.step();
|
||||
pSt.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bulkStore(const std::vector< NodeObject::pointer >& objects)
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pStB(mDb->getDB()->getSqliteDB(), "BEGIN TRANSACTION;");
|
||||
static SqliteStatement pStE(mDb->getDB()->getSqliteDB(), "END TRANSACTION;");
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"INSERT OR IGNORE INTO CommittedObjects "
|
||||
"(Hash,ObjType,LedgerIndex,Object) VALUES (?, ?, ?, ?);");
|
||||
|
||||
pStB.step();
|
||||
pStB.reset();
|
||||
|
||||
BOOST_FOREACH(NodeObject::ref object, objects)
|
||||
{
|
||||
bind(pSt, object);
|
||||
pSt.step();
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
pStE.step();
|
||||
pStE.reset();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
NodeObject::pointer retrieve(uint256 const& hash)
|
||||
{
|
||||
NodeObject::pointer ret;
|
||||
|
||||
{
|
||||
ScopedLock sl(mDb->getDBLock());
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = ?;");
|
||||
|
||||
pSt.bind(1, hash.GetHex());
|
||||
|
||||
if (pSt.isRow(pSt.step()))
|
||||
ret = boost::make_shared<NodeObject>(getType(pSt.peekString(0)), pSt.getUInt32(1), pSt.getBlob(2), hash);
|
||||
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void visitAll(FUNCTION_TYPE<void (NodeObject::pointer)> func)
|
||||
{
|
||||
uint256 hash;
|
||||
|
||||
static SqliteStatement pSt(mDb->getDB()->getSqliteDB(),
|
||||
"SELECT ObjType,LedgerIndex,Object,Hash FROM CommittedObjects;");
|
||||
|
||||
while (pSt.isRow(pSt.step()))
|
||||
{
|
||||
hash.SetHexExact(pSt.getString(3));
|
||||
func(boost::make_shared<NodeObject>(getType(pSt.peekString(0)), pSt.getUInt32(1), pSt.getBlob(2), hash));
|
||||
}
|
||||
|
||||
pSt.reset();
|
||||
}
|
||||
|
||||
void bind(SqliteStatement& statement, NodeObject::ref object)
|
||||
{
|
||||
char const* type;
|
||||
switch (object->getType())
|
||||
{
|
||||
case hotLEDGER: type = "L"; break;
|
||||
case hotTRANSACTION: type = "T"; break;
|
||||
case hotACCOUNT_NODE: type = "A"; break;
|
||||
case hotTRANSACTION_NODE: type = "N"; break;
|
||||
default: type = "U";
|
||||
}
|
||||
|
||||
statement.bind(1, object->getHash().GetHex());
|
||||
statement.bind(2, type);
|
||||
statement.bind(3, object->getIndex());
|
||||
statement.bindStatic(4, object->getData());
|
||||
}
|
||||
|
||||
NodeObjectType getType(std::string const& type)
|
||||
{
|
||||
NodeObjectType htype = hotUNKNOWN;
|
||||
if (!type.empty())
|
||||
{
|
||||
switch (type[0])
|
||||
{
|
||||
case 'L': htype = hotLEDGER; break;
|
||||
case 'T': htype = hotTRANSACTION; break;
|
||||
case 'A': htype = hotACCOUNT_NODE; break;
|
||||
case 'N': htype = hotTRANSACTION_NODE; break;
|
||||
}
|
||||
}
|
||||
return htype;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
DatabaseCon* mDb;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SqliteBackendFactory::SqliteBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
SqliteBackendFactory::~SqliteBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
SqliteBackendFactory& SqliteBackendFactory::getInstance ()
|
||||
{
|
||||
static SqliteBackendFactory instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
String SqliteBackendFactory::getName () const
|
||||
{
|
||||
return "Sqlite";
|
||||
}
|
||||
|
||||
NodeStore::Backend* SqliteBackendFactory::createInstance (HashMap <String, String> const& keyValueParameters)
|
||||
{
|
||||
return new Backend (keyValueParameters ["path"].toStdString ());
|
||||
}
|
||||
27
modules/ripple_app/node/ripple_NodeStoreSqlite.h
Normal file
27
modules/ripple_app/node/ripple_NodeStoreSqlite.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_NODESTORESQLITE_H_INCLUDED
|
||||
#define RIPPLE_NODESTORESQLITE_H_INCLUDED
|
||||
|
||||
/** Factory to produce SQLite backends for the NodeStore.
|
||||
*/
|
||||
class SqliteBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
private:
|
||||
class Backend;
|
||||
|
||||
SqliteBackendFactory ();
|
||||
~SqliteBackendFactory ();
|
||||
|
||||
public:
|
||||
static SqliteBackendFactory& getInstance ();
|
||||
|
||||
String getName () const;
|
||||
NodeStore::Backend* createInstance (HashMap <String, String> const& keyValueParameters);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -96,8 +96,8 @@ namespace ripple
|
||||
|
||||
#include "node/ripple_NodeObject.h"
|
||||
#include "node/ripple_NodeStore.h"
|
||||
#include "node/ripple_HSBELevelDB.h"
|
||||
#include "node/ripple_HSBESqlite.h"
|
||||
#include "node/ripple_NodeStoreLevelDB.h"
|
||||
#include "node/ripple_NodeStoreSqlite.h"
|
||||
|
||||
#include "src/cpp/ripple/ripple_SHAMapItem.h"
|
||||
#include "src/cpp/ripple/ripple_SHAMapNode.h"
|
||||
@@ -236,8 +236,8 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
|
||||
#include "basics/ripple_RPCServerHandler.cpp"
|
||||
#include "node/ripple_NodeObject.cpp"
|
||||
#include "node/ripple_NodeStore.cpp"
|
||||
#include "node/ripple_HSBELevelDB.cpp"
|
||||
#include "node/ripple_HSBESqlite.cpp"
|
||||
#include "node/ripple_NodeStoreLevelDB.cpp"
|
||||
#include "node/ripple_NodeStoreSqlite.cpp"
|
||||
|
||||
#include "src/cpp/ripple/Ledger.cpp"
|
||||
#include "src/cpp/ripple/ripple_SHAMapDelta.cpp"
|
||||
|
||||
Reference in New Issue
Block a user