Skip to content

sgns::storage::rocksdb

An implementation of PersistentBufferMap interface, which uses rocksdb as underlying storage.

#include <rocksdb.hpp>

Inherits from sgns::storage::face::GenericStorage< Buffer, Buffer >, sgns::storage::face::ReadOnlyMap< K, V >, sgns::storage::face::BatchWriteMap< K, V >, IComponent, sgns::storage::face::Iterable< K, V >, sgns::storage::face::Readable< K, V >, sgns::storage::face::Writeable< K, V >, sgns::storage::face::Batchable< K, V >

Public Classes

Name
class Batch
Class that is used to implement efficient bulk (batch) modifications of the Map.
class Cursor
Instance of cursor can be used as bidirectional iterator over key-value bindings of the Map.

Public Types

Name
using ::ROCKSDB_NAMESPACE::Iterator Iterator
using ::ROCKSDB_NAMESPACE::Options Options
using ::ROCKSDB_NAMESPACE::ReadOptions ReadOptions
using ::ROCKSDB_NAMESPACE::WriteOptions WriteOptions
using ::ROCKSDB_NAMESPACE::DB DB
using ::ROCKSDB_NAMESPACE::Status Status
using ::ROCKSDB_NAMESPACE::Slice Slice
using std::map< Buffer, Buffer > QueryResult
using std::pair< Buffer, Buffer > KeyValuePair

Public Functions

Name
~rocksdb() override
void setReadOptions(ReadOptions ro)
Set read options, which are used in.
void setWriteOptions(WriteOptions wo)
Set write options, which are used in.
virtual std::unique_ptr< BufferMapCursor > cursor() override
Returns new key-value iterator.
virtual std::unique_ptr< BufferBatch > batch() override
Creates new Write Batch - an object, which can be used to efficiently write bulk data.
virtual outcome::result< Buffer > get(const Buffer & key) const override
Get value by key.
outcome::result< QueryResult > query(const Buffer & keyPrefix) const
outcome::result< QueryResult > query(const std::string & prefix_base, const std::string & middle_part, const std::string & remainder_prefix) const
Queries with a middle part that can be a wildcard, negated string or normal string.
virtual bool contains(const Buffer & key) const override
Returns true if given key-value binding exists in the storage.
virtual bool empty() const override
Returns true if the storage is empty.
virtual outcome::result< void > put(const Buffer & key, const Buffer & value) override
Store value by key.
outcome::result< void > put(const Buffer & key, Buffer && value) override
virtual outcome::result< void > remove(const Buffer & key) override
Remove value by key.
virtual std::string GetName() override
std::shared_ptr< DB > getDB() const
std::vector< KeyValuePair > GetAll() const
Gets all key value pairs on rocksdb.
outcome::result< std::shared_ptr< rocksdb > > create(std::string_view path, const Options & options =Options())
Factory method to create an instance of rocksdb class.
outcome::result< std::shared_ptr< rocksdb > > create(const std::shared_ptr< DB > & db)
Factory method to create an instance of rocksdb class.

Additional inherited members

Public Functions inherited from IComponent

Name
virtual ~IComponent() =default

Public Functions inherited from sgns::storage::face::Iterable< K, V >

Name
virtual ~Iterable() =default

Public Functions inherited from sgns::storage::face::Readable< K, V >

Name
virtual ~Readable() =default

Public Functions inherited from sgns::storage::face::Writeable< K, V >

Name
virtual ~Writeable() =default

Public Functions inherited from sgns::storage::face::Batchable< K, V >

Name
virtual ~Batchable() =default

Public Types Documentation

using Iterator

using sgns::storage::rocksdb::Iterator = ::ROCKSDB_NAMESPACE::Iterator;

using Options

using sgns::storage::rocksdb::Options = ::ROCKSDB_NAMESPACE::Options;

using ReadOptions

using sgns::storage::rocksdb::ReadOptions = ::ROCKSDB_NAMESPACE::ReadOptions;

