diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h index 48cba42a86..9e0ebe9f83 100644 --- a/be/src/olap/olap_common.h +++ b/be/src/olap/olap_common.h @@ -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 { diff --git a/be/src/olap/storage_engine.cpp b/be/src/olap/storage_engine.cpp index 7fe2f8549c..ed73ce242f 100644 --- a/be/src/olap/storage_engine.cpp +++ b/be/src/olap/storage_engine.cpp @@ -593,6 +593,7 @@ OLAPStatus StorageEngine::_start_trash_sweep(double* usage) { std::vector 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; } diff --git a/be/test/olap/CMakeLists.txt b/be/test/olap/CMakeLists.txt index 34152e9e4a..5256cb3c2c 100644 --- a/be/test/olap/CMakeLists.txt +++ b/be/test/olap/CMakeLists.txt @@ -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) diff --git a/be/test/olap/common_test.cpp b/be/test/olap/common_test.cpp new file mode 100644 index 0000000000..e3750e1330 --- /dev/null +++ b/be/test/olap/common_test.cpp @@ -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 + +#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 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(); +}