mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add Sophia backend (http://sphia.org)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "ripple_sophia.h"
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILBLE
|
||||
//#if RIPPLE_SOPHIA_AVAILBLE
|
||||
|
||||
#include "../sophia/db/cat.c"
|
||||
#include "../sophia/db/crc.c"
|
||||
@@ -23,4 +23,4 @@
|
||||
#include "../sophia/db/sp.c"
|
||||
#include "../sophia/db/util.c"
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
@@ -13,6 +13,16 @@
|
||||
|
||||
#define RIPPLE_SOPHIA_AVAILABLE 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../sophia/db/sophia.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define RIPPLE_SOPHIA_AVAILABLE 0
|
||||
|
||||
@@ -554,6 +554,10 @@ void NodeStore::addAvailableBackends ()
|
||||
NodeStore::addBackendFactory (MdbBackendFactory::getInstance ());
|
||||
#endif
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILABLE
|
||||
NodeStore::addBackendFactory (SophiaBackendFactory::getInstance ());
|
||||
#endif
|
||||
|
||||
NodeStore::addBackendFactory (KeyvaDBBackendFactory::getInstance ());
|
||||
}
|
||||
|
||||
@@ -888,6 +892,10 @@ public:
|
||||
#if RIPPLE_MDB_AVAILABLE
|
||||
testBackend ("mdb", seedValue);
|
||||
#endif
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILABLE
|
||||
testBackend ("sophia", seedValue);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -995,6 +1003,10 @@ public:
|
||||
testBackend ("mdb", seedValue);
|
||||
#endif
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILABLE
|
||||
testBackend ("sophia", seedValue);
|
||||
#endif
|
||||
|
||||
testBackend ("sqlite", seedValue);
|
||||
}
|
||||
};
|
||||
@@ -1160,6 +1172,10 @@ public:
|
||||
#if RIPPLE_MDB_AVAILABLE
|
||||
testNodeStore ("mdb", useEphemeralDatabase, true, seedValue);
|
||||
#endif
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILABLE
|
||||
testNodeStore ("sophia", useEphemeralDatabase, true, seedValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -1176,6 +1192,10 @@ public:
|
||||
//testImport ("mdb", "mdb", seedValue);
|
||||
#endif
|
||||
|
||||
#if RIPPLE_SOPHIA_AVAILABLE
|
||||
//testImport ("sophia", "sophia", seedValue);
|
||||
#endif
|
||||
|
||||
testImport ("sqlite", "sqlite", seedValue);
|
||||
}
|
||||
|
||||
|
||||
173
src/ripple_core/node/SophiaBackendFactory.cpp
Normal file
173
src/ripple_core/node/SophiaBackendFactory.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class SophiaBackendFactory::Backend
|
||||
: public NodeStore::Backend
|
||||
, LeakChecked <SophiaBackendFactory::Backend>
|
||||
{
|
||||
public:
|
||||
typedef RecycledObjectPool <std::string> StringPool;
|
||||
typedef NodeStore::Batch Batch;
|
||||
typedef NodeStore::EncodedBlob EncodedBlob;
|
||||
typedef NodeStore::DecodedBlob DecodedBlob;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Backend (int keyBytes,
|
||||
StringPairArray const& keyValues,
|
||||
NodeStore::Scheduler& scheduler)
|
||||
: m_keyBytes (keyBytes)
|
||||
, m_scheduler (scheduler)
|
||||
, m_name (keyValues ["path"].toStdString ())
|
||||
, m_env (nullptr)
|
||||
, m_db (nullptr)
|
||||
{
|
||||
if (m_name.empty())
|
||||
Throw (std::runtime_error ("Missing path in Sophia backend"));
|
||||
|
||||
m_env = sp_env ();
|
||||
|
||||
if (m_env != nullptr)
|
||||
{
|
||||
sp_ctl (m_env, SPDIR, SPO_RDWR | SPO_CREAT, m_name.c_str());
|
||||
m_db = sp_open (m_env);
|
||||
}
|
||||
}
|
||||
|
||||
~Backend ()
|
||||
{
|
||||
if (m_db != nullptr)
|
||||
sp_destroy (m_db);
|
||||
|
||||
if (m_env != nullptr)
|
||||
sp_destroy (m_env);
|
||||
}
|
||||
|
||||
std::string getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Status fetch (void const* key, NodeObject::Ptr* pObject)
|
||||
{
|
||||
pObject->reset ();
|
||||
|
||||
Status status (unknown);
|
||||
|
||||
void* v (nullptr);
|
||||
std::size_t vsize;
|
||||
|
||||
int rc (sp_get (m_db, key, m_keyBytes, &v, &vsize));
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
DecodedBlob decoded (key, v, vsize);
|
||||
|
||||
if (decoded.wasOk ())
|
||||
{
|
||||
*pObject = decoded.createObject ();
|
||||
status = ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = dataCorrupt;
|
||||
}
|
||||
|
||||
::free (v);
|
||||
}
|
||||
else if (rc == 0)
|
||||
{
|
||||
status = notFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
// error
|
||||
String s;
|
||||
s << "Sophia failed with error code " << rc;
|
||||
Throw (std::runtime_error (s.toStdString()), __FILE__, __LINE__);
|
||||
status = notFound;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void store (NodeObject::ref object)
|
||||
{
|
||||
EncodedBlob::Pool::ScopedItem item (m_blobPool);
|
||||
EncodedBlob& encoded (item.getObject ());
|
||||
encoded.prepare (object);
|
||||
|
||||
int rv (sp_set (m_db,
|
||||
encoded.getKey(), m_keyBytes,
|
||||
encoded.getData(), encoded.getSize()));
|
||||
}
|
||||
|
||||
void storeBatch (Batch const& batch)
|
||||
{
|
||||
for (NodeStore::Batch::const_iterator iter (batch.begin());
|
||||
iter != batch.end(); ++iter)
|
||||
{
|
||||
store (*iter);
|
||||
}
|
||||
}
|
||||
|
||||
void visitAll (VisitCallback& callback)
|
||||
{
|
||||
}
|
||||
|
||||
int getWriteLoad ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t const m_keyBytes;
|
||||
NodeStore::Scheduler& m_scheduler;
|
||||
StringPool m_stringPool;
|
||||
NodeStore::EncodedBlob::Pool m_blobPool;
|
||||
std::string m_name;
|
||||
void* m_env;
|
||||
void* m_db;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SophiaBackendFactory::SophiaBackendFactory ()
|
||||
{
|
||||
leveldb::Options options;
|
||||
options.create_if_missing = true;
|
||||
options.block_cache = leveldb::NewLRUCache (getConfig ().getSize (
|
||||
siHashNodeDBCache) * 1024 * 1024);
|
||||
}
|
||||
|
||||
SophiaBackendFactory::~SophiaBackendFactory ()
|
||||
{
|
||||
}
|
||||
|
||||
SophiaBackendFactory& SophiaBackendFactory::getInstance ()
|
||||
{
|
||||
static SophiaBackendFactory instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
String SophiaBackendFactory::getName () const
|
||||
{
|
||||
return "sophia";
|
||||
}
|
||||
|
||||
NodeStore::Backend* SophiaBackendFactory::createInstance (
|
||||
size_t keyBytes,
|
||||
StringPairArray const& keyValues,
|
||||
NodeStore::Scheduler& scheduler)
|
||||
{
|
||||
return new SophiaBackendFactory::Backend (keyBytes, keyValues, scheduler);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
32
src/ripple_core/node/SophiaBackendFactory.h
Normal file
32
src/ripple_core/node/SophiaBackendFactory.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_CORE_SOPHIABACKENDFACTORY_H_INCLUDED
|
||||
#define RIPPLE_CORE_SOPHIABACKENDFACTORY_H_INCLUDED
|
||||
|
||||
/** Factory to produce Sophia backends for the NodeStore.
|
||||
|
||||
@see NodeStore
|
||||
*/
|
||||
class SophiaBackendFactory : public NodeStore::BackendFactory
|
||||
{
|
||||
private:
|
||||
class Backend;
|
||||
|
||||
SophiaBackendFactory ();
|
||||
~SophiaBackendFactory ();
|
||||
|
||||
public:
|
||||
static SophiaBackendFactory& getInstance ();
|
||||
|
||||
String getName () const;
|
||||
|
||||
NodeStore::Backend* createInstance (size_t keyBytes,
|
||||
StringPairArray const& keyValues,
|
||||
NodeStore::Scheduler& scheduler);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "../ripple_hyperleveldb/ripple_hyperleveldb.h"
|
||||
#include "../ripple_leveldb/ripple_leveldb.h"
|
||||
#include "../ripple_mdb/ripple_mdb.h"
|
||||
#include "../ripple/sophia/ripple_sophia.h"
|
||||
|
||||
namespace ripple
|
||||
{
|
||||
@@ -48,6 +49,8 @@ namespace ripple
|
||||
# include "node/NullBackendFactory.cpp"
|
||||
# include "node/MdbBackendFactory.h"
|
||||
# include "node/MdbBackendFactory.cpp"
|
||||
# include "node/SophiaBackendFactory.h"
|
||||
# include "node/SophiaBackendFactory.cpp"
|
||||
#include "node/NodeStore.cpp"
|
||||
#include "node/NodeObject.cpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user