Skip to content

Commit

Permalink
[improve](path gc) Execute path gc interval adaptive to disk size #34538
Browse files Browse the repository at this point in the history
 (#41341)

cherry pick from #34538

Co-authored-by: deardeng <565620795@qq.com>
  • Loading branch information
w41ter and deardeng authored Sep 30, 2024
1 parent eca9555 commit 21718c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 35 additions & 6 deletions be/src/olap/olap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,21 +356,50 @@ void StorageEngine::_unused_rowset_monitor_thread_callback() {
!k_doris_exit);
}

int32_t StorageEngine::_auto_get_interval_by_disk_capacity(DataDir* data_dir) {
double disk_used = data_dir->get_usage(0);
double remain_used = 1 - disk_used;
DCHECK(remain_used >= 0 && remain_used <= 1);
DCHECK(config::path_gc_check_interval_second >= 0);
int32_t ret = 0;
if (remain_used > 0.9) {
// if config::path_gc_check_interval_second == 24h
ret = config::path_gc_check_interval_second;
} else if (remain_used > 0.7) {
// 12h
ret = config::path_gc_check_interval_second / 2;
} else if (remain_used > 0.5) {
// 6h
ret = config::path_gc_check_interval_second / 4;
} else if (remain_used > 0.3) {
// 4h
ret = config::path_gc_check_interval_second / 6;
} else {
// 3h
ret = config::path_gc_check_interval_second / 8;
}
return ret;
}

void StorageEngine::_path_gc_thread_callback(DataDir* data_dir) {
LOG(INFO) << "try to start path gc thread!";
int32_t interval = config::path_gc_check_interval_second;
int32_t last_exec_time = 0;
do {
LOG(INFO) << "try to perform path gc!";
data_dir->perform_path_gc();
int32_t current_time = time(nullptr);

interval = config::path_gc_check_interval_second;
int32_t interval = _auto_get_interval_by_disk_capacity(data_dir);
if (interval <= 0) {
LOG(WARNING) << "path gc thread check interval config is illegal:" << interval
<< "will be forced set to half hour";
interval = 1800; // 0.5 hour
}
} while (!_stop_background_threads_latch.wait_for(std::chrono::seconds(interval)) &&
!k_doris_exit);
if (current_time - last_exec_time >= interval) {
LOG(INFO) << "try to perform path gc! disk remain [" << 1 - data_dir->get_usage(0)
<< "] internal [" << interval << "]";
data_dir->perform_path_gc();
last_exec_time = time(nullptr);
}
} while (!_stop_background_threads_latch.wait_for(std::chrono::seconds(5)) && !k_doris_exit);
LOG(INFO) << "stop path gc thread!";
}

Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/storage_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ class StorageEngine {

int _get_and_set_next_disk_index(int64 partition_id, TStorageMedium::type storage_medium);

int32_t _auto_get_interval_by_disk_capacity(DataDir* data_dir);

private:
EngineOptions _options;
std::mutex _store_lock;
Expand Down

0 comments on commit 21718c5

Please sign in to comment.