Skip to content

Commit

Permalink
[fix](binlog) Avoid clear binlog dir #45581 (#45620)
Browse files Browse the repository at this point in the history
cherry pick from #45581
  • Loading branch information
w41ter authored Dec 19, 2024
1 parent cc691b6 commit c459ad7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions be/src/olap/rowset/beta_rowset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "olap/rowset/beta_rowset.h"

#include <ctype.h>
#include <errno.h>
#include <fmt/format.h>

#include <algorithm>
Expand Down Expand Up @@ -549,9 +550,6 @@ Status BetaRowset::add_to_binlog() {
}
auto* local_fs = static_cast<io::LocalFileSystem*>(fs.get());

// all segments are in the same directory, so cache binlog_dir without multi times check
std::string binlog_dir;

auto segments_num = num_segments();
VLOG_DEBUG << fmt::format("add rowset to binlog. rowset_id={}, segments_num={}",
rowset_id().to_string(), segments_num);
Expand All @@ -571,6 +569,12 @@ Status BetaRowset::add_to_binlog() {
}
}};

// The publish_txn might fail even if the add_to_binlog success, so we need to check
// whether a file already exists before linking.
auto errno_is_file_exists = []() { return Errno::no() == EEXIST; };

// all segments are in the same directory, so cache binlog_dir without multi times check
std::string binlog_dir;
for (int i = 0; i < segments_num; ++i) {
auto seg_file = segment_file_path(i);

Expand All @@ -588,7 +592,7 @@ Status BetaRowset::add_to_binlog() {
(std::filesystem::path(binlog_dir) / std::filesystem::path(seg_file).filename())
.string();
VLOG_DEBUG << "link " << seg_file << " to " << binlog_file;
if (!local_fs->link_file(seg_file, binlog_file).ok()) {
if (!local_fs->link_file(seg_file, binlog_file).ok() && !errno_is_file_exists()) {
status = Status::Error<OS_ERROR>("fail to create hard link. from={}, to={}, errno={}",
seg_file, binlog_file, Errno::no());
return status;
Expand All @@ -607,7 +611,8 @@ Status BetaRowset::add_to_binlog() {
std::filesystem::path(index_file).filename())
.string();
VLOG_DEBUG << "link " << index_file << " to " << binlog_index_file;
if (!local_fs->link_file(index_file, binlog_index_file).ok()) {
if (!local_fs->link_file(index_file, binlog_index_file).ok() &&
!errno_is_file_exists()) {
status = Status::Error<OS_ERROR>(
"fail to create hard link. from={}, to={}, errno={}", index_file,
binlog_index_file, Errno::no());
Expand All @@ -622,7 +627,8 @@ Status BetaRowset::add_to_binlog() {
std::filesystem::path(index_file).filename())
.string();
VLOG_DEBUG << "link " << index_file << " to " << binlog_index_file;
if (!local_fs->link_file(index_file, binlog_index_file).ok()) {
if (!local_fs->link_file(index_file, binlog_index_file).ok() &&
!errno_is_file_exists()) {
status = Status::Error<OS_ERROR>(
"fail to create hard link. from={}, to={}, errno={}", index_file,
binlog_index_file, Errno::no());
Expand Down

0 comments on commit c459ad7

Please sign in to comment.