ClickHouse/dbms/src/DataStreams/BlockIO.h

61 lines
1.6 KiB
C++
Raw Normal View History

2012-03-11 08:55:04 +00:00
#pragma once
#include <DataStreams/IBlockInputStream.h>
#include <DataStreams/IBlockOutputStream.h>
2012-03-11 08:55:04 +00:00
namespace DB
{
class ProcessListEntry;
2012-03-11 08:55:04 +00:00
struct BlockIO
{
/** process_list_entry should be destroyed after in and after out,
* since in and out contain pointer to objects inside process_list_entry (query-level MemoryTracker for example),
* which could be used before destroying of in and out.
*/
std::shared_ptr<ProcessListEntry> process_list_entry;
BlockInputStreamPtr in;
BlockOutputStreamPtr out;
/// Callbacks for query logging could be set here.
std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback;
std::function<void()> exception_callback;
2017-05-13 22:19:04 +00:00
/// Call these functions if you want to log the request.
void onFinish()
{
if (finish_callback)
finish_callback(in.get(), out.get());
}
void onException()
{
if (exception_callback)
exception_callback();
}
BlockIO & operator= (const BlockIO & rhs)
{
2017-05-13 22:19:04 +00:00
/// We provide the correct order of destruction.
out = nullptr;
in = nullptr;
process_list_entry = nullptr;
process_list_entry = rhs.process_list_entry;
in = rhs.in;
out = rhs.out;
finish_callback = rhs.finish_callback;
exception_callback = rhs.exception_callback;
return *this;
}
~BlockIO();
2012-03-11 08:55:04 +00:00
};
}