@@ -448,44 +448,29 @@ flatbuffers::DetachedBuffer Flush::encodeOpenCollections(
448448
449449flatbuffers::DetachedBuffer Flush::encodeDroppedCollections (
450450 std::vector<Collections::KVStore::DroppedCollection>& existingDropped) {
451- flatbuffers::FlatBufferBuilder builder;
452- std::vector<flatbuffers::Offset<Collections::KVStore::Dropped>> output;
453-
454- // Add Collection's to this set only if they are in both old and new
455- // sets of dropped collections - this ensures we generate it once into
456- // the new output.
457- std::unordered_set<CollectionID> skip;
458-
459451 // Iterate through the existing dropped collections and look each up in the
460452 // commit metadata. If the collection is in both lists, we will just update
461453 // the existing data (adjusting the endSeqno) and then erase the collection
462454 // from the commit meta's dropped collections.
463455 for (auto & collection : existingDropped) {
464456 if (auto itr = droppedCollections.find (collection.collectionId );
465457 itr != droppedCollections.end ()) {
466- // Collection is in both old and new 'sets' of dropped collections
467- // we only want it in the output once - update the end-seqno here
468- // and add to skip set
469458 collection.endSeqno = itr->second .endSeqno ;
470- skip.emplace (collection.collectionId );
459+
460+ // Now kick the collection out of collectionsMeta, its contribution
461+ // to the final output is complete
462+ droppedCollections.erase (itr);
471463 }
472- auto newEntry = Collections::KVStore::CreateDropped (
473- builder,
474- collection.startSeqno ,
475- collection.endSeqno ,
476- uint32_t (collection.collectionId ));
477- output.push_back (newEntry);
478464 }
479465
480- // Now add the newly dropped collections
481- // Iterate through the set of collections dropped in the commit batch and
466+ flatbuffers::FlatBufferBuilder builder;
467+ std::vector<flatbuffers::Offset<Collections::KVStore::Dropped>> output;
468+
469+ // Now merge, first the newly dropped collections
470+ // Iterate through the list collections dropped in the commit batch and
482471 // and create flatbuffer versions of each one
483472 for (const auto & [cid, dropped] : droppedCollections) {
484473 (void )cid;
485- if (skip.count (cid) > 0 ) {
486- // This collection is already in output
487- continue ;
488- }
489474 auto newEntry = Collections::KVStore::CreateDropped (
490475 builder,
491476 dropped.startSeqno ,
@@ -494,6 +479,16 @@ flatbuffers::DetachedBuffer Flush::encodeDroppedCollections(
494479 output.push_back (newEntry);
495480 }
496481
482+ // and now copy across the existing dropped collections
483+ for (const auto & entry : existingDropped) {
484+ auto newEntry = Collections::KVStore::CreateDropped (
485+ builder,
486+ entry.startSeqno ,
487+ entry.endSeqno ,
488+ uint32_t (entry.collectionId ));
489+ output.push_back (newEntry);
490+ }
491+
497492 auto vector = builder.CreateVector (output);
498493 auto final =
499494 Collections::KVStore::CreateDroppedCollections (builder, vector);
0 commit comments