Skip to content

Commit 1ec32ec

Browse files
Merge branch 'apache:master' into s7
2 parents 02a6613 + 73fe371 commit 1ec32ec

File tree

101 files changed

+3910
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3910
-505
lines changed

be/src/http/action/file_cache_action.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ constexpr static std::string_view BASE_PATH = "base_path";
5858
constexpr static std::string_view RELEASED_ELEMENTS = "released_elements";
5959
constexpr static std::string_view DUMP = "dump";
6060
constexpr static std::string_view VALUE = "value";
61+
constexpr static std::string_view RELOAD = "reload";
6162

6263
Status FileCacheAction::_handle_header(HttpRequest* req, std::string* json_metrics) {
6364
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.data());
@@ -161,6 +162,41 @@ Status FileCacheAction::_handle_header(HttpRequest* req, std::string* json_metri
161162
*json_metrics = json.ToString();
162163
}
163164
}
165+
} else if (operation == RELOAD) {
166+
#ifdef BE_TEST
167+
std::string doris_home = getenv("DORIS_HOME");
168+
std::string conffile = std::string(doris_home) + "/conf/be.conf";
169+
if (!doris::config::init(conffile.c_str(), true, true, true)) {
170+
return Status::InternalError("Error reading config file");
171+
}
172+
173+
std::string custom_conffile = doris::config::custom_config_dir + "/be_custom.conf";
174+
if (!doris::config::init(custom_conffile.c_str(), true, false, false)) {
175+
return Status::InternalError("Error reading custom config file");
176+
}
177+
178+
if (!doris::config::enable_file_cache) {
179+
return Status::InternalError("config::enbale_file_cache should be true!");
180+
}
181+
182+
std::unordered_set<std::string> cache_path_set;
183+
std::vector<doris::CachePath> cache_paths;
184+
RETURN_IF_ERROR(doris::parse_conf_cache_paths(doris::config::file_cache_path, cache_paths));
185+
186+
std::vector<CachePath> cache_paths_no_dup;
187+
cache_paths_no_dup.reserve(cache_paths.size());
188+
for (const auto& cache_path : cache_paths) {
189+
if (cache_path_set.contains(cache_path.path)) {
190+
LOG(WARNING) << fmt::format("cache path {} is duplicate", cache_path.path);
191+
continue;
192+
}
193+
cache_path_set.emplace(cache_path.path);
194+
cache_paths_no_dup.emplace_back(cache_path);
195+
}
196+
RETURN_IF_ERROR(doris::io::FileCacheFactory::instance()->reload_file_cache(cache_paths));
197+
#else
198+
return Status::InternalError("Do not use reload in production environment!!!!");
199+
#endif
164200
} else {
165201
st = Status::InternalError("invalid operation: {}", operation);
166202
}

be/src/io/cache/block_file_cache_factory.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,42 @@ Status FileCacheFactory::create_file_cache(const std::string& cache_base_path,
120120
return Status::OK();
121121
}
122122

