ClickHouse/src/Storages/MergeTree/MergeTreeSink.cpp

46 lines
1.5 KiB
C++
Raw Normal View History

2021-07-26 16:48:25 +00:00
#include <Storages/MergeTree/MergeTreeSink.h>
2020-05-20 12:02:02 +00:00
#include <Storages/MergeTree/MergeTreeDataPartInMemory.h>
#include <Storages/StorageMergeTree.h>
#include <Interpreters/PartLog.h>
namespace DB
{
2021-07-23 19:33:59 +00:00
void MergeTreeSink::onStart()
{
/// Only check "too many parts" before write,
/// because interrupting long-running INSERT query in the middle is not convenient for users.
2019-05-03 02:00:57 +00:00
storage.delayInsertOrThrowIfNeeded();
}
2021-07-23 19:33:59 +00:00
void MergeTreeSink::consume(Chunk chunk)
{
auto block = getHeader().cloneWithColumns(chunk.detachColumns());
2021-07-23 19:33:59 +00:00
auto part_blocks = storage.writer.splitBlockIntoParts(block, max_parts_per_block, metadata_snapshot, context);
for (auto & current_block : part_blocks)
{
Stopwatch watch;
MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block, metadata_snapshot, context);
2021-02-12 14:02:04 +00:00
/// If optimize_on_insert setting is true, current_block could become empty after merge
/// and we didn't create part.
if (!part)
continue;
2021-04-02 17:54:24 +00:00
/// Part can be deduplicated, so increment counters and add to part log only if it's really added
2021-04-02 16:45:18 +00:00
if (storage.renameTempPartAndAdd(part, &storage.increment, nullptr, storage.getDeduplicationLog()))
2021-04-02 11:46:42 +00:00
{
PartLog::addNewPart(storage.getContext(), part, watch.elapsed());
2021-04-02 16:45:18 +00:00
/// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'.
2021-09-08 00:21:21 +00:00
storage.background_operations_assignee.trigger();
2021-04-02 16:45:18 +00:00
}
}
}
}