summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/sharding_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/sharding_state.cpp')
-rw-r--r--src/mongo/db/s/sharding_state.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 2f46a11552e..608a4bac233 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -243,26 +243,23 @@ Status ShardingState::onStaleShardVersion(OperationContext* opCtx,
auto& oss = OperationShardingState::get(opCtx);
oss.waitForMigrationCriticalSectionSignal(opCtx);
- ChunkVersion collectionShardVersion;
-
- // Fast path - check if the requested version is at a higher version than the current metadata
- // version or a different epoch before verifying against config server.
- ScopedCollectionMetadata currentMetadata;
-
- {
+ const auto collectionShardVersion = [&] {
+ // Fast path - check if the requested version is at a higher version than the current
+ // metadata version or a different epoch before verifying against config server
AutoGetCollection autoColl(opCtx, nss, MODE_IS);
-
- currentMetadata = CollectionShardingState::get(opCtx, nss)->getMetadata();
+ const auto currentMetadata = CollectionShardingState::get(opCtx, nss)->getMetadata();
if (currentMetadata) {
- collectionShardVersion = currentMetadata->getShardVersion();
+ return currentMetadata->getShardVersion();
}
- if (collectionShardVersion.epoch() == expectedVersion.epoch() &&
- collectionShardVersion >= expectedVersion) {
- // Don't need to remotely reload if we're in the same epoch and the requested version is
- // smaller than the one we know about. This means that the remote side is behind.
- return Status::OK();
- }
+ return ChunkVersion::UNSHARDED();
+ }();
+
+ if (collectionShardVersion.epoch() == expectedVersion.epoch() &&
+ collectionShardVersion >= expectedVersion) {
+ // Don't need to remotely reload if we're in the same epoch and the requested version is
+ // smaller than the one we know about. This means that the remote side is behind.
+ return Status::OK();
}
try {