123+
Status FileCacheFactory::reload_file_cache(const std::vector<CachePath>& cache_base_paths) {
124+
{
125+
std::unique_lock lock(_mtx);
126+
for (const auto& cache_path : cache_base_paths) {
127+
if (_path_to_cache.find(cache_path.path) == _path_to_cache.end()) {
128+
return Status::InternalError(
129+
"Current file cache not support file cache num changes");
130+
}
131+
}
132+
133+
for (const auto& cache_path : cache_base_paths) {
134+
auto cache_map_iter = _path_to_cache.find(cache_path.path);
135+
auto cache_iter = std::find_if(_caches.begin(), _caches.end(),
136+
[cache_map_iter](const auto& cache_uptr) {
137+
return cache_uptr.get() == cache_map_iter->second;
138+
});
139+
140+
if (cache_iter == _caches.end()) {
141+
return Status::InternalError("Target relaod cache in path {} may has been released",
142+
cache_path.path);
143+
}
144+
145+
// deconstruct target reload first
146+
*cache_iter = std::unique_ptr<BlockFileCache>();
147+
// after deconstruct the BlockFileCache, construct the BlockFileCache again
148+
*cache_iter =
149+
std::make_unique<BlockFileCache>(cache_path.path, cache_path.init_settings());
150+
cache_map_iter->second = cache_iter->get();
151+
152+
RETURN_IF_ERROR(cache_iter->get()->initialize());
153+
}
154+
}
155+
156+
return Status::OK();
157+
}
158+
123159
std::vector<doris::CacheBlockPB> FileCacheFactory::get_cache_data_by_path(const std::string& path) {
124160
auto cache_hash = BlockFileCache::hash(path);
125161
return get_cache_data_by_path(cache_hash);

be/src/io/cache/block_file_cache_factory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "gen_cpp/internal_service.pb.h"
3131
#include "io/cache/block_file_cache.h"
3232
#include "io/cache/file_cache_common.h"
33+
#include "olap/options.h"
3334
namespace doris {
3435
class TUniqueId;
3536

@@ -49,6 +50,8 @@ class FileCacheFactory {
4950
Status create_file_cache(const std::string& cache_base_path,
5051
FileCacheSettings file_cache_settings);
5152

53+
Status reload_file_cache(const std::vector<CachePath>& cache_base_paths);
54+
5255
size_t try_release();
5356

5457
size_t try_release(const std::string& base_path);

be/src/io/cache/fs_file_cache_storage.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <filesystem>
2727
#include <mutex>
2828
#include <system_error>
29+
#include <vector>
2930

3031
#include "common/logging.h"
3132
#include "common/status.h"
@@ -877,8 +878,8 @@ void FSFileCacheStorage::load_cache_info_into_memory(BlockFileCache* _mgr) const
877878
// If the difference is more than threshold, load from filesystem as well
878879
if (estimated_file_count > 100) {
879880
double difference_ratio =
880-
static_cast<double>(estimated_file_count) -
881-
static_cast<double>(db_block_count) / static_cast<double>(estimated_file_count);
881+
(static_cast<double>(estimated_file_count) - static_cast<double>(db_block_count)) /
882+
static_cast<double>(estimated_file_count);
882883

883884
if (difference_ratio > config::file_cache_meta_store_vs_file_system_diff_num_threshold) {
884885
LOG(WARNING) << "Significant difference between DB blocks (" << db_block_count
@@ -983,13 +984,53 @@ size_t FSFileCacheStorage::estimate_file_count_from_statfs() const {
983984
// Get total size of cache directory to estimate file count
984985
std::error_code ec;
985986
uintmax_t total_size = 0;
986-
for (const auto& entry : std::filesystem::recursive_directory_iterator(_cache_base_path, ec)) {
987+
std::vector<std::filesystem::path> pending_dirs {std::filesystem::path(_cache_base_path)};
988+
while (!pending_dirs.empty()) {
989+
auto current_dir = pending_dirs.back();
990+
pending_dirs.pop_back();
991+
992+
std::filesystem::directory_iterator it(current_dir, ec);
987993
if (ec) {
988-
LOG(WARNING) << "Error accessing directory entry: " << ec.message();
994+
LOG(WARNING) << "Failed to list directory while estimating file count, dir="
995+
<< current_dir << ", err=" << ec.message();
996+
ec.clear();
989997
continue;
990998
}
991-
if (entry.is_regular_file()) {
992-
total_size += entry.file_size();
999+
1000+
for (; it != std::filesystem::directory_iterator(); ++it) {
1001+
std::error_code status_ec;
1002+
auto entry_status = it->symlink_status(status_ec);
1003+
TEST_SYNC_POINT_CALLBACK(
1004+
"FSFileCacheStorage::estimate_file_count_from_statfs::AfterEntryStatus",
1005+
&status_ec);
1006+
if (status_ec) {
1007+
LOG(WARNING) << "Failed to stat entry while estimating file count, path="
1008+
<< it->path() << ", err=" << status_ec.message();
1009+
continue;
1010+
}
1011+
1012+
if (std::filesystem::is_directory(entry_status)) {
1013+
auto next_dir = it->path();
1014+
TEST_SYNC_POINT_CALLBACK(
1015+
"FSFileCacheStorage::estimate_file_count_from_statfs::OnDirectory",
1016+
&next_dir);
1017+
pending_dirs.emplace_back(next_dir);
1018+
continue;
1019+
}
1020+
1021+
if (std::filesystem::is_regular_file(entry_status)) {
1022+
std::error_code size_ec;
1023+
auto file_size = it->file_size(size_ec);
1024+
TEST_SYNC_POINT_CALLBACK(
1025+
"FSFileCacheStorage::estimate_file_count_from_statfs::AfterFileSize",
1026+
&size_ec);
1027+
if (size_ec) {
1028+
LOG(WARNING) << "Failed to get file size while estimating file count, path="
1029+
<< it->path() << ", err=" << size_ec.message();
1030+
continue;
1031+
}
1032+
total_size += file_size;
1033+
}
9931034
}
9941035
}
9951036

0 commit comments

Comments
 (0)