diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-12-05 13:43:52 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-11-14 09:47:52 -0500 |
commit | dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012 (patch) | |
tree | 36664490ee71eb77ddf183dcd5c642b3e732f179 /src/mongo/db/s/set_shard_version_command.cpp | |
parent | c2cc425b9d2b23eead06ecbfd996375e47c81baa (diff) | |
download | mongo-dcf7e0dd89d34f58b592f1adb3d41e5edd6e2012.tar.gz |
SERVER-32198 Split CollectionShardingState::getMetadata into three methods
o getCurrentMetadataIfKnown - which returns the current filtering
metadata if any is available
o getMetadataForOperation - which returns the metadata which is required
by the current opertion, based on the OperationShardingState
o getCurrentMetadata - which returns the currently available filtering
metadata (or UNSHARDED if not known)
This is in preparation for making
getMetadataForOperation/getCurrentMetadata throw
StaleShardVersion exception if the metadata has not been loaded yet.
Diffstat (limited to 'src/mongo/db/s/set_shard_version_command.cpp')
-rw-r--r-- | src/mongo/db/s/set_shard_version_command.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index b12aeea4435..12a8d0ef469 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -231,11 +231,12 @@ public: boost::optional<Lock::CollectionLock> collLock; collLock.emplace(opCtx->lockState(), nss.ns(), MODE_IS); - auto const css = CollectionShardingState::get(opCtx, nss); + auto* const css = CollectionShardingState::get(opCtx, nss); const ChunkVersion collectionShardVersion = [&] { - auto metadata = css->getMetadata(opCtx); - return metadata->isSharded() ? metadata->getShardVersion() - : ChunkVersion::UNSHARDED(); + auto optMetadata = css->getCurrentMetadataIfKnown(); + return (optMetadata && (*optMetadata)->isSharded()) + ? (*optMetadata)->getShardVersion() + : ChunkVersion::UNSHARDED(); }(); if (requestedVersion.isWriteCompatibleWith(collectionShardVersion)) { @@ -349,11 +350,13 @@ public: { AutoGetCollection autoColl(opCtx, nss, MODE_IS); - ChunkVersion currVersion = ChunkVersion::UNSHARDED(); - auto metadata = CollectionShardingState::get(opCtx, nss)->getMetadata(opCtx); - if (metadata->isSharded()) { - currVersion = metadata->getShardVersion(); - } + const ChunkVersion currVersion = [&] { + auto* const css = CollectionShardingState::get(opCtx, nss); + auto optMetadata = css->getCurrentMetadataIfKnown(); + return (optMetadata && (*optMetadata)->isSharded()) + ? (*optMetadata)->getShardVersion() + : ChunkVersion::UNSHARDED(); + }(); if (!status.isOK()) { // The reload itself was interrupted or confused here |