mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 03:12:43 +00:00
35 lines
910 B
C++
35 lines
910 B
C++
#include <Storages/MergeTree/MergeTreeBlockOutputStream.h>
|
|
#include <Storages/StorageMergeTree.h>
|
|
#include <Interpreters/PartLog.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
Block MergeTreeBlockOutputStream::getHeader() const
|
|
{
|
|
return storage.getSampleBlock();
|
|
}
|
|
|
|
|
|
void MergeTreeBlockOutputStream::write(const Block & block)
|
|
{
|
|
storage.data.delayInsertOrThrowIfNeeded();
|
|
|
|
auto part_blocks = storage.writer.splitBlockIntoParts(block);
|
|
for (auto & current_block : part_blocks)
|
|
{
|
|
Stopwatch watch;
|
|
|
|
MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block);
|
|
storage.data.renameTempPartAndAdd(part, &storage.increment);
|
|
|
|
PartLog::addNewPart(storage.context, part, watch.elapsed());
|
|
|
|
/// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'.
|
|
storage.merge_task_handle->wake();
|
|
}
|
|
}
|
|
|
|
}
|