Skip to content

Commit

Permalink
dont create backup_input if compaction filter v2 is not used
Browse files Browse the repository at this point in the history
Summary:
Compaction creates backup_input iterator even though it only needed
when compaction filter v2 is enabled

Test Plan: make all check

Reviewers: sdong, yhchiang, igor

Reviewed By: igor

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D23769
  • Loading branch information
Lei Jin committed Sep 22, 2014
1 parent 49b5f94 commit 5e6aee4
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3117,9 +3117,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
const uint64_t start_micros = env_->NowMicros();
unique_ptr<Iterator> input(versions_->MakeInputIterator(compact->compaction));
input->SeekToFirst();
shared_ptr<Iterator> backup_input(
versions_->MakeInputIterator(compact->compaction));
backup_input->SeekToFirst();

Status status;
ParsedInternalKey ikey;
Expand All @@ -3132,14 +3129,30 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
auto compaction_filter_v2 =
compaction_filter_from_factory_v2.get();

// temp_backup_input always point to the start of the current buffer
// temp_backup_input = backup_input;
// iterate through input,
// 1) buffer ineligible keys and value keys into 2 separate buffers;
// 2) send value_buffer to compaction filter and alternate the values;
// 3) merge value_buffer with ineligible_value_buffer;
// 4) run the modified "compaction" using the old for loop.
if (compaction_filter_v2) {
if (!compaction_filter_v2) {
status = ProcessKeyValueCompaction(
is_snapshot_supported,
visible_at_tip,
earliest_snapshot,
latest_snapshot,
deletion_state,
bottommost_level,
imm_micros,
input.get(),
compact,
false,
log_buffer);
} else {
// temp_backup_input always point to the start of the current buffer
// temp_backup_input = backup_input;
// iterate through input,
// 1) buffer ineligible keys and value keys into 2 separate buffers;
// 2) send value_buffer to compaction filter and alternate the values;
// 3) merge value_buffer with ineligible_value_buffer;
// 4) run the modified "compaction" using the old for loop.
shared_ptr<Iterator> backup_input(
versions_->MakeInputIterator(compact->compaction));
backup_input->SeekToFirst();
while (backup_input->Valid() && !shutting_down_.Acquire_Load() &&
!cfd->IsDropped()) {
// FLUSH preempts compaction
Expand Down Expand Up @@ -3267,21 +3280,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
log_buffer);
} // checking for compaction filter v2

if (!compaction_filter_v2) {
status = ProcessKeyValueCompaction(
is_snapshot_supported,
visible_at_tip,
earliest_snapshot,
latest_snapshot,
deletion_state,
bottommost_level,
imm_micros,
input.get(),
compact,
false,
log_buffer);
}

if (status.ok() && (shutting_down_.Acquire_Load() || cfd->IsDropped())) {
status = Status::ShutdownInProgress(
"Database shutdown or Column family drop during compaction");
Expand Down

0 comments on commit 5e6aee4

Please sign in to comment.