rippled
Loading...
Searching...
No Matches
Public Member Functions | List of all members
xrpl::NodeStore::Backend Class Referenceabstract

A backend used for the NodeStore. More...

#include <Backend.h>

Inheritance diagram for xrpl::NodeStore::Backend:
Inheritance graph
[legend]

Public Member Functions

virtual ~Backend ()=default
 Destroy the backend.
 
virtual std::string getName ()=0
 Get the human-readable name of this backend.
 
virtual std::optional< std::size_tgetBlockSize () const
 Get the block size for backends that support it.
 
virtual void open (bool createIfMissing=true)=0
 Open the backend.
 
virtual bool isOpen ()=0
 Returns true is the database is open.
 
virtual void open (bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
 Open the backend.
 
virtual void close ()=0
 Close the backend.
 
virtual Status fetch (void const *key, std::shared_ptr< NodeObject > *pObject)=0
 Fetch a single object.
 
virtual std::pair< std::vector< std::shared_ptr< NodeObject > >, StatusfetchBatch (std::vector< uint256 const * > const &hashes)=0
 Fetch a batch synchronously.
 
virtual void store (std::shared_ptr< NodeObject > const &object)=0
 Store a single object.
 
virtual void storeBatch (Batch const &batch)=0
 Store a group of objects.
 
virtual void sync ()=0
 
virtual void for_each (std::function< void(std::shared_ptr< NodeObject >)> f)=0
 Visit every object in the database This is usually called during import.
 
virtual int getWriteLoad ()=0
 Estimate the number of write operations pending.
 
virtual void setDeletePath ()=0
 Remove contents on disk upon destruction.
 
virtual void verify ()
 Perform consistency checks on database.
 
virtual int fdRequired () const =0
 Returns the number of file descriptors the backend expects to need.
 

Detailed Description

A backend used for the NodeStore.

The NodeStore uses a swappable backend so that other database systems can be tried. Different databases may offer various features such as improved performance, fault tolerant or distributed storage, or all in-memory operation.

A given instance of a backend is fixed to a particular key size.

Definition at line 20 of file Backend.h.

Constructor & Destructor Documentation

◆ ~Backend()

virtual xrpl::NodeStore::Backend::~Backend ( )
virtualdefault

Destroy the backend.

All open files are closed and flushed. If there are batched writes or other tasks scheduled, they will be completed before this call returns.

Member Function Documentation

◆ getName()

virtual std::string xrpl::NodeStore::Backend::getName ( )
pure virtual

Get the human-readable name of this backend.

This is used for diagnostic output.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ getBlockSize()

virtual std::optional< std::size_t > xrpl::NodeStore::Backend::getBlockSize ( ) const
virtual

Get the block size for backends that support it.

Reimplemented in xrpl::NodeStore::NuDBBackend.

Definition at line 40 of file Backend.h.

◆ open() [1/2]

virtual void xrpl::NodeStore::Backend::open ( bool  createIfMissing = true)
pure virtual

Open the backend.

Parameters
createIfMissingCreate the database files if necessary. This allows the caller to catch exceptions.

Implemented in xrpl::NodeStore::NuDBBackend, xrpl::NodeStore::NullBackend, and xrpl::NodeStore::MemoryBackend.

◆ isOpen()

virtual bool xrpl::NodeStore::Backend::isOpen ( )
pure virtual

Returns true is the database is open.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ open() [2/2]

virtual void xrpl::NodeStore::Backend::open ( bool  createIfMissing,
uint64_t  appType,
uint64_t  uid,
uint64_t  salt 
)
virtual

Open the backend.

Parameters
createIfMissingCreate the database files if necessary.
appTypeDeterministic appType used to create a backend.
uidDeterministic uid used to create a backend.
saltDeterministic salt used to create a backend.
Exceptions
std::runtime_erroris function is called not for NuDB backend.

Reimplemented in xrpl::NodeStore::NuDBBackend.

Definition at line 65 of file Backend.h.

◆ close()

virtual void xrpl::NodeStore::Backend::close ( )
pure virtual

Close the backend.

This allows the caller to catch exceptions.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ fetch()

virtual Status xrpl::NodeStore::Backend::fetch ( void const *  key,
std::shared_ptr< NodeObject > *  pObject 
)
pure virtual

Fetch a single object.

If the object is not found or an error is encountered, the result will indicate the condition.

Note
This will be called concurrently.
Parameters
keyA pointer to the key data.
pObject[out] The created object if successful.
Returns
The result of the operation.

Implemented in xrpl::NodeStore::NullBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::MemoryBackend.

◆ fetchBatch()

virtual std::pair< std::vector< std::shared_ptr< NodeObject > >, Status > xrpl::NodeStore::Backend::fetchBatch ( std::vector< uint256 const * > const &  hashes)
pure virtual

◆ store()

virtual void xrpl::NodeStore::Backend::store ( std::shared_ptr< NodeObject > const &  object)
pure virtual

Store a single object.

Depending on the implementation this may happen immediately or deferred using a scheduled task.

Note
This will be called concurrently.
Parameters
objectThe object to store.

Implemented in xrpl::NodeStore::NuDBBackend, xrpl::NodeStore::MemoryBackend, and xrpl::NodeStore::NullBackend.

◆ storeBatch()

virtual void xrpl::NodeStore::Backend::storeBatch ( Batch const &  batch)
pure virtual

Store a group of objects.

Note
This function will not be called concurrently with itself or store.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ sync()

virtual void xrpl::NodeStore::Backend::sync ( )
pure virtual

◆ for_each()

virtual void xrpl::NodeStore::Backend::for_each ( std::function< void(std::shared_ptr< NodeObject >)>  f)
pure virtual

Visit every object in the database This is usually called during import.

Note
This routine will not be called concurrently with itself or other methods.
See also
import

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ getWriteLoad()

virtual int xrpl::NodeStore::Backend::getWriteLoad ( )
pure virtual

Estimate the number of write operations pending.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ setDeletePath()

virtual void xrpl::NodeStore::Backend::setDeletePath ( )
pure virtual

Remove contents on disk upon destruction.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.

◆ verify()

virtual void xrpl::NodeStore::Backend::verify ( )
virtual

Perform consistency checks on database.

This method is implemented only by NuDBBackend. It is not yet called anywhere, but it might be a good idea to one day call it at startup to avert a crash.

Reimplemented in xrpl::NodeStore::NuDBBackend.

Definition at line 136 of file Backend.h.

◆ fdRequired()

virtual int xrpl::NodeStore::Backend::fdRequired ( ) const
pure virtual

Returns the number of file descriptors the backend expects to need.

Implemented in xrpl::NodeStore::MemoryBackend, xrpl::NodeStore::NuDBBackend, and xrpl::NodeStore::NullBackend.