ClickHouse/src/Storages/MergeTree/MergeTreeBlockOutputStream.cpp

49 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::write(const Block & block)
{
2019-05-03 02:00:57 +00:00
storage.delayInsertOrThrowIfNeeded();
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);
2019-05-03 02:00:57 +00:00
storage.renameTempPartAndAdd(part, &storage.increment);
PartLog::addNewPart(storage.global_context, part, watch.elapsed());
2020-06-05 20:47:46 +00:00
if (auto part_in_memory = asInMemoryPart(part))
{
2020-05-20 12:02:02 +00:00
storage.in_memory_merges_throttler.add(part_in_memory->block.bytes(), part_in_memory->rows_count);
if (storage.merging_mutating_task_handle && !storage.in_memory_merges_throttler.needDelayMerge())
2020-05-20 12:02:02 +00:00
{
storage.in_memory_merges_throttler.reset();
storage.merging_mutating_task_handle->signalReadyToRun();
2020-05-20 12:02:02 +00:00
}
}
else if (storage.merging_mutating_task_handle)
{
/// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'.
2020-06-02 15:18:36 +00:00
storage.merging_mutating_task_handle->signalReadyToRun();
}
}
}
}