Skip to content

Commit

Permalink
MB-47604: Make it possible to swap Flush::manifest
Browse files Browse the repository at this point in the history
NexusKVStore needs to be able to swap the VB::Manifest of a
Collections::Flush object so that the copy created for the secondary
KVStore does not break the stats tracked in the primary VB::Manifest.

Change-Id: I3a14dbb18422cb6574214b711bc88fd1c9a99504
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/158672
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Paolo Cocchi <paolo.cocchi@couchbase.com>
  • Loading branch information
BenHuddleston committed Aug 12, 2021
1 parent 4a9e8db commit a939113
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 10 additions & 5 deletions engines/ep/src/collections/flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Flush::saveCollectionStats(
}

// Get the current stats of the collection (for the seqno).
auto collsFlushStats = manifest.lock().getStatsForFlush(
auto collsFlushStats = manifest.get().lock().getStatsForFlush(
cid, flushStats.getPersistedHighSeqno());

// Generate new stats, add the deltas from this flush batch for count
Expand Down Expand Up @@ -93,7 +93,8 @@ uint32_t Flush::countNonEmptyDroppedCollections() const {
if (sItr == flushAccounting.getStats().end() ||
!sItr->second.itemInBatch()) {
const auto highSeqno =
manifest.lock()
manifest.get()
.lock()
.getStatsForFlush(cid, dropped.endSeqno)
.highSeqno;
if (highSeqno != 0 && highSeqno != dropped.startSeqno) {
Expand Down Expand Up @@ -130,7 +131,7 @@ void Flush::forEachDroppedCollection(
// longer applicable and are not pushed to the VB::Manifest.
void Flush::postCommitMakeStatsVisible() {
for (const auto& [cid, flushStats] : flushAccounting.getStats()) {
auto lock = manifest.lock(cid);
auto lock = manifest.get().lock(cid);
if (!lock.valid() ||
lock.isLogicallyDeleted(flushStats.getPersistedHighSeqno())) {
// Can be flushing for a dropped collection (no longer in the
Expand Down Expand Up @@ -161,7 +162,7 @@ void Flush::flushSuccess(Vbid vbid, EPBucket& bucket) {
void Flush::notifyManifestOfAnyDroppedCollections() {
for (const auto& [cid, droppedData] :
flushAccounting.getDroppedCollections()) {
manifest.collectionDropPersisted(cid, droppedData.endSeqno);
manifest.get().collectionDropPersisted(cid, droppedData.endSeqno);
}
}

Expand Down Expand Up @@ -603,7 +604,7 @@ flatbuffers::DetachedBuffer Flush::encodeOpenScopes(
}

bool Flush::droppedCollectionsExists() const {
return manifest.isDropInProgress();
return manifest.get().isDropInProgress();
}

FlushAccounting::StatisticsUpdate Flush::getDroppedStats(CollectionID cid) {
Expand Down Expand Up @@ -670,4 +671,8 @@ void Flush::updateStats(const DocKey& key,
}
}

void Flush::setManifest(Manifest& newManifest) {
manifest = newManifest;
}

} // namespace Collections::VB
10 changes: 9 additions & 1 deletion engines/ep/src/collections/flush.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class Flush {
*/
void setManifestUid(ManifestUid uid);

/**
* Set the manifest to the given manifest. Required by the NexusKVStore to
* generate a VB::Commit/Collections::Flush to track collections stats
* for the secondary KVStore without altering the stats tracked in the
* primary VB::Manifest.
*/
void setManifest(Manifest& newManifest);

/**
* Called after a flush was successful so that purging can be triggered and
* statistic changes applied.
Expand Down Expand Up @@ -351,7 +359,7 @@ class Flush {
* ref to the 'parent' manifest for this VB::Flusher, this will receive item
* count updates
*/
Manifest& manifest;
std::reference_wrapper<Manifest> manifest;

/**
* Flushing counts how many non-empty collections were committed and uses
Expand Down

0 comments on commit a939113

Please sign in to comment.