From cd77d3c5588e4c9fbd6282feaa2358ec1e150326 Mon Sep 17 00:00:00 2001 From: Mike Kolupaev Date: Wed, 24 Apr 2019 17:07:31 -0700 Subject: [PATCH] Don't call FindObsoleteFiles() in ~ColumnFamilyHandleImpl() if CF is not dropped (#5238) Summary: We have a DB with ~4k column families and ~70k files. On shutdown, destroying the 4k ColumnFamilyHandle-s takes over 2 minutes. Most of this time is spent in VersionSet::AddLiveFiles() called from FindObsoleteFiles() from ~ColumnFamilyHandleImpl(). It's just iterating over the list of files in memory. This seems completely unnecessary as no obsolete files are actually found since the CFs are not even dropped. This PR fixes that. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5238 Differential Revision: D15056342 Pulled By: siying fbshipit-source-id: 2aa342ef3770b4aa384ce81f8768e485480e4f08 --- db/column_family.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/column_family.cc b/db/column_family.cc index da4cc7311..4592c945f 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -63,9 +63,14 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() { JobContext job_context(0); mutex_->Lock(); if (cfd_->Unref()) { + bool dropped = cfd_->IsDropped(); + delete cfd_; + + if (dropped) { + db_->FindObsoleteFiles(&job_context, false, true); + } } - db_->FindObsoleteFiles(&job_context, false, true); mutex_->Unlock(); if (job_context.HaveSomethingToDelete()) { bool defer_purge =