#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Aliases.h" namespace DB { namespace ErrorCodes { extern const int NO_ZOOKEEPER; extern const int BAD_ARGUMENTS; extern const int UNKNOWN_TABLE; extern const int UNFINISHED; extern const int UNKNOWN_ELEMENT_IN_CONFIG; } [[maybe_unused]] ConfigurationPtr getConfigurationFromXMLString(const std::string &xml_data); [[maybe_unused]] String getQuotedTable(const String &database, const String &table); [[maybe_unused]] String getQuotedTable(const DatabaseAndTableName &db_and_table); enum class TaskState { Started = 0, Finished, Unknown }; /// Used to mark status of shard partition tasks struct TaskStateWithOwner { TaskStateWithOwner() = default; TaskStateWithOwner(TaskState state_, const String &owner_) : state(state_), owner(owner_) {} TaskState state{TaskState::Unknown}; String owner; static String getData(TaskState state, const String &owner) { return TaskStateWithOwner(state, owner).toString(); } String toString() { WriteBufferFromOwnString wb; wb << static_cast(state) << "\n" << escape << owner; return wb.str(); } static TaskStateWithOwner fromString(const String &data) { ReadBufferFromString rb(data); TaskStateWithOwner res; UInt32 state; rb >> state >> "\n" >> escape >> res.owner; if (state >= static_cast(TaskState::Unknown)) throw Exception("Unknown state " + data, ErrorCodes::LOGICAL_ERROR); res.state = static_cast(state); return res; } }; struct ShardPriority { UInt8 is_remote = 1; size_t hostname_difference = 0; UInt8 random = 0; static bool greaterPriority(const ShardPriority ¤t, const ShardPriority &other) { return std::forward_as_tuple(current.is_remote, current.hostname_difference, current.random) < std::forward_as_tuple(other.is_remote, other.hostname_difference, other.random); } }; /// Execution status of a task enum class PartitionTaskStatus { Active, Finished, Error, }; struct MultiTransactionInfo { int32_t code; Coordination::Requests requests; Coordination::Responses responses; }; // Creates AST representing 'ENGINE = Distributed(cluster, db, table, [sharding_key]) [[maybe_unused]] std::shared_ptr createASTStorageDistributed( const String &cluster_name, const String &database, const String &table, const ASTPtr &sharding_key_ast = nullptr); [[maybe_unused]] BlockInputStreamPtr squashStreamIntoOneBlock(const BlockInputStreamPtr &stream); [[maybe_unused]] Block getBlockWithAllStreamData(const BlockInputStreamPtr &stream); [[maybe_unused]] bool isExtendedDefinitionStorage(const ASTPtr &storage_ast); [[maybe_unused]] ASTPtr extractPartitionKey(const ASTPtr &storage_ast); [[maybe_unused]] ShardPriority getReplicasPriority(const Cluster::Addresses & replicas, const std::string & local_hostname, UInt8 random); }