From fbff4628a96c1431ce2b20e24850aeb8aeb9580e Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Fri, 16 Dec 2016 17:31:15 -0800 Subject: [PATCH] Reduce compaction iterator status checks Summary: seems it's expensive to check status since the underlying merge iterator checks status of all its children. so only do it when it's really necessary to get the status before invoking Next(), i.e., when we're advancing to get the first key in the next file. Closes https://github.com/facebook/rocksdb/pull/1691 Differential Revision: D4343446 Pulled By: siying fbshipit-source-id: 70ab315 --- db/compaction_job.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/compaction_job.cc b/db/compaction_job.cc index 8604f21f9..4e3a5ecbb 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -853,9 +853,6 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { } } - Status input_status = input->status(); - c_iter->Next(); - // Close output file if it is big enough // TODO(aekmekji): determine if file should be closed earlier than this // during subcompactions (i.e. if output size, estimated by input size, is @@ -864,6 +861,9 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { if (sub_compact->compaction->output_level() != 0 && sub_compact->current_output_file_size >= sub_compact->compaction->max_output_file_size()) { + Status input_status = input->status(); + c_iter->Next(); + const Slice* next_key = nullptr; if (c_iter->Valid()) { next_key = &c_iter->key(); @@ -879,6 +879,8 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { // files. sub_compact->compression_dict = std::move(compression_dict); } + } else { + c_iter->Next(); } }