Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 5c9288f

Browse files
jordistEvergreen Agent
authored andcommitted
SERVER-56956 ScopedShardVersionCriticalSection can leave critical section held if filtering metadata refresh fails
1 parent f62706d commit 5c9288f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/mongo/db/s/shard_filtering_metadata_refresh.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,16 @@ ScopedShardVersionCriticalSection::ScopedShardVersionCriticalSection(OperationCo
318318
}
319319
}
320320

321-
forceShardFilteringMetadataRefresh(_opCtx, _nss);
321+
try {
322+
forceShardFilteringMetadataRefresh(_opCtx, _nss);
323+
} catch (const DBException&) {
324+
_cleanup();
325+
throw;
326+
}
322327
}
323328

324329
ScopedShardVersionCriticalSection::~ScopedShardVersionCriticalSection() {
325-
UninterruptibleLockGuard noInterrupt(_opCtx->lockState());
326-
// DBLock and CollectionLock are used here to avoid throwing further recursive stale config
327-
// errors.
328-
Lock::DBLock dbLock(_opCtx, _nss.db(), MODE_IX);
329-
Lock::CollectionLock collLock(_opCtx, _nss, MODE_IX);
330-
auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss);
331-
auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(_opCtx, csr);
332-
csr->exitCriticalSection(csrLock, _reason);
330+
_cleanup();
333331
}
334332

335333
void ScopedShardVersionCriticalSection::enterCommitPhase() {
@@ -344,6 +342,17 @@ void ScopedShardVersionCriticalSection::enterCommitPhase() {
344342
csr->enterCriticalSectionCommitPhase(csrLock, _reason);
345343
}
346344

345+
void ScopedShardVersionCriticalSection::_cleanup() {
346+
UninterruptibleLockGuard noInterrupt(_opCtx->lockState());
347+
// DBLock and CollectionLock are used here to avoid throwing further recursive stale config
348+
// errors.
349+
Lock::DBLock dbLock(_opCtx, _nss.db(), MODE_IX);
350+
Lock::CollectionLock collLock(_opCtx, _nss, MODE_IX);
351+
auto* const csr = CollectionShardingRuntime::get(_opCtx, _nss);
352+
auto csrLock = CollectionShardingRuntime::CSRLock::lockExclusive(_opCtx, csr);
353+
csr->exitCriticalSection(csrLock, _reason);
354+
}
355+
347356
Status onShardVersionMismatchNoExcept(OperationContext* opCtx,
348357
const NamespaceString& nss,
349358
boost::optional<ChunkVersion> shardVersionReceived) noexcept {

src/mongo/db/s/shard_filtering_metadata_refresh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ScopedShardVersionCriticalSection {
119119
void enterCommitPhase();
120120

121121
private:
122+
void _cleanup();
123+
122124
OperationContext* const _opCtx;
123125
const NamespaceString _nss;
124126
const BSONObj _reason;

0 commit comments

Comments
 (0)