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

Mark more files for periodic compaction during offpeak #12031

Closed

Conversation

jaykorean
Copy link
Contributor

@jaykorean jaykorean commented Oct 30, 2023

Summary

  • The struct previously named OffpeakTimeInfo has been renamed to OffpeakTimeOption to indicate that it's a user-configurable option. Additionally, a new struct, OffpeakTimeInfo, has been introduced, which includes two fields: is_now_offpeak and seconds_till_next_offpeak_start. This change prevents the need to parse the daily_offpeak_time_utc string twice.
  • It's worth noting that we may consider adding more fields to the OffpeakTimeInfo struct, such as elapsed_seconds and total_seconds, as needed for further optimization.
  • Within VersionStorageInfo::ComputeFilesMarkedForPeriodicCompaction(), we've adjusted the allowed_time_limit to include files that are expected to expire by the next offpeak start.
  • We might explore further optimizations, such as evenly distributing files to mark during offpeak hours, if the initial approach results in marking too many files simultaneously during the first scoring in offpeak hours. The primary objective of this PR is to prevent periodic compactions during non-offpeak hours when offpeak hours are configured. We'll start with this straightforward solution and assess whether it suffices for now.

Test Plan

Unit Tests added

  • DBCompactionTest::LevelPeriodicCompactionOffpeak for Leveled
  • DBTestUniversalCompaction2::PeriodicCompaction for Universal

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch 4 times, most recently from d07f183 to 16afcb0 Compare November 1, 2023 20:00
@jaykorean jaykorean requested review from pdillinger and cbi42 November 1, 2023 20:38
@jaykorean jaykorean marked this pull request as ready for review November 1, 2023 20:38
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

AFAIK, the implementation is fine. The tests seem verbose and perhaps not well controlled (changing one variable at a time).

db/db_universal_compaction_test.cc Show resolved Hide resolved
@@ -2230,6 +2231,209 @@ TEST_F(DBTestUniversalCompaction2, PeriodicCompaction) {
ASSERT_EQ(4, output_level);
}

TEST_F(DBTestUniversalCompaction2, PeriodicCompactionOffpeak) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a significant difference in universal and leveled behavior here? It seems like a lot of duplication (more or less).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the perspective of picking files based on their age, no. But just wanted to have the coverage on both compaction types.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, code duplication in tests (more or less) is a greater sin than keeping tests neatly organized by feature. Features interact, so there's no way to be absolutely clean in organization--assuming your tests are interesting and not just a rehash of the implementation; you just put things some place reasonable and respect the greater threats to maintenance burden such as verbosity / unnecessary repetition.

It would probably be different if compaction strategies were pluggable components, but they are deeply integrated.

I appreciate the narrative comments to help future engineers to understand what is being tested and how. Clarity in the "what & why" of a test is most important. :) (Sometimes it's obvious: feature X has its documented effect when turned on and does not when it's turned off.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the test for Leveled one, added comment and addressed the feedback in the Universal one.

db/db_compaction_test.cc Outdated Show resolved Hide resolved
Copy link
Member

@cbi42 cbi42 left a comment

Choose a reason for hiding this comment

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

Do we plan to extend the logic to TTL compaction too?

db/version_set.cc Outdated Show resolved Hide resolved
options/offpeak_time_info.cc Outdated Show resolved Hide resolved
Random rnd(test::RandomSeed());
int days = rnd.Uniform(100);

int periodic_compactions = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Probably will need atomic_int.

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't compaction picking happen while holding the DB mutex? If so, there would only be a race with the test code if there's a race in executing the periodic compactions.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, compaction picking happens while holding the db mutex. I was worried that the test code can access periodic_compactions while compaction picking is happening. That seems to be not the case. I guess if TSAN complains about it, it's fine too and it means the test has a bug.

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 will leave it without atomic and see what TSAN says.

@jaykorean
Copy link
Contributor Author

@cbi42 Regarding the comment on TTL, no, not at the moment since we are going to start with Zippy first which is Universal. But it's definitely something that we can consider adding in the later PRs.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 26c4fa9 to 4e73db6 Compare November 3, 2023 17:40
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 4e73db6 to a4944f3 Compare November 3, 2023 17:41
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from a4944f3 to 5060b8a Compare November 3, 2023 17:59
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 5060b8a to ed84fe9 Compare November 3, 2023 18:05
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

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

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

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

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 2d68d9a to a14eb23 Compare November 3, 2023 21:28
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

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

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 7490f2a to 788d092 Compare November 3, 2023 22:29
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 788d092 to 083041e Compare November 3, 2023 22:30
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@jaykorean jaykorean force-pushed the periodic_compaction_during_offpeak branch from 083041e to 4ccc413 Compare November 3, 2023 22:32
@facebook-github-bot
Copy link
Contributor

@jaykorean has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

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

@jaykorean jaykorean requested review from pdillinger and cbi42 November 3, 2023 23:23
Copy link
Member

@cbi42 cbi42 left a comment

Choose a reason for hiding this comment

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

LGTM

@facebook-github-bot
Copy link
Contributor

@jaykorean merged this pull request in 2dab137.

@jaykorean jaykorean deleted the periodic_compaction_during_offpeak branch November 6, 2023 21:06
@sakae-nakajima
Copy link

@jaykorean , thanks for the change. I'd like to try this option in Java application. How can we set this? I see no options in Options nor DBOptions. Thanks

@jaykorean
Copy link
Contributor Author

@sakae-nakajima The option to enable this feature is not exposed in Java API yet. Feel free to try adding it yourself and add me as a reviewer. I'd be more than happy to review the PR. You may also want to try reaching out to the Java API contributors (@adamretter, @alanpaxton and more) for help.

Or I will try finding some time later in December or early next year to add it.

@adamretter
Copy link
Collaborator

@jaykorean @sakae-nakajima my colleague @alanpaxton has implemented this here - #13148 it is just waiting to be merged by the FB team?

@jaykorean
Copy link
Contributor Author

@adamretter I must have missed it. Let me review and import this to the internal repo. Thanks for the heads up!

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.

6 participants