rippled
Loading...
Searching...
No Matches
Backend.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_NODESTORE_BACKEND_H_INCLUDED
21#define RIPPLE_NODESTORE_BACKEND_H_INCLUDED
22
23#include <xrpld/nodestore/Types.h>
24
25#include <cstdint>
26
27namespace ripple {
28namespace NodeStore {
29
40{
41public:
48 virtual ~Backend() = default;
49
53 virtual std::string
54 getName() = 0;
55
60 {
61 return std::nullopt;
62 }
63
68 virtual void
69 open(bool createIfMissing = true) = 0;
70
73 virtual bool
74 isOpen() = 0;
75
83 virtual void
84 open(bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
85 {
86 Throw<std::runtime_error>(
87 "Deterministic appType/uid/salt not supported by backend " +
88 getName());
89 }
90
94 virtual void
95 close() = 0;
96
105 virtual Status
106 fetch(void const* key, std::shared_ptr<NodeObject>* pObject) = 0;
107
111
118 virtual void
120
125 virtual void
126 storeBatch(Batch const& batch) = 0;
127
128 virtual void
129 sync() = 0;
130
137 virtual void
139
141 virtual int
143
145 virtual void
147
154 virtual void
156 {
157 }
158
160 virtual int
161 fdRequired() const = 0;
162};
163
164} // namespace NodeStore
165} // namespace ripple
166
167#endif
A backend used for the NodeStore.
Definition Backend.h:40
virtual std::string getName()=0
Get the human-readable name of this backend.
virtual void open(bool createIfMissing=true)=0
Open the backend.
virtual std::optional< std::size_t > getBlockSize() const
Get the block size for backends that support it.
Definition Backend.h:59
virtual void close()=0
Close the backend.
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 ~Backend()=default
Destroy the backend.
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
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.
virtual std::pair< std::vector< std::shared_ptr< NodeObject > >, Status > fetchBatch(std::vector< uint256 const * > const &hashes)=0
Fetch a batch synchronously.
virtual int getWriteLoad()=0
Estimate the number of write operations pending.
virtual void storeBatch(Batch const &batch)=0
Store a group of objects.
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.
Definition Backend.h:84
virtual void verify()
Perform consistency checks on database.
Definition Backend.h:155
T is_same_v
Status
Return codes from Backend operations.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25