CatapultServer  v0.5.0.1 (Elephant)
RocksDatabase.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "RocksPruningFilter.h"
24 #include "catapult/types.h"
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 namespace rocksdb {
30  class ColumnFamilyHandle;
31  class DB;
32  class PinnableSlice;
33  class Slice;
34  class WriteBatch;
35 }
36 
37 namespace catapult { namespace cache {
38 
41  private:
43 
44  explicit RdbDataIterator(StorageStrategy storageStrategy);
45 
46  public:
49 
52 
53  public:
56 
59 
60  public:
62  static RdbDataIterator End();
63 
64  public:
66  bool operator==(const RdbDataIterator& rhs) const;
67 
69  bool operator!=(const RdbDataIterator& rhs) const;
70 
71  public:
73  rocksdb::PinnableSlice& storage() const;
74 
76  void setFound(bool found);
77 
79  RawBuffer buffer() const;
80 
81  private:
82  struct Impl;
83  std::shared_ptr<Impl> m_pImpl;
84  bool m_isFound;
85  };
86 
89  public:
92 
96  const std::string& databaseDirectory,
97  const std::vector<std::string>& columnFamilyNames,
98  utils::FileSize maxDatabaseWriteBatchSize,
99  FilterPruningMode pruningMode);
100 
101  public:
103  const std::string DatabaseDirectory;
104 
106  const std::vector<std::string> ColumnFamilyNames;
107 
110 
113  };
114 
117  public:
119  RocksDatabase();
120 
122  explicit RocksDatabase(const RocksDatabaseSettings& settings);
123 
125  ~RocksDatabase();
126 
127  public:
129  const std::vector<std::string>& columnFamilyNames() const;
130 
132  bool canPrune() const;
133 
134  public:
136  void get(size_t columnId, const rocksdb::Slice& key, RdbDataIterator& result);
137 
139  void put(size_t columnId, const rocksdb::Slice& key, const std::string& value);
140 
142  void del(size_t columnId, const rocksdb::Slice& key);
143 
145  size_t prune(size_t columnId, uint64_t boundary);
146 
148  void flush();
149 
150  private:
151  void saveIfBatchFull();
152 
153  private:
156  std::unique_ptr<rocksdb::WriteBatch> m_pWriteBatch;
157 
158  std::unique_ptr<rocksdb::DB> m_pDb;
159  std::vector<rocksdb::ColumnFamilyHandle*> m_handles;
160  };
161 }}
catapult::cache::RdbDataIterator::setFound
void setFound(bool found)
Sets flag to found indicating that iterator contains data.
Definition: RocksDatabase.cpp:68
catapult::utils::ExtractDirectoryName
constexpr RawString ExtractDirectoryName(const char *fullPath)
Definition: PathUtils.h:77
catapult::cache::RdbDataIterator::End
static RdbDataIterator End()
Iterator representing no match.
Definition: RocksDatabase.cpp:52
catapult::cache::RocksDatabaseSettings
RocksDb settings.
Definition: RocksDatabase.h:88
catapult::utils::FileSize::bytes
constexpr uint64_t bytes() const
Returns the number of bytes.
Definition: FileSize.h:67
exceptions.h
catapult::cache::RdbDataIterator::operator==
bool operator==(const RdbDataIterator &rhs) const
Returns true if this iterator and rhs are equal.
Definition: RocksDatabase.cpp:56
catapult::cache::RdbDataIterator::m_isFound
bool m_isFound
Definition: RocksDatabase.h:84
catapult::cache::RocksDatabase::columnFamilyNames
const std::vector< std::string > & columnFamilyNames() const
Gets the database column family names.
Definition: RocksDatabase.cpp:136
catapult::cache::RdbDataIterator::storage
rocksdb::PinnableSlice & storage() const
Returns storage associated with iterator.
Definition: RocksDatabase.cpp:64
CATAPULT_THROW_RUNTIME_ERROR_2
#define CATAPULT_THROW_RUNTIME_ERROR_2(MESSAGE, PARAM1, PARAM2)
Macro used to throw a catapult runtime error with two parameters.
Definition: exceptions.h:175
catapult::cache::RdbDataIterator::buffer
RawBuffer buffer() const
Returns storage as raw buffer.
Definition: RocksDatabase.cpp:72
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
RocksInclude.h
catapult::cache::RdbDataIterator::StorageStrategy::Allocate
catapult::cache::RocksDatabase::saveIfBatchFull
void saveIfBatchFull()
Definition: RocksDatabase.cpp:218
catapult::tools::Options
boost::program_options::variables_map Options
Provides access to parsed options.
Definition: Options.h:34
catapult::cache::RocksDatabase::m_pWriteBatch
std::unique_ptr< rocksdb::WriteBatch > m_pWriteBatch
Definition: RocksDatabase.h:156
catapult::cache::RocksDatabase::~RocksDatabase
~RocksDatabase()
Destroys database.
Definition: RocksDatabase.cpp:131
FileSize.h
catapult::cache::RocksPruningFilter::numRemoved
size_t numRemoved() const
Returns number of pruned entries since last prune.
Definition: RocksPruningFilter.cpp:87
catapult::cache::RdbDataIterator::Impl::Result
rocksdb::PinnableSlice Result
Definition: RocksDatabase.cpp:35
catapult::cache::RocksPruningFilter::compactionFilter
rocksdb::CompactionFilter * compactionFilter()
Returns underlying compaction filter.
Definition: RocksPruningFilter.cpp:79
catapult::cache::RocksDatabaseSettings::MaxDatabaseWriteBatchSize
const utils::FileSize MaxDatabaseWriteBatchSize
Maximum size of database write batch.
Definition: RocksDatabase.h:109
catapult::cache::RocksPruningFilter
Rocks pruning filter.
Definition: RocksPruningFilter.h:38
m_settings
const AsyncTcpServerSettings m_settings
Definition: AsyncTcpServer.cpp:203
catapult::cache::FilterPruningMode
FilterPruningMode
Possible modes of rocks pruning filter.
Definition: RocksPruningFilter.h:29
catapult::cache::RocksDatabase::m_handles
std::vector< rocksdb::ColumnFamilyHandle * > m_handles
Definition: RocksDatabase.h:159
CATAPULT_THROW_DB_KEY_ERROR
#define CATAPULT_THROW_DB_KEY_ERROR(message)
Definition: RocksDatabase.cpp:151
catapult::cache::RdbDataIterator::RdbDataIterator
RdbDataIterator()
Creates an iterator.
Definition: RocksDatabase.cpp:43
catapult::cache::RocksDatabase::m_pruningFilter
RocksPruningFilter m_pruningFilter
Definition: RocksDatabase.h:155
RocksPruningFilter.h
catapult::cache::FilterPruningMode::Enabled
Enabled, allocate underlying filter implementation.
catapult::cache::RocksDatabase::m_settings
const RocksDatabaseSettings m_settings
Definition: RocksDatabase.h:154
catapult::cache::RdbDataIterator
Iterator adapter, allowing existence check on keys and data retrieval.
Definition: RocksDatabase.h:40
CATAPULT_THROW_RUNTIME_ERROR_1
#define CATAPULT_THROW_RUNTIME_ERROR_1(MESSAGE, PARAM1)
Macro used to throw a catapult runtime error with a single parameter.
Definition: exceptions.h:171
catapult::cache::RocksDatabaseSettings::RocksDatabaseSettings
RocksDatabaseSettings()
Creates default database settings.
Definition: RocksDatabase.cpp:80
catapult::cache::RocksDatabaseSettings::ColumnFamilyNames
const std::vector< std::string > ColumnFamilyNames
Names of database columns.
Definition: RocksDatabase.h:106
catapult::cache::RocksDatabase::prune
size_t prune(size_t columnId, uint64_t boundary)
Prunes elements from columnId below boundary. Returns number of pruned elements.
Definition: RocksDatabase.cpp:193
catapult::utils::SlowOperationLogger
Simple RAII class that logs slow operation messages.
Definition: StackLogger.h:51
HexFormatter.h
catapult::cache::RocksDatabase::RocksDatabase
RocksDatabase()
Creates an empty database.
catapult::cache::RocksDatabase::canPrune
bool canPrune() const
Returns true if pruning is enabled.
Definition: RocksDatabase.cpp:140
catapult::utils::FileSize
Represents a file size.
Definition: FileSize.h:29
catapult::cache::RocksDatabase
RocksDb-backed database.
Definition: RocksDatabase.h:116
catapult::cache::RdbDataIterator::~RdbDataIterator
~RdbDataIterator()
Destroys an iterator.
catapult::cache::RdbDataIterator::StorageStrategy
StorageStrategy
Definition: RocksDatabase.h:42
StackLogger.h
catapult::cache::RocksDatabaseSettings::DatabaseDirectory
const std::string DatabaseDirectory
Database directory.
Definition: RocksDatabase.h:103
catapult::utils::FileSize::FromKilobytes
static constexpr FileSize FromKilobytes(uint64_t kilobytes)
Creates a file size from the given number of kilobytes.
Definition: FileSize.h:46
catapult::cache::RocksDatabase::del
void del(size_t columnId, const rocksdb::Slice &key)
Deletes key from columnId.
Definition: RocksDatabase.cpp:180
types.h
catapult::cache::PatriciaTreeStorageMode::Disabled
Patricia tree storage should be disabled.
catapult::cache::RocksDatabaseSettings::PruningMode
const FilterPruningMode PruningMode
Database pruning mode.
Definition: RocksDatabase.h:112
CATAPULT_THROW_INVALID_ARGUMENT
#define CATAPULT_THROW_INVALID_ARGUMENT(MESSAGE)
Macro used to throw a catapult invalid argument.
Definition: exceptions.h:179
catapult::cache::RocksDatabase::flush
void flush()
Finalize batched operations.
Definition: RocksDatabase.cpp:202
catapult::cache::RdbDataIterator::m_pImpl
std::shared_ptr< Impl > m_pImpl
Definition: RocksDatabase.h:82
catapult::cache::RdbDataIterator::operator!=
bool operator!=(const RdbDataIterator &rhs) const
Returns true if this iterator and rhs are not equal.
Definition: RocksDatabase.cpp:60
catapult
Definition: AddressExtractionExtension.cpp:28
RocksDatabase.h
catapult::cache::RdbDataIterator::operator=
RdbDataIterator & operator=(RdbDataIterator &&)
Move assignment operator.
catapult::cache::RocksDatabase::put
void put(size_t columnId, const rocksdb::Slice &key, const std::string &value)
Puts value with key in columnId.
Definition: RocksDatabase.cpp:169
catapult::cache::RocksDatabase::m_pDb
std::unique_ptr< rocksdb::DB > m_pDb
Definition: RocksDatabase.h:158
rocksdb
Definition: RocksDatabase.h:29
catapult::cache::RdbDataIterator::StorageStrategy::Do_Not_Allocate
PathUtils.h
catapult::utils::LogLevel::Warning
Level for logging warning events.
catapult::cache::RocksPruningFilter::setPruningBoundary
void setPruningBoundary(uint64_t pruningBoundary)
Sets pruning boundary.
Definition: RocksPruningFilter.cpp:91
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62
catapult::cache::RocksDatabase::get
void get(size_t columnId, const rocksdb::Slice &key, RdbDataIterator &result)
Gets key from columnId returning data in result.
Definition: RocksDatabase.cpp:154
catapult::cache::RdbDataIterator::Impl
Definition: RocksDatabase.cpp:34