ClickHouse/src/Storages/MergeTree/ReplicatedMergeTreeBlockOutputStream.h

84 lines
2.1 KiB
C++
Raw Normal View History

2014-04-02 07:59:43 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <Storages/MergeTree/MergeTreeData.h>
2020-09-15 09:55:57 +00:00
#include <common/types.h>
2014-04-02 07:59:43 +00:00
namespace Poco { class Logger; }
namespace zkutil
{
class ZooKeeper;
using ZooKeeperPtr = std::shared_ptr<ZooKeeper>;
}
2014-04-02 07:59:43 +00:00
namespace DB
{
2016-01-17 05:22:22 +00:00
class StorageReplicatedMergeTree;
2014-04-02 07:59:43 +00:00
class ReplicatedMergeTreeBlockOutputStream : public IBlockOutputStream
{
public:
ReplicatedMergeTreeBlockOutputStream(
StorageReplicatedMergeTree & storage_,
const StorageMetadataPtr & metadata_snapshot_,
size_t quorum_,
size_t quorum_timeout_ms_,
size_t max_parts_per_block_,
2020-09-30 23:16:27 +00:00
bool quorum_parallel_,
2020-11-13 07:54:05 +00:00
bool deduplicate_,
bool optimize_on_insert,
// special flag to determine the ALTER TABLE ATTACH PART without the query context,
// needed to set the special LogEntryType::ATTACH_PART
bool is_attach_ = false);
Block getHeader() const override;
void writePrefix() override;
void write(const Block & block) override;
2014-04-02 07:59:43 +00:00
/// For ATTACHing existing data on filesystem.
void writeExistingPart(MergeTreeData::MutableDataPartPtr & part);
/// For proper deduplication in MaterializedViews
bool lastBlockIsDuplicate() const
{
return last_block_is_duplicate;
}
2014-04-02 07:59:43 +00:00
private:
struct QuorumInfo
{
String status_path;
String is_active_node_value;
int is_active_node_version = -1;
int host_node_version = -1;
};
QuorumInfo quorum_info;
void checkQuorumPrecondition(zkutil::ZooKeeperPtr & zookeeper);
/// Rename temporary part and commit to ZooKeeper.
void commitPart(zkutil::ZooKeeperPtr & zookeeper, MergeTreeData::MutableDataPartPtr & part, const String & block_id);
StorageReplicatedMergeTree & storage;
StorageMetadataPtr metadata_snapshot;
size_t quorum;
size_t quorum_timeout_ms;
size_t max_parts_per_block;
bool is_attach = false;
2020-09-30 23:16:27 +00:00
bool quorum_parallel = false;
bool deduplicate = true;
bool last_block_is_duplicate = false;
using Logger = Poco::Logger;
2020-05-30 21:57:37 +00:00
Poco::Logger * log;
2020-11-13 07:54:05 +00:00
bool optimize_on_insert;
2014-04-02 07:59:43 +00:00
};
}