mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Add memory backend for node store
This commit is contained in:
@@ -157,12 +157,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_KeyvaDB.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_KeyvaDBBackendFactory.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -175,6 +169,10 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_MemoryBackendFactory.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_NodeObject.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -1415,9 +1413,9 @@
|
||||
<ClInclude Include="..\..\modules\ripple_app\ledger\ripple_LedgerHistory.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\ledger\SerializedValidation.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HyperLevelDBBackendFactory.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_KeyvaDB.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_KeyvaDBBackendFactory.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_MdbBackendFactory.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_MemoryBackendFactory.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_LevelDBBackendFactory.h" />
|
||||
|
||||
@@ -891,9 +891,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_HyperLevelDBBackendFactory.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_KeyvaDB.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_KeyvaDBBackendFactory.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
@@ -906,6 +903,9 @@
|
||||
<ClCompile Include="..\..\Subtrees\beast\modules\beast_db\beast_db.cpp">
|
||||
<Filter>[0] Subtrees\beast</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_app\node\ripple_MemoryBackendFactory.cpp">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\Subtrees\sqlite\sqlite3.h">
|
||||
@@ -1677,9 +1677,6 @@
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_HyperLevelDBBackendFactory.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_KeyvaDB.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_KeyvaDBBackendFactory.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
@@ -1695,6 +1692,9 @@
|
||||
<ClInclude Include="..\..\modules\ripple_core\functional\ripple_ConfigSections.h">
|
||||
<Filter>[1] Ripple\ripple_core\functional</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_app\node\ripple_MemoryBackendFactory.h">
|
||||
<Filter>[1] Ripple\ripple_app\node</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\cpp\ripple\ripple.proto" />
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#if RIPPLE_HYPERLEVELDB_AVAILABLE
|
||||
|
||||
/** Factory to produce HyperLevelDB backends for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class HyperLevelDBBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define RIPPLE_KEYVABACKENDFACTORY_H_INCLUDED
|
||||
|
||||
/** Factory to produce KeyvaDB backends for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class KeyvaDBBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define RIPPLE_LEVELDBBACKENDFACTORY_H_INCLUDED
|
||||
|
||||
/** Factory to produce LevelDB backends for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class LevelDBBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
/** Factory to produce a backend using MDB.
|
||||
|
||||
@note MDB is not currently available for Win32
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class MdbBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
113
modules/ripple_app/node/ripple_MemoryBackendFactory.cpp
Normal file
113
modules/ripple_app/node/ripple_MemoryBackendFactory.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class MemoryBackendFactory::Backend : public NodeStore::Backend
|
||||
{
|
||||
private:
|
||||
typedef std::map <uint256 const, NodeObject::Ptr> Map;
|
||||
|
||||
public:
|
||||
Backend (size_t keyBytes, StringPairArray const& keyValues)
|
||||
: m_keyBytes (keyBytes)
|
||||
{
|
||||
}
|
||||
|
||||
~Backend ()
|
||||
{
|
||||
}
|
||||
|
||||
std::string getName ()
|
||||
{
|
||||
return "memory";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Status fetch (void const* key, NodeObject::Ptr* pObject)
|
||||
{
|
||||
uint256 const hash (key);
|
||||
|
||||
Map::iterator iter = m_map.find (hash);
|
||||
|
||||
if (iter != m_map.end ())
|
||||
{
|
||||
*pObject = iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pObject->reset ();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void store (NodeObject::ref object)
|
||||
{
|
||||
Map::iterator iter = m_map.find (object->getHash ());
|
||||
|
||||
if (iter == m_map.end ())
|
||||
{
|
||||
m_map.insert (std::make_pair (object->getHash (), object));
|
||||
}
|
||||
}
|
||||
|
||||
void storeBatch (NodeStore::Batch const& batch)
|
||||
{
|
||||
for (int i = 0; i < batch.size (); ++i)
|
||||
store (batch [i]);
|
||||
}
|
||||
|
||||
void visitAll (VisitCallback& callback)
|
||||
{
|
||||
for (Map::const_iterator iter = m_map.begin (); iter != m_map.end (); ++iter)
|
||||
callback.visitObject (iter->second);
|
||||
}
|
||||
|
||||
int getWriteLoad ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
size_t const m_keyBytes;
|
||||
|
||||
Map m_map;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
MemoryBackendFactory::MemoryBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
MemoryBackendFactory::~MemoryBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
MemoryBackendFactory& MemoryBackendFactory::getInstance ()
|
||||
{
|
||||
static MemoryBackendFactory instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
String MemoryBackendFactory::getName () const
|
||||
{
|
||||
return "Memory";
|
||||
}
|
||||
|
||||
NodeStore::Backend* MemoryBackendFactory::createInstance (
|
||||
size_t keyBytes,
|
||||
StringPairArray const& keyValues,
|
||||
NodeStore::Scheduler& scheduler)
|
||||
{
|
||||
return new MemoryBackendFactory::Backend (keyBytes, keyValues);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
32
modules/ripple_app/node/ripple_MemoryBackendFactory.h
Normal file
32
modules/ripple_app/node/ripple_MemoryBackendFactory.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_MEMORYBACKENDFACTORY_H_INCLUDED
|
||||
#define RIPPLE_MEMORYBACKENDFACTORY_H_INCLUDED
|
||||
|
||||
/** Factory to produce a RAM based backend for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class MemoryBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
private:
|
||||
class Backend;
|
||||
|
||||
MemoryBackendFactory ();
|
||||
~MemoryBackendFactory ();
|
||||
|
||||
public:
|
||||
static MemoryBackendFactory& getInstance ();
|
||||
|
||||
String getName () const;
|
||||
|
||||
NodeStore::Backend* createInstance (size_t keyBytes,
|
||||
StringPairArray const& keyValues,
|
||||
NodeStore::Scheduler& scheduler);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1043,7 +1043,10 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void testNodeStore (String type, bool const useEphemeralDatabase, int64 const seedValue)
|
||||
void testNodeStore (String type,
|
||||
bool const useEphemeralDatabase,
|
||||
bool const testPersistence,
|
||||
int64 const seedValue)
|
||||
{
|
||||
String s;
|
||||
s << String ("NodeStore backend '") + type + "'";
|
||||
@@ -1092,6 +1095,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (testPersistence)
|
||||
{
|
||||
{
|
||||
// Re-open the database without the ephemeral DB
|
||||
ScopedPointer <NodeStore> db (NodeStore::New (nodeParams));
|
||||
@@ -1121,23 +1126,24 @@ public:
|
||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void runBackendTests (bool useEphemeralDatabase, int64 const seedValue)
|
||||
{
|
||||
testNodeStore ("keyvadb", useEphemeralDatabase, seedValue);
|
||||
testNodeStore ("keyvadb", useEphemeralDatabase, true, seedValue);
|
||||
|
||||
testNodeStore ("leveldb", useEphemeralDatabase, seedValue);
|
||||
testNodeStore ("leveldb", useEphemeralDatabase, true, seedValue);
|
||||
|
||||
testNodeStore ("sqlite", useEphemeralDatabase, seedValue);
|
||||
testNodeStore ("sqlite", useEphemeralDatabase, true, seedValue);
|
||||
|
||||
#if RIPPLE_HYPERLEVELDB_AVAILABLE
|
||||
testNodeStore ("hyperleveldb", useEphemeralDatabase, seedValue);
|
||||
testNodeStore ("hyperleveldb", useEphemeralDatabase, true, seedValue);
|
||||
#endif
|
||||
|
||||
#if RIPPLE_MDB_AVAILABLE
|
||||
testNodeStore ("mdb", useEphemeralDatabase, seedValue);
|
||||
testNodeStore ("mdb", useEphemeralDatabase, true, seedValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1166,6 +1172,8 @@ public:
|
||||
{
|
||||
int64 const seedValue = 50;
|
||||
|
||||
testNodeStore ("memory", false, false, seedValue);
|
||||
|
||||
runBackendTests (false, seedValue);
|
||||
|
||||
runBackendTests (true, seedValue);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
/** Factory to produce a null backend.
|
||||
|
||||
This is for standalone / testing mode.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class NullBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define RIPPLE_SQLITEBACKENDFACTORY_H_INCLUDED
|
||||
|
||||
/** Factory to produce SQLite backends for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class SqliteBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
|
||||
@@ -108,6 +108,7 @@ namespace ripple
|
||||
#include "node/ripple_KeyvaDBBackendFactory.h"
|
||||
#include "node/ripple_LevelDBBackendFactory.h"
|
||||
#include "node/ripple_MdbBackendFactory.h"
|
||||
#include "node/ripple_MemoryBackendFactory.h"
|
||||
#include "node/ripple_NullBackendFactory.h"
|
||||
#include "node/ripple_SqliteBackendFactory.h"
|
||||
|
||||
@@ -250,6 +251,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1;
|
||||
#include "node/ripple_HyperLevelDBBackendFactory.cpp"
|
||||
#include "node/ripple_KeyvaDBBackendFactory.cpp"
|
||||
#include "node/ripple_LevelDBBackendFactory.cpp"
|
||||
#include "node/ripple_MemoryBackendFactory.cpp"
|
||||
#include "node/ripple_NullBackendFactory.cpp"
|
||||
#include "node/ripple_MdbBackendFactory.cpp"
|
||||
#include "node/ripple_SqliteBackendFactory.cpp"
|
||||
|
||||
@@ -259,6 +259,7 @@ int rippleMain (int argc, char** argv)
|
||||
// These must be added before the Application object is created
|
||||
NodeStore::addBackendFactory (KeyvaDBBackendFactory::getInstance ());
|
||||
NodeStore::addBackendFactory (LevelDBBackendFactory::getInstance ());
|
||||
NodeStore::addBackendFactory (MemoryBackendFactory::getInstance ());
|
||||
NodeStore::addBackendFactory (NullBackendFactory::getInstance ());
|
||||
NodeStore::addBackendFactory (SqliteBackendFactory::getInstance ());
|
||||
#if RIPPLE_HYPERLEVELDB_AVAILABLE
|
||||
|
||||
Reference in New Issue
Block a user