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 
25 namespace ripple {
26 namespace NodeStore {
27 
37 class Backend
38 {
39 public:
46  virtual ~Backend() = default;
47 
51  virtual std::string
52  getName() = 0;
53 
58  virtual void
59  open(bool createIfMissing = true) = 0;
60 
68  virtual void
70  bool createIfMissing,
71  boost::optional<uint64_t> appType,
72  boost::optional<uint64_t> uid,
73  boost::optional<uint64_t> salt)
74  {
75  Throw<std::runtime_error>(std::string(
76  "Deterministic appType/uid/salt not supported by backend " +
77  getName()));
78  }
79 
83  virtual void
84  close() = 0;
85 
94  virtual Status
95  fetch(void const* key, std::shared_ptr<NodeObject>* pObject) = 0;
96 
98  virtual bool
99  canFetchBatch() = 0;
100 
103  fetchBatch(std::size_t n, void const* const* keys) = 0;
104 
111  virtual void
112  store(std::shared_ptr<NodeObject> const& object) = 0;
113 
118  virtual void
119  storeBatch(Batch const& batch) = 0;
120 
127  virtual void
129 
131  virtual int
132  getWriteLoad() = 0;
133 
135  virtual void
136  setDeletePath() = 0;
137 
139  virtual void
140  verify() = 0;
141 
143  virtual int
144  fdRequired() const = 0;
145 
147  bool
148  backed() const
149  {
150  return fdRequired();
151  }
152 };
153 
154 } // namespace NodeStore
155 } // namespace ripple
156 
157 #endif
ripple::NodeStore::Backend::backed
bool backed() const
Returns true if the backend uses permanent storage.
Definition: Backend.h:148
std::string
STL class.
std::shared_ptr< NodeObject >
ripple::NodeStore::Backend::getWriteLoad
virtual int getWriteLoad()=0
Estimate the number of write operations pending.
std::vector
STL class.
std::function
ripple::NodeStore::Backend::store
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
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::~Backend
virtual ~Backend()=default
Destroy the backend.
ripple::NodeStore::Backend::open
virtual void open(bool createIfMissing, boost::optional< uint64_t > appType, boost::optional< uint64_t > uid, boost::optional< uint64_t > salt)
Open the backend.
Definition: Backend.h:69
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::fetchBatch
virtual std::vector< std::shared_ptr< NodeObject > > fetchBatch(std::size_t n, void const *const *keys)=0
Fetch a batch synchronously.
std::size_t
ripple::NodeStore::Backend::canFetchBatch
virtual bool canFetchBatch()=0
Return true if batch fetches are optimized.
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::verify
virtual void verify()=0
Perform consistency checks on database.
ripple::NodeStore::Backend::fetch
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
ripple::NodeStore::Backend
A backend used for the NodeStore.
Definition: Backend.h:37