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:
parent
1b70e48327
commit
c863c42ed1
32 changed files with 3276 additions and 318 deletions
|
@ -22,12 +22,22 @@
|
|||
#include <map>
|
||||
|
||||
namespace td {
|
||||
|
||||
struct Merger {
|
||||
virtual ~Merger() = default;
|
||||
virtual void merge_value_and_update(std::string &value, Slice update) = 0;
|
||||
virtual void merge_update_and_update(std::string &left_update, Slice right_update) = 0;
|
||||
};
|
||||
class MemoryKeyValue : public KeyValue {
|
||||
public:
|
||||
Result<GetStatus> get(Slice key, std::string &value) override;
|
||||
MemoryKeyValue() = default;
|
||||
MemoryKeyValue(std::shared_ptr<Merger> merger) : merger_(std::move(merger)) {
|
||||
}
|
||||
Result<GetStatus> get(Slice key, std::string& value) override;
|
||||
Status for_each(std::function<Status(Slice, Slice)> f) override;
|
||||
Status for_each_in_range(Slice begin, Slice end, std::function<Status(Slice, Slice)> f) override;
|
||||
Status set(Slice key, Slice value) override;
|
||||
Status merge(Slice key, Slice value) override;
|
||||
Status erase(Slice key) override;
|
||||
Result<size_t> count(Slice prefix) override;
|
||||
|
||||
|
@ -43,8 +53,30 @@ class MemoryKeyValue : public KeyValue {
|
|||
|
||||
std::string stats() const override;
|
||||
|
||||
UsageStats get_usage_stats() override {
|
||||
return usage_stats_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string, std::less<>> map_;
|
||||
static constexpr size_t buckets_n = 64;
|
||||
struct Bucket {
|
||||
std::mutex mutex;
|
||||
std::map<std::string, std::string, std::less<>> map;
|
||||
};
|
||||
struct Unlock {
|
||||
void operator()(Bucket* bucket) const {
|
||||
bucket->mutex.unlock();
|
||||
}
|
||||
};
|
||||
std::array<Bucket, buckets_n> buckets_{};
|
||||
int64 get_count_{0};
|
||||
UsageStats usage_stats_{};
|
||||
std::shared_ptr<Merger> merger_;
|
||||
|
||||
std::unique_ptr<Bucket, Unlock> lock(Bucket& bucket) {
|
||||
bucket.mutex.lock();
|
||||
return std::unique_ptr<Bucket, Unlock>(&bucket);
|
||||
}
|
||||
std::unique_ptr<Bucket, Unlock> lock(td::Slice key);
|
||||
};
|
||||
} // namespace td
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue