CatapultServer  v0.5.0.1 (Elephant)
RdbColumnContainer.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/exceptions.h"
23 #include "catapult/functions.h"
24 #include "catapult/types.h"
25 
26 namespace catapult {
27  namespace cache {
28  class RdbDataIterator;
29  class RocksDatabase;
30  }
31 }
32 
33 namespace catapult { namespace cache {
34 
37  public:
39  RdbColumnContainer(RocksDatabase& database, size_t columnId);
40 
41  public:
43  size_t size() const;
44 
46  void setSize(size_t newSize);
47 
50  template<typename TValue>
51  bool prop(const std::string& propertyName, TValue& value) const {
52  bool result = false;
53  load(propertyName, [&result, &value](const char* buffer) {
54  if (!buffer)
55  return;
56 
57  result = true;
58  value = reinterpret_cast<const TValue&>(*buffer);
59  });
60 
61  return result;
62  }
63 
65  template<typename TValue>
66  void setProp(const std::string& propertyName, const TValue& value) {
67  std::string strValue(sizeof(TValue), 0);
68  reinterpret_cast<TValue&>(strValue[0]) = value;
69  save(propertyName, strValue);
70  }
71 
74  return m_database;
75  }
76 
77  protected:
79  void find(const RawBuffer& key, RdbDataIterator& iterator) const;
80 
82  void insert(const RawBuffer& key, const std::string& value);
83 
85  void remove(const RawBuffer& key);
86 
88  size_t prune(uint64_t pruningBoundary);
89 
90  private:
91  void load(const std::string& propertyName, const consumer<const char*>& sink) const;
92 
93  void save(const std::string& propertyName, const std::string& strValue);
94 
95  private:
97  size_t m_columnId;
98  size_t m_size;
99  };
100 }}
catapult::cache::RdbDataIterator::End
static RdbDataIterator End()
Iterator representing no match.
Definition: RocksDatabase.cpp:52
catapult::cache::RdbColumnContainer::setSize
void setSize(size_t newSize)
Sets size of the column to newSize.
Definition: RdbColumnContainer.cpp:68
catapult::cache::RdbColumnContainer::prop
bool prop(const std::string &propertyName, TValue &value) const
Definition: RdbColumnContainer.h:51
exceptions.h
catapult::cache::RdbDataIterator::storage
rocksdb::PinnableSlice & storage() const
Returns storage associated with iterator.
Definition: RocksDatabase.cpp:64
RocksInclude.h
catapult::cache::RdbColumnContainer::prune
size_t prune(uint64_t pruningBoundary)
Prunes elements below pruningBoundary. Returns number of pruned elements.
Definition: RdbColumnContainer.cpp:85
catapult::cache::RdbColumnContainer::m_columnId
size_t m_columnId
Definition: RdbColumnContainer.h:97
catapult::cache::RdbColumnContainer::RdbColumnContainer
RdbColumnContainer(RocksDatabase &database, size_t columnId)
Creates an adapter around database and columnId.
Definition: RdbColumnContainer.cpp:38
functions.h
catapult::cache::RdbColumnContainer::setProp
void setProp(const std::string &propertyName, const TValue &value)
Sets property value of a column (propertyName) to value.
Definition: RdbColumnContainer.h:66
m_database
MongoDatabase m_database
Definition: MongoBlockStorage.cpp:242
catapult::cache::Special_Key_Max_Length
constexpr size_t Special_Key_Max_Length
Definition: RocksInclude.h:30
catapult::cache::RdbColumnContainer::database
RocksDatabase & database()
Returns underlying database.
Definition: RdbColumnContainer.h:73
catapult::cache::RdbColumnContainer::m_size
size_t m_size
Definition: RdbColumnContainer.h:98
catapult::cache::RdbDataIterator
Iterator adapter, allowing existence check on keys and data retrieval.
Definition: RocksDatabase.h:40
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
RdbColumnContainer.h
catapult::cache::RdbColumnContainer::remove
void remove(const RawBuffer &key)
Removes element with key.
Definition: RdbColumnContainer.cpp:81
catapult::cache::RocksDatabase
RocksDb-backed database.
Definition: RocksDatabase.h:116
catapult::cache::RdbColumnContainer::m_database
RocksDatabase & m_database
Definition: RdbColumnContainer.h:96
CATAPULT_THROW_INVALID_ARGUMENT_1
#define CATAPULT_THROW_INVALID_ARGUMENT_1(MESSAGE, PARAM1)
Macro used to throw a catapult invalid argument with a single parameter.
Definition: exceptions.h:183
catapult::cache::RdbColumnContainer::size
size_t size() const
Returns size of the column.
Definition: RdbColumnContainer.cpp:64
catapult::cache::RdbColumnContainer::save
void save(const std::string &propertyName, const std::string &strValue)
Definition: RdbColumnContainer.cpp:52
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::RdbColumnContainer
RocksDb-backed container adapter.
Definition: RdbColumnContainer.h:36
catapult::cache::RdbColumnContainer::load
void load(const std::string &propertyName, const consumer< const char * > &sink) const
Definition: RdbColumnContainer.cpp:57
catapult
Definition: AddressExtractionExtension.cpp:28
RocksDatabase.h
catapult::cache::RdbColumnContainer::find
void find(const RawBuffer &key, RdbDataIterator &iterator) const
Finds element with key, storing result in iterator.
Definition: RdbColumnContainer.cpp:73
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::RdbColumnContainer::insert
void insert(const RawBuffer &key, const std::string &value)
Inserts element with key and value.
Definition: RdbColumnContainer.cpp:77
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
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