From c6655551acbf7f5740eb3d71043e959fe7f18473 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 6 Sep 2023 12:28:36 +0100 Subject: [PATCH] fixed bug in store::clear() - builds batch of delete operations to be applied to the column family --- nano/node/rocksdb/rocksdb.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/nano/node/rocksdb/rocksdb.cpp b/nano/node/rocksdb/rocksdb.cpp index 7beac09aa4..bf3591964a 100644 --- a/nano/node/rocksdb/rocksdb.cpp +++ b/nano/node/rocksdb/rocksdb.cpp @@ -722,20 +722,20 @@ int nano::rocksdb::store::drop (nano::write_transaction const & transaction_a, t int nano::rocksdb::store::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 ()); - - // 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); - release_assert (status.ok ()); - handle_it->reset (column_family); - return status.code (); + ::rocksdb::ReadOptions read_options; + ::rocksdb::WriteOptions write_options; + ::rocksdb::WriteBatch write_batch; + std::unique_ptr<::rocksdb::Iterator> it(db->NewIterator(read_options, 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()); + + return status.code(); } void nano::rocksdb::store::construct_column_family_mutexes ()