From e21d5b8bbc9c5ef05caf740bd69366602953e591 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Tue, 4 Mar 2014 17:16:40 -0800 Subject: [PATCH] [CF] Flush all memtables on column family drop Summary: When column family is dropped, we want to delete all WALs that refer to it. To do that, we need to make them obsolete by flushing all the memtables Test Plan: column_family_test Reviewers: dhruba, haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D16557 --- db/db_impl.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 61753493c..d0ae32bcc 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3155,17 +3155,23 @@ Status DBImpl::DropColumnFamily(ColumnFamilyHandle* column_family) { edit.DropColumnFamily(); edit.SetColumnFamily(cfd->GetID()); - MutexLock l(&mutex_); Status s; - if (cfd->IsDropped()) { - s = Status::InvalidArgument("Column family already dropped!\n"); - } - if (s.ok()) { - s = versions_->LogAndApply(cfd, &edit, &mutex_); + { + MutexLock l(&mutex_); + if (cfd->IsDropped()) { + s = Status::InvalidArgument("Column family already dropped!\n"); + } + if (s.ok()) { + s = versions_->LogAndApply(cfd, &edit, &mutex_); + } } if (s.ok()) { Log(options_.info_log, "Dropped column family with id %u\n", cfd->GetID()); + // Flush the memtables. This will make all WAL files referencing dropped + // column family to be obsolete. They will be deleted when user deletes + // column family handle + Write(WriteOptions(), nullptr); // ignore error } else { Log(options_.info_log, "Dropping column family with id %u FAILED -- %s\n", cfd->GetID(), s.ToString().c_str());