summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2022-11-15 19:22:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-15 20:15:10 +0000
commit92431698408a4f6863bb4375d611ff51c6322116 (patch)
tree3e02a61476a3c2926b6b817fd119e966b6eb5562
parent6cdad7c65db24d28d5f7b26ea7cece1495ac3dff (diff)
downloadmongo-92431698408a4f6863bb4375d611ff51c6322116.tar.gz
SERVER-71272 Do not remove archived bucket if reopening fails
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.cpp36
1 files 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();