Skip to content

Commit 433487e

Browse files
authored
fix: add ScopeGuard to wait async tasks before early return in OrphanFilesCleanerImpl::Clean() (alibaba#307)
1 parent 10ef482 commit 433487e

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
@@ -45,6 +45,9 @@ namespace paimon {
4545
/// execution.
4646
///
4747
/// @note If `func` returns `void`, the returned future is of type `std::future<void>`.
48+
///
49+
/// TODO: Since paimon-cpp uses `Status`/`Result` for error handling throughout, the exception
50+
/// capture logic (try/catch + set_exception) in `Via()` will be removed in the future.
4851
template <typename Func>
4952
auto Via(Executor* executor, Func&& func) -> std::future<decltype(func())> {
5053
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
@@ -97,11 +97,14 @@ Result<std::set<std::string>> OrphanFilesCleanerImpl::Clean() {
9797
}
9898
PAIMON_ASSIGN_OR_RAISE(std::set<std::string> all_dirs, ListPaimonFileDirs());
9999
std::vector<std::future<std::vector<std::unique_ptr<FileStatus>>>> file_statuses_futures;
100+
ScopeGuard file_statuses_guard(
101+
[&file_statuses_futures]() { CollectAll(file_statuses_futures); });
100102
for (const auto& dir : all_dirs) {
101103
file_statuses_futures.push_back(
102104
Via(executor_.get(), [this, dir] { return TryBestListingDirs(dir); }));
103105
}
104106
PAIMON_ASSIGN_OR_RAISE(std::set<std::string> used_file_names, GetUsedFiles());
107+
file_statuses_guard.Release();
105108

106109
Duration duration;
107110
std::set<std::string> need_to_deletes;

0 commit comments

Comments
 (0)