aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/visitor.cpp
blob: 821b98ab7b22b2499283ec438685392df6025335 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "visitor.h"
#include <vespa/document/fieldset/fieldsets.h>
#include <vespa/vespalib/util/array.hpp>
#include <climits>
#include <ostream>

namespace storage::api {

IMPLEMENT_COMMAND(CreateVisitorCommand, CreateVisitorReply)
IMPLEMENT_REPLY(CreateVisitorReply)
IMPLEMENT_COMMAND(DestroyVisitorCommand, DestroyVisitorReply)
IMPLEMENT_REPLY(DestroyVisitorReply)
IMPLEMENT_COMMAND(VisitorInfoCommand, VisitorInfoReply)
IMPLEMENT_REPLY(VisitorInfoReply)

CreateVisitorCommand::CreateVisitorCommand(document::BucketSpace bucketSpace,
                                           vespalib::stringref libraryName,
                                           vespalib::stringref instanceId,
                                           vespalib::stringref docSelection)
    : StorageCommand(MessageType::VISITOR_CREATE),
      _bucketSpace(bucketSpace),
      _libName(libraryName),
      _params(),
      _controlDestination(),
      _dataDestination(),
      _docSelection(docSelection),
      _buckets(),
      _fromTime(0),
      _toTime(api::MAX_TIMESTAMP),
      _visitorCmdId(getMsgId()),
      _instanceId(instanceId),
      _visitorId(0),
      _visitRemoves(false),
      _fieldSet(document::AllFields::NAME),
      _visitInconsistentBuckets(false),
      _queueTimeout(2000ms),
      _maxPendingReplyCount(2),
      _version(50),
      _maxBucketsPerVisitor(1)
{
}

CreateVisitorCommand::CreateVisitorCommand(const CreateVisitorCommand& o)
    : StorageCommand(o),
      _bucketSpace(o._bucketSpace),
      _libName(o._libName),
      _params(o._params),
      _controlDestination(o._controlDestination),
      _dataDestination(o._dataDestination),
      _docSelection(o._docSelection),
      _buckets(o._buckets),
      _fromTime(o._fromTime),
      _toTime(o._toTime),
      _visitorCmdId(getMsgId()),
      _instanceId(o._instanceId),
      _visitorId(o._visitorId),
      _visitRemoves(o._visitRemoves),
      _fieldSet(o._fieldSet),
      _visitInconsistentBuckets(o._visitInconsistentBuckets),
      _queueTimeout(o._queueTimeout),
      _maxPendingReplyCount(o._maxPendingReplyCount),
      _version(o._version),
      _maxBucketsPerVisitor(o._maxBucketsPerVisitor)
{
}

CreateVisitorCommand::~CreateVisitorCommand() = default;

document::Bucket
CreateVisitorCommand::getBucket() const
{
    return document::Bucket(_bucketSpace, document::BucketId());
}

document::BucketId
CreateVisitorCommand::super_bucket_id() const
{
    if (_buckets.empty()) {
        // TODO STRIPE: Is this actually an error situation? Should be fixed elsewhere.
        return document::BucketId();
    }
    return _buckets[0];
}

void
CreateVisitorCommand::print(std::ostream& out, bool verbose,
                            const std::string& indent) const
{
    out << "CreateVisitorCommand(" << _libName << ", " << _docSelection;
    if (verbose) {
        out << ") {";
        out << "\n" << indent << "  Library name: '" << _libName << "'";
        out << "\n" << indent << "  Instance Id: '" << _instanceId << "'";
        out << "\n" << indent << "  Control Destination: '" << _controlDestination << "'";
        out << "\n" << indent << "  Data Destination: '" << _dataDestination << "'";
        out << "\n" << indent << "  Doc Selection: '" << _docSelection << "'";
        out << "\n" << indent << "  Max pending: '" << _maxPendingReplyCount << "'";
        out << "\n" << indent << "  Timeout: " << vespalib::count_ms(getTimeout()) << " ms";
        out << "\n" << indent << "  Queue timeout: " << vespalib::count_ms(_queueTimeout) << " ms";
        out << "\n" << indent << "  VisitorDispatcher version: '" << _version << "'";
        if (visitRemoves()) {
            out << "\n" << indent << "  Visiting remove entries too";
        }

        out << "\n" << indent << "  Returning fields: " << _fieldSet;

        if (visitInconsistentBuckets()) {
            out << "\n" << indent << "  Visiting inconsistent buckets";
        }
        out << "\n" << indent << "  From " << _fromTime << " to " << _toTime;
        for (std::vector<document::BucketId>::const_iterator it
                = _buckets.begin(); it != _buckets.end(); ++it)
        {
            out << "\n" << indent << "  " << (*it);
        }
        out << "\n" << indent << "  ";
        _params.print(out, verbose, indent + "  ");
        out << "\n" << indent << "  Max buckets: '" << _maxBucketsPerVisitor << "'";
        out << "\n" << indent << "} : ";
        StorageCommand::print(out, verbose, indent);
    } else if (_buckets.size() == 2) {
        out << ", top " << _buckets[0] << ", progress " << _buckets[1] << ")";
    } else {
        out << ", " << _buckets.size() << " buckets)";
    }

}

CreateVisitorReply::CreateVisitorReply(const CreateVisitorCommand& cmd)
    : StorageReply(cmd),
      _super_bucket_id(cmd.super_bucket_id()),
      _lastBucket(document::BucketId(INT_MAX))
{
}

void
CreateVisitorReply::print(std::ostream& out, bool verbose,
                          const std::string& indent) const
{
    out << "CreateVisitorReply(last=" << _lastBucket << ")";
    if (verbose) {
        out << " : ";
        StorageReply::print(out, verbose, indent);
    }
}

DestroyVisitorCommand::DestroyVisitorCommand(vespalib::stringref instanceId)
    : StorageCommand(MessageType::VISITOR_DESTROY),
      _instanceId(instanceId)
{
}

void
DestroyVisitorCommand::print(std::ostream& out, bool verbose, const std::string& indent) const
{
    out << "DestroyVisitorCommand(" << _instanceId << ")";
    if (verbose) {
        out << " : ";
        StorageCommand::print(out, verbose, indent);
    }
}

DestroyVisitorReply::DestroyVisitorReply(const DestroyVisitorCommand& cmd)
    : StorageReply(cmd)
{
}

void
DestroyVisitorReply::print(std::ostream& out, bool verbose, const std::string& indent) const
{
    out << "DestroyVisitorReply()";
    if (verbose) {
        out << " : ";
        StorageReply::print(out, verbose, indent);
    }
}

VisitorInfoCommand::VisitorInfoCommand()
    : StorageCommand(MessageType::VISITOR_INFO),
      _completed(false),
      _bucketsCompleted(),
      _error(ReturnCode::OK)
{
}

VisitorInfoCommand::~VisitorInfoCommand() = default;

void
VisitorInfoCommand::print(std::ostream& out, bool verbose, const std::string& indent) const
{
    out << "VisitorInfoCommand(";
    if (_completed) { out << "completed"; }
    if (_error.failed()) {
        out << _error;
    }
    if (verbose) {
        out << ") : ";
        StorageCommand::print(out, verbose, indent);
    } else {
        if (!_bucketsCompleted.empty()) {
            out << _bucketsCompleted.size() << " buckets completed";
        }
        out << ")";
    }
}

VisitorInfoReply::VisitorInfoReply(const VisitorInfoCommand& cmd)
    : StorageReply(cmd),
      _completed(cmd.visitorCompleted())
{
}

void
VisitorInfoReply::print(std::ostream& out, bool verbose, const std::string& indent) const
{
    out << "VisitorInfoReply(";
    if (_completed) { out << "completed"; }
    if (verbose) {
        out << ") : ";
        StorageReply::print(out, verbose, indent);
    } else {
        out << ")";
    }
}

std::ostream&
operator<<(std::ostream& out, const VisitorInfoCommand::BucketTimestampPair& pair) {
    return out << pair.bucketId << " - " << pair.timestamp;
}

}