Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions be/src/http/action/file_cache_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ constexpr static std::string_view BASE_PATH = "base_path";
constexpr static std::string_view RELEASED_ELEMENTS = "released_elements";
constexpr static std::string_view DUMP = "dump";
constexpr static std::string_view VALUE = "value";
constexpr static std::string_view RELOAD = "reload";

Status FileCacheAction::_handle_header(HttpRequest* req, std::string* json_metrics) {
req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.data());
Expand Down Expand Up @@ -161,6 +162,41 @@ Status FileCacheAction::_handle_header(HttpRequest* req, std::string* json_metri
*json_metrics = json.ToString();
}
}
} else if (operation == RELOAD) {
#ifdef BE_TEST
std::string doris_home = getenv("DORIS_HOME");
std::string conffile = std::string(doris_home) + "/conf/be.conf";
if (!doris::config::init(conffile.c_str(), true, true, true)) {
return Status::InternalError("Error reading config file");
}

std::string custom_conffile = doris::config::custom_config_dir + "/be_custom.conf";
if (!doris::config::init(custom_conffile.c_str(), true, false, false)) {
return Status::InternalError("Error reading custom config file");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be_custom.conf is optional

}

if (!doris::config::enable_file_cache) {
return Status::InternalError("config::enbale_file_cache should be true!");
}

std::unordered_set<std::string> cache_path_set;
std::vector<doris::CachePath> cache_paths;
RETURN_IF_ERROR(doris::parse_conf_cache_paths(doris::config::file_cache_path, cache_paths));

std::vector<CachePath> cache_paths_no_dup;
cache_paths_no_dup.reserve(cache_paths.size());
for (const auto& cache_path : cache_paths) {
if (cache_path_set.contains(cache_path.path)) {
LOG(WARNING) << fmt::format("cache path {} is duplicate", cache_path.path);
continue;
}
cache_path_set.emplace(cache_path.path);
cache_paths_no_dup.emplace_back(cache_path);
}
RETURN_IF_ERROR(doris::io::FileCacheFactory::instance()->reload_file_cache(cache_paths));
#else
return Status::InternalError("Do not use reload in production environment!!!!");
#endif
} else {
st = Status::InternalError("invalid operation: {}", operation);
}
Expand Down
36 changes: 36 additions & 0 deletions be/src/io/cache/block_file_cache_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ Status FileCacheFactory::create_file_cache(const std::string& cache_base_path,
return Status::OK();
}

Status FileCacheFactory::reload_file_cache(const std::vector<CachePath>& cache_base_paths) {
{
std::unique_lock lock(_mtx);
for (const auto& cache_path : cache_base_paths) {
if (_path_to_cache.find(cache_path.path) == _path_to_cache.end()) {
return Status::InternalError(
"Current file cache not support file cache num changes");
}
}

for (const auto& cache_path : cache_base_paths) {
auto cache_map_iter = _path_to_cache.find(cache_path.path);
auto cache_iter = std::find_if(_caches.begin(), _caches.end(),
[cache_map_iter](const auto& cache_uptr) {
return cache_uptr.get() == cache_map_iter->second;
});

if (cache_iter == _caches.end()) {
return Status::InternalError("Target relaod cache in path {} may has been released",
cache_path.path);
}

// deconstruct target reload first
*cache_iter = std::unique_ptr<BlockFileCache>();
// after deconstruct the BlockFileCache, construct the BlockFileCache again
*cache_iter =
std::make_unique<BlockFileCache>(cache_path.path, cache_path.init_settings());
cache_map_iter->second = cache_iter->get();

RETURN_IF_ERROR(cache_iter->get()->initialize());
}
}

return Status::OK();
}

std::vector<doris::CacheBlockPB> FileCacheFactory::get_cache_data_by_path(const std::string& path) {
auto cache_hash = BlockFileCache::hash(path);
return get_cache_data_by_path(cache_hash);
Expand Down
3 changes: 3 additions & 0 deletions be/src/io/cache/block_file_cache_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "gen_cpp/internal_service.pb.h"
#include "io/cache/block_file_cache.h"
#include "io/cache/file_cache_common.h"
#include "olap/options.h"
namespace doris {
class TUniqueId;

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

Status reload_file_cache(const std::vector<CachePath>& cache_base_paths);

size_t try_release();

size_t try_release(const std::string& base_path);
Expand Down
Loading
Loading