Ethereum  PoC-8
The C++ Implementation of Ethereum
RocksDB.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #pragma once
19 
20 #include "db.h"
21 
22 #include <boost/filesystem.hpp>
23 #include <rocksdb/db.h>
24 #include <rocksdb/write_batch.h>
25 
26 namespace dev
27 {
28 namespace db
29 {
30 class RocksDB : public DatabaseFace
31 {
32 public:
33  static rocksdb::ReadOptions defaultReadOptions();
34  static rocksdb::WriteOptions defaultWriteOptions();
35  static rocksdb::Options defaultDBOptions();
36 
37  explicit RocksDB(boost::filesystem::path const& _path,
38  rocksdb::ReadOptions _readOptions = defaultReadOptions(),
39  rocksdb::WriteOptions _writeOptions = defaultWriteOptions(),
40  rocksdb::Options _dbOptions = defaultDBOptions());
41 
42  std::string lookup(Slice _key) const override;
43  bool exists(Slice _key) const override;
44  void insert(Slice _key, Slice _value) override;
45  void kill(Slice _key) override;
46 
47  std::unique_ptr<WriteBatchFace> createWriteBatch() const override;
48  void commit(std::unique_ptr<WriteBatchFace> _batch) override;
49 
50  void forEach(std::function<bool(Slice, Slice)> f) const override;
51 
52 private:
53  std::unique_ptr<rocksdb::DB> m_db;
54  rocksdb::ReadOptions const m_readOptions;
55  rocksdb::WriteOptions const m_writeOptions;
56 };
57 
58 } // namespace db
59 } // namespace dev
dev::vector_ref
Definition: vector_ref.h:22
dev::db::RocksDB::defaultWriteOptions
static rocksdb::WriteOptions defaultWriteOptions()
Definition: RocksDB.cpp:103
dev::db::RocksDB
Definition: RocksDB.h:31
dev::db::RocksDB::forEach
void forEach(std::function< bool(Slice, Slice)> f) const override
Definition: RocksDB.cpp:188
dev::db::RocksDB::defaultDBOptions
static rocksdb::Options defaultDBOptions()
Definition: RocksDB.cpp:108
db.h
dev::db::RocksDB::RocksDB
RocksDB(boost::filesystem::path const &_path, rocksdb::ReadOptions _readOptions=defaultReadOptions(), rocksdb::WriteOptions _writeOptions=defaultWriteOptions(), rocksdb::Options _dbOptions=defaultDBOptions())
Definition: RocksDB.cpp:116
dev::db::RocksDB::defaultReadOptions
static rocksdb::ReadOptions defaultReadOptions()
Definition: RocksDB.cpp:98
dev::db::RocksDB::kill
void kill(Slice _key) override
Definition: RocksDB.cpp:163
dev::db::RocksDB::createWriteBatch
std::unique_ptr< WriteBatchFace > createWriteBatch() const override
Definition: RocksDB.cpp:170
dev::db::RocksDB::insert
void insert(Slice _key, Slice _value) override
Definition: RocksDB.cpp:155
dev::db::RocksDB::lookup
std::string lookup(Slice _key) const override
Definition: RocksDB.cpp:128
dev::db::DatabaseFace
Definition: db.h:55
dev::db::RocksDB::commit
void commit(std::unique_ptr< WriteBatchFace > _batch) override
Definition: RocksDB.cpp:175
dev
Definition: Address.cpp:21
dev::db::RocksDB::exists
bool exists(Slice _key) const override
Definition: RocksDB.cpp:140