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

@ -19,6 +19,7 @@
#pragma once
#include "port/thread.h"
#include "td/utils/common.h"
#include "td/utils/Slice.h"
#include "td/utils/StringBuilder.h"
@ -26,6 +27,7 @@
#include <array>
#include <atomic>
#include <map>
#include <mutex>
namespace td {
@ -69,6 +71,50 @@ class ThreadSafeCounter {
ThreadSafeMultiCounter<1> counter_;
};
struct NamedStats {
std::map<std::string, td::int64> stats_int;
std::map<std::string, std::string> stats_str;
NamedStats with_suffix(const std::string &suffix) const {
NamedStats res;
for (auto &p : stats_int) {
res.stats_int[p.first + suffix] = p.second;
}
for (auto &p : stats_str) {
res.stats_str[p.first + suffix] = p.second;
}
return res;
}
NamedStats with_prefix(const std::string &prefix) const {
NamedStats res;
for (auto &p : stats_int) {
res.stats_int[prefix + p.first] = p.second;
}
for (auto &p : stats_str) {
res.stats_str[prefix + p.first] = p.second;
}
return res;
}
void apply_diff(const NamedStats &other) {
for (auto &p : other.stats_int) {
stats_int[p.first] += p.second;
}
for (auto &p : other.stats_str) {
stats_str[p.first] = p.second;
}
}
void subtract_diff(const NamedStats &other) {
for (auto &p : other.stats_int) {
stats_int[p.first] -= p.second;
}
}
NamedStats combine_with(const NamedStats &other) const {
NamedStats res = *this;
res.apply_diff(other);
return res;
}
};
class NamedThreadSafeCounter {
static constexpr int N = 128;
using Counter = ThreadSafeMultiCounter<N>;
@ -79,6 +125,9 @@ class NamedThreadSafeCounter {
CounterRef() = default;
CounterRef(size_t index, Counter *counter) : index_(index), counter_(counter) {
}
void inc() {
add(1);
}
void add(int64 diff) {
counter_->add(index_, diff);
}
@ -119,6 +168,11 @@ class NamedThreadSafeCounter {
f(names_[i], counter_.sum(i));
}
}
NamedStats get_stats() const {
NamedStats res;
for_each([&](Slice name, int64 cnt) { res.stats_int.emplace(name.str(), cnt); });
return res;
}
void clear() {
std::unique_lock<std::mutex> guard(mutex_);
@ -181,11 +235,11 @@ struct NamedPerfCounter {
} // namespace td
#define TD_PERF_COUNTER(name) \
#define TD_PERF_COUNTER(name) \
static auto perf_##name = td::NamedPerfCounter::get_default().get_counter(td::Slice(#name)); \
auto scoped_perf_##name = td::NamedPerfCounter::ScopedPerfCounterRef{.perf_counter = perf_##name};
#define TD_PERF_COUNTER_SINCE(name, since) \
#define TD_PERF_COUNTER_SINCE(name, since) \
static auto perf_##name = td::NamedPerfCounter::get_default().get_counter(td::Slice(#name)); \
auto scoped_perf_##name = \
auto scoped_perf_##name = \
td::NamedPerfCounter::ScopedPerfCounterRef{.perf_counter = perf_##name, .started_at_ticks = since};