You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ya...@apache.org on 2021/03/12 05:43:37 UTC

[incubator-doris] branch master updated: [Enhance] Sort directories by available space when do trash sweep (#5498)

This is an automated email from the ASF dual-hosted git repository.

yangzhg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ead0aa  [Enhance] Sort directories by available space when do trash sweep (#5498)
8ead0aa is described below

commit 8ead0aaad80c4b570b59bf6cf741d28d71ea0e25
Author: Yingchun Lai <40...@qq.com>
AuthorDate: Fri Mar 12 13:43:27 2021 +0800

    [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
---
 be/src/olap/olap_common.h      | 22 +++++++++++--------
 be/src/olap/storage_engine.cpp |  2 ++
 be/test/olap/CMakeLists.txt    |  1 +
 be/test/olap/common_test.cpp   | 50 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h
index 48cba42..9e0ebe9 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 7fe2f85..ed73ce2 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<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;
         }
diff --git a/be/test/olap/CMakeLists.txt b/be/test/olap/CMakeLists.txt
index 34152e9..5256cb3 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 0000000..e3750e1
--- /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 <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();
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org