summaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/common/bucketmessages.h
blob: 428b526829327d74dd6a1ac97cd900674b5f9c3e (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/persistence/spi/result.h>
#include <vespa/storageapi/message/internal.h>
#include <vespa/storageapi/buckets/bucketinfo.h>

namespace storage {

/**
 * @class ReadBucketList
 * @ingroup common
 *
 * @brief List buckets existing on a partition.
 */
class ReadBucketList : public api::InternalCommand {
    document::BucketSpace _bucketSpace;

public:
    typedef std::unique_ptr<ReadBucketList> UP;
    static const uint32_t ID = 2003;

    ReadBucketList(document::BucketSpace bucketSpace);
    ~ReadBucketList();
    document::BucketSpace getBucketSpace() const { return _bucketSpace; }
    document::Bucket getBucket() const override;

    std::unique_ptr<api::StorageReply> makeReply() override;

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};


/**
 * @class ReadBucketListReply
 * @ingroup common
 */
class ReadBucketListReply : public api::InternalReply {
    document::BucketSpace _bucketSpace;
    spi::BucketIdListResult::List _buckets;

public:
    typedef std::unique_ptr<ReadBucketListReply> UP;
    typedef std::shared_ptr<ReadBucketListReply> SP;
    static const uint32_t ID = 2004;

    ReadBucketListReply(const ReadBucketList& cmd);
    ~ReadBucketListReply();

    document::BucketSpace getBucketSpace() const { return _bucketSpace; }
    document::Bucket getBucket() const override;

    spi::BucketIdListResult::List& getBuckets() { return _buckets; }
    const spi::BucketIdListResult::List& getBuckets() const {
        return _buckets;
    }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

/**
 * @class ReadBucketInfo
 * @ingroup common
 *
 * @brief Get more detailed information about a set of buckets.
 *
 * The distributor wants some information for each bucket, that one
 * have to open the bucket and read its headers to find. This class is
 * used to retrieve such information.
 */
class ReadBucketInfo : public api::InternalCommand {
    document::Bucket _bucket;

public:
    static const uint32_t ID = 2005;

    ReadBucketInfo(const document::Bucket &bucket);
    ~ReadBucketInfo();

    document::Bucket getBucket() const override { return _bucket; }
    bool hasSingleBucketId() const override { return true; }

    std::unique_ptr<api::StorageReply> makeReply() override;

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
private:
    vespalib::string getSummary() const override;
};


/**
 * @class ReadBucketInfoReply
 * @ingroup common
 */
class ReadBucketInfoReply : public api::InternalReply {
    document::Bucket _bucket;

public:
    static const uint32_t ID = 2006;

    ReadBucketInfoReply(const ReadBucketInfo& cmd);
    ~ReadBucketInfoReply();

    document::Bucket getBucket() const override { return _bucket; }
    bool hasSingleBucketId() const override { return true; }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

/**
 * @class InternalBucketJoinCommand
 * @ingroup common
 *
 * @brief Joins multiple versions of the same bucket.
 *
 * In case disks are reintroduced, we might have several copies of the same
 * bucket on multiple disks. In such cases we should join these buckets during
 * initialization as we cannot cope with multiple versions of the same bucket
 * while storage is running.
 */
class InternalBucketJoinCommand : public api::InternalCommand {
    document::Bucket _bucket;
    uint16_t _keepOnDisk;
    uint16_t _joinFromDisk;

public:
    static const uint32_t ID = 2015;

    InternalBucketJoinCommand(const document::Bucket &bucket, uint16_t keepOnDisk, uint16_t joinFromDisk);
    ~InternalBucketJoinCommand();

    document::Bucket getBucket() const override { return _bucket; }
    bool hasSingleBucketId() const override { return true; }

    uint16_t getDiskOfInstanceToKeep() const { return _keepOnDisk; }
    uint16_t getDiskOfInstanceToJoin() const { return _joinFromDisk; }

    std::unique_ptr<api::StorageReply> makeReply() override;

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

/**
 * @class InternalBucketJoinReply
 * @ingroup common
 */
class InternalBucketJoinReply : public api::InternalReply {
    document::Bucket _bucket;
    api::BucketInfo _bucketInfo;

public:
    static const uint32_t ID = 2016;

    InternalBucketJoinReply(const InternalBucketJoinCommand& cmd,
                            const api::BucketInfo& info = api::BucketInfo());
    ~InternalBucketJoinReply();

    document::Bucket getBucket() const override { return _bucket; }
    bool hasSingleBucketId() const override { return true; }

    const api::BucketInfo& getBucketInfo() const { return _bucketInfo; }

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};

} // storage