Skip to content

Conversation

joshkang97
Copy link

@joshkang97 joshkang97 commented Sep 15, 2025

Summary:

It is useful to be able to specify output temperatures in the CompactFiles API. For example it may be useful to store small L0 files produced by flushes locally, while larger intra-L0 compactions can store the compacted L0 file remotely.

Test Plan:

New unit tests

Reviewers:

Subscribers:

Tasks:

Tags:

@meta-cla meta-cla bot added the CLA Signed label Sep 15, 2025
@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

@joshkang97 joshkang97 changed the title [rocksdb][wip] Support output temperature in CompactFiles [rocksdb] Support output temperature in CompactFiles Sep 15, 2025
@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

@joshkang97 joshkang97 changed the title [rocksdb] Support output temperature in CompactFiles Support output temperature in CompactFiles Sep 16, 2025
@joshkang97 joshkang97 marked this pull request as ready for review September 16, 2025 16:55
@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

output_temperature_(_output_temperature),
output_temperature_(
_output_temperature_override == Temperature::kUnknown
? (is_last_level()
Copy link
Contributor

Choose a reason for hiding this comment

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

The proximal level check is missing. (!outputs.IsProximalLevel())

Output level might be last level, but the compaction may end up writing to the proximal level if tiering is enabled and this will set the wrong temperature to those files.

@joshkang97 joshkang97 marked this pull request as draft September 19, 2025 00:29
@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

@joshkang97 joshkang97 marked this pull request as ready for review September 19, 2025 16:04
Copy link
Contributor

@jaykorean jaykorean left a comment

Choose a reason for hiding this comment

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

IMO, can_temperature_be_overriden is more confusing. I'd rather do the following

Rename CompactinOptions::output_temperature to output_temperature_override and simply comment that unless this is kUnknown, compaction will ignore the internal logic and force-set the temperature for the file with this value.

In Compaction.cc

  • output_temperature_ can be renamed to output_temperature_override_ as well to avoid confusion.
  • Introduce GetOutputTemperature(bool is_proximal_level) and returns the right temperature based on all the variables we have output_temperature_override_, outputs.IsProximalLevel(), is_last_level(),mutable_cf_options().last_level_temperature and mutable_cf_options().default_write_temperature

In CompactionPicker,

  • Just pass in compact_options.output_temperature_override to the Compaction object as is without checking anything.

ASSERT_OK(level_compaction_picker.GetCompactionInputsFromFileNumbers(
&input_files, &input, vstorage_.get(), CompactionOptions()));

auto compactionOptions = CompactionOptions();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we use snake_case for variable names

auto compaction_options = CompactionOptions();

BlobGarbageCollectionPolicy::kUseDefault,
double blob_garbage_collection_age_cutoff = -1);
double blob_garbage_collection_age_cutoff = -1,
bool can_temperature_be_overriden = true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we need this extra boolean flag here (especially when it's default to true and we don't seem to set it to false anywhere)

Copy link
Author

Choose a reason for hiding this comment

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

Oops I meant to set it to false in compaction_picker.cc, I guess I forgot to push my latest changes

@joshkang97
Copy link
Author

Originally I thought about doing it that way, but I noticed that not all new Compaction instances set the temperature as the default_write temperature. For example in compaction_picker_fifo, there seems be some custom logic to pick the write temperature. The current behavior is that it gets overriden by last level temp, but if we write that into output_temperature_override_, that behavior will change.

// 1. Override temp if not kUnknown
// 2. Temperature of the last level files if applicable
// 3. Default write temperature
Temperature output_temperature(bool is_proximal_level = false) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand it's not super clear at first look, this is now no longer an accessor of a private variable, so it needs to be PascalCase Getter

Temperature GetOutputTemperature(bool is_proximal_level = false)

@@ -0,0 +1 @@
* Allow specifying output temperature in CompactionOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be separated as a behavior change note, but with this PR, I'd add the following behavior change to the release note.

kChangeTemperature FIFO compaction will now honor compaction_target_temp to all levels regardless of cf_options::last_level_temperature.

Context: Previously, we used to need last_level_temperature to be explicitly set as kUnknown for that to happen in the last level which is basically the only level in most FIFO style DBs.

Copy link
Contributor

@jaykorean jaykorean left a comment

Choose a reason for hiding this comment

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

Thank you! 👍

@facebook-github-bot
Copy link
Contributor

@joshkang97 has imported this pull request. If you are a Meta employee, you can view this in D82492503.

@facebook-github-bot
Copy link
Contributor

@joshkang97 merged this pull request in 7ae602e.

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.

3 participants