Kagome
Polkadot Runtime Engine in C++17
rocksdb_util.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_ROCKSDB_UTIL_HPP
7 #define KAGOME_ROCKSDB_UTIL_HPP
8 
9 #include <rocksdb/status.h>
10 #include "common/buffer.hpp"
12 
13 namespace kagome::storage {
14  inline DatabaseError status_as_error(const rocksdb::Status &s) {
15  if (s.IsNotFound()) {
17  }
18 
19  if (s.IsIOError()) {
20  static log::Logger log = log::createLogger("RocksDb", "storage");
21  SL_ERROR(log, ":{}", s.ToString());
23  }
24 
25  if (s.IsInvalidArgument()) {
27  }
28 
29  if (s.IsCorruption()) {
31  }
32 
33  if (s.IsNotSupported()) {
35  }
36 
38  }
39 
40  inline rocksdb::Slice make_slice(const common::BufferView &buf) {
41  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
42  const auto *ptr = reinterpret_cast<const char *>(buf.data());
43  size_t n = buf.size();
44  return rocksdb::Slice{ptr, n};
45  }
46 
47  inline gsl::span<const uint8_t> make_span(const rocksdb::Slice &s) {
48  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
49  const auto *ptr = reinterpret_cast<const uint8_t *>(s.data());
50  return gsl::make_span(ptr, s.size());
51  }
52 
53  inline common::Buffer make_buffer(const rocksdb::Slice &s) {
54  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
55  const auto *ptr = reinterpret_cast<const uint8_t *>(s.data());
56  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
57  return common::Buffer{ptr, ptr + s.size()};
58  }
59 } // namespace kagome::storage
60 
61 #endif // KAGOME_ROCKSDB_UTIL_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
DatabaseError
universal database interface error
DatabaseError status_as_error(const rocksdb::Status &s)
gsl::span< const uint8_t > make_span(const rocksdb::Slice &s)
rocksdb::Slice make_slice(const common::BufferView &buf)
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
common::Buffer make_buffer(const rocksdb::Slice &s)
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112