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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "updateoperation.h"
#include <vespa/document/base/exceptions.h>
#include <vespa/document/update/documentupdate.h>
#include <cassert>
#include <vespa/log/log.h>
LOG_SETUP(".proton.feedoperation.updateoperation");
using document::BucketId;
using document::DocumentType;
using document::DocumentTypeRepo;
using document::DocumentUpdate;
using vespalib::make_string;
namespace proton {
UpdateOperation::UpdateOperation()
: UpdateOperation(FeedOperation::UPDATE)
{
}
UpdateOperation::UpdateOperation(Type type)
: DocumentOperation(type),
_upd()
{
}
UpdateOperation::UpdateOperation(Type type, const BucketId &bucketId,
Timestamp timestamp, DocumentUpdate::SP upd)
: DocumentOperation(type, bucketId, timestamp),
_upd(std::move(upd))
{
}
UpdateOperation::UpdateOperation(const BucketId &bucketId, Timestamp timestamp, DocumentUpdate::SP upd)
: UpdateOperation(FeedOperation::UPDATE, bucketId, timestamp, std::move(upd))
{
}
UpdateOperation::~UpdateOperation() = default;
void
UpdateOperation::serializeUpdate(vespalib::nbostream &os) const
{
assert(getType() == UPDATE);
_upd->serializeHEAD(os);
}
void
UpdateOperation::deserializeUpdate(vespalib::nbostream && is, const document::DocumentTypeRepo &repo)
{
_upd = DocumentUpdate::createHEAD(repo, std::move(is));
}
void
UpdateOperation::serialize(vespalib::nbostream &os) const
{
assertValidBucketId(_upd->getId());
DocumentOperation::serialize(os);
serializeUpdate(os);
}
void
UpdateOperation::deserialize(vespalib::nbostream &is, const DocumentTypeRepo &repo)
{
DocumentOperation::deserialize(is, repo);
try {
deserializeUpdate(std::move(is), repo);
} catch (document::DocumentTypeNotFoundException &e) {
LOG(warning, "Failed deserialize update operation using unknown document type '%s'",
e.getDocumentTypeName().c_str());
// Ignore this piece of data
is.clear();
}
}
void
UpdateOperation::verifyUpdate(const DocumentTypeRepo &repo)
{
vespalib::nbostream stream;
serializeUpdate(stream);
deserializeUpdate(std::move(stream), repo);
_upd->eagerDeserialize(); // Will trigger exceptions if incompatible
}
vespalib::string
UpdateOperation::toString() const {
return make_string("%s(%s, %s)",
((getType() == FeedOperation::UPDATE_42) ? "Update42" : "Update"),
_upd.get() ? _upd->getId().getScheme().toString().c_str() : "NULL",
docArgsToString().c_str());
}
} // namespace proton
|