Skip to content

Commit 10985ce

Browse files
committed
Add kCool Temperature (facebook#14000)
Summary: also requested by internal user, like kIce in facebook#13927 Pull Request resolved: facebook#14000 Test Plan: unit tests updated Reviewed By: archang19 Differential Revision: D83200479 Pulled By: pdillinger fbshipit-source-id: 31f2842d87bcad40227aeee9687ff5772393689c
1 parent cd6491d commit 10985ce

16 files changed

Lines changed: 129 additions & 53 deletions

File tree

db/compaction/tiered_compaction_test.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,10 @@ TEST_P(PrecludeLastLevelTest, SmallPrecludeTime) {
17641764
options.env = mock_env_.get();
17651765
options.level0_file_num_compaction_trigger = kNumTrigger;
17661766
options.num_levels = kNumLevels;
1767-
// This existing test selected to also check the kIce case, which should not
1768-
// be interesting enough to exercise across all the test cases
1769-
options.last_level_temperature = Temperature::kIce;
1767+
// This existing test selected to also check the case of various temperatures
1768+
// for last_level_temperature, which should not be interesting enough to
1769+
// exercise across many/all test cases
1770+
options.last_level_temperature = RandomKnownTemperature();
17701771
DestroyAndReopen(options);
17711772

17721773
Random rnd(301);
@@ -1794,8 +1795,9 @@ TEST_P(PrecludeLastLevelTest, SmallPrecludeTime) {
17941795
auto seqs = tp_mapping.TEST_GetInternalMapping();
17951796
ASSERT_FALSE(seqs.empty());
17961797
ASSERT_GE(GetSstSizeHelper(Temperature::kUnknown), 1);
1797-
ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0);
1798-
ASSERT_EQ(GetSstSizeHelper(Temperature::kIce), 0);
1798+
for (auto t : kKnownTemperatures) {
1799+
ASSERT_EQ(GetSstSizeHelper(t), 0);
1800+
}
17991801

18001802
// Wait more than preclude_last_level time, then make sure all the data is
18011803
// compacted to the last level even there's no write (no seqno -> time
@@ -1804,9 +1806,14 @@ TEST_P(PrecludeLastLevelTest, SmallPrecludeTime) {
18041806

18051807
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr));
18061808
ASSERT_EQ("0,0,0,0,0,0,1", FilesPerLevel());
1807-
ASSERT_EQ(GetSstSizeHelper(Temperature::kUnknown), 0);
1808-
ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0);
1809-
ASSERT_GE(GetSstSizeHelper(Temperature::kIce), 1);
1809+
1810+
for (auto t : kKnownTemperatures) {
1811+
if (t == options.last_level_temperature) {
1812+
ASSERT_GT(GetSstSizeHelper(t), 0);
1813+
} else {
1814+
ASSERT_EQ(GetSstSizeHelper(t), 0);
1815+
}
1816+
}
18101817

18111818
Close();
18121819
}

db/db_compaction_test.cc

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9915,6 +9915,20 @@ static void VerifyTemperatureFileReadStats(const Statistics& st,
99159915
EXPECT_EQ(iostats->file_io_stats_by_temperature.warm_file_read_count, 0);
99169916
}
99179917

9918+
if (temps.Contains(Temperature::kCool)) {
9919+
EXPECT_GE(st.getTickerCount(COOL_FILE_READ_BYTES), min_bytes);
9920+
EXPECT_GE(st.getTickerCount(COOL_FILE_READ_COUNT), min_count);
9921+
EXPECT_GE(iostats->file_io_stats_by_temperature.cool_file_bytes_read,
9922+
min_bytes);
9923+
EXPECT_GE(iostats->file_io_stats_by_temperature.cool_file_read_count,
9924+
min_count);
9925+
} else {
9926+
EXPECT_EQ(st.getTickerCount(COOL_FILE_READ_BYTES), 0);
9927+
EXPECT_EQ(st.getTickerCount(COOL_FILE_READ_COUNT), 0);
9928+
EXPECT_EQ(iostats->file_io_stats_by_temperature.cool_file_bytes_read, 0);
9929+
EXPECT_EQ(iostats->file_io_stats_by_temperature.cool_file_read_count, 0);
9930+
}
9931+
99189932
if (temps.Contains(Temperature::kCold)) {
99199933
EXPECT_GE(st.getTickerCount(COLD_FILE_READ_BYTES), min_bytes);
99209934
EXPECT_GE(st.getTickerCount(COLD_FILE_READ_COUNT), min_count);
@@ -9945,7 +9959,7 @@ static void VerifyTemperatureFileReadStats(const Statistics& st,
99459959
}
99469960

99479961
TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
9948-
// Test multi-tier aging: Hot -> Warm -> Cold -> Ice
9962+
// Test multi-tier aging: Hot -> Warm -> Cool -> Cold -> Ice
99499963
Options options = CurrentOptions();
99509964
options.compaction_style = kCompactionStyleFIFO;
99519965
options.num_levels = 1;
@@ -9961,8 +9975,9 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
99619975
// Multi-tier aging: files age through multiple temperatures
99629976
fifo_options.file_temperature_age_thresholds = {
99639977
{Temperature::kWarm, 500}, // Hot -> Warm after 500s
9964-
{Temperature::kCold, 1000}, // Warm -> Cold after 1000s
9965-
{Temperature::kIce, 1500} // Cold -> Ice after 1500s
9978+
{Temperature::kCool, 1000}, // Warm -> Cool
9979+
{Temperature::kCold, 1500}, // Cool -> Cold
9980+
{Temperature::kIce, 2000} // Cold -> Ice
99669981
};
99679982
fifo_options.max_table_files_size = 100000000;
99689983
fifo_options.allow_trivial_copy_when_change_temperature = true;
@@ -9973,8 +9988,8 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
99739988
env_->SetMockSleep();
99749989

99759990
// Track all temperature file creations
9976-
int total_hot = 0, total_warm = 0, total_cold = 0, total_ice = 0,
9977-
total_unknown = 0;
9991+
int total_hot = 0, total_warm = 0, total_cool = 0, total_cold = 0,
9992+
total_ice = 0, total_unknown = 0;
99789993
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
99799994
"NewWritableFile::FileOptions.temperature", [&](void* arg) {
99809995
Temperature temperature = *(static_cast<Temperature*>(arg));
@@ -9985,6 +10000,9 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
998510000
case Temperature::kWarm:
998610001
total_warm++;
998710002
break;
10003+
case Temperature::kCool:
10004+
total_cool++;
10005+
break;
998810006
case Temperature::kCold:
998910007
total_cold++;
999010008
break;
@@ -10016,8 +10034,11 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
1001610034

1001710035
VerifyTemperatureFileReadStats(*options.statistics, Temperature::kHot);
1001810036

10037+
// Land well into each time interval
10038+
env_->MockSleepForSeconds(100);
10039+
1001910040
// Age initial files to warm
10020-
env_->MockSleepForSeconds(600);
10041+
env_->MockSleepForSeconds(500);
1002110042
ASSERT_OK(Put(Key(1), Random::GetTLSInstance()->RandomBinaryString(101)));
1002210043
ASSERT_OK(Flush());
1002310044
ASSERT_OK(dbfull()->TEST_WaitForCompact());
@@ -10031,12 +10052,26 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
1003110052
// Verify Warm file statistics
1003210053
VerifyTemperatureFileReadStats(*options.statistics, Temperature::kWarm);
1003310054

10034-
// Age initial files to cold
10035-
env_->MockSleepForSeconds(600);
10055+
// Age initial files to cool
10056+
env_->MockSleepForSeconds(500);
1003610057
ASSERT_OK(Put(Key(2), Random::GetTLSInstance()->RandomBinaryString(102)));
1003710058
ASSERT_OK(Flush());
1003810059
ASSERT_OK(dbfull()->TEST_WaitForCompact());
1003910060

10061+
// Test reading from Cool temperature file (the aged file)
10062+
ASSERT_OK(options.statistics->Reset());
10063+
get_iostats_context()->Reset();
10064+
10065+
ASSERT_EQ(100U, Get(Key(0)).size());
10066+
10067+
VerifyTemperatureFileReadStats(*options.statistics, Temperature::kCool);
10068+
10069+
// Age initial files to cold
10070+
env_->MockSleepForSeconds(500);
10071+
ASSERT_OK(Put(Key(3), Random::GetTLSInstance()->RandomBinaryString(103)));
10072+
ASSERT_OK(Flush());
10073+
ASSERT_OK(dbfull()->TEST_WaitForCompact());
10074+
1004010075
// Test reading from Cold temperature file (the aged file)
1004110076
ASSERT_OK(options.statistics->Reset());
1004210077
get_iostats_context()->Reset();
@@ -10046,8 +10081,8 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
1004610081
VerifyTemperatureFileReadStats(*options.statistics, Temperature::kCold);
1004710082

1004810083
// Age initial files to ice
10049-
env_->MockSleepForSeconds(600);
10050-
ASSERT_OK(Put(Key(3), Random::GetTLSInstance()->RandomBinaryString(103)));
10084+
env_->MockSleepForSeconds(500);
10085+
ASSERT_OK(Put(Key(4), Random::GetTLSInstance()->RandomBinaryString(104)));
1005110086
ASSERT_OK(Flush());
1005210087
ASSERT_OK(dbfull()->TEST_WaitForCompact());
1005310088

@@ -10072,12 +10107,14 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
1007210107
// Verify current files temperatures
1007310108
EXPECT_EQ(temp_counts[Temperature::kHot], 1);
1007410109
EXPECT_EQ(temp_counts[Temperature::kWarm], 1);
10110+
EXPECT_EQ(temp_counts[Temperature::kCool], 1);
1007510111
EXPECT_EQ(temp_counts[Temperature::kCold], 1);
1007610112
EXPECT_EQ(temp_counts[Temperature::kIce], 3);
1007710113

1007810114
// Verify historical (and current) file temperatures
10079-
EXPECT_EQ(total_hot, 6);
10080-
EXPECT_EQ(total_warm, 5);
10115+
EXPECT_EQ(total_hot, 7);
10116+
EXPECT_EQ(total_warm, 6);
10117+
EXPECT_EQ(total_cool, 5);
1008110118
EXPECT_EQ(total_cold, 4);
1008210119
EXPECT_EQ(total_ice, 3);
1008310120

@@ -10087,7 +10124,7 @@ TEST_F(DBCompactionTest, FIFOMultiTierTemperatureAging) {
1008710124
get_iostats_context()->Reset();
1008810125

1008910126
// Read from all files to verify cumulative statistics
10090-
for (int i = 0; i < 4; i++) {
10127+
for (int i = 0; i < 5; i++) {
1009110128
ASSERT_EQ(static_cast<unsigned>(100 + i), Get(Key(i)).size());
1009210129
}
1009310130

db/db_test2.cc

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6063,16 +6063,9 @@ TEST_F(DBTest2, VariousFileTemperatures) {
60636063
};
60646064

60656065
// We don't have enough non-unknown temps to confidently distinguish that
6066-
// a specific setting caused a specific outcome, in a single run. This is a
6067-
// reasonable work-around without blowing up test time. Only returns
6068-
// non-unknown temperatures.
6069-
auto RandomTemp = [] {
6070-
static std::vector<Temperature> temps = {
6071-
Temperature::kHot, Temperature::kWarm, Temperature::kCold,
6072-
Temperature::kIce};
6073-
return temps[Random::GetTLSInstance()->Uniform(
6074-
static_cast<int>(temps.size()))];
6075-
};
6066+
// a specific setting caused a specific outcome, in a single run. Using
6067+
// RandomKnownTemperature() is a reasonable work-around without blowing up
6068+
// test time.
60766069

60776070
auto test_fs = std::make_shared<MyTestFS>(env_->GetFileSystem());
60786071
std::unique_ptr<Env> env(new CompositeEnvWrapper(env_, test_fs));
@@ -6088,22 +6081,22 @@ TEST_F(DBTest2, VariousFileTemperatures) {
60886081
options.env = env.get();
60896082
test_fs->Reset();
60906083
if (use_optimize) {
6091-
test_fs->optimize_manifest_temperature = RandomTemp();
6084+
test_fs->optimize_manifest_temperature = RandomKnownTemperature();
60926085
test_fs->expected_manifest_temperature =
60936086
test_fs->optimize_manifest_temperature;
6094-
test_fs->optimize_wal_temperature = RandomTemp();
6087+
test_fs->optimize_wal_temperature = RandomKnownTemperature();
60956088
test_fs->expected_wal_temperature = test_fs->optimize_wal_temperature;
60966089
}
60976090
if (use_temp_options) {
6098-
options.metadata_write_temperature = RandomTemp();
6091+
options.metadata_write_temperature = RandomKnownTemperature();
60996092
test_fs->expected_manifest_temperature =
61006093
options.metadata_write_temperature;
61016094
test_fs->expected_other_metadata_temperature =
61026095
options.metadata_write_temperature;
6103-
options.wal_write_temperature = RandomTemp();
6096+
options.wal_write_temperature = RandomKnownTemperature();
61046097
test_fs->expected_wal_temperature = options.wal_write_temperature;
6105-
options.last_level_temperature = RandomTemp();
6106-
options.default_write_temperature = RandomTemp();
6098+
options.last_level_temperature = RandomKnownTemperature();
6099+
options.default_write_temperature = RandomKnownTemperature();
61076100
}
61086101

61096102
DestroyAndReopen(options);

db/db_test_util.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,4 +1872,13 @@ template class TargetCacheChargeTrackingCache<
18721872
CacheEntryRole::kBlockBasedTableReader>;
18731873
template class TargetCacheChargeTrackingCache<CacheEntryRole::kFileMetadata>;
18741874

1875+
const std::vector<Temperature> kKnownTemperatures = {
1876+
Temperature::kHot, Temperature::kWarm, Temperature::kCool,
1877+
Temperature::kCold, Temperature::kIce};
1878+
1879+
Temperature RandomKnownTemperature() {
1880+
return kKnownTemperatures[Random::GetTLSInstance()->Uniform(
1881+
static_cast<int>(kKnownTemperatures.size()))];
1882+
}
1883+
18751884
} // namespace ROCKSDB_NAMESPACE

db/db_test_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,4 +1467,8 @@ class DBTestBase : public testing::Test {
14671467
// unique ids.
14681468
void VerifySstUniqueIds(const TablePropertiesCollection& props);
14691469

1470+
// Excludes kUnknown
1471+
extern const std::vector<Temperature> kKnownTemperatures;
1472+
Temperature RandomKnownTemperature();
1473+
14701474
} // namespace ROCKSDB_NAMESPACE

db_stress_tool/db_stress_test_base.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ bool StressTest::BuildOptionsTable() {
428428
options_tbl.emplace(
429429
"file_temperature_age_thresholds",
430430
std::vector<std::string>{
431-
"{{temperature=kWarm;age=10}:{temperature=kCold;age=50}:{"
432-
"temperature=kIce;age=250}}",
431+
"{{temperature=kWarm;age=10}:{temperature=kCool;age=30}:{"
432+
"temperature=kCold;age=100}:{"
433+
"temperature=kIce;age=300}}",
433434
"{{temperature=kWarm;age=30}:{temperature=kCold;age=300}}",
434435
"{{temperature=kCold;age=100}}", "{}"});
435436
options_tbl.emplace(

file/random_access_file_reader.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ inline void RecordIOStats(Statistics* stats, Temperature file_temperature,
8080
RecordTick(stats, WARM_FILE_READ_BYTES, size);
8181
RecordTick(stats, WARM_FILE_READ_COUNT, 1);
8282
break;
83+
case Temperature::kCool:
84+
IOSTATS_ADD(file_io_stats_by_temperature.cool_file_bytes_read, size);
85+
IOSTATS_ADD(file_io_stats_by_temperature.cool_file_read_count, 1);
86+
RecordTick(stats, COOL_FILE_READ_BYTES, size);
87+
RecordTick(stats, COOL_FILE_READ_COUNT, 1);
88+
break;
8389
case Temperature::kCold:
8490
IOSTATS_ADD(file_io_stats_by_temperature.cold_file_bytes_read, size);
8591
IOSTATS_ADD(file_io_stats_by_temperature.cold_file_read_count, 1);

include/rocksdb/iostats_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct FileIOByTemperature {
3232
uint64_t hot_file_bytes_read;
3333
// the number of bytes read to Temperature::kWarm file
3434
uint64_t warm_file_bytes_read;
35+
// the number of bytes read to Temperature::kCool file
36+
uint64_t cool_file_bytes_read;
3537
// the number of bytes read to Temperature::kCold file
3638
uint64_t cold_file_bytes_read;
3739
// the number of bytes read to Temperature::kIce file
@@ -40,6 +42,8 @@ struct FileIOByTemperature {
4042
uint64_t hot_file_read_count;
4143
// total number of reads to Temperature::kWarm file
4244
uint64_t warm_file_read_count;
45+
// total number of reads to Temperature::kCool file
46+
uint64_t cool_file_read_count;
4347
// total number of reads to Temperature::kCold file
4448
uint64_t cold_file_read_count;
4549
// total number of reads to Temperature::kIce file
@@ -48,10 +52,12 @@ struct FileIOByTemperature {
4852
void Reset() {
4953
hot_file_bytes_read = 0;
5054
warm_file_bytes_read = 0;
55+
cool_file_bytes_read = 0;
5156
cold_file_bytes_read = 0;
5257
ice_file_bytes_read = 0;
5358
hot_file_read_count = 0;
5459
warm_file_read_count = 0;
60+
cool_file_read_count = 0;
5561
cold_file_read_count = 0;
5662
ice_file_read_count = 0;
5763
}

include/rocksdb/statistics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,12 @@ enum Tickers : uint32_t {
443443
// Tiered storage related statistics
444444
HOT_FILE_READ_BYTES,
445445
WARM_FILE_READ_BYTES,
446+
COOL_FILE_READ_BYTES,
446447
COLD_FILE_READ_BYTES,
447448
ICE_FILE_READ_BYTES,
448449
HOT_FILE_READ_COUNT,
449450
WARM_FILE_READ_COUNT,
451+
COOL_FILE_READ_COUNT,
450452
COLD_FILE_READ_COUNT,
451453
ICE_FILE_READ_COUNT,
452454

include/rocksdb/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ enum class Temperature : uint8_t {
118118
kUnknown = 0,
119119
kHot = 0x04,
120120
kWarm = 0x08,
121+
kCool = 0x0A,
121122
kCold = 0x0C,
122123
kIce = 0x10,
123124
// XXX: this is mis-named. It is instead an invalid temperature beyond the

0 commit comments

Comments
 (0)