Skip to content

Commit 8e12694

Browse files
[opt](filecache) support config hot reload of file cache microbench in running state (#58922)
Co-authored-by: LHG41278 <[email protected]>
1 parent 9c39ca3 commit 8e12694

File tree

5 files changed

+506
-207
lines changed

5 files changed

+506
-207
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);

0 commit comments

Comments
 (0)