1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

celldb: version 2

- thread safe cache
- parallel commit
- multiple optimizations
- support of key-value merge operations
- improved tests and benchmarks
- in-memory version won't read from key value after start - uses vector in-memory table now
- use rocksdb::WALRecoveryMode::kTolerateCorruptedTailRecords - do not silently ignore errors during recovery
This commit is contained in:
birydrad 2024-12-11 14:48:48 +03:00
parent 1b70e48327
commit c863c42ed1
32 changed files with 3276 additions and 318 deletions

View file

@ -20,19 +20,51 @@
#include "td/utils/Status.h"
#include "td/utils/Time.h"
#include "td/utils/logging.h"
#include "td/utils/ThreadSafeCounter.h"
#include <functional>
namespace td {
struct UsageStats {
size_t get_count{};
size_t get_found_count{};
size_t get_not_found_count{};
size_t set_count{};
UsageStats operator+(const UsageStats& other) const {
return UsageStats{.get_count = get_count + other.get_count,
.get_found_count = get_found_count + other.get_found_count,
.get_not_found_count = get_not_found_count + other.get_not_found_count,
.set_count = set_count + other.set_count};
}
UsageStats operator-(const UsageStats& other) const {
return UsageStats{.get_count = get_count - other.get_count,
.get_found_count = get_found_count - other.get_found_count,
.get_not_found_count = get_not_found_count - other.get_not_found_count,
.set_count = set_count - other.set_count};
}
NamedStats to_named_stats() const {
NamedStats ns;
ns.stats_int["usage_get_count"] += get_count;
ns.stats_int["usage_get_found_count"] += get_found_count;
ns.stats_int["usage_get_not_found_count"] += get_not_found_count;
ns.stats_int["usage_set_count"] += set_count;
return ns;
}
};
inline td::StringBuilder& operator<<(td::StringBuilder& sb, const UsageStats& stats) {
sb << "get: " << stats.get_count << ", +" << stats.get_found_count << ", -" << stats.get_not_found_count;
return sb;
}
class KeyValueReader {
public:
virtual ~KeyValueReader() = default;
enum class GetStatus : int32 { Ok, NotFound };
virtual Result<GetStatus> get(Slice key, std::string &value) = 0;
virtual Result<GetStatus> get(Slice key, std::string& value) = 0;
virtual Result<size_t> count(Slice prefix) = 0;
virtual Status for_each(std::function<Status(Slice, Slice)> f) {
return Status::Error("for_each is not supported");
}
virtual Status for_each_in_range (Slice begin, Slice end, std::function<Status(Slice, Slice)> f) {
virtual Status for_each_in_range(Slice begin, Slice end, std::function<Status(Slice, Slice)> f) {
return td::Status::Error("foreach_range is not supported");
}
};
@ -42,7 +74,7 @@ class PrefixedKeyValueReader : public KeyValueReader {
PrefixedKeyValueReader(std::shared_ptr<KeyValueReader> reader, Slice prefix)
: reader_(std::move(reader)), prefix_(prefix.str()) {
}
Result<GetStatus> get(Slice key, std::string &value) override {
Result<GetStatus> get(Slice key, std::string& value) override {
return reader_->get(PSLICE() << prefix_ << key, value);
}
Result<size_t> count(Slice prefix) override {
@ -54,14 +86,16 @@ class PrefixedKeyValueReader : public KeyValueReader {
std::string prefix_;
};
class KeyValueUtils {
public:
};
class KeyValue : public KeyValueReader {
public:
virtual Status set(Slice key, Slice value) = 0;
virtual Status erase(Slice key) = 0;
virtual Status merge(Slice key, Slice value) {
return Status::Error("merge is not supported");
}
virtual Status run_gc() {
return Status::OK();
}
virtual Status begin_write_batch() = 0;
virtual Status commit_write_batch() = 0;
@ -80,12 +114,15 @@ class KeyValue : public KeyValueReader {
virtual Status flush() {
return Status::OK();
}
virtual UsageStats get_usage_stats() {
return {};
}
};
class PrefixedKeyValue : public KeyValue {
public:
PrefixedKeyValue(std::shared_ptr<KeyValue> kv, Slice prefix) : kv_(std::move(kv)), prefix_(prefix.str()) {
}
Result<GetStatus> get(Slice key, std::string &value) override {
Result<GetStatus> get(Slice key, std::string& value) override {
return kv_->get(PSLICE() << prefix_ << key, value);
}
Result<size_t> count(Slice prefix) override {