@@ -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+
431454cb::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
491514const char * Filter::CollectionsKey = " collections" ;
492515const char * Filter::ScopeKey = " scope" ;
516+ const char * Filter::UidKey = " uid" ;
493517const char * Filter::StreamIdKey = " sid" ;
494518
495519std::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;
0 commit comments