Skip to content

Commit

Permalink
clang tidy deleters fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ErakhtinB committed Nov 14, 2024
1 parent 4421182 commit 23f96df
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions core/storage/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,28 @@ namespace kagome::storage {
status.ToString());
return status_as_error(status);
}
auto defer_db = std::shared_ptr<int>(
new int, [&db, &column_family_handles, &log](int *) mutable {
auto status = db->Flush(rocksdb::FlushOptions());
if (!status.ok()) {
SL_ERROR(log, "Can't flush database: {}", status.ToString());
}
status = db->WaitForCompact(rocksdb::WaitForCompactOptions());
if (!status.ok()) {
SL_ERROR(log,
"Can't wait for background compaction: {}",
status.ToString());
}
for (auto *handle : column_family_handles) {
db->DestroyColumnFamilyHandle(handle);
}
status = db->Close();
if (!status.ok()) {
SL_ERROR(log, "Can't close database: {}", status.ToString());
}
db.reset();
});

auto cleanup = [&db, &column_family_handles, &log](int *i) {
auto status = db->Flush(rocksdb::FlushOptions());
if (not status.ok()) {
SL_ERROR(log, "Can't flush database: {}", status.ToString());
}
status = db->WaitForCompact(rocksdb::WaitForCompactOptions());
if (not status.ok()) {
SL_ERROR(
log, "Can't wait for background compaction: {}", status.ToString());
}
for (auto *handle : column_family_handles) {
db->DestroyColumnFamilyHandle(handle);
}
status = db->Close();
if (not status.ok()) {
SL_ERROR(log, "Can't close database: {}", status.ToString());
}
db.reset();
delete i;
};

std::unique_ptr<int, decltype(cleanup)> defer_db(new int, cleanup);
rocksdb::DBWithTTL *db_with_ttl_raw = nullptr;
std::vector<ColumnFamilyHandlePtr> column_family_handles_with_ttl;
const auto ttl_path = path.parent_path() / "db_ttl";
Expand All @@ -254,29 +253,30 @@ namespace kagome::storage {
return status_as_error(status);
}
std::unique_ptr<rocksdb::DBWithTTL> db_with_ttl(db_with_ttl_raw);
const auto ttl_cleanup = [&db_with_ttl,
&column_family_handles_with_ttl,
&log](int *i) {
auto status = db_with_ttl->Flush(rocksdb::FlushOptions());
if (not status.ok()) {
SL_ERROR(log, "Can't flush ttl database: {}", status.ToString());
}
status = db_with_ttl->WaitForCompact(rocksdb::WaitForCompactOptions());
if (not status.ok()) {
SL_ERROR(
log, "Can't wait for background compaction: {}", status.ToString());
}
for (auto *handle : column_family_handles_with_ttl) {
db_with_ttl->DestroyColumnFamilyHandle(handle);
}
status = db_with_ttl->Close();
if (not status.ok()) {
SL_ERROR(log, "Can't close ttl database: {}", status.ToString());
}
db_with_ttl.reset();
delete i;
};
std::unique_ptr<int, decltype(ttl_cleanup)> defer_ttl(new int, ttl_cleanup);
auto defer_ttl = std::shared_ptr<int>(
new int,
[&db_with_ttl, &column_family_handles_with_ttl, &log](int *) mutable {
auto status = db_with_ttl->Flush(rocksdb::FlushOptions());
if (!status.ok()) {
SL_ERROR(log, "Can't flush ttl database: {}", status.ToString());
}
status =
db_with_ttl->WaitForCompact(rocksdb::WaitForCompactOptions());
if (!status.ok()) {
SL_ERROR(log,
"Can't wait for background compaction: {}",
status.ToString());
}
for (auto *handle : column_family_handles_with_ttl) {
db_with_ttl->DestroyColumnFamilyHandle(handle);
}
status = db_with_ttl->Close();
if (!status.ok()) {
SL_ERROR(log, "Can't close ttl database: {}", status.ToString());
}
db_with_ttl.reset();
});

for (std::size_t i = 0; i < column_family_handles.size(); ++i) {
const auto from_handle = column_family_handles[i];
auto to_handle = column_family_handles_with_ttl[i];
Expand Down

0 comments on commit 23f96df

Please sign in to comment.