1#pragma once
2
3#include <Storages/MergeTree/MergeTreeDataPartChecksum.h>
4#include <Core/Types.h>
5#include <IO/WriteBuffer.h>
6#include <IO/ReadBuffer.h>
7#include <IO/Operators.h>
8#include <array>
9
10
11namespace DB
12{
13
14class NamesAndTypesList;
15
16/// This class provides a compact representation of part metadata (available columns and checksums)
17/// that is intended to be stored in the part znode in ZooKeeper.
18/// It can also be initialized from the legacy format (from the contents of separate <part>/columns
19/// and <part>/checksums znodes).
20class ReplicatedMergeTreePartHeader
21{
22public:
23 ReplicatedMergeTreePartHeader() = default;
24
25 static ReplicatedMergeTreePartHeader fromColumnsAndChecksumsZNodes(
26 const String & columns_znode, const String & checksums_znode);
27
28 static ReplicatedMergeTreePartHeader fromColumnsAndChecksums(
29 const NamesAndTypesList & columns, const MergeTreeDataPartChecksums & full_checksums);
30
31 void read(ReadBuffer & in);
32 static ReplicatedMergeTreePartHeader fromString(const String & str);
33
34 void write(WriteBuffer & out) const;
35 String toString() const;
36
37 const std::array<char, 16> & getColumnsHash() const { return columns_hash; }
38 const MinimalisticDataPartChecksums & getChecksums() const { return checksums; }
39
40private:
41 ReplicatedMergeTreePartHeader(std::array<char, 16> columns_hash_, MinimalisticDataPartChecksums checksums_)
42 : columns_hash(std::move(columns_hash_)), checksums(std::move(checksums_))
43 {
44 }
45
46 std::array<char, 16> columns_hash;
47 MinimalisticDataPartChecksums checksums;
48};
49
50}
51