2017-06-25 00:01:10 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeBlockOutputStream.h>
|
|
|
|
#include <Storages/StorageMergeTree.h>
|
|
|
|
#include <Interpreters/PartLog.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-02-19 00:45:32 +00:00
|
|
|
Block MergeTreeBlockOutputStream::getHeader() const
|
|
|
|
{
|
|
|
|
return storage.getSampleBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
void MergeTreeBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
2018-05-21 23:17:57 +00:00
|
|
|
storage.data.delayInsertOrThrowIfNeeded();
|
2017-06-25 00:01:10 +00:00
|
|
|
|
|
|
|
auto part_blocks = storage.writer.splitBlockIntoParts(block);
|
|
|
|
for (auto & current_block : part_blocks)
|
|
|
|
{
|
|
|
|
Stopwatch watch;
|
|
|
|
|
|
|
|
MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block);
|
|
|
|
storage.data.renameTempPartAndAdd(part, &storage.increment);
|
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
PartLog::addNewPart(storage.context, part, watch.elapsed());
|
2017-06-25 00:01:10 +00:00
|
|
|
|
|
|
|
/// Initiate async merge - it will be done if it's good time for merge and if there are space in 'background_pool'.
|
2018-07-09 15:34:11 +00:00
|
|
|
storage.background_task_handle->wake();
|
2017-06-25 00:01:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|