From ef10d156581eb2ebdbe24454ddb25b141553fd2a Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Thu, 23 May 2024 17:55:40 +0800 Subject: [PATCH] fix: [2.4]Throw an exception after all the threads in thread pool finished (#32810) (#33314) issue: #32487 master pr: #32810 Signed-off-by: Cai Zhang --- internal/core/src/storage/Util.cpp | 49 ++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/internal/core/src/storage/Util.cpp b/internal/core/src/storage/Util.cpp index 0e714f0a97..33df073cef 100644 --- a/internal/core/src/storage/Util.cpp +++ b/internal/core/src/storage/Util.cpp @@ -575,11 +575,22 @@ GetObjectData(std::shared_ptr space, } std::vector datas; - for (int i = 0; i < futures.size(); ++i) { - auto res = futures[i].get(); - datas.emplace_back(res->GetFieldData()); + std::exception_ptr first_exception = nullptr; + for (auto& future : futures) { + try { + auto res = future.get(); + datas.emplace_back(res->GetFieldData()); + } catch (...) { + if (!first_exception) { + first_exception = std::current_exception(); + } + } } ReleaseArrowUnused(); + if (first_exception) { + std::rethrow_exception(first_exception); + } + return datas; } @@ -612,12 +623,22 @@ PutIndexData(ChunkManager* remote_chunk_manager, } std::map remote_paths_to_size; + std::exception_ptr first_exception = nullptr; for (auto& future : futures) { - auto res = future.get(); - remote_paths_to_size[res.first] = res.second; + try { + auto res = future.get(); + remote_paths_to_size[res.first] = res.second; + } catch (...) { + if (!first_exception) { + first_exception = std::current_exception(); + } + } + } + ReleaseArrowUnused(); + if (first_exception) { + std::rethrow_exception(first_exception); } - ReleaseArrowUnused(); return remote_paths_to_size; } @@ -650,12 +671,22 @@ PutIndexData(std::shared_ptr space, } std::map remote_paths_to_size; + std::exception_ptr first_exception = nullptr; for (auto& future : futures) { - auto res = future.get(); - remote_paths_to_size[res.first] = res.second; + try { + auto res = future.get(); + remote_paths_to_size[res.first] = res.second; + } catch (...) { + if (!first_exception) { + first_exception = std::current_exception(); + } + } + } + ReleaseArrowUnused(); + if (first_exception) { + std::rethrow_exception(first_exception); } - ReleaseArrowUnused(); return remote_paths_to_size; }