aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/messages/visitor.h
blob: 00667d006feb08f5c0a470319a24d138d6459b83 (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
272
273
274
275
276
277
278
279
280
281
282
283
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "writedocumentreply.h"
#include "documentmessage.h"
#include "documentreply.h"
#include <vespa/vdslib/container/parameters.h>
#include <vespa/vdslib/container/visitorstatistics.h>
#include <vespa/document/bucket/bucketid.h>
#include <vespa/documentapi/messagebus/documentprotocol.h>

namespace document { class Document; }
namespace documentapi {

using Timestamp = uint64_t;

/**
 * @class CreateVisitorMessage
 * @ingroup message
 *
 * @brief Message for creating a visitor.
 */
class CreateVisitorMessage : public DocumentMessage {
private:
    string _libName;
    string _instanceId;
    string _controlDestination;
    string _dataDestination;
    string _bucketSpace;
    string _docSelection;
    uint32_t _maxPendingReplyCount;
    std::vector<document::BucketId> _buckets;
    Timestamp _fromTime;
    Timestamp _toTime;
    bool   _visitRemoves;
    string _fieldSet;
    bool _visitInconsistentBuckets;
    vdslib::Parameters _params;
    uint32_t _version;
    uint32_t _maxBucketsPerVisitor;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    using UP = std::unique_ptr<CreateVisitorMessage>;

    CreateVisitorMessage(); // must be deserialized into
    CreateVisitorMessage(const string& libraryName,
                         const string& instanceId,
                         const string& controlDestination,
                         const string& dataDestination);
    ~CreateVisitorMessage() override;

    const string& getLibraryName() const { return _libName; }
    void setLibraryName(const string& value) { _libName = value; }

    const string& getInstanceId() const { return _instanceId; }
    void setInstanceId(const string& value) { _instanceId = value; }

    const string& getDocumentSelection() const { return _docSelection; }
    void setDocumentSelection(const string& value) { _docSelection = value; }

    const string& getControlDestination() const { return _controlDestination; }
    void setControlDestination(const string& value) { _controlDestination = value; };

    const string& getDataDestination() const { return _dataDestination; }
    void setDataDestination(const string& value) { _dataDestination = value; }

    const string& getBucketSpace() const { return _bucketSpace; }
    void setBucketSpace(const string& value) { _bucketSpace = value; }

    const vdslib::Parameters& getParameters() const { return _params; }
    vdslib::Parameters& getParameters() { return _params; }
    void setParameters(const vdslib::Parameters& params) { _params = params; }

    uint32_t getMaximumPendingReplyCount() const { return _maxPendingReplyCount; }
    void setMaximumPendingReplyCount(uint32_t count) { _maxPendingReplyCount = count; }

    const std::vector<document::BucketId>& getBuckets() const { return _buckets; }
    std::vector<document::BucketId>& getBuckets() { return _buckets; }

    const document::BucketId getBucketId() const { return *_buckets.begin(); }

    bool visitRemoves() const { return _visitRemoves; }
    void setVisitRemoves(bool val) { _visitRemoves = val; }

    const string & getFieldSet() const { return _fieldSet; }
    void setFieldSet(vespalib::stringref fieldSet) { _fieldSet = fieldSet; }

    bool visitInconsistentBuckets() const { return _visitInconsistentBuckets; }
    void setVisitInconsistentBuckets(bool val) { _visitInconsistentBuckets = val; }

    Timestamp getFromTimestamp() const { return _fromTime; };
    void setFromTimestamp(Timestamp from) { _fromTime = from; };

    Timestamp getToTimestamp() const { return _toTime; };
    void setToTimestamp(Timestamp to) { _toTime = to; };

    uint32_t getMaxBucketsPerVisitor() const { return _maxBucketsPerVisitor; }
    void setMaxBucketsPerVisitor(uint32_t max) { _maxBucketsPerVisitor = max; }

    uint32_t getType() const override;

    void setVisitorDispatcherVersion(uint32_t version) { _version = version; };
    uint32_t getVisitorDispatcherVersion() const { return _version; };

    string toString() const override { return "createvisitormessage"; }
};

/**
 * @class DestroyVisitorMessage
 * @ingroup message
 *
 * @brief Message for removing a visitor.
 */
class DestroyVisitorMessage : public DocumentMessage {
private:
    string _instanceId;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    using UP = std::unique_ptr<DestroyVisitorMessage>;

    DestroyVisitorMessage(); // must be deserialized into
    DestroyVisitorMessage(const string &instanceId);
    ~DestroyVisitorMessage();

    const string& getInstanceId() const { return _instanceId; }
    void setInstanceId(const string& id) { _instanceId = id; }

    uint32_t getType() const override;
    string toString() const override { return "destroyvisitormessage"; }
};

/**
 * Superclass for all commands sent from VisitorManager to a Visitor
 * client.
 */
class VisitorMessage : public DocumentMessage {
protected:
    VisitorMessage() { }
};

/**
 * Superclass for all commands sent from VisitorManager to a Visitor
 * client.
 */
class VisitorReply : public WriteDocumentReply {
public:
    VisitorReply(uint32_t type);
};

class CreateVisitorReply : public DocumentReply {
private:
    document::BucketId _lastBucket;
    vdslib::VisitorStatistics _visitorStatistics;

public:
    CreateVisitorReply(uint32_t type);

    void setLastBucket(document::BucketId lastBucket) { _lastBucket = lastBucket; }

    document::BucketId getLastBucket() const { return _lastBucket; }

    const vdslib::VisitorStatistics& getVisitorStatistics() const { return _visitorStatistics; }
    void setVisitorStatistics(const vdslib::VisitorStatistics& stats) { _visitorStatistics = stats; }

    string toString() const override { return "createvisitorreply"; }
};

/**
 * @class VisitorInfoMessage
 * @ingroup message
 *
 * @brief Sends status information of an ongoing visitor.
 *
 *  - Notification when individual buckets have been completely visited.
 */
class VisitorInfoMessage : public VisitorMessage {
private:
    std::vector<document::BucketId> _finishedBuckets;
    string                     _errorMessage;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    using UP = std::unique_ptr<VisitorInfoMessage>;

    VisitorInfoMessage();
    ~VisitorInfoMessage();

    std::vector<document::BucketId>& getFinishedBuckets() { return _finishedBuckets; }
    const std::vector<document::BucketId>& getFinishedBuckets() const { return _finishedBuckets; }

    const string& getErrorMessage() const { return _errorMessage; }
    void setErrorMessage(const string& errorMessage) { _errorMessage = errorMessage; };

    uint32_t getType() const override;
    string toString() const override { return "visitorinfomessage"; }
};

/**
 * @class MapVisitorMessage
 * @ingroup message
 *
 * @brief Sends a docblock to a visitor.
 */
class MapVisitorMessage : public VisitorMessage {
private:
    vdslib::Parameters _data;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    using UP = std::unique_ptr<MapVisitorMessage>;

    MapVisitorMessage();

    vdslib::Parameters& getData() { return _data; };
    const vdslib::Parameters& getData() const { return _data; };

    uint32_t getApproxSize() const override;
    uint32_t getType() const override;
    string toString() const override { return "mapvisitormessage"; }
};

/**
 * @class DocumentListMessage
 * @ingroup message
 */
class DocumentListMessage : public VisitorMessage {
public:
    using UP = std::unique_ptr<DocumentListMessage>;
    using DocumentSP = std::shared_ptr<document::Document>;

    class Entry {
    public:
        Entry();
        Entry(int64_t timestamp, DocumentSP doc, bool removeEntry);
        Entry(const Entry& other);
        Entry(const document::DocumentTypeRepo &repo, document::ByteBuffer& buf);

        int64_t getTimestamp() { return _timestamp; }
        const DocumentSP & getDocument() { return _document; }
        bool isRemoveEntry() { return _removeEntry; }

        void serialize(vespalib::GrowableByteBuffer& buf) const;
    private:
        int64_t    _timestamp;
        DocumentSP _document;
        bool       _removeEntry;
    };

private:
    document::BucketId _bucketId;
    std::vector<Entry> _documents;

protected:
    DocumentReply::UP doCreateReply() const override;

public:
    DocumentListMessage() noexcept;
    DocumentListMessage(document::BucketId bid) noexcept;
    ~DocumentListMessage() override;

    const document::BucketId& getBucketId() const { return _bucketId; };
    void setBucketId(const document::BucketId& id) { _bucketId = id; };

    std::vector<Entry>& getDocuments() { return _documents; };
    const std::vector<Entry>& getDocuments() const { return _documents; };

    uint32_t getType() const override;
    string toString() const override { return "documentlistmessage"; }
};

}