[Enhance] Sort directories by available space when do trash sweep (#5498)

* [Enhance] Sort directories by available space when do trash sweep

In the case when one disk is about to be full, we want to sweep trash
data on this disk as quickly as possible. The currently trash sweep
function is to remove trashed files order by path's name, however, disk
data directories may have some large different available space because
of the load balance algorithm, this patch improve it to remove files by
directories' available space.

* add log
This commit is contained in:
Yingchun Lai
2021-03-12 13:43:27 +08:00
committed by GitHub
parent 511ddab3b1
commit 8ead0aaad8
4 changed files with 66 additions and 9 deletions

View File

@ -593,6 +593,7 @@ OLAPStatus StorageEngine::_start_trash_sweep(double* usage) {
std::vector<DataDirInfo> data_dir_infos;
RETURN_NOT_OK_LOG(get_all_data_dir_info(&data_dir_infos, false),
"failed to get root path stat info when sweep trash.")
std::sort(data_dir_infos.begin(), data_dir_infos.end(), DataDirInfoLessAvailability());
time_t now = time(nullptr); //获取UTC时间
tm local_tm_now;
@ -603,6 +604,7 @@ OLAPStatus StorageEngine::_start_trash_sweep(double* usage) {
const time_t local_now = mktime(&local_tm_now); //得到当地日历时间
for (DataDirInfo& info : data_dir_infos) {
LOG(INFO) << "Start to sweep path " << info.path;
if (!info.is_used) {
continue;
}