Skip to content

Commit

Permalink
rocksdb related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dungeon-master-666 committed Aug 18, 2024
1 parent e344339 commit eab0813
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ if (TON_USE_ROCKSDB)
set(WITH_TOOLS OFF CACHE BOOL "build with tools")
set(FAIL_ON_WARNINGS OFF CACHE BOOL "fail on warnings")
message("Add rocksdb")
if (TON_USE_JEMALLOC)
set(WITH_JEMALLOC ON CACHE BOOL "build with jemalloc")
endif()
add_subdirectory(third-party/rocksdb EXCLUDE_FROM_ALL)
endif()

Expand Down
5 changes: 2 additions & 3 deletions tddb/td/db/RocksDbReadOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ RocksDbReadOnly RocksDbReadOnly::clone() const {
}

Result<RocksDbReadOnly> RocksDbReadOnly::open(std::string path, RocksDbOptions options) {
rocksdb::DB *db;
auto statistics = rocksdb::CreateDBStatistics();
rocksdb::DB *db;
{
rocksdb::Options db_options;

Expand All @@ -76,7 +75,7 @@ rocksdb::DB *db;
db_options.bytes_per_sync = 1 << 20;
db_options.writable_file_max_buffer_size = 2 << 14;
db_options.keep_log_file_num = 1;
db_options.statistics = statistics;
db_options.statistics = options.statistics;
rocksdb::ColumnFamilyOptions cf_options(db_options);
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, cf_options));
Expand Down
4 changes: 2 additions & 2 deletions tddb/td/db/RocksDbSecondary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Result<RocksDbSecondary> RocksDbSecondary::open(std::string path, RocksDbOptions

rocksdb::BlockBasedTableOptions table_options;
// commenting this line because in recent rocksdb version it leads to NotFound error (file not in archive slice)
// table_options.block_cache = cache;
// table_options.block_cache = options.block_cache;
db_options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));

db_options.manual_wal_flush = true;
Expand All @@ -77,7 +77,7 @@ Result<RocksDbSecondary> RocksDbSecondary::open(std::string path, RocksDbOptions
db_options.bytes_per_sync = 1 << 20;
db_options.writable_file_max_buffer_size = 2 << 14;
db_options.keep_log_file_num = 1;
db_options.statistics = statistics;
db_options.statistics = options.statistics;
rocksdb::ColumnFamilyOptions cf_options(db_options);
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
column_families.push_back(rocksdb::ColumnFamilyDescriptor(rocksdb::kDefaultColumnFamilyName, cf_options));
Expand Down
6 changes: 5 additions & 1 deletion validator/db/archive-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,11 @@ td::Status ArchiveManager::catch_up_package(const PackageId& id) {
if (it->second.first_blocks != first_blocks || it->second.deleted != x->deleted_) {
FileDescription desc{id, x->deleted_};
desc.first_blocks = std::move(first_blocks);
desc.file = std::move(it->second.file);
if (x->deleted_) {
it->second.file.release();
} else {
desc.file = std::move(it->second.file);
}
map.erase(it);
map.emplace(id, std::move(desc));
}
Expand Down
24 changes: 13 additions & 11 deletions validator/db/archive-slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,32 +837,34 @@ void destroy_db(std::string name, td::uint32 attempt, td::Promise<td::Unit> prom
LOG(DEBUG) << "failed to destroy index " << name << ": " << S;
}
delay_action(
[name, attempt, promise = std::move(promise)]() mutable { destroy_db(name, attempt, std::move(promise)); },
[name, attempt, promise = std::move(promise)]() mutable { destroy_db(name, attempt + 1, std::move(promise)); },
td::Timestamp::in(1.0));
}
} // namespace

void ArchiveSlice::destroy(td::Promise<td::Unit> promise) {
before_query();
td::MultiPromise mp;
auto ig = mp.init_guard();
ig.add_promise(std::move(promise));
destroyed_ = true;

for (auto &p : packages_) {
td::unlink(p.path).ensure();
if (mode_ == td::DbOpenMode::db_primary) {
for (auto &p : packages_) {
td::unlink(p.path).ensure();
}
}

if (statistics_.pack_statistics) {
statistics_.pack_statistics->record_close(packages_.size());
}
packages_.clear();
kv_ = nullptr;

PackageId p_id{archive_id_, key_blocks_only_, temp_};
std::string db_path = PSTRING() << db_root_ << p_id.path() << p_id.name() << ".index";
delay_action([name = db_path, attempt = 0,
promise = ig.get_promise()]() mutable { destroy_db(name, attempt, std::move(promise)); },
td::Timestamp::in(0.0));
if (mode_ == td::DbOpenMode::db_primary) {
delay_action([name = db_path_, attempt = 0,
promise = std::move(promise)]() mutable { destroy_db(name, attempt, std::move(promise)); },
td::Timestamp::in(0.0));
} else {
promise.set_value(td::Unit());
}
}

BlockSeqno ArchiveSlice::max_masterchain_seqno() {
Expand Down

0 comments on commit eab0813

Please sign in to comment.