-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Avoid double-compacting data in bottom level in manual compactions #5138
Avoid double-compacting data in bottom level in manual compactions #5138
Conversation
Hey @ajkr , do you mind taking a quick look to see if this approach makes sense? Thanks! |
Thanks for doing this, will take a look. BTW, do you mind reminding me what @yoshinorim's reason was for only operating on the bottom level? I remember he wrote some insightful reason on the task. |
Never mind, I think it makes sense. We wouldn't want to skip files in middle levels because the latest data for the range (as of the time |
db/compaction_picker.cc
Outdated
if (inputs_shrinked.empty()) { | ||
return nullptr; | ||
} | ||
inputs.files.swap(inputs_shrinked); |
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.
Is it a problem that the files may not cover a contiguous key-range after this code filters some out?
I wonder if we should pick each compaction consisting of one contiguous range of files that all need to be compacted. We can then set compaction_end
to the end of that range and another call will be made for the next contiguous range, etc.
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.
Hm, it looks like the following ExpandInputsToCleanCut
refills any holes if we pick non-contiguous files here. It seems safe, but OTOH some cases may be suboptimal. For example, the first and last file might be the only ones that need compaction (i.e., inputs_shrinked
contains only those two). But then ExpandInputsToCleanCut
will repopulate the input files with everything in the range, which leaves us with no files skipped.
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.
Thanks @ajkr !
let me see if I understood the idea correctly:
so in CompactionPicker::CompactRange
, after the call to ExpandInputsToCleanCut
and SetupOtherInputs
, we will still filter out new files larger than max_sst_file_number
, then maybe call a new function to break up inputs_shrinked
into continuous ranges of files, and for each range, call SetupOtherInputs
and then create/register one new Compaction?
This will create a number of Compaction
objects but the caller DBImpl::RunManualCompaction
seems to expect only one Compaction
?
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.
I guess if it's only suboptimal in some corner cases but optimizes in general cases, we can live with that. Or if really needed, we can also do some trick in ExpandInputsToCleanCut
but that might be a bit error-prone
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.
Rather than leaving holes in the middle, should we just cut the compaction?
If we have files [a b] [c d] [e f], and [c d] is newly generated, should we pick [a b] to compact itself, and then [e f] in a following one?
@ajkr was in a meeting earlier, but here is from @yoshinorim :
I believe it's the exact same reason that you summarized in the next comment |
I think you can return one compaction at a time consisting of a range of
contiguous files. The caller (manual compaction) will have to call
CompactRange again to get the next compaction of contiguous files. It can
know where to search for the next range of contiguous files if we set
compaction_end to the end of the current range.
…On Tue, Apr 2, 2019, 4:48 PM Zhongyi Xie ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In db/compaction_picker.cc
<#5138 (comment)>:
> @@ -660,6 +661,22 @@ Compaction* CompactionPicker::CompactRange(
}
assert(output_path_id < static_cast<uint32_t>(ioptions_.cf_paths.size()));
+ // for bottom level compaction, skip files that are created during the
+ // current compaction
+ if (max_sst_file_number > 0) {
+ assert(input_level == output_level);
+ std::vector<FileMetaData*> inputs_shrinked;
+ for (size_t i = 0; i < inputs.size(); ++i) {
+ if (inputs[i]->fd.GetNumber() <= max_sst_file_number) {
+ inputs_shrinked.emplace_back(inputs[i]);
+ }
+ }
+ if (inputs_shrinked.empty()) {
+ return nullptr;
+ }
+ inputs.files.swap(inputs_shrinked);
Thanks @ajkr <https://github.com/ajkr> !
let me see if I understood the idea correctly:
so in CompactionPicker::CompactRange, after the call to
GetOverlappingInputs, we will still filter out new files larger than
max_sst_file_number, then maybe call a new function to break up
inputs_shrinked into continuous ranges of files, and for each range, call
SetupOtherInputs and then create/register one new Compaction?
This will create a number of Compaction objects but the caller
DBImpl::RunManualCompaction seems to expect only one Compaction?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5138 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEjxSq-gYF4CFCb4ekIBBKaR72P1W2Pcks5vc-xPgaJpZM4cZFUa>
.
|
I see what you mean now, |
@miasantreble oops, I didn't see your latest comments. I was just trying to mention the same thing as you guys concluded:) |
num = comp_stats2[2].num_input_files_in_output_level; | ||
ASSERT_EQ(num, 0); | ||
} | ||
|
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.
We have compaction_picker_test.cc
. Can we have more thorough test coverage there for some corner cases?
I gave it a pass, and I believe we are on the right track! |
39ea4b9
to
1127a66
Compare
8652a22
to
9305fe1
Compare
9305fe1
to
855556d
Compare
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.
LGTM. Defer to @ajkr for approval.
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.
@miasantreble has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@ajkr do you mind taking another look before we land the PR? Thanks! |
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.
Makes sense to me. Nice!
HISTORY.md
Outdated
@@ -18,6 +18,7 @@ | |||
## 6.1.0 (3/27/2019) | |||
### New Features | |||
* Introduce two more stats levels, kExceptHistogramOrTimers and kExceptTimers. | |||
* Added BottommostLevelCompaction::kForceOptimized to avoid double compacting newly compacted files in bottom level compaction of manual compaction. |
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.
I guess it should be under "Unreleased" in master branch and under "6.1.x" in 6.1.fb branch, assuming you're going to backport it. Although perhaps the protocol changed after my tenure.
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.
Right, thanks for pointing out. The protocol hasn't changed yet :)
HISTORY.md
Outdated
@@ -18,6 +18,7 @@ | |||
## 6.1.0 (3/27/2019) | |||
### New Features | |||
* Introduce two more stats levels, kExceptHistogramOrTimers and kExceptTimers. | |||
* Added BottommostLevelCompaction::kForceOptimized to avoid double compacting newly compacted files in bottom level compaction of manual compaction. |
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.
For my understanding, is it an option because kForce
should be able to force recompaction even on files that were trivially moved to the bottom level?
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.
Yes, we decided to make it an option because tools like option_change_migration
and tests like DBCompactionTestWithParam .ConvertCompactionStyle
expects manual compactions to generate one single file in the bottom level
@miasantreble has updated the pull request. Re-import the pull request |
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.
@miasantreble has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@miasantreble merged this pull request in baa5302. |
…acebook#5138) Summary: Depending on the config, manual compaction (leveled compaction style) does following compactions: L0->L1 L1->L2 ... Ln-1 -> Ln Ln -> Ln The final Ln -> Ln compaction is partly unnecessary as it recompacts all the files that were just generated by the Ln-1 -> Ln. We should avoid recompacting such files. This rule should be applied to Lmax only. Resolves issue facebook#4995 Pull Request resolved: facebook#5138 Differential Revision: D14940106 Pulled By: miasantreble fbshipit-source-id: 8d3cf5507a17e76f3333cfd4bac5256d005636e5
Depending on the config, manual compaction (leveled compaction style) does following compactions:
L0->L1
L1->L2
...
Ln-1 -> Ln
Ln -> Ln
The final Ln -> Ln compaction is partly unnecessary as it recompacts all the files that were just generated by the Ln-1 -> Ln. We should avoid recompacting such files. This rule should be applied to Lmax only.
Resolves issue #4995