@@ -237,27 +237,26 @@ ManifestUpdateStatus Manifest::update(VBucket& vb,
237237
238238 // If manifest was equal.
239239 if (manifest.getUid () == manifestUid) {
240- if (changes.empty ()) {
240+ if (changes.none ()) {
241241 return ManifestUpdateStatus::Success;
242- } else if (changes.onlyScopesModified ()) {
243- EP_LOG_WARN (" Manifest::update {} equal uid and {} scopes modified" ,
244- vb.getId (),
245- changes.scopesToModify .size ());
246- } else {
247- // Log verbosely for this case
242+ } else if (changes.wouldCreateOrDrop ()) {
243+ // Log verbosely for this case. An equal manifest should not change
244+ // the scope or collection membership
248245 EP_LOG_WARN (
249246 " Manifest::update {} with equal uid:{:#x} but differences "
250- " scopes+:{}, collections+:{}, scopes-:{}, collections-:{}, "
251- " scopes-modified:{}" ,
247+ " scopes+:{}, collections+:{}, scopes-:{}, collections-:{}" ,
252248 vb.getId (),
253249 manifestUid,
254250 changes.scopesToCreate .size (),
255251 changes.collectionsToCreate .size (),
256252 changes.scopesToDrop .size (),
257- changes.collectionsToDrop .size (),
258- changes.scopesToModify .size ());
253+ changes.collectionsToDrop .size ());
259254 return ManifestUpdateStatus::EqualUidWithDifferences;
260255 }
256+ // else a scope modification or change of scopeWithDataLimitExists is
257+ // allowed when the uid is equal
258+ Expects (!changes.scopesToModify .empty () ||
259+ changes.changeScopeWithDataLimitExists );
261260 }
262261
263262 completeUpdate (std::move (upgradeLock), vb, changes);
@@ -292,25 +291,39 @@ void Manifest::completeUpdate(mutex_type::UpgradeHolder&& upgradeLock,
292291 WriteHandle wHandle (*this , std::move (upgradeLock));
293292
294293 // Capture the UID
295- if (changeset.empty ()) {
294+ if (changeset.none ()) {
296295 updateUid (changeset.uid , false /* reset*/ );
297296 return ;
298297 }
299298
299+ if (changeset.changeScopeWithDataLimitExists ) {
300+ EP_LOG_INFO (
301+ " Manifest::completeUpdate {} toggling scopeWithDataLimitExists "
302+ " {} -> {}" ,
303+ vb.getId (),
304+ scopeWithDataLimitExists,
305+ changeset.changeScopeWithDataLimitExists .value ());
306+ scopeWithDataLimitExists =
307+ changeset.changeScopeWithDataLimitExists .value ();
308+ }
309+
300310 auto finalDeletion = applyDrops (wHandle, vb, changeset.collectionsToDrop );
301311 if (finalDeletion) {
302- auto uid = changeset.empty () ? changeset.uid : manifestUid;
303- dropCollection (
304- wHandle, vb, uid, *finalDeletion, OptionalSeqno{/* no-seqno*/ });
312+ // if the changeset is now 'drained' of create/drop, then this is final
313+ // the final change to make - so use changeset.uid
314+ dropCollection (wHandle,
315+ vb,
316+ changeset.getUidForChange (manifestUid),
317+ *finalDeletion,
318+ OptionalSeqno{/* no-seqno*/ });
305319 }
306320
307321 auto finalScopeCreate =
308322 applyScopeCreates (wHandle, vb, changeset.scopesToCreate );
309323 if (finalScopeCreate) {
310- auto uid = changeset.empty () ? changeset.uid : manifestUid;
311324 createScope (wHandle,
312325 vb,
313- uid ,
326+ changeset. getUidForChange (manifestUid) ,
314327 finalScopeCreate.value ().sid ,
315328 finalScopeCreate.value ().name ,
316329 finalScopeCreate.value ().dataLimit ,
@@ -321,10 +334,9 @@ void Manifest::completeUpdate(mutex_type::UpgradeHolder&& upgradeLock,
321334 applyCreates (wHandle, vb, changeset.collectionsToCreate );
322335
323336 if (finalAddition) {
324- auto uid = changeset.empty () ? changeset.uid : manifestUid;
325337 createCollection (wHandle,
326338 vb,
327- uid ,
339+ changeset. getUidForChange (manifestUid) ,
328340 finalAddition.value ().identifiers ,
329341 finalAddition.value ().name ,
330342 finalAddition.value ().maxTtl ,
@@ -346,6 +358,7 @@ void Manifest::completeUpdate(mutex_type::UpgradeHolder&& upgradeLock,
346358 // Can do the scope modifications last - these generate no events but will
347359 // just sync any scope to the manifest
348360 for (const auto & modified : changeset.scopesToModify ) {
361+ // Here the changeset.uid is used as it's for logging
349362 modifyScope (wHandle, vb, changeset.uid , modified);
350363 }
351364}
@@ -696,6 +709,8 @@ Manifest::ManifestChanges Manifest::processManifest(
696709 const Collections::Manifest& manifest) {
697710 ManifestChanges rv{manifest.getUid ()};
698711
712+ bool scopeWithDataLimitExists{false };
713+
699714 // First iterate through the collections of this VB::Manifest
700715 for (const auto & [cid, entry] : map) {
701716 // Look-up the collection inside the new manifest
@@ -737,6 +752,10 @@ Manifest::ManifestChanges Manifest::processManifest(
737752 }
738753 }
739754
755+ if (scopeItr->second .dataLimit ) {
756+ scopeWithDataLimitExists = true ;
757+ }
758+
740759 for (const auto & m : scopeItr->second .collections ) {
741760 auto mapItr = map.find (m.cid );
742761
@@ -747,6 +766,10 @@ Manifest::ManifestChanges Manifest::processManifest(
747766 }
748767 }
749768
769+ if (this ->scopeWithDataLimitExists != scopeWithDataLimitExists) {
770+ rv.changeScopeWithDataLimitExists = scopeWithDataLimitExists;
771+ }
772+
750773 return rv;
751774}
752775
@@ -1167,6 +1190,10 @@ bool Manifest::addScopeStats(Vbid vbid, const StatCollector& collector) const {
11671190 format_to (key, " vb_{}:manifest:uid" , vbid.get ());
11681191 collector.addStat (std::string_view (key.data (), key.size ()), manifestUid);
11691192
1193+ format_to (key, " vb_{}:scope_data_limit" , vbid.get ());
1194+ collector.addStat (std::string_view (key.data (), key.size ()),
1195+ scopeWithDataLimitExists);
1196+
11701197 for (const auto & [sid, value] : scopes) {
11711198 key.resize (0 );
11721199 format_to (key, " vb_{}:{}:name:" , vbid.get (), sid);
@@ -1273,6 +1300,10 @@ bool Manifest::operator!=(const Manifest& rhs) const {
12731300
12741301cb::engine_errc Manifest::getScopeDataLimitStatus (
12751302 const container::const_iterator itr, size_t nBytes) const {
1303+ if (!scopeWithDataLimitExists) {
1304+ return cb::engine_errc::success;
1305+ }
1306+
12761307 const auto & entry = getScopeEntry (itr->second .getScopeID ());
12771308
12781309 if (entry.getDataLimit () &&
@@ -1446,6 +1477,8 @@ std::ostream& operator<<(std::ostream& os,
14461477std::ostream& operator <<(std::ostream& os, const Manifest& manifest) {
14471478 os << " VB::Manifest: "
14481479 << " uid:" << manifest.manifestUid
1480+ << " scopeWithDataLimitExists:" << manifest.scopeWithDataLimitExists
1481+ << " dropInProgress:" << manifest.dropInProgress .load ()
14491482 << " , scopes.size:" << manifest.scopes .size ()
14501483 << " , map.size:" << manifest.map .size () << std::endl;
14511484 for (const auto & [cid, entry] : manifest.map ) {
0 commit comments