From de9df6e818774998c50e715c73736531ea42ad44 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Wed, 30 Mar 2022 20:48:23 -0700 Subject: [PATCH] Do not release and re-acquire dbmutex on memtable-switch if no listener (#9758) Summary: There is no need to release-and-acquire immediately when no listener is registered. This is what we have been doing for `NotifyOnFlushBegin()`, `NotifyOnFlushCompleted()`, `NotifyOnCompactionBegin()`, `NotifyOnCompactionCompleted()`, and some other `NotifyOnXX` methods in event_helpers.cc. Do the same for `NotifyOnMemTableSealed ()`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9758 Test Plan: make check Reviewed By: jay-zhuang Differential Revision: D35159552 Pulled By: riversand963 fbshipit-source-id: 6e0aac50bd5c8f506d809b6638c33a7a28d1e87f --- db/db_impl/db_impl_write.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index 6aaff802d..39657d462 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -1882,9 +1882,11 @@ void DBImpl::NotifyOnMemTableSealed(ColumnFamilyData* /*cfd*/, return; } + mutex_.Unlock(); for (auto listener : immutable_db_options_.listeners) { listener->OnMemTableSealed(mem_table_info); } + mutex_.Lock(); } #endif // ROCKSDB_LITE @@ -2085,11 +2087,9 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) { mutable_cf_options); #ifndef ROCKSDB_LITE - mutex_.Unlock(); // Notify client that memtable is sealed, now that we have successfully // installed a new memtable NotifyOnMemTableSealed(cfd, memtable_info); - mutex_.Lock(); #endif // ROCKSDB_LITE // It is possible that we got here without checking the value of i_os, but // that is okay. If we did, it most likely means that s was already an error.