Skip to content

Commit

Permalink
Fixed bug in nano::rocksdb::store::clear() (#4304)
Browse files Browse the repository at this point in the history
Fixes rocksdb implementation of store::clear so it is atomic. Previously this was implemented by dropping the column family then re-adding it, however, this was not done atomically.

---------

Co-authored-by: Brandon <[email protected]>
  • Loading branch information
RickiNano and brandon-bb authored Oct 1, 2023
1 parent daf5b1e commit 30a6bc5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions nano/store/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,19 +697,19 @@ int nano::store::rocksdb::component::drop (store::write_transaction const & tran

int nano::store::rocksdb::component::clear (::rocksdb::ColumnFamilyHandle * column_family)
{
// Dropping completely removes the column
auto name = column_family->GetName ();
auto status = db->DropColumnFamily (column_family);
release_assert (status.ok ());
::rocksdb::ReadOptions read_options;
::rocksdb::WriteOptions write_options;
::rocksdb::WriteBatch write_batch;
std::unique_ptr<::rocksdb::Iterator> it (db->NewIterator (read_options, column_family));

// Need to add it back as we just want to clear the contents
auto handle_it = std::find_if (handles.begin (), handles.end (), [column_family] (auto & handle) {
return handle.get () == column_family;
});
debug_assert (handle_it != handles.cend ());
status = db->CreateColumnFamily (get_cf_options (name), name, &column_family);
for (it->SeekToFirst (); it->Valid (); it->Next ())
{
write_batch.Delete (column_family, it->key ());
}

::rocksdb::Status status = db->Write (write_options, &write_batch);
release_assert (status.ok ());
handle_it->reset (column_family);

return status.code ();
}

Expand Down

0 comments on commit 30a6bc5

Please sign in to comment.