From 2f712235ab48783af5d85e65e2fb43448d61859f Mon Sep 17 00:00:00 2001 From: shuzz Date: Wed, 19 Jul 2023 12:52:39 -0700 Subject: [PATCH] optimized code (#11614) Summary: improvement code by std::move and c++17 Pull Request resolved: https://github.com/facebook/rocksdb/pull/11614 Reviewed By: ajkr Differential Revision: D47599519 Pulled By: jowlyzhang fbshipit-source-id: 6b897876f4e87e94a74c53d8db2a01303d500bff --- db/db_impl/db_impl_compaction_flush.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index 8274dd587..c64d4ecdb 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -852,8 +852,8 @@ void DBImpl::NotifyOnFlushBegin(ColumnFamilyData* cfd, FileMetaData* file_meta, } } mutex_.Lock(); -// no need to signal bg_cv_ as it will be signaled at the end of the -// flush process. + // no need to signal bg_cv_ as it will be signaled at the end of the + // flush process. } void DBImpl::NotifyOnFlushCompleted( @@ -2775,7 +2775,7 @@ ColumnFamilyData* DBImpl::PopFirstFromCompactionQueue() { DBImpl::FlushRequest DBImpl::PopFirstFromFlushQueue() { assert(!flush_queue_.empty()); - FlushRequest flush_req = flush_queue_.front(); + FlushRequest flush_req = std::move(flush_queue_.front()); flush_queue_.pop_front(); if (!immutable_db_options_.atomic_flush) { assert(flush_req.cfd_to_max_mem_id_to_persist.size() == 1); @@ -2970,14 +2970,12 @@ Status DBImpl::BackgroundFlush(bool* made_progress, JobContext* job_context, autovector column_families_not_to_flush; while (!flush_queue_.empty()) { // This cfd is already referenced - const FlushRequest& flush_req = PopFirstFromFlushQueue(); - FlushReason flush_reason = flush_req.flush_reason; + auto [flush_reason, cfd_to_max_mem_id_to_persist] = + PopFirstFromFlushQueue(); superversion_contexts.clear(); - superversion_contexts.reserve( - flush_req.cfd_to_max_mem_id_to_persist.size()); + superversion_contexts.reserve(cfd_to_max_mem_id_to_persist.size()); - for (const auto& iter : flush_req.cfd_to_max_mem_id_to_persist) { - ColumnFamilyData* cfd = iter.first; + for (const auto& [cfd, max_memtable_id] : cfd_to_max_mem_id_to_persist) { if (cfd->GetMempurgeUsed()) { // If imm() contains silent memtables (e.g.: because // MemPurge was activated), requesting a flush will @@ -2991,7 +2989,7 @@ Status DBImpl::BackgroundFlush(bool* made_progress, JobContext* job_context, continue; } superversion_contexts.emplace_back(SuperVersionContext(true)); - bg_flush_args.emplace_back(cfd, iter.second, + bg_flush_args.emplace_back(cfd, max_memtable_id, &(superversion_contexts.back()), flush_reason); } if (!bg_flush_args.empty()) {