aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Disks/ObjectStorages/DiskObjectStorageMetadata.h
blob: 6dced85d0b1e10a6351969b541a5555b8c363075 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once

#include <Disks/IDisk.h>
#include <Disks/ObjectStorages/IMetadataStorage.h>
#include <Core/Types.h>

namespace DB
{


/// Metadata for DiskObjectStorage, stored on local disk
struct DiskObjectStorageMetadata
{
private:
    /// Metadata file version.
    static constexpr uint32_t VERSION_ABSOLUTE_PATHS = 1;
    static constexpr uint32_t VERSION_RELATIVE_PATHS = 2;
    static constexpr uint32_t VERSION_READ_ONLY_FLAG = 3;
    static constexpr uint32_t VERSION_INLINE_DATA = 4;

    const std::string & common_metadata_path;

    /// Relative paths of blobs.
    RelativePathsWithMetadata storage_objects;

    const std::string object_storage_root_path;

    /// Relative path to metadata file on local FS.
    const std::string metadata_file_path;

    /// Total size of all remote FS (S3, HDFS) objects.
    size_t total_size = 0;

    /// Number of references (hardlinks) to this metadata file.
    ///
    /// FIXME: Why we are tracking it explicetly, without
    /// info from filesystem????
    uint32_t ref_count = 0;

    /// Flag indicates that file is read only.
    bool read_only = false;

    /// This data will be stored inline
    std::string inline_data;

public:

    DiskObjectStorageMetadata(
        const std::string & common_metadata_path_,
        const std::string & object_storage_root_path_,
        const std::string & metadata_file_path_);

    void addObject(const std::string & path, size_t size);

    void deserialize(ReadBuffer & buf);
    void deserializeFromString(const std::string & data);

    void serialize(WriteBuffer & buf, bool sync) const;
    std::string serializeToString() const;

    std::string getBlobsCommonPrefix() const
    {
        return object_storage_root_path;
    }

    RelativePathsWithMetadata getBlobsRelativePaths() const
    {
        return storage_objects;
    }

    bool isReadOnly() const
    {
        return read_only;
    }

    uint32_t getRefCount() const
    {
        return ref_count;
    }

    uint64_t getTotalSizeBytes() const
    {
        return total_size;
    }

    void incrementRefCount()
    {
        ++ref_count;
    }

    void decrementRefCount()
    {
        --ref_count;
    }

    void resetRefCount()
    {
        ref_count = 0;
    }

    void setReadOnly()
    {
        read_only = true;
    }

    void setInlineData(const std::string & data)
    {
        inline_data = data;
    }

    const std::string & getInlineData() const
    {
        return inline_data;
    }
};

using DiskObjectStorageMetadataPtr = std::unique_ptr<DiskObjectStorageMetadata>;

}