using WriteOptions

using sgns::storage::rocksdb::WriteOptions = ::ROCKSDB_NAMESPACE::WriteOptions;

using DB

using sgns::storage::rocksdb::DB = ::ROCKSDB_NAMESPACE::DB;

using Status

using sgns::storage::rocksdb::Status = ::ROCKSDB_NAMESPACE::Status;

using Slice

using sgns::storage::rocksdb::Slice = ::ROCKSDB_NAMESPACE::Slice;

using QueryResult

using sgns::storage::rocksdb::QueryResult = std::map<Buffer, Buffer>;

using KeyValuePair

using sgns::storage::rocksdb::KeyValuePair = std::pair<Buffer, Buffer>;

Public Functions Documentation

function ~rocksdb

~rocksdb() override

function setReadOptions

void setReadOptions(
    ReadOptions ro
)

Set read options, which are used in.

Parameters:

  • ro options

See: rocksdb::get

function setWriteOptions

void setWriteOptions(
    WriteOptions wo
)

Set write options, which are used in.

Parameters:

  • wo options

See: rocksdb::put

function cursor

virtual std::unique_ptr< BufferMapCursor > cursor() override

Returns new key-value iterator.

Return: kv iterator

Reimplements: sgns::storage::face::Iterable::cursor

function batch

virtual std::unique_ptr< BufferBatch > batch() override

Creates new Write Batch - an object, which can be used to efficiently write bulk data.

Reimplements: sgns::storage::face::Batchable::batch

function get

virtual outcome::result< Buffer > get(
    const Buffer & key
) const override

Get value by key.

Parameters:

  • key K

Return: V

Reimplements: sgns::storage::face::Readable::get

function query

outcome::result< QueryResult > query(
    const Buffer & keyPrefix
) const

function query

outcome::result< QueryResult > query(
    const std::string & prefix_base,
    const std::string & middle_part,
    const std::string & remainder_prefix
) const

Queries with a middle part that can be a wildcard, negated string or normal string.

Parameters:

  • prefix_base The base prefix to query
  • middle_part Either a string (normal query), '*' or !string
  • remainder_prefix The remainder part of the query prefix

Return: List of query results

function contains

virtual bool contains(
    const Buffer & key
) const override

Returns true if given key-value binding exists in the storage.

Parameters:

  • key K

Return: true if key has value, false otherwise.

Reimplements: sgns::storage::face::Readable::contains

function empty

virtual bool empty() const override

Returns true if the storage is empty.

Reimplements: sgns::storage::face::Readable::empty

function put

virtual outcome::result< void > put(
    const Buffer & key,
    const Buffer & value
) override

Store value by key.

Parameters:

  • key key
  • value value

Return: result containing void if put successful, error otherwise

Reimplements: sgns::storage::face::Writeable::put

function put

outcome::result< void > put(
    const Buffer & key,
    Buffer && value
) override

function remove

virtual outcome::result< void > remove(
    const Buffer & key
) override

Remove value by key.

Parameters:

  • key K

Return: error code if error happened

Reimplements: sgns::storage::face::Writeable::remove

function GetName

inline virtual std::string GetName() override

Reimplements: IComponent::GetName

function getDB

inline std::shared_ptr< DB > getDB() const

function GetAll

std::vector< KeyValuePair > GetAll() const

Gets all key value pairs on rocksdb.

function create

static outcome::result< std::shared_ptr< rocksdb > > create(
    std::string_view path,
    const Options & options =Options()
)

Factory method to create an instance of rocksdb class.

Parameters:

  • path filesystem path where database is going to be
  • options rocksdb options, such as caching, logging, etc.

Return: instance of rocksdb

function create

static outcome::result< std::shared_ptr< rocksdb > > create(
    const std::shared_ptr< DB > & db
)

Factory method to create an instance of rocksdb class.

Parameters:

  • db pointer to rocksdb database instance

Updated on 2026-03-04 at 13:10:44 -0800