aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/persistence/messages.h
blob: faba3995c6f6a205aaf3463e0302e57834d3ce4b (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/storageapi/message/internal.h>
#include <vespa/persistence/spi/bucket.h>
#include <vespa/persistence/spi/selection.h>
#include <vespa/persistence/spi/read_consistency.h>
#include <vespa/persistence/spi/bucketexecutor.h>

namespace storage {

namespace spi { class DocEntry; }

class GetIterCommand : public api::InternalCommand {
private:
    document::Bucket _bucket;
    spi::IteratorId _iteratorId;
    uint32_t _maxByteSize;

public:
    static constexpr uint32_t ID = 1001;
    using UP = std::unique_ptr<GetIterCommand>;
    using SP = std::shared_ptr<GetIterCommand>;

    GetIterCommand(const document::Bucket &bucket,
                   spi::IteratorId iteratorId,
                   uint32_t maxByteSize);
    ~GetIterCommand() override;

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

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

    spi::IteratorId getIteratorId() const { return _iteratorId; }
    uint32_t getMaxByteSize() const { return _maxByteSize; }

    api::LockingRequirements lockingRequirements() const noexcept override {
        return api::LockingRequirements::Shared;
    }

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

class GetIterReply : public api::InternalReply {
private:
    using List = std::vector<std::unique_ptr<spi::DocEntry>>;
    document::Bucket _bucket;
    List             _entries;
    bool             _completed;

public:
    using UP = std::unique_ptr<GetIterReply>;
    using SP = std::shared_ptr<GetIterReply>;
    static constexpr uint32_t ID = 1002;

    explicit GetIterReply(GetIterCommand& cmd);
    ~GetIterReply() override;

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

    const List & getEntries() const { return _entries; }

    List & getEntries() { return _entries; }

    void setCompleted(bool completed = true) { _completed = completed; }
    bool isCompleted() const { return _completed; }

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

class CreateIteratorCommand : public api::InternalCommand
{
    document::Bucket _bucket;
    spi::Selection _selection;
    std::string _fieldSet;
    spi::IncludedVersions _includedVersions;
    spi::ReadConsistency _readConsistency;

public:
    static constexpr uint32_t ID = 1003;
    using UP = std::unique_ptr<CreateIteratorCommand>;
    using SP = std::shared_ptr<CreateIteratorCommand>;

    CreateIteratorCommand(const document::Bucket &bucket,
                          const spi::Selection& selection,
                          const std::string& fields,
                          spi::IncludedVersions includedVersions);
    ~CreateIteratorCommand() override;
    document::Bucket getBucket() const override { return _bucket; }
    const spi::Selection& getSelection() const { return _selection; }
    spi::IncludedVersions getIncludedVersions() const { return _includedVersions; }
    const std::string& getFields() const { return _fieldSet; }

    void setReadConsistency(spi::ReadConsistency consistency) noexcept {
        _readConsistency = consistency;
    }
    spi::ReadConsistency getReadConsistency() const noexcept {
        return _readConsistency;
    }
    api::LockingRequirements lockingRequirements() const noexcept override {
        return api::LockingRequirements::Shared;
    }

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

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

class CreateIteratorReply : public api::InternalReply
{
    document::Bucket _bucket;
    spi::IteratorId _iteratorId;
public:
    static constexpr uint32_t ID = 1004;
    using UP = std::unique_ptr<CreateIteratorReply>;
    using SP = std::shared_ptr<CreateIteratorReply>;

    CreateIteratorReply(const CreateIteratorCommand& cmd, spi::IteratorId iteratorId);
    ~CreateIteratorReply() override;

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

    spi::IteratorId getIteratorId() const { return _iteratorId; }

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

class DestroyIteratorCommand : public api::InternalCommand
{
    spi::IteratorId _iteratorId;
public:
    static constexpr uint32_t ID = 1005;
    using UP = std::unique_ptr<DestroyIteratorCommand>;
    using SP = std::shared_ptr<DestroyIteratorCommand>;

    explicit DestroyIteratorCommand(spi::IteratorId iteratorId);
    ~DestroyIteratorCommand() override;

    spi::IteratorId getIteratorId() const { return _iteratorId; }

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

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

class DestroyIteratorReply : public api::InternalReply
{
    spi::IteratorId _iteratorId;
public:
    static constexpr uint32_t ID = 1006;
    using UP = std::unique_ptr<DestroyIteratorReply>;
    using SP = std::shared_ptr<DestroyIteratorReply>;

    explicit DestroyIteratorReply(const DestroyIteratorCommand& cmd);
    ~DestroyIteratorReply() override;

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

class RecheckBucketInfoCommand : public api::InternalCommand
{
    document::Bucket _bucket;
public:
    static constexpr uint32_t ID = 1007;
    using SP = std::shared_ptr<RecheckBucketInfoCommand>;
    using UP = std::unique_ptr<RecheckBucketInfoCommand>;

    explicit RecheckBucketInfoCommand(const document::Bucket &bucket);
    ~RecheckBucketInfoCommand() override;

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

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

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

class RecheckBucketInfoReply : public api::InternalReply
{
    document::Bucket _bucket;
public:
    static constexpr uint32_t ID = 1008;
    using SP = std::shared_ptr<RecheckBucketInfoReply>;
    using UP = std::unique_ptr<RecheckBucketInfoReply>;

    explicit RecheckBucketInfoReply(const RecheckBucketInfoCommand& cmd);
    ~RecheckBucketInfoReply() override;

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

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

class AbortBucketOperationsCommand : public api::InternalCommand
{
public:
    class AbortPredicate {
        virtual bool doShouldAbort(const document::Bucket&) const = 0;
    public:
        virtual ~AbortPredicate() {}
        bool shouldAbort(const document::Bucket &bucket) const {
            return doShouldAbort(bucket);
        }
    };

    static constexpr uint32_t ID = 1009;
    using SP = std::shared_ptr<AbortBucketOperationsCommand>;
    using CSP = std::shared_ptr<const AbortBucketOperationsCommand>;
private:
    std::unique_ptr<AbortPredicate> _predicate;
public:
    explicit AbortBucketOperationsCommand(std::unique_ptr<AbortPredicate> predicate);
    ~AbortBucketOperationsCommand() override;

    bool shouldAbort(const document::Bucket &bucket) const {
        return _predicate->shouldAbort(bucket);
    }

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

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

class AbortBucketOperationsReply : public api::InternalReply
{
public:
    static constexpr uint32_t ID = 1010;
    using SP = std::shared_ptr<AbortBucketOperationsReply>;
    using CSP = std::shared_ptr<const AbortBucketOperationsReply>;

    explicit AbortBucketOperationsReply(const AbortBucketOperationsCommand& cmd);
    ~AbortBucketOperationsReply() override;

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


// Internal Command task for bringing along a Bucket and a BucketTask in
// the inner workings of the storagelink chain.
class RunTaskCommand : public api::InternalCommand {
public:
    static constexpr uint32_t ID = 1011;
    RunTaskCommand(const spi::Bucket &bucket, std::unique_ptr<spi::BucketTask> task);
    ~RunTaskCommand();

    document::Bucket getBucket() const override { return _bucket.getBucket(); }
    std::unique_ptr<api::StorageReply> makeReply() override;
    void run(const spi::Bucket & bucket, std::shared_ptr<vespalib::IDestructorCallback> onComplete);

    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
    std::unique_ptr<spi::BucketTask> stealTask() { return std::move(_task); }
private:
    std::unique_ptr<spi::BucketTask> _task;
    spi::Bucket                      _bucket;
};

// Simple reply for matching the RunTaskCommand
class RunTaskReply : public api::InternalReply
{
public:
    explicit RunTaskReply(const RunTaskCommand&);
    ~RunTaskReply();
    void print(std::ostream& out, bool verbose, const std::string& indent) const override;
private:
    static constexpr uint32_t ID = 1012;
};

} // ns storage