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

Support periodic compaction in universal compaction #5970

Closed
wants to merge 6 commits into from

Conversation

siying
Copy link
Contributor

@siying siying commented Oct 25, 2019

Summary:
Previously, periodic compaction is not supported in universal compaction. Add the support using following approach: if any file is marked as qualified for periodid compaction, trigger a full compaction. If a full compaction is prevented by files being compacted, try to compact the higher levels than files currently being compacted. If in this way we can only compact the last sorted run and none of the file to be compacted qualifies for periodic compaction, skip the compact. This is to prevent the same single level compaction from being executed again and again.

Test Plan: Add several test cases.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@siying has updated the pull request. Re-import the pull request

2 similar comments
@facebook-github-bot
Copy link
Contributor

@siying has updated the pull request. Re-import the pull request

@facebook-github-bot
Copy link
Contributor

@siying has updated the pull request. Re-import the pull request

@@ -499,6 +499,120 @@ TEST_F(CompactionPickerTest, AllowsTrivialMoveUniversal) {
ASSERT_TRUE(compaction->is_trivial_move());
}

TEST_F(CompactionPickerTest, UniversalPeriodiCompaction1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/PeriodiCompaction/PeriodicCompaction/g

db/version_set.h Outdated
@@ -312,6 +312,10 @@ class VersionStorageInfo {
return files_marked_for_periodic_compaction_;
}

void AddFileMarkedForPeriodiCompaction(int level, FileMetaData* f) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be prepended with "TEST_" prefix ?

@@ -2150,6 +2150,72 @@ TEST_F(DBTestUniversalDeleteTrigCompaction, IngestBehind) {
ASSERT_GT(NumTableFilesAtLevel(5), 0);
}

TEST_F(DBTestUniversalDeleteTrigCompaction, PeriodicCompaction) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be under "DBTestUniversalCompaction" instead of "DBTestUniversalDeleteTrigCompaction".
However, the test code itself looks and it is easy to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels very odd but non existing test under DBTestUniversalDeleteTrigCompaction is related to delete triggered compaction. I'll just rename this class name to DBTestUniversalCompaction2.

ASSERT_EQ(0, start_level);
ASSERT_EQ(4, output_level);

// Case 2: Oldest compacted file exccceeds periodic compaction threshold
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exccceeds/exceeds/

for (size_t i = 0; i < inputs.size(); ++i) {
inputs[i].level = start_level + static_cast<int>(i);
}
// We always compact all the files, so always compress.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No way related to this PR:
I know this comment is from the original code, but I don't understand what does "so always compress" mean here, and the reason for it. May be this needs to be fixed or elaborated if possible, either in this or a later PR.

Is it talking about enable_compression always being set to true for Compaction() when getting the compression type and options, on lines 1014 and 1016?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember either. Reading the code, it seems to satisfy option mutable_cf_options_.compaction_options_universal.compression_size_percent. Full compaction is always compressed there. Will add a comment.

}
}

Compaction* c = PickCompactionToOldest(start_index,
Copy link
Contributor

@sagar0 sagar0 Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic appears simple, but are you not concerned that it might increase write amplification by triggering a full compaction most of the times a periodic compaction is picked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I chose this way: in universal compaction, the largest file is almost always generated by a full compaction so it's almost always the oldest. So it's pretty uncommon if a periodic compaction doesn't include the oldest file. If we include the oldest file, it makes sense to do a full compaction, because we already compact a big portion of the data. Does it make sense?

Copy link
Contributor

@riversand963 riversand963 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM with a few minor comments.

@@ -90,6 +90,19 @@ class UniversalCompactionBuilder {

Compaction* PickDeleteTriggeredCompaction();

// Form a compaction from the sorted run indicated by start_index to the
// oldest sorted run.
// The caller is responsbilt to make sure that those files are not in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/responsbilt to make/responsible for making/

if (sorted_runs_.size() >=
static_cast<size_t>(
mutable_cf_options_.level0_file_num_compaction_trigger)) {
if (!vstorage_->FilesMarkedForPeriodicCompaction().empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does periodic compaction have higher priority than size-amp-based compaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be the case, as periodic compaction is a hard requirement. Is it the case in the code?

Summary:
Previously, periodid compaction is not supported in universal compaction. Add the support using following approach: if any file is marked as qualified for periodid compaction, trigger a full compaction. If a full compaction is prevented by files being compacted, try to compact the higher levels than files currently being compacted. If in this way we can only compact the last level and none of the file at the level qualifies for periodic compaction, skip the compact. This is to prevent the same single level compaction from being executed again and again.

Test Plan: Add several test cases.
@facebook-github-bot
Copy link
Contributor

@siying has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siying has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@sagar0 sagar0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thanks!

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in aa6f7d0.

merryChris pushed a commit to merryChris/rocksdb that referenced this pull request Nov 18, 2019
Summary:
Previously, periodic compaction is not supported in universal compaction. Add the support using following approach: if any file is marked as qualified for periodid compaction, trigger a full compaction. If a full compaction is prevented by files being compacted, try to compact the higher levels than files currently being compacted. If in this way we can only compact the last sorted run and none of the file to be compacted qualifies for periodic compaction, skip the compact. This is to prevent the same single level compaction from being executed again and again.
Pull Request resolved: facebook#5970

Test Plan: Add several test cases.

Differential Revision: D18147097

fbshipit-source-id: 8ecc308154d9aca96fb192c51fbceba3947550c1
facebook-github-bot pushed a commit that referenced this pull request Nov 23, 2019
Summary:
`options.ttl` is now supported in universal compaction, similar to how periodic compactions are implemented in PR #5970 .
Setting `options.ttl` will simply set `options.periodic_compaction_seconds` to execute the periodic compactions code path.
Discarded PR #4749 in lieu of this.

This is a short term work-around/hack of falling back to periodic compactions when ttl is set.
Pull Request resolved: #6071

Test Plan: Added a unit test.

Differential Revision: D18668336

Pulled By: sagar0

fbshipit-source-id: e75f5b81ba949f77ef9eff05e44bb1c757f58612
wolfkdy pushed a commit to wolfkdy/rocksdb that referenced this pull request Dec 22, 2019
Summary:
`options.ttl` is now supported in universal compaction, similar to how periodic compactions are implemented in PR facebook#5970 .
Setting `options.ttl` will simply set `options.periodic_compaction_seconds` to execute the periodic compactions code path.
Discarded PR facebook#4749 in lieu of this.

This is a short term work-around/hack of falling back to periodic compactions when ttl is set.
Pull Request resolved: facebook#6071

Test Plan: Added a unit test.

Differential Revision: D18668336

Pulled By: sagar0

fbshipit-source-id: e75f5b81ba949f77ef9eff05e44bb1c757f58612
facebook-github-bot pushed a commit that referenced this pull request Feb 21, 2023
Summary:
the comment for option `periodic_compaction_seconds` only mentions support for Leveled and FIFO compaction, while the implementation supports all compaction styles after #5970. This PR updates comment to reflect this.

Pull Request resolved: #11227

Reviewed By: ajkr

Differential Revision: D43325046

Pulled By: cbi42

fbshipit-source-id: 2364dcb5a01cd098ad52c818fe10d621445e2188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants