[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:
@ -52,16 +52,20 @@ typedef UniqueId TabletUid;
|
||||
enum CompactionType { BASE_COMPACTION = 1, CUMULATIVE_COMPACTION = 2 };
|
||||
|
||||
struct DataDirInfo {
|
||||
DataDirInfo()
|
||||
: path_hash(0), disk_capacity(1), available(0), data_used_capacity(0), is_used(false) {}
|
||||
|
||||
std::string path;
|
||||
size_t path_hash;
|
||||
int64_t disk_capacity; // actual disk capacity
|
||||
int64_t available; // 可用空间,单位字节
|
||||
int64_t data_used_capacity;
|
||||
bool is_used; // 是否可用标识
|
||||
TStorageMedium::type storage_medium; // 存储介质类型:SSD|HDD
|
||||
size_t path_hash = 0;
|
||||
int64_t disk_capacity = 1; // actual disk capacity
|
||||
int64_t available = 0; // 可用空间,单位字节
|
||||
int64_t data_used_capacity = 0;
|
||||
bool is_used = false; // 是否可用标识
|
||||
TStorageMedium::type storage_medium = TStorageMedium::HDD; // 存储介质类型:SSD|HDD
|
||||
};
|
||||
|
||||
// Sort DataDirInfo by available space.
|
||||
struct DataDirInfoLessAvailability {
|
||||
bool operator() (const DataDirInfo& left, const DataDirInfo& right) const {
|
||||
return left.available < right.available;
|
||||
}
|
||||
};
|
||||
|
||||
struct TabletInfo {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -95,3 +95,4 @@ ADD_BE_TEST(memory/column_test)
|
||||
ADD_BE_TEST(memory/partial_row_batch_test)
|
||||
ADD_BE_TEST(memory/mem_tablet_test)
|
||||
#ADD_BE_TEST(push_handler_test)
|
||||
ADD_BE_TEST(common_test)
|
||||
|
||||
50
be/test/olap/common_test.cpp
Normal file
50
be/test/olap/common_test.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "olap/olap_common.h"
|
||||
|
||||
namespace doris {
|
||||
|
||||
TEST(DataDirInfo, DataDirInfoLessAvailability) {
|
||||
DataDirInfo a;
|
||||
a.available = 100;
|
||||
DataDirInfo b;
|
||||
b.available = 200;
|
||||
DataDirInfo c;
|
||||
c.available = 300;
|
||||
DataDirInfo d;
|
||||
d.available = 400;
|
||||
std::vector<DataDirInfo> data_dir_infos;
|
||||
data_dir_infos.push_back(c);
|
||||
data_dir_infos.push_back(d);
|
||||
data_dir_infos.push_back(a);
|
||||
data_dir_infos.push_back(b);
|
||||
std::sort(data_dir_infos.begin(), data_dir_infos.end(), DataDirInfoLessAvailability());
|
||||
ASSERT_EQ(data_dir_infos[0].available, 100);
|
||||
ASSERT_EQ(data_dir_infos[1].available, 200);
|
||||
ASSERT_EQ(data_dir_infos[2].available, 300);
|
||||
ASSERT_EQ(data_dir_infos[3].available, 400);
|
||||
}
|
||||
|
||||
} // namespace doris
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user