From e740f5f86cb4602714c0c42705eaa402eb8557fb Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 6 Dec 2021 13:58:11 +0300 Subject: [PATCH] Try a few times to find the new binlog after renaming it. This could help on some virtual file systems like /mnt directory on WSL 2.0. --- tddb/td/db/binlog/Binlog.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index 873cfd6c8..7af598373 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -16,6 +16,7 @@ #include "td/utils/port/FileFd.h" #include "td/utils/port/path.h" #include "td/utils/port/PollFlags.h" +#include "td/utils/port/sleep.h" #include "td/utils/port/Stat.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" @@ -670,14 +671,19 @@ void Binlog::do_reindex() { auto finish_time = Clocks::monotonic(); auto finish_size = fd_size_; auto finish_events = fd_events_; - { + for (size_t i = 10; i > 0; i--) { auto r_stat = stat(path_); if (r_stat.is_error()) { + if (i != 1) { + usleep_for(200000 / i); + continue; + } LOG(FATAL) << "Failed to rename binlog of size " << fd_size_ << " to " << path_ << ": " << r_stat.error() - << ". Old file size is " << detail::file_size(new_path); + << ". Temp file size is " << detail::file_size(new_path) << ", new size " << detail::file_size(path_); } LOG_CHECK(fd_size_ == r_stat.ok().size_) << fd_size_ << ' ' << r_stat.ok().size_ << ' ' << detail::file_size(new_path) << ' ' << fd_events_ << ' ' << path_; + break; } auto ratio = static_cast(start_size) / static_cast(finish_size + 1);