Merge pull request #71038 from vitlibar/fix-error-message-in-read-buffer-from-s3

Fix showing error message in ReadBufferFromS3 when retrying
This commit is contained in:
Vitaly Baranov 2024-10-25 13:05:52 +00:00 committed by GitHub
commit 7ae91eeda6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 9 deletions

View File

@ -138,9 +138,9 @@ bool ReadBufferFromS3::nextImpl()
next_result = impl->next();
break;
}
catch (Poco::Exception & e)
catch (...)
{
if (!processException(e, getPosition(), attempt) || last_attempt)
if (!processException(getPosition(), attempt) || last_attempt)
throw;
/// Pause before next attempt.
@ -202,9 +202,9 @@ size_t ReadBufferFromS3::readBigAt(char * to, size_t n, size_t range_begin, cons
/// Read remaining bytes after the end of the payload
istr.ignore(INT64_MAX);
}
catch (Poco::Exception & e)
catch (...)
{
if (!processException(e, range_begin, attempt) || last_attempt)
if (!processException(range_begin, attempt) || last_attempt)
throw;
sleepForMilliseconds(sleep_time_with_backoff_milliseconds);
@ -219,7 +219,7 @@ size_t ReadBufferFromS3::readBigAt(char * to, size_t n, size_t range_begin, cons
return initial_n;
}
bool ReadBufferFromS3::processException(Poco::Exception & e, size_t read_offset, size_t attempt) const
bool ReadBufferFromS3::processException(size_t read_offset, size_t attempt) const
{
ProfileEvents::increment(ProfileEvents::ReadBufferFromS3RequestsErrors, 1);
@ -227,10 +227,11 @@ bool ReadBufferFromS3::processException(Poco::Exception & e, size_t read_offset,
log,
"Caught exception while reading S3 object. Bucket: {}, Key: {}, Version: {}, Offset: {}, "
"Attempt: {}/{}, Message: {}",
bucket, key, version_id.empty() ? "Latest" : version_id, read_offset, attempt, request_settings.max_single_read_retries, e.message());
bucket, key, version_id.empty() ? "Latest" : version_id, read_offset, attempt, request_settings.max_single_read_retries,
getCurrentExceptionMessage(/* with_stacktrace = */ false));
if (auto * s3_exception = dynamic_cast<S3Exception *>(&e))
if (auto * s3_exception = exception_cast<S3Exception *>(std::current_exception()))
{
/// It doesn't make sense to retry Access Denied or No Such Key
if (!s3_exception->isRetryableError())
@ -241,7 +242,7 @@ bool ReadBufferFromS3::processException(Poco::Exception & e, size_t read_offset,
}
/// It doesn't make sense to retry allocator errors
if (e.code() == ErrorCodes::CANNOT_ALLOCATE_MEMORY)
if (getCurrentExceptionCode() == ErrorCodes::CANNOT_ALLOCATE_MEMORY)
{
tryLogCurrentException(log);
return false;

View File

@ -86,7 +86,7 @@ private:
/// Call inside catch() block if GetObject fails. Bumps metrics, logs the error.
/// Returns true if the error looks retriable.
bool processException(Poco::Exception & e, size_t read_offset, size_t attempt) const;
bool processException(size_t read_offset, size_t attempt) const;
Aws::S3::Model::GetObjectResult sendRequest(size_t attempt, size_t range_begin, std::optional<size_t> range_end_incl) const;