Skip to content

Commit 8431b14

Browse files
author
Josh Kang
committed
[rocksdb] Support output temperature in CompactFiles
1 parent 2620c85 commit 8431b14

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

db/compaction/compaction_picker.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,18 @@ Compaction* CompactionPicker::PickCompactionForCompactFiles(
375375
// without configurable `CompressionOptions`, which is inconsistent.
376376
compression_type = compact_options.compression;
377377
}
378+
379+
auto writeTemperature =
380+
compact_options.output_temperature == Temperature::kUnknown
381+
? mutable_cf_options.default_write_temperature
382+
: compact_options.output_temperature;
383+
378384
auto c = new Compaction(
379385
vstorage, ioptions_, mutable_cf_options, mutable_db_options, input_files,
380386
output_level, compact_options.output_file_size_limit,
381387
mutable_cf_options.max_compaction_bytes, output_path_id, compression_type,
382388
GetCompressionOptions(mutable_cf_options, vstorage, output_level),
383-
mutable_cf_options.default_write_temperature,
384-
compact_options.max_subcompactions,
389+
writeTemperature, compact_options.max_subcompactions,
385390
/* grandparents */ {}, earliest_snapshot, snapshot_checker,
386391
CompactionReason::kManualCompaction);
387392
RegisterCompaction(c);

db/compaction/compaction_picker_test.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ TEST_F(CompactionPickerTest, CompactionUniversalIngestBehindReservedLevel) {
589589
}
590590
}
591591
}
592+
592593
// Tests if the files can be trivially moved in multi level
593594
// universal compaction when allow_trivial_move option is set
594595
// In this test as the input files overlaps, they cannot
@@ -1470,6 +1471,29 @@ TEST_F(CompactionPickerTest, FIFOToHotAndWarm) {
14701471
}
14711472
}
14721473

1474+
TEST_F(CompactionPickerTest, CompactFilesOutputTemperature) {
1475+
NewVersionStorage(6, kCompactionStyleLevel);
1476+
auto file_number = 66U;
1477+
Add(0, file_number, "150", "200", 1000000000U);
1478+
UpdateVersionStorageInfo();
1479+
1480+
std::unordered_set<uint64_t> input{file_number};
1481+
std::vector<CompactionInputFiles> input_files;
1482+
ASSERT_OK(level_compaction_picker.GetCompactionInputsFromFileNumbers(
1483+
&input_files, &input, vstorage_.get(), CompactionOptions()));
1484+
1485+
auto compactionOptions = CompactionOptions();
1486+
compactionOptions.output_temperature = Temperature::kCold;
1487+
1488+
std::unique_ptr<Compaction> compaction(
1489+
level_compaction_picker.PickCompactionForCompactFiles(
1490+
compactionOptions, input_files, 1, vstorage_.get(),
1491+
mutable_cf_options_, mutable_db_options_, /*output_path_id=*/0));
1492+
1493+
ASSERT_TRUE(compaction.get() != nullptr);
1494+
ASSERT_EQ(compaction->output_temperature(), Temperature::kCold);
1495+
}
1496+
14731497
TEST_F(CompactionPickerTest, CompactionPriMinOverlapping1) {
14741498
NewVersionStorage(6, kCompactionStyleLevel);
14751499
ioptions_.compaction_pri = kMinOverlappingRatio;

include/rocksdb/options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,11 @@ struct CompactionOptions {
23512351
// canceled variable in CompactionOptions, as it does for CompactRangeOptions
23522352
// - this is because ManualCompactionState is not used
23532353

2354+
// Create output compaction file using this file temperature. If unset, will
2355+
// default to "last_level_temperature" if output level is last level otherwise
2356+
// "default_write_temperature"
2357+
Temperature output_temperature = Temperature::kUnknown;
2358+
23542359
CompactionOptions()
23552360
: compression(kDisableCompressionOption),
23562361
output_file_size_limit(std::numeric_limits<uint64_t>::max()),

0 commit comments

Comments
 (0)