Skip to content

Commit be8b3fe

Browse files
authored
fix: add ScopeGuard to wait async tasks before early return in OrphanFilesCleanerImpl::Clean() (#307) (#150)
1 parent f98d67e commit be8b3fe

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/paimon/common/executor/future.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace paimon {
4747
/// execution.
4848
///
4949
/// @note If `func` returns `void`, the returned future is of type `std::future<void>`.
50+
///
51+
/// TODO: Since paimon-cpp uses `Status`/`Result` for error handling throughout, the exception
52+
/// capture logic (try/catch + set_exception) in `Via()` will be removed in the future.
5053
template <typename Func>
5154
auto Via(Executor* executor, Func&& func) -> std::future<decltype(func())> {
5255
using ResultType = decltype(func());

src/paimon/core/operation/orphan_files_cleaner_impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ Result<std::set<std::string>> OrphanFilesCleanerImpl::Clean() {
9999
}
100100
PAIMON_ASSIGN_OR_RAISE(std::set<std::string> all_dirs, ListPaimonFileDirs());
101101
std::vector<std::future<std::vector<std::unique_ptr<FileStatus>>>> file_statuses_futures;
102+
ScopeGuard file_statuses_guard(
103+
[&file_statuses_futures]() { CollectAll(file_statuses_futures); });
102104
for (const auto& dir : all_dirs) {
103105
file_statuses_futures.push_back(
104106
Via(executor_.get(), [this, dir] { return TryBestListingDirs(dir); }));
105107
}
106108
PAIMON_ASSIGN_OR_RAISE(std::set<std::string> used_file_names, GetUsedFiles());
109+
file_statuses_guard.Release();
107110

108111
Duration duration;
109112
std::set<std::string> need_to_deletes;

0 commit comments

Comments
 (0)