From a820cdb19432d19d962c42353c348c6b2ea78145 Mon Sep 17 00:00:00 2001 From: dimitrisstaratzis Date: Wed, 13 Mar 2024 20:14:31 +0200 Subject: [PATCH] throw error when an upload fails due to bad state --- tiledb/sm/filesystem/s3.cc | 30 ++++++++++++++---------------- tiledb/sm/filesystem/s3.h | 4 +++- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tiledb/sm/filesystem/s3.cc b/tiledb/sm/filesystem/s3.cc index d1d13b5e72d8..c538bfcfbf1d 100644 --- a/tiledb/sm/filesystem/s3.cc +++ b/tiledb/sm/filesystem/s3.cc @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -633,13 +634,11 @@ Status S3::disconnect() { Aws::S3::Model::AbortMultipartUploadRequest abort_request = make_multipart_abort_request(*state); auto outcome = client_->AbortMultipartUpload(abort_request); - if (!outcome.IsSuccess()) { - const Status st = LOG_STATUS(Status_S3Error( - std::string("Failed to disconnect and flush S3 objects. ") + - outcome_error_message(outcome))); - if (!st.ok()) { - ret_st = st; - } + const Status st = LOG_STATUS(Status_S3Error( + std::string("Failed to disconnect and flush S3 objects. ") + + outcome_error_message(outcome))); + if (!st.ok()) { + ret_st = st; } } return Status::Ok(); @@ -714,7 +713,7 @@ Status S3::flush_object(const URI& uri) { throw_if_not_ok(wait_for_object_to_propagate(move(bucket), move(key))); - return finish_flush_object(std::move(outcome), uri, buff); + return finish_flush_object(std::move(outcome), uri, buff, false); } else { Aws::S3::Model::AbortMultipartUploadRequest abort_request = make_multipart_abort_request(*state); @@ -723,7 +722,7 @@ Status S3::flush_object(const URI& uri) { state_lck.unlock(); - return finish_flush_object(std::move(outcome), uri, buff); + return finish_flush_object(std::move(outcome), uri, buff, true); } } @@ -799,11 +798,9 @@ void S3::finalize_and_flush_object(const URI& uri) { make_multipart_abort_request(state); auto outcome = client_->AbortMultipartUpload(abort_request); - if (!outcome.IsSuccess()) { - throw S3Exception{ - std::string("Failed to flush S3 object ") + uri.c_str() + - outcome_error_message(outcome)}; - } + throw S3Exception{ + std::string("Failed to flush S3 object ") + uri.c_str() + + outcome_error_message(outcome)}; } // Remove intermediate chunk files if any @@ -1689,7 +1686,8 @@ template Status S3::finish_flush_object( const Aws::Utils::Outcome& outcome, const URI& uri, - Buffer* const buff) { + Buffer* const buff, + bool is_abort) { Aws::Http::URI aws_uri = uri.c_str(); UniqueWriteLock unique_wl(&multipart_upload_rwlock_); @@ -1701,7 +1699,7 @@ Status S3::finish_flush_object( file_buffers_lck.unlock(); tdb_delete(buff); - if (!outcome.IsSuccess()) { + if (!outcome.IsSuccess() || is_abort) { return LOG_STATUS(Status_S3Error( std::string("Failed to flush S3 object ") + uri.c_str() + outcome_error_message(outcome))); diff --git a/tiledb/sm/filesystem/s3.h b/tiledb/sm/filesystem/s3.h index ebbe827a59a4..82a905dc3138 100644 --- a/tiledb/sm/filesystem/s3.h +++ b/tiledb/sm/filesystem/s3.h @@ -1509,13 +1509,15 @@ class S3 : FilesystemBase { * @param outcome The returned outcome from the complete or abort request. * @param uri The URI of the S3 file to be written to. * @param buff The file buffer associated with 'uri'. + * @param abort Should be true only when this is an abort request. * @return Status */ template Status finish_flush_object( const Aws::Utils::Outcome& outcome, const URI& uri, - Buffer* const buff); + Buffer* const buff, + bool is_abort); /** * Writes the input buffer to a file by issuing one PutObject