2023-06-16 14:34:50 +00:00
|
|
|
#include "WriteBuffer.h"
|
|
|
|
|
|
|
|
#include <Common/logger_useful.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Calling finalize() in the destructor of derived classes is a bad practice.
|
|
|
|
/// This causes objects to be left on the remote FS when a write operation is rolled back.
|
|
|
|
/// Do call finalize() explicitly, before this call you have no guarantee that the file has been written
|
|
|
|
WriteBuffer::~WriteBuffer()
|
|
|
|
{
|
|
|
|
// That destructor could be call with finalized=false in case of exceptions
|
2024-05-27 22:09:39 +00:00
|
|
|
if (count() > 0 && !finalized && !canceled)
|
2023-06-16 14:34:50 +00:00
|
|
|
{
|
|
|
|
/// It is totally OK to destroy instance without finalization when an exception occurs
|
|
|
|
/// However it is suspicious to destroy instance without finalization at the green path
|
|
|
|
if (!std::uncaught_exceptions() && std::current_exception() == nullptr)
|
|
|
|
{
|
2024-01-23 17:04:50 +00:00
|
|
|
LoggerPtr log = getLogger("WriteBuffer");
|
2023-06-16 14:34:50 +00:00
|
|
|
LOG_ERROR(
|
|
|
|
log,
|
2024-06-21 18:12:34 +00:00
|
|
|
"WriteBuffer is neither finalized nor canceled when destructor is called. "
|
2023-06-16 14:34:50 +00:00
|
|
|
"No exceptions in flight are detected. "
|
|
|
|
"The file might not be written at all or might be truncated. "
|
|
|
|
"Stack trace: {}",
|
|
|
|
StackTrace().toString());
|
|
|
|
chassert(false && "WriteBuffer is not finalized in destructor.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|