mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-28 05:43:50 +00:00
2dab137182
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. Pull Request resolved: https://github.com/facebook/rocksdb/pull/12031 Test Plan: Unit Tests added - `DBCompactionTest::LevelPeriodicCompactionOffpeak` for Leveled - `DBTestUniversalCompaction2::PeriodicCompaction` for Universal Reviewed By: cbi42 Differential Revision: D50900292 Pulled By: jaykorean fbshipit-source-id: 267e7d3332d45a5d9881796786c8650fa0a3b43d
60 lines
2.4 KiB
C++
60 lines
2.4 KiB
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#include "options/offpeak_time_info.h"
|
|
|
|
#include "rocksdb/system_clock.h"
|
|
#include "util/string_util.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
OffpeakTimeOption::OffpeakTimeOption() : OffpeakTimeOption("") {}
|
|
OffpeakTimeOption::OffpeakTimeOption(const std::string& offpeak_time_string) {
|
|
SetFromOffpeakTimeString(offpeak_time_string);
|
|
}
|
|
|
|
void OffpeakTimeOption::SetFromOffpeakTimeString(
|
|
const std::string& offpeak_time_string) {
|
|
const int old_start_time = daily_offpeak_start_time_utc;
|
|
const int old_end_time = daily_offpeak_end_time_utc;
|
|
if (TryParseTimeRangeString(offpeak_time_string, daily_offpeak_start_time_utc,
|
|
daily_offpeak_end_time_utc)) {
|
|
daily_offpeak_time_utc = offpeak_time_string;
|
|
} else {
|
|
daily_offpeak_start_time_utc = old_start_time;
|
|
daily_offpeak_end_time_utc = old_end_time;
|
|
}
|
|
}
|
|
|
|
OffpeakTimeInfo OffpeakTimeOption::GetOffpeakTimeInfo(
|
|
const int64_t& current_time) const {
|
|
OffpeakTimeInfo offpeak_time_info;
|
|
if (daily_offpeak_start_time_utc == daily_offpeak_end_time_utc) {
|
|
return offpeak_time_info;
|
|
}
|
|
int seconds_since_midnight = static_cast<int>(current_time % kSecondsPerDay);
|
|
int seconds_since_midnight_to_nearest_minute =
|
|
(seconds_since_midnight / kSecondsPerMinute) * kSecondsPerMinute;
|
|
// if the offpeak duration spans overnight (i.e. 23:30 - 4:30 next day)
|
|
if (daily_offpeak_start_time_utc > daily_offpeak_end_time_utc) {
|
|
offpeak_time_info.is_now_offpeak =
|
|
daily_offpeak_start_time_utc <=
|
|
seconds_since_midnight_to_nearest_minute ||
|
|
seconds_since_midnight_to_nearest_minute <= daily_offpeak_end_time_utc;
|
|
} else {
|
|
offpeak_time_info.is_now_offpeak =
|
|
daily_offpeak_start_time_utc <=
|
|
seconds_since_midnight_to_nearest_minute &&
|
|
seconds_since_midnight_to_nearest_minute <= daily_offpeak_end_time_utc;
|
|
}
|
|
offpeak_time_info.seconds_till_next_offpeak_start =
|
|
seconds_since_midnight < daily_offpeak_start_time_utc
|
|
? daily_offpeak_start_time_utc - seconds_since_midnight
|
|
: ((daily_offpeak_start_time_utc + kSecondsPerDay) -
|
|
seconds_since_midnight);
|
|
return offpeak_time_info;
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|