Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate compaction output at user key boundary #375

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -926,16 +926,10 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
}

Slice key = input->key();
if (compact->compaction->ShouldStopBefore(key) &&
compact->builder != NULL) {
status = FinishCompactionOutputFile(compact, input);
if (!status.ok()) {
break;
}
}

// Handle key/value, add to state, etc.
bool drop = false;
bool first_occurrence = false;
if (!ParseInternalKey(key, &ikey)) {
// Do not hide error keys
current_user_key.clear();
Expand All @@ -947,6 +941,8 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
Slice(current_user_key)) != 0) {
// First occurrence of this user key
current_user_key.assign(ikey.user_key.data(), ikey.user_key.size());
// Don't rotate at this key if last key is an error key.
first_occurrence = last_sequence_for_key != kMaxSequenceNumber;
has_current_user_key = true;
last_sequence_for_key = kMaxSequenceNumber;
}
Expand Down Expand Up @@ -980,6 +976,19 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
#endif

if (!drop) {
// Close output file if it is overlapping too much grandparents
// or big enough. We never put keys with same user key to
// different files in same level in level compaction.
if (compact->builder != NULL && first_occurrence &&
(compact->compaction->ShouldStopBefore(key) ||
compact->builder->FileSize() >=
compact->compaction->MaxOutputFileSize())) {
status = FinishCompactionOutputFile(compact, input);
if (!status.ok()) {
break;
}
}

// Open output file if necessary
if (compact->builder == NULL) {
status = OpenCompactionOutputFile(compact);
Expand All @@ -992,15 +1001,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
}
compact->current_output()->largest.DecodeFrom(key);
compact->builder->Add(key, input->value());

// Close output file if it is big enough
if (compact->builder->FileSize() >=
compact->compaction->MaxOutputFileSize()) {
status = FinishCompactionOutputFile(compact, input);
if (!status.ok()) {
break;
}
}
}

input->Next();
Expand Down