xrpld
Loading...
Searching...
No Matches
Backend.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/nodestore/NodeObject.h>
6#include <xrpl/nodestore/Types.h>
7
8#include <cstddef>
9#include <cstdint>
10#include <functional>
11#include <memory>
12#include <optional>
13#include <stdexcept>
14#include <string>
15
16namespace xrpl::node_store {
17
29{
30public:
38 virtual ~Backend() = default;
39
44 virtual std::string
45 getName() = 0;
46
50 [[nodiscard]] virtual std::optional<std::size_t>
52 {
53 return std::nullopt;
54 }
55
61 virtual void
62 open(bool createIfMissing = true) = 0;
63
67 virtual bool
68 isOpen() = 0;
69
78 virtual void
79 open(bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
80 {
82 "Deterministic appType/uid/salt not supported by backend " + getName());
83 }
84
89 virtual void
90 close() = 0;
91
101 virtual Status
102 fetch(uint256 const& hash, std::shared_ptr<NodeObject>* pObject) = 0;
103
111 virtual void
113
119 virtual void
120 storeBatch(Batch const& batch) = 0;
121
122 virtual void
123 sync() = 0;
124
132 virtual void
134
138 virtual int
140
144 virtual void
146
154 virtual void
156 {
157 }
158
162 [[nodiscard]] virtual int
163 fdRequired() const = 0;
164};
165
166} // namespace xrpl::node_store
A backend used for the NodeStore.
Definition Backend.h:29
virtual void close()=0
Close the backend.
virtual int getWriteLoad()=0
Estimate the number of write operations pending.
virtual bool isOpen()=0
Returns true is the database is open.
virtual ~Backend()=default
Destroy the backend.
virtual void verify()
Perform consistency checks on database.
Definition Backend.h:155
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
virtual void open(bool createIfMissing=true)=0
Open the backend.
virtual void sync()=0
virtual std::string getName()=0
Get the human-readable name of this backend.
virtual Status fetch(uint256 const &hash, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
virtual void open(bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
Open the backend.
Definition Backend.h:79
virtual std::optional< std::size_t > getBlockSize() const
Get the block size for backends that support it.
Definition Backend.h:51
virtual void forEach(std::function< void(std::shared_ptr< NodeObject >)> f)=0
Visit every object in the database This is usually called during import.
virtual void storeBatch(Batch const &batch)=0
Store a group of objects.
virtual void setDeletePath()=0
Remove contents on disk upon destruction.
virtual int fdRequired() const =0
Returns the number of file descriptors the backend expects to need.
std::vector< std::shared_ptr< NodeObject > > Batch
A batch of NodeObjects to write at once.
Status
Return codes from Backend operations.
BaseUInt< 256 > uint256
Definition base_uint.h:580
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52