Merge pull request #46451 from ClickHouse/copy-s3-file-fix

Wait for tasks finish when scheduler failed
This commit is contained in:
Dmitry Novik 2023-02-17 20:11:23 +01:00 committed by GitHub
commit 197116dfeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,17 +66,7 @@ namespace
{
}
virtual ~UploadHelper()
{
try
{
waitForAllBackGroundTasks();
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
virtual ~UploadHelper() = default;
protected:
std::shared_ptr<const S3::Client> client_ptr;
@ -219,17 +209,29 @@ 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__);
// Multipart upload failed because it wasn't possible to schedule all the tasks.
// To avoid execution of already scheduled tasks we abort MultipartUpload.
abortMultipartUpload();
waitForAllBackGroundTasks();
throw;
}
waitForAllBackGroundTasks();