From 92431698408a4f6863bb4375d611ff51c6322116 Mon Sep 17 00:00:00 2001 From: Dan Larkin-York Date: Tue, 15 Nov 2022 19:22:06 +0000 Subject: SERVER-71272 Do not remove archived bucket if reopening fails --- src/mongo/db/timeseries/bucket_catalog.cpp | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp index 81c8987be40..cef4bb3a964 100644 --- a/src/mongo/db/timeseries/bucket_catalog.cpp +++ b/src/mongo/db/timeseries/bucket_catalog.cpp @@ -1506,24 +1506,6 @@ BucketCatalog::Bucket* BucketCatalog::_reopenBucket(Stripe* stripe, _expireIdleBuckets(stripe, stripeLock, stats, closedBuckets); - // If this bucket was archived, we need to remove it from the set of archived buckets. - if (auto setIt = stripe->archivedBuckets.find(key.hash); - setIt != stripe->archivedBuckets.end()) { - auto& archivedSet = setIt->second; - if (auto bucketIt = archivedSet.find(bucket->getTime()); - bucketIt != archivedSet.end() && bucket->id() == bucketIt->second.bucketId) { - long long memory = - _marginalMemoryUsageForArchivedBucket(bucketIt->second, archivedSet.size() == 1); - if (archivedSet.size() == 1) { - stripe->archivedBuckets.erase(setIt); - } else { - archivedSet.erase(bucketIt); - } - _memoryUsage.fetchAndSubtract(memory); - _numberOfActiveBuckets.fetchAndSubtract(1); - } - } - hangTimeseriesInsertBeforeReopeningBucket.pauseWhileSet(); // We may need to initialize the bucket's state. @@ -1544,6 +1526,24 @@ BucketCatalog::Bucket* BucketCatalog::_reopenBucket(Stripe* stripe, return nullptr; } + // If this bucket was archived, we need to remove it from the set of archived buckets. + if (auto setIt = stripe->archivedBuckets.find(key.hash); + setIt != stripe->archivedBuckets.end()) { + auto& archivedSet = setIt->second; + if (auto bucketIt = archivedSet.find(bucket->getTime()); + bucketIt != archivedSet.end() && bucket->id() == bucketIt->second.bucketId) { + long long memory = + _marginalMemoryUsageForArchivedBucket(bucketIt->second, archivedSet.size() == 1); + if (archivedSet.size() == 1) { + stripe->archivedBuckets.erase(setIt); + } else { + archivedSet.erase(bucketIt); + } + _memoryUsage.fetchAndSubtract(memory); + _numberOfActiveBuckets.fetchAndSubtract(1); + } + } + // Pass ownership of the reopened bucket to the bucket catalog. auto [it, inserted] = stripe->allBuckets.try_emplace(bucket->id(), std::move(bucket)); Bucket* unownedBucket = it->second.get(); -- cgit v1.2.1