-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Properly set smallest key of subcompaction output #4723
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0b5049
Properly set smallest key of subcompaction output
abhimadan f410a11
Fix compile error in release builds
abhimadan 7a6a66e
Don't decode an empty ikey
abhimadan 3ea12bb
Do faster sanity check on file bound
abhimadan a6f1339
Fix comment, set assertion seqnum
abhimadan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1192,10 +1192,12 @@ Status CompactionJob::FinishCompactionOutputFile( | |
Slice lower_bound_guard, upper_bound_guard; | ||
std::string smallest_user_key; | ||
const Slice *lower_bound, *upper_bound; | ||
bool lower_bound_from_sub_compact = false; | ||
if (sub_compact->outputs.size() == 1) { | ||
// For the first output table, include range tombstones before the min key | ||
// but after the subcompaction boundary. | ||
lower_bound = sub_compact->start; | ||
lower_bound_from_sub_compact = true; | ||
} else if (meta->smallest.size() > 0) { | ||
// For subsequent output tables, only include range tombstones from min | ||
// key onwards since the previous file was extended to contain range | ||
|
@@ -1265,11 +1267,22 @@ Status CompactionJob::FinishCompactionOutputFile( | |
// (the max key in the previous table or subcompaction) in order for | ||
// files to appear key-space partitioned. | ||
// | ||
// Choose lowest seqnum so this file's smallest internal key comes | ||
// after the previous file's/subcompaction's largest. The fake seqnum | ||
// is OK because the read path's file-picking code only considers user | ||
// key. | ||
smallest_candidate = InternalKey(*lower_bound, 0, kTypeRangeDeletion); | ||
// When lower_bound is chosen by a subcompaction, we know that | ||
// subcompactions over smaller keys cannot contain any keys at | ||
// lower_bound. We also know that smaller subcompactions exist, because | ||
// otherwise the subcompaction woud be unbounded on the left. As a | ||
// result, we know that no other files on the output level will contain | ||
// keys at lower_bound. Therefore, it is safe to use the tombstone's | ||
// sequence number, to ensure that keys at lower_bound at lower levels | ||
// are covered by truncated tombstones. | ||
// | ||
// If lower_bound was chosen by the smallest data key in the file, | ||
// choose lowest seqnum so this file's smallest internal key comes after | ||
// the previous file's largest. The fake seqnum is OK because the read | ||
// path's file-picking code only considers user key. | ||
smallest_candidate = InternalKey( | ||
*lower_bound, lower_bound_from_sub_compact ? tombstone.seq_ : 0, | ||
kTypeRangeDeletion); | ||
} | ||
InternalKey largest_candidate = tombstone.SerializeEndKey(); | ||
if (upper_bound != nullptr && | ||
|
@@ -1291,9 +1304,23 @@ Status CompactionJob::FinishCompactionOutputFile( | |
largest_candidate = | ||
InternalKey(*upper_bound, kMaxSequenceNumber, kTypeRangeDeletion); | ||
} | ||
#ifndef NDEBUG | ||
SequenceNumber smallest_ikey_seqnum = kMaxSequenceNumber; | ||
if (meta->smallest.size() > 0) { | ||
GetInternalKeySeqno(meta->smallest.Encode()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops forgot to assign the result to |
||
} | ||
#endif | ||
meta->UpdateBoundariesForRange(smallest_candidate, largest_candidate, | ||
tombstone.seq_, | ||
cfd->internal_comparator()); | ||
|
||
// The smallest key in a file is used for range tombstone truncation, so | ||
// it cannot have a seqnum of 0 (unless the smallest data key in a file | ||
// has a seqnum of 0). Otherwise, the truncated tombstone may expose | ||
// deleted keys at lower levels. | ||
assert(smallest_ikey_seqnum == 0 || | ||
ExtractInternalKeyFooter(meta->smallest.Encode()) != | ||
PackSequenceAndType(0, kTypeRangeDeletion)); | ||
} | ||
meta->marked_for_compaction = sub_compact->builder->NeedCompact(); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible though that another output level file's end key is at lower_bound with kMaxSeqnum, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, that's definitely possible. I'll adjust this to say that "real" keys can't be at lower_bound in other output files.