Kagome
Polkadot Runtime Engine in C++17
rocksdb.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_ROCKSDB_HPP
7 #define KAGOME_ROCKSDB_HPP
8 
10 
11 #include <rocksdb/db.h>
12 #include <boost/filesystem/path.hpp>
13 #include "log/logger.hpp"
14 
15 namespace kagome::storage {
16 
17  class RocksDB : public BufferStorage {
18  public:
19  class Batch;
20 
21  ~RocksDB() override;
22 
30  static outcome::result<std::unique_ptr<RocksDB>> create(
31  const boost::filesystem::path &path,
32  rocksdb::Options options = rocksdb::Options(),
33  bool prevent_destruction = false);
34 
35  std::unique_ptr<BufferBatch> batch() override;
36 
37  size_t size() const override;
38 
39  std::unique_ptr<Cursor> cursor() override;
40 
41  outcome::result<bool> contains(const Key &key) const override;
42 
43  bool empty() const override;
44 
45  outcome::result<kagome::storage::Buffer> load(
46  const Key &key) const override;
47 
48  outcome::result<std::optional<Buffer>> tryLoad(
49  const Key &key) const override;
50 
51  outcome::result<void> put(const BufferView &key,
52  const Buffer &value) override;
53 
54  outcome::result<void> put(const BufferView &key, Buffer &&value) override;
55 
56  outcome::result<void> remove(const BufferView &key) override;
57 
58  void compact(const Buffer &first, const Buffer &last);
59 
60  private:
61  RocksDB(bool prevent_destruction);
62 
63  bool prevent_destruction_ = false;
64 
65  std::unique_ptr<rocksdb::DB> db_;
66  rocksdb::ReadOptions ro_;
67  rocksdb::WriteOptions wo_;
69  };
70 } // namespace kagome::storage
71 
72 #endif // KAGOME_ROCKSDB_HPP
void compact(const Buffer &first, const Buffer &last)
Definition: rocksdb.cpp:179
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
rocksdb::WriteOptions wo_
Definition: rocksdb.hpp:67
outcome::result< kagome::storage::Buffer > load(const Key &key) const override
Load value by key.
Definition: rocksdb.cpp:126
rocksdb::ReadOptions ro_
Definition: rocksdb.hpp:66
outcome::result< bool > contains(const Key &key) const override
Checks if given key-value binding exists in the storage.
Definition: rocksdb.cpp:106
std::unique_ptr< Cursor > cursor() override
Returns new key-value iterator.
Definition: rocksdb.cpp:101
outcome::result< std::optional< Buffer > > tryLoad(const Key &key) const override
Load value by key.
Definition: rocksdb.cpp:138
outcome::result< void > put(const BufferView &key, const Buffer &value) override
Definition: rocksdb.cpp:155
size_t size() const override
Definition: rocksdb.cpp:83
std::unique_ptr< rocksdb::DB > db_
Definition: rocksdb.hpp:65
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::unique_ptr< BufferBatch > batch() override
Creates new Write Batch - an object, which can be used to efficiently write bulk data.
Definition: rocksdb.cpp:79
bool empty() const override
Returns true if the storage is empty.
Definition: rocksdb.cpp:120
RocksDB(bool prevent_destruction)
Definition: rocksdb.cpp:19
static outcome::result< std::unique_ptr< RocksDB > > create(const boost::filesystem::path &path, rocksdb::Options options=rocksdb::Options(), bool prevent_destruction=false)
Factory method to create an instance of RocksDB class.
Definition: rocksdb.cpp:37