be/src/load/load_path_mgr.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <stdint.h> |
21 | | #include <time.h> |
22 | | |
23 | | #include <mutex> |
24 | | #include <string> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "util/countdown_latch.h" |
29 | | #include "util/once.h" |
30 | | |
31 | | namespace doris { |
32 | | |
33 | | class TUniqueId; |
34 | | class ExecEnv; |
35 | | class Thread; |
36 | | |
37 | | // In every directory, '.trash' directory is used to save data need to delete |
38 | | // daemon thread is check no used directory to delete |
39 | | class LoadPathMgr { |
40 | | public: |
41 | | LoadPathMgr(ExecEnv* env); |
42 | 4 | ~LoadPathMgr() = default; |
43 | | |
44 | | Status init(); |
45 | | void stop(); |
46 | | |
47 | | Status allocate_dir(const std::string& db, const std::string& label, std::string* prefix, |
48 | | int64_t file_bytes); |
49 | | |
50 | | bool check_disk_space(size_t disk_capacity_bytes, size_t available_bytes, int64_t file_bytes); |
51 | | |
52 | | void get_load_data_path(std::vector<std::string>* data_paths); |
53 | | |
54 | | Status get_load_error_file_name(const std::string& db, const std::string& label, |
55 | | const TUniqueId& fragment_instance_id, std::string* error_path); |
56 | | std::string get_load_error_absolute_path(const std::string& file_path); |
57 | 8 | const std::string& get_load_error_file_dir() const { return _error_log_dir; } |
58 | | |
59 | 19 | void clean_tmp_files(const std::string& file_path) { clean_files_in_path_vec(file_path); } |
60 | | |
61 | | private: |
62 | | bool is_too_old(time_t cur_time, const std::string& label_dir, int64_t reserve_hours); |
63 | | void clean_one_path(const std::string& path); |
64 | | void clean_error_log(); |
65 | | void clean(); |
66 | | void process_path(time_t now, const std::string& path, int64_t reserve_hours); |
67 | | |
68 | | void clean_files_in_path_vec(const std::string& path); |
69 | | |
70 | | ExecEnv* _exec_env = nullptr; |
71 | | std::mutex _lock; |
72 | | std::vector<std::string> _path_vec; |
73 | | int _idx; |
74 | | int64_t _reserved_hours; |
75 | | std::string _error_log_dir; |
76 | | uint32_t _next_shard; |
77 | | uint32_t _error_path_next_shard; |
78 | | CountDownLatch _stop_background_threads_latch; |
79 | | std::shared_ptr<Thread> _clean_thread; |
80 | | DorisCallOnce<Status> _init_once; |
81 | | }; |
82 | | |
83 | | } // namespace doris |