2014-04-02 07:59:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
2017-06-25 00:01:10 +00:00
|
|
|
#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
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2017-02-02 22:08:19 +00:00
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
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;
|
2016-01-11 21:46:36 +00:00
|
|
|
|
|
|
|
|
2014-04-02 07:59:43 +00:00
|
|
|
class ReplicatedMergeTreeBlockOutputStream : public IBlockOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2020-06-16 15:51:29 +00:00
|
|
|
ReplicatedMergeTreeBlockOutputStream(
|
|
|
|
StorageReplicatedMergeTree & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
|
|
|
size_t quorum_,
|
|
|
|
size_t quorum_timeout_ms_,
|
|
|
|
size_t max_parts_per_block_,
|
2019-03-29 09:33:39 +00:00
|
|
|
bool deduplicate_);
|
2015-09-11 02:13:59 +00:00
|
|
|
|
2018-02-19 00:45:32 +00:00
|
|
|
Block getHeader() const override;
|
2018-05-21 23:17:57 +00:00
|
|
|
void writePrefix() override;
|
2017-04-01 07:20:54 +00:00
|
|
|
void write(const Block & block) override;
|
2014-04-02 07:59:43 +00:00
|
|
|
|
2017-06-25 00:51:51 +00:00
|
|
|
/// For ATTACHing existing data on filesystem.
|
|
|
|
void writeExistingPart(MergeTreeData::MutableDataPartPtr & part);
|
|
|
|
|
2017-10-24 19:32:23 +00:00
|
|
|
/// For proper deduplication in MaterializedViews
|
|
|
|
bool lastBlockIsDuplicate() const
|
|
|
|
{
|
|
|
|
return last_block_is_duplicate;
|
|
|
|
}
|
|
|
|
|
2014-04-02 07:59:43 +00:00
|
|
|
private:
|
2017-06-25 00:01:10 +00:00
|
|
|
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.
|
2017-06-25 00:51:51 +00:00
|
|
|
void commitPart(zkutil::ZooKeeperPtr & zookeeper, MergeTreeData::MutableDataPartPtr & part, const String & block_id);
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageReplicatedMergeTree & storage;
|
2020-06-16 15:51:29 +00:00
|
|
|
StorageMetadataPtr metadata_snapshot;
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t quorum;
|
|
|
|
size_t quorum_timeout_ms;
|
2019-03-29 09:33:39 +00:00
|
|
|
size_t max_parts_per_block;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-10-24 19:32:23 +00:00
|
|
|
bool deduplicate = true;
|
|
|
|
bool last_block_is_duplicate = false;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using Logger = Poco::Logger;
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log;
|
2014-04-02 07:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|