github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/fs/rocksdb_storage.h (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 #pragma once 21 22 #include "common/address.h" 23 #include "common/common.h" 24 #include "fs/storage.h" 25 #include <rocksdb/db.h> 26 #include <rocksdb/write_batch.h> 27 28 namespace neb { 29 namespace fs { 30 31 class rocksdb_storage : public storage { 32 public: 33 rocksdb_storage(); 34 ~rocksdb_storage(); 35 rocksdb_storage(const rocksdb_storage &rs) = delete; 36 rocksdb_storage &operator=(const rocksdb_storage &) = delete; 37 38 void open_database(const std::string &db_name, storage_open_flag flag); 39 void close_database(); 40 41 virtual bytes get_bytes(const bytes &key); 42 virtual void put_bytes(const bytes &key, const bytes &val); 43 virtual void del_by_bytes(const bytes &key); 44 45 virtual void enable_batch(); 46 virtual void disable_batch(); 47 virtual void flush(); 48 49 virtual void display(const std::function<void(rocksdb::Iterator *)> &cb); 50 51 private: 52 std::unique_ptr<rocksdb::DB> m_db; 53 bool m_enable_batch; 54 typedef std::function<void(rocksdb::WriteBatch &wb)> batch_operation_t; 55 std::vector<batch_operation_t> m_batched_ops; 56 }; // end class rocksdb_storage 57 } // end namespace fs 58 } // end namespace neb 59