Skip to content

Commit 8723f19

Browse files
rdemellowowend74
authored andcommitted
MB-45670: Revert "MB-45505: VB::Filter 'uid' clean-up"
This reverts commit 7efc1df. Reason for revert: Reverting patch as this has broken multiple DCP clients when sending stream requests with just a collection manifest uid (MB-45670 & MB-45673). Change-Id: Id64c932ea14af9c4408252659b5f23e6fc068cc2 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/151130 Reviewed-by: Dave Rigby <[email protected]> Reviewed-by: Daniel Owen <[email protected]> Tested-by: Richard de Mellow <[email protected]>
1 parent bfd3953 commit 8723f19

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

engines/ep/src/collections/vbucket_filter.cc

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ std::pair<cb::engine_errc, uint64_t> Filter::constructFromJson(
113113
}
114114
}
115115

116+
const auto uidObject = json.find(UidKey);
117+
// Check if a uid is specified and parse it
118+
if (uidObject != json.end()) {
119+
auto jsonUid = cb::getJsonObject(
120+
json, UidKey, UidType, "Filter::constructFromJson");
121+
uid = makeUid(jsonUid.get<std::string>());
122+
}
123+
116124
const auto scopesObject = json.find(ScopeKey);
117125
const auto collectionsObject = json.find(CollectionsKey);
118126
if (scopesObject != json.end()) {
@@ -154,10 +162,10 @@ std::pair<cb::engine_errc, uint64_t> Filter::constructFromJson(
154162
}
155163
}
156164

157-
// The input JSON must of contained at least a sid, scope, or
165+
// The input JSON must of contained at least a sid, uid, scope, or
158166
// collections key
159-
if (collectionsObject == json.end() && scopesObject == json.end() &&
160-
streamIdObject == json.end()) {
167+
if (uidObject == json.end() && collectionsObject == json.end() &&
168+
scopesObject == json.end() && streamIdObject == json.end()) {
161169
throw cb::engine_error(
162170
cb::engine_errc::invalid_arguments,
163171
"Filter::constructFromJson no sid, uid, scope or "
@@ -333,16 +341,20 @@ bool Filter::processScopeEvent(const Item& item) {
333341
}
334342

335343
// scope filter we check if event matches our scope
344+
// passthrough we check if the event manifest-id is greater than the clients
336345
if (scopeID || passthrough) {
337346
ScopeID sid = 0;
347+
ManifestUid manifestUid{0};
338348

339349
if (!item.isDeleted()) {
340350
auto dcpData = VB::Manifest::getCreateScopeEventData(
341351
{item.getData(), item.getNBytes()});
352+
manifestUid = dcpData.manifestUid;
342353
sid = dcpData.metaData.sid;
343354
} else {
344355
auto dcpData = VB::Manifest::getDropScopeEventData(
345356
{item.getData(), item.getNBytes()});
357+
manifestUid = dcpData.manifestUid;
346358
sid = dcpData.sid;
347359

348360
if (sid == scopeID) {
@@ -411,6 +423,10 @@ void Filter::addStats(const AddStatFn& add_stat,
411423
add_casted_stat(buffer, scopeIsDropped, add_stat, c);
412424
}
413425

426+
checked_snprintf(
427+
buffer, bsize, "%s:filter_%d_uid", prefix.c_str(), vb.get());
428+
add_casted_stat(buffer, getUid(), add_stat, c);
429+
414430
checked_snprintf(
415431
buffer, bsize, "%s:filter_%d_sid", prefix.c_str(), vb.get());
416432
add_casted_stat(buffer, streamId.to_string(), add_stat, c);
@@ -428,6 +444,13 @@ void Filter::addStats(const AddStatFn& add_stat,
428444
}
429445
}
430446

447+
std::string Filter::getUid() const {
448+
if (uid) {
449+
return std::to_string(*uid);
450+
}
451+
return "none";
452+
}
453+
431454
cb::engine_errc Filter::checkPrivileges(
432455
gsl::not_null<const void*> cookie,
433456
const EventuallyPersistentEngine& engine) {
@@ -490,6 +513,7 @@ void Filter::dump() const {
490513
// To use the keys in json::find, they need to be statically allocated
491514
const char* Filter::CollectionsKey = "collections";
492515
const char* Filter::ScopeKey = "scope";
516+
const char* Filter::UidKey = "uid";
493517
const char* Filter::StreamIdKey = "sid";
494518

495519
std::ostream& operator<<(std::ostream& os, const Filter& filter) {
@@ -505,6 +529,9 @@ std::ostream& operator<<(std::ostream& os, const Filter& filter) {
505529
os << ", lastCheckedPrivilegeRevision: "
506530
<< filter.lastCheckedPrivilegeRevision.value();
507531
}
532+
if (filter.uid) {
533+
os << ", uid:" << *filter.uid;
534+
}
508535

509536
os << ", sid:" << filter.streamId;
510537
os << ", filter.size:" << filter.filter.size() << std::endl;

engines/ep/src/collections/vbucket_filter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class Filter {
180180
return filter.begin()->first;
181181
}
182182

183+
std::string getUid() const;
184+
183185
cb::mcbp::DcpStreamId getStreamId() const {
184186
return streamId;
185187
}
@@ -290,6 +292,7 @@ class Filter {
290292

291293
Container filter;
292294

295+
std::optional<Collections::ManifestUid> uid;
293296
std::optional<ScopeID> scopeID;
294297
// use an optional so we don't use any special values to mean unset
295298
std::optional<uint32_t> lastCheckedPrivilegeRevision;
@@ -304,6 +307,7 @@ class Filter {
304307
// keys and types used in JSON parsing
305308
static const char* CollectionsKey;
306309
static const char* ScopeKey;
310+
static const char* UidKey;
307311
static const char* StreamIdKey;
308312
};
309313

engines/ep/src/dcp/active_stream.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ ActiveStream::ActiveStream(EventuallyPersistentEngine* e,
108108

109109
log(spdlog::level::info,
110110
"{} Creating {}stream with start seqno {} and end seqno {}; "
111-
"requested end seqno was {}, collections-manifest filter:{} {}",
111+
"requested end seqno was {}, collections-manifest uid:{}, filter:{} {}",
112112
logPrefix,
113113
type,
114114
st_seqno,
115115
end_seqno_,
116116
en_seqno,
117+
filter.getUid(),
117118
filter.size(),
118119
sid);
119120

0 commit comments

Comments
 (0)