ClickHouse/src/IO/WriteBufferFromFileDecorator.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
1.8 KiB
C++
Raw Normal View History

2021-04-20 18:29:03 +00:00
#include "WriteBufferFromFileDecorator.h"
#include <IO/WriteBuffer.h>
2023-04-18 11:11:42 +00:00
#include <IO/SwapHelper.h>
2021-04-20 18:29:03 +00:00
namespace DB
{
2021-04-20 18:52:58 +00:00
WriteBufferFromFileDecorator::WriteBufferFromFileDecorator(std::unique_ptr<WriteBuffer> impl_)
2021-04-20 18:29:03 +00:00
: WriteBufferFromFileBase(0, nullptr, 0), impl(std::move(impl_))
{
swap(*impl);
}
2021-11-10 22:58:56 +00:00
void WriteBufferFromFileDecorator::finalizeImpl()
2021-04-20 18:29:03 +00:00
{
2023-04-18 11:11:42 +00:00
/// In case of exception in preFinalize as a part of finalize call
/// WriteBufferFromFileDecorator.finalized is set as true
/// but impl->finalized is remain false
/// That leads to situation when the destructor of impl is called with impl->finalized equal false.
if (!is_prefinalized)
WriteBufferFromFileDecorator::preFinalize();
2023-04-18 11:11:42 +00:00
{
SwapHelper swap(*this, *impl);
impl->finalize();
}
2021-04-20 18:29:03 +00:00
}
void WriteBufferFromFileDecorator::cancelImpl() noexcept
{
SwapHelper swap(*this, *impl);
impl->cancel();
}
2021-04-20 18:52:58 +00:00
WriteBufferFromFileDecorator::~WriteBufferFromFileDecorator()
2021-04-20 18:29:03 +00:00
{
2023-04-18 11:11:42 +00:00
/// It is not a mistake that swap is called here
/// Swap has been called at constructor, it should be called at destructor
/// In oreder to provide valid buffer for impl's d-tor call
swap(*impl);
2021-04-20 18:29:03 +00:00
}
2021-04-20 18:52:58 +00:00
void WriteBufferFromFileDecorator::sync()
2021-04-20 18:29:03 +00:00
{
2023-04-18 11:11:42 +00:00
next();
{
SwapHelper swap(*this, *impl);
impl->sync();
}
2021-04-20 18:29:03 +00:00
}
2021-04-20 18:52:58 +00:00
std::string WriteBufferFromFileDecorator::getFileName() const
2021-04-20 18:29:03 +00:00
{
2021-04-20 18:52:58 +00:00
if (WriteBufferFromFileBase * buffer = dynamic_cast<WriteBufferFromFileBase*>(impl.get()))
return buffer->getFileName();
2021-04-20 18:29:03 +00:00
return std::string();
}
2023-04-18 11:11:42 +00:00
void WriteBufferFromFileDecorator::preFinalize()
{
next();
{
SwapHelper swap(*this, *impl);
impl->preFinalize();
}
is_prefinalized = true;
}
2021-04-20 18:52:58 +00:00
void WriteBufferFromFileDecorator::nextImpl()
2021-04-20 18:29:03 +00:00
{
2023-04-18 11:11:42 +00:00
SwapHelper swap(*this, *impl);
2021-04-20 18:29:03 +00:00
impl->next();
}
}