hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
flat_file.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_FLAT_FILE_HPP
7 #define IROHA_FLAT_FILE_HPP
8 
9 #include <memory>
10 #include <regex>
11 #include <set>
12 
14 #include "common/result_fwd.hpp"
15 #include "logger/logger_fwd.hpp"
16 
17 namespace iroha {
18  namespace ametsuchi {
19 
23  class FlatFile : public KeyValueStorage {
28  struct private_tag {};
29 
30  public:
31  // ----------| public API |----------
32 
33  using BlockIdCollectionType = std::set<Identifier>;
34 
35  static const uint32_t DIGIT_CAPACITY = 16;
36 
37  static const std::string kTempFileExtension;
38 
39  static const std::regex kBlockFilenameRegex;
40 
53  static std::string id_to_name(Identifier id);
54 
60  static boost::optional<Identifier> name_to_id(const std::string &name);
61 
69  create(const std::string &path, logger::LoggerPtr log);
70 
71  bool add(Identifier id, const Bytes &blob) override;
72 
73  boost::optional<Bytes> get(Identifier id) const override;
74 
75  std::string directory() const override;
76 
77  Identifier last_id() const override;
78 
79  void reload() override;
80 
81  void dropAll() override;
82 
87 
88  // ----------| modify operations |----------
89 
90  FlatFile(const FlatFile &rhs) = delete;
91 
92  FlatFile(FlatFile &&rhs) = delete;
93 
94  FlatFile &operator=(const FlatFile &rhs) = delete;
95 
96  FlatFile &operator=(FlatFile &&rhs) = delete;
97 
98  // ----------| private API |----------
99 
105  FlatFile(std::string path,
106  FlatFile::private_tag,
107  logger::LoggerPtr log);
108 
109  private:
113  const std::string dump_dir_;
114 
118  BlockIdCollectionType available_blocks_;
119 
120  logger::LoggerPtr log_;
121 
122  public:
123  ~FlatFile() = default;
124  };
125  } // namespace ametsuchi
126 } // namespace iroha
127 #endif // IROHA_FLAT_FILE_HPP
FlatFile(const FlatFile &rhs)=delete
static std::string id_to_name(Identifier id)
Definition: flat_file.cpp:39
Definition: block_query.hpp:17
Identifier last_id() const override
Definition: flat_file.cpp:148
uint32_t Identifier
Definition: key_value_storage.hpp:25
std::set< Identifier > BlockIdCollectionType
Definition: flat_file.hpp:33
static const std::string kTempFileExtension
Definition: flat_file.hpp:37
Definition: flat_file.hpp:23
Definition: result_fwd.hpp:27
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::vector< uint8_t > Bytes
Definition: key_value_storage.hpp:26
Definition: block_query.hpp:15
FlatFile & operator=(const FlatFile &rhs)=delete
static const std::regex kBlockFilenameRegex
Definition: flat_file.hpp:39
std::string directory() const override
Definition: flat_file.cpp:144
static boost::optional< Identifier > name_to_id(const std::string &name)
Definition: flat_file.cpp:45
static iroha::expected::Result< std::unique_ptr< FlatFile >, std::string > create(const std::string &path, logger::LoggerPtr log)
Definition: flat_file.cpp:58
const BlockIdCollectionType & blockIdentifiers() const
Definition: flat_file.cpp:175
void reload() override
Definition: flat_file.cpp:152
bool add(Identifier id, const Bytes &blob) override
Definition: flat_file.cpp:69
static const uint32_t DIGIT_CAPACITY
Definition: flat_file.hpp:35
void dropAll() override
Definition: flat_file.cpp:170
Definition: key_value_storage.hpp:20