fix WriteBufferFromFileDecorator cancelation

This commit is contained in:
Sema Checherinda 2024-06-21 20:12:34 +02:00
parent 19bafb5063
commit 90231e302e
7 changed files with 24 additions and 20 deletions

View File

@ -20,7 +20,7 @@ WriteBuffer::~WriteBuffer()
LoggerPtr log = getLogger("WriteBuffer");
LOG_ERROR(
log,
"WriteBuffer is not finalized when destructor is called. "
"WriteBuffer is neither finalized nor canceled when destructor is called. "
"No exceptions in flight are detected. "
"The file might not be written at all or might be truncated. "
"Stack trace: {}",

View File

@ -59,6 +59,9 @@ public:
*/
pos = working_buffer.begin();
bytes += bytes_in_buffer;
cancel();
throw;
}
@ -133,28 +136,21 @@ public:
catch (...)
{
pos = working_buffer.begin();
finalized = true;
cancel();
throw;
}
}
void cancel()
void cancel() noexcept
{
if (canceled || finalized)
return;
LockMemoryExceptionInThread lock(VariableContext::Global);
try
{
cancelImpl();
canceled = true;
}
catch (...)
{
pos = working_buffer.begin();
canceled = true;
throw;
}
cancelImpl();
canceled = true;
}
/// Wait for data to be reliably written. Mainly, call fsync for fd.
@ -172,7 +168,7 @@ protected:
next();
}
virtual void cancelImpl()
virtual void cancelImpl() noexcept
{
}

View File

@ -47,7 +47,7 @@ public:
}
}
void cancelImpl() override
void cancelImpl() noexcept override
{
out->cancel();
}

View File

@ -28,6 +28,12 @@ void WriteBufferFromFileDecorator::finalizeImpl()
}
}
void WriteBufferFromFileDecorator::cancelImpl() noexcept
{
SwapHelper swap(*this, *impl);
impl->cancel();
}
WriteBufferFromFileDecorator::~WriteBufferFromFileDecorator()
{
/// It is not a mistake that swap is called here

View File

@ -24,6 +24,8 @@ public:
protected:
void finalizeImpl() override;
void cancelImpl() noexcept override;
std::unique_ptr<WriteBuffer> impl;
private:

View File

@ -224,7 +224,7 @@ void WriteBufferFromS3::finalizeImpl()
}
}
void WriteBufferFromS3::cancelImpl()
void WriteBufferFromS3::cancelImpl() noexcept
{
tryToAbortMultipartUpload();
}
@ -251,7 +251,7 @@ String WriteBufferFromS3::getShortLogDetails() const
bucket, key, multipart_upload_details);
}
void WriteBufferFromS3::tryToAbortMultipartUpload()
void WriteBufferFromS3::tryToAbortMultipartUpload() noexcept
{
try
{

View File

@ -54,7 +54,7 @@ private:
/// Receives response from the server after sending all data.
void finalizeImpl() override;
void cancelImpl() override;
void cancelImpl() noexcept override;
String getVerboseLogDetails() const;
String getShortLogDetails() const;
@ -73,7 +73,7 @@ private:
void createMultipartUpload();
void completeMultipartUpload();
void abortMultipartUpload();
void tryToAbortMultipartUpload();
void tryToAbortMultipartUpload() noexcept;
S3::PutObjectRequest getPutRequest(PartData & data);
void makeSinglepartUpload(PartData && data);