2017-06-25 00:01:10 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeBlockOutputStream.h>
|
2020-05-20 12:02:02 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataPartInMemory.h>
|
2017-06-25 00:01:10 +00:00
|
|
|
#include <Storages/StorageMergeTree.h>
|
|
|
|
#include <Interpreters/PartLog.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-02-19 00:45:32 +00:00
|
|
|
Block MergeTreeBlockOutputStream::getHeader() const
|
|
|
|
{
|
2020-06-16 15:51:29 +00:00
|
|
|
return metadata_snapshot->getSampleBlock();
|
2018-02-19 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-29 15:08:02 +00:00
|
|
|
void MergeTreeBlockOutputStream::writePrefix()
|
2017-06-25 00:01:10 +00:00
|
|
|
{
|
2020-11-29 15:08:02 +00:00
|
|
|
/// 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();
|
2020-11-29 15:08:02 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2020-11-29 15:08:02 +00:00
|
|
|
void MergeTreeBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
2020-06-17 10:34:23 +00:00
|
|
|
auto part_blocks = storage.writer.splitBlockIntoParts(block, max_parts_per_block, metadata_snapshot);
|
2017-06-25 00:01:10 +00:00
|
|
|
for (auto & current_block : part_blocks)
|
|
|
|
{
|
|
|
|
Stopwatch watch;
|
|
|
|
|
2020-12-04 16:25:30 +00:00
|
|
|
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;
|
|
|
|
|
2019-05-03 02:00:57 +00:00
|
|
|
storage.renameTempPartAndAdd(part, &storage.increment);
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
PartLog::addNewPart(storage.global_context, part, watch.elapsed());
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2020-10-13 14:25:42 +00:00
|
|
|
/// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'.
|
2020-10-15 07:43:50 +00:00
|
|
|
storage.background_executor.triggerTask();
|
2017-06-25 00:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|