rippled
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 <ripple/nodestore/Types.h>
24 #include <atomic>
25 #include <cstdint>
26 
27 namespace ripple {
28 namespace NodeStore {
29 
39 class Backend
40 {
41 public:
42  template <typename T>
43  struct Counters
44  {
45  Counters() = default;
46  Counters(Counters const&) = default;
47 
48  template <typename U>
49  Counters(Counters<U> const& other)
51  , writeRetries(other.writeRetries)
53  , readRetries(other.readRetries)
54  , readErrors(other.readErrors)
55  {
56  }
57 
59  T writeRetries = {};
60  T writesDelayed = {};
61  T readRetries = {};
62  T readErrors = {};
63  };
64 
71  virtual ~Backend() = default;
72 
76  virtual std::string
77  getName() = 0;
78 
83  virtual void
84  open(bool createIfMissing = true) = 0;
85 
88  virtual bool
89  isOpen() = 0;
90 
98  virtual void
99  open(bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
100  {
101  Throw<std::runtime_error>(
102  "Deterministic appType/uid/salt not supported by backend " +
103  getName());
104  }
105 
109  virtual void
110  close() = 0;
111 
120  virtual Status
121  fetch(void const* key, std::shared_ptr<NodeObject>* pObject) = 0;
122 
125  fetchBatch(std::vector<uint256 const*> const& hashes) = 0;
126 
133  virtual void
134  store(std::shared_ptr<NodeObject> const& object) = 0;
135 
140  virtual void
141  storeBatch(Batch const& batch) = 0;
142 
143  virtual void
144  sync() = 0;
145 
152  virtual void
154 
156  virtual int
157  getWriteLoad() = 0;
158 
160  virtual void
161  setDeletePath() = 0;
162 
169  virtual void
171  {
172  }
173 
175  virtual int
176  fdRequired() const = 0;
177 
184  counters() const
185  {
186  return std::nullopt;
187  }
188 };
189 
190 } // namespace NodeStore
191 } // namespace ripple
192 
193 #endif
std::string
STL class.
std::shared_ptr< NodeObject >
ripple::NodeStore::Backend::getWriteLoad
virtual int getWriteLoad()=0
Estimate the number of write operations pending.
std::pair
std::vector
STL class.
ripple::NodeStore::Backend::sync
virtual void sync()=0
std::function
ripple::NodeStore::Backend::verify
virtual void verify()
Perform consistency checks on database.
Definition: Backend.h:170
ripple::NodeStore::Backend::store
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
ripple::NodeStore::Backend::Counters::Counters
Counters()=default
ripple::NodeStore::Backend::close
virtual void close()=0
Close the backend.
ripple::NodeStore::Backend::for_each
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.
ripple::NodeStore::Backend::counters
virtual std::optional< Counters< std::uint64_t > > counters() const
Returns read and write stats.
Definition: Backend.h:184
ripple::NodeStore::Backend::Counters::Counters
Counters(Counters< U > const &other)
Definition: Backend.h:49
ripple::NodeStore::Backend::~Backend
virtual ~Backend()=default
Destroy the backend.
ripple::NodeStore::Backend::Counters::readErrors
T readErrors
Definition: Backend.h:62
ripple::NodeStore::Backend::fetchBatch
virtual std::pair< std::vector< std::shared_ptr< NodeObject > >, Status > fetchBatch(std::vector< uint256 const * > const &hashes)=0
Fetch a batch synchronously.
cstdint
atomic
ripple::NodeStore::Backend::isOpen
virtual bool isOpen()=0
Returns true is the database is open.
ripple::NodeStore::Backend::Counters::writesDelayed
T writesDelayed
Definition: Backend.h:60
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:44
ripple::NodeStore::Backend::setDeletePath
virtual void setDeletePath()=0
Remove contents on disk upon destruction.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::Backend::fdRequired
virtual int fdRequired() const =0
Returns the number of file descriptors the backend expects to need.
ripple::NodeStore::Backend::getName
virtual std::string getName()=0
Get the human-readable name of this backend.
ripple::NodeStore::Backend::open
virtual void open(bool createIfMissing, uint64_t appType, uint64_t uid, uint64_t salt)
Open the backend.
Definition: Backend.h:99
std::optional
ripple::NodeStore::Backend::Counters::readRetries
T readRetries
Definition: Backend.h:61
ripple::NodeStore::Backend::storeBatch
virtual void storeBatch(Batch const &batch)=0
Store a group of objects.
ripple::NodeStore::Backend::open
virtual void open(bool createIfMissing=true)=0
Open the backend.
ripple::NodeStore::Backend::fetch
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
ripple::NodeStore::Backend::Counters::writeDurationUs
T writeDurationUs
Definition: Backend.h:58
ripple::NodeStore::Backend::Counters::writeRetries
T writeRetries
Definition: Backend.h:59
ripple::NodeStore::Backend
A backend used for the NodeStore.
Definition: Backend.h:39
ripple::NodeStore::Backend::Counters
Definition: Backend.h:43