| 1 | #include <Storages/MergeTree/MergeTreeBlockOutputStream.h> |
|---|---|
| 2 | #include <Storages/StorageMergeTree.h> |
| 3 | #include <Interpreters/PartLog.h> |
| 4 | |
| 5 | |
| 6 | namespace DB |
| 7 | { |
| 8 | |
| 9 | Block MergeTreeBlockOutputStream::getHeader() const |
| 10 | { |
| 11 | return storage.getSampleBlock(); |
| 12 | } |
| 13 | |
| 14 | |
| 15 | void MergeTreeBlockOutputStream::write(const Block & block) |
| 16 | { |
| 17 | storage.delayInsertOrThrowIfNeeded(); |
| 18 | |
| 19 | auto part_blocks = storage.writer.splitBlockIntoParts(block, max_parts_per_block); |
| 20 | for (auto & current_block : part_blocks) |
| 21 | { |
| 22 | Stopwatch watch; |
| 23 | |
| 24 | MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block); |
| 25 | storage.renameTempPartAndAdd(part, &storage.increment); |
| 26 | |
| 27 | PartLog::addNewPart(storage.global_context, part, watch.elapsed()); |
| 28 | |
| 29 | /// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'. |
| 30 | if (storage.merging_mutating_task_handle) |
| 31 | storage.merging_mutating_task_handle->wake(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | } |
| 36 |