ClickHouse/src/Storages/MergeTree/MergeTreeBlockOutputStream.cpp

50 lines
1.6 KiB
C++
Raw Normal View History

#include <Storages/MergeTree/MergeTreeBlockOutputStream.h>
2020-05-20 12:02:02 +00:00
#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.
2019-05-03 02:00:57 +00:00
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);
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
{
2021-04-02 16:45:18 +00:00
PartLog::addNewPart(storage.global_context, 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'.
storage.background_executor.triggerTask();
}
}
}
}