mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 19:02:04 +00:00
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include <Storages/MergeTree/MergeTreeBlockOutputStream.h>
|
|
#include <Storages/MergeTree/MergeTreeDataPartInMemory.h>
|
|
#include <Storages/StorageMergeTree.h>
|
|
#include <Interpreters/PartLog.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
Block MergeTreeBlockOutputStream::getHeader() const
|
|
{
|
|
return metadata_snapshot->getSampleBlock();
|
|
}
|
|
|
|
|
|
void MergeTreeBlockOutputStream::writePrefix()
|
|
{
|
|
/// Only check "too many parts" before write,
|
|
/// because interrupting long-running INSERT query in the middle is not convenient for users.
|
|
storage.delayInsertOrThrowIfNeeded();
|
|
}
|
|
|
|
|
|
void MergeTreeBlockOutputStream::write(const Block & block)
|
|
{
|
|
auto part_blocks = storage.writer.splitBlockIntoParts(block, max_parts_per_block, metadata_snapshot);
|
|
for (auto & current_block : part_blocks)
|
|
{
|
|
Stopwatch watch;
|
|
|
|
MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block, metadata_snapshot, optimize_on_insert);
|
|
storage.renameTempPartAndAdd(part, &storage.increment);
|
|
|
|
PartLog::addNewPart(storage.global_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.background_executor.triggerTask();
|
|
}
|
|
}
|
|
|
|
}
|