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

@ -40,6 +40,9 @@ class RootCell : public Cell {
struct PrivateTag {};
public:
td::Status set_data_cell(Ref<DataCell> &&data_cell) const override {
return cell_->set_data_cell(std::move(data_cell));
}
td::Result<LoadedCell> load_cell() const override {
return cell_->load_cell();
}
@ -94,11 +97,11 @@ class DataCellCacheNoop {
class DataCellCacheMutex {
public:
Ref<DataCell> store(int idx, Ref<DataCell> cell) {
auto lock = cells_rw_mutex_.lock_write();
std::lock_guard lock(mutex_);
return cells_.emplace(idx, std::move(cell)).first->second;
}
Ref<DataCell> load(int idx) {
auto lock = cells_rw_mutex_.lock_read();
std::lock_guard lock(mutex_);
auto it = cells_.find(idx);
if (it != cells_.end()) {
return it->second;
@ -106,12 +109,13 @@ class DataCellCacheMutex {
return {};
}
void clear() {
auto guard = cells_rw_mutex_.lock_write();
std::lock_guard lock(mutex_);
cells_.clear();
}
private:
td::RwMutex cells_rw_mutex_;
std::mutex mutex_;
// NB: in case of high contention, one should use multiple buckets with per bucket mutexes
td::HashMap<int, Ref<DataCell>> cells_;
};
@ -246,7 +250,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
BagOfCells::Info info_;
std::mutex index_i_mutex_;
td::RwMutex index_data_rw_mutex_;
std::mutex index_mutex_;
std::string index_data_;
std::atomic<int> index_i_{0};
size_t index_offset_{0};
@ -319,7 +323,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
info_.index_offset + (td::int64)idx * info_.offset_byte_size));
offset_view = new_offset_view;
} else {
guard = index_data_rw_mutex_.lock_read().move_as_ok();
std::lock_guard guard(index_mutex_);
offset_view = td::Slice(index_data_).substr((td::int64)idx * info_.offset_byte_size, info_.offset_byte_size);
}
@ -432,7 +436,7 @@ class StaticBagOfCellsDbLazyImpl : public StaticBagOfCellsDb {
}
td::uint8 tmp[8];
info_.write_offset(tmp, index_offset_);
auto guard = index_data_rw_mutex_.lock_write();
std::lock_guard guard(index_mutex_);
index_data_.append(reinterpret_cast<const char*>(tmp), info_.offset_byte_size);
}
return td::Status::OK();