From cfb832b20528080e20cd3fa557ab2fb596936a7a Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Wed, 15 Feb 2023 15:50:06 +0000 Subject: [PATCH] Wait for tasks finish when scheduler failed --- src/IO/S3/copyS3File.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/IO/S3/copyS3File.cpp b/src/IO/S3/copyS3File.cpp index 7f48c338d06..f687fcca8ae 100644 --- a/src/IO/S3/copyS3File.cpp +++ b/src/IO/S3/copyS3File.cpp @@ -66,17 +66,7 @@ namespace { } - virtual ~UploadHelper() - { - try - { - waitForAllBackGroundTasks(); - } - catch (...) - { - tryLogCurrentException(__PRETTY_FUNCTION__); - } - } + virtual ~UploadHelper() = default; protected: std::shared_ptr client_ptr; @@ -219,17 +209,27 @@ namespace size_t position = start_offset; size_t end_position = start_offset + size; - for (size_t part_number = 1; position < end_position; ++part_number) + try { - if (multipart_upload_aborted) - break; /// No more part uploads. + for (size_t part_number = 1; position < end_position; ++part_number) + { + if (multipart_upload_aborted) + break; /// No more part uploads. - size_t next_position = std::min(position + normal_part_size, end_position); - size_t part_size = next_position - position; /// `part_size` is either `normal_part_size` or smaller if it's the final part. + size_t next_position = std::min(position + normal_part_size, end_position); + size_t part_size = next_position - position; /// `part_size` is either `normal_part_size` or smaller if it's the final part. - uploadPart(part_number, position, part_size); + uploadPart(part_number, position, part_size); - position = next_position; + position = next_position; + } + } + catch (...) + { + tryLogCurrentException(__PRETTY_FUNCTION__); + abortMultipartUpload(); + waitForAllBackGroundTasks(); + throw; } waitForAllBackGroundTasks();