Skip to content

Commit

Permalink
[opt](file cache) set failed_if_exists=true when create the cache dir…
Browse files Browse the repository at this point in the history
…ectory (#35096)

follow up: #34935
There are many segment files for a cache remote file, so the cached directory will create many times. Therefore, we should call `fs->create_directory(dir, failed_if_exists=false)` instead of `fs->create_directory(dir, failed_if_exists=true)`.
When `failed_if_exists=true`, the next line `if (!st.ok() && !st.is<ErrorCode::ALREADY_EXIST>())` try to prevent the `ALREADY_EXIST` errors.
  • Loading branch information
AshinGau authored May 21, 2024
1 parent 807bd67 commit c004fe4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 0 additions & 2 deletions be/src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ class [[nodiscard]] Status {
if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
// Delete the first one frame pointers, which are inside the status.h
status._err_msg->_stack = get_stack_trace(1);
LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
}
#endif
return status;
Expand All @@ -431,7 +430,6 @@ class [[nodiscard]] Status {
#ifdef ENABLE_STACKTRACE
if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
status._err_msg->_stack = get_stack_trace(1);
LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
}
#endif
return status;
Expand Down
2 changes: 1 addition & 1 deletion be/src/io/cache/fs_file_cache_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Status FSFileCacheStorage::append(const FileCacheKey& key, const Slice& value) {
writer = iter->second.get();
} else {
std::string dir = get_path_in_local_cache(key.hash, key.meta.expiration_time);
auto st = fs->create_directory(dir, true);
auto st = fs->create_directory(dir, false);
if (!st.ok() && !st.is<ErrorCode::ALREADY_EXIST>()) {
return st;
}
Expand Down
20 changes: 10 additions & 10 deletions be/src/io/fs/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ Status LocalFileSystem::open_file_impl(const Path& file, FileReaderSPtr* reader,
}

Status LocalFileSystem::create_directory_impl(const Path& dir, bool failed_if_exists) {
if (failed_if_exists) {
bool exists = true;
RETURN_IF_ERROR(exists_impl(dir, &exists));
if (exists) {
return Status::AlreadyExist("failed to create {}, already exists", dir.native());
}
bool exists = true;
RETURN_IF_ERROR(exists_impl(dir, &exists));
if (exists && failed_if_exists) {
return Status::AlreadyExist("failed to create {}, already exists", dir.native());
}
std::error_code ec;
std::filesystem::create_directories(dir, ec);
if (ec) {
return localfs_error(ec, fmt::format("failed to create {}", dir.native()));
if (!exists) {
std::error_code ec;
std::filesystem::create_directories(dir, ec);
if (ec) {
return localfs_error(ec, fmt::format("failed to create {}", dir.native()));
}
}
return Status::OK();
}
Expand Down

0 comments on commit c004fe4

Please sign in to comment.