summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAllison Easton <allison.easton@mongodb.com>2023-02-06 08:17:10 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-06 08:53:16 +0000
commit5b2fe7d1a17dbee9ab5ce3cf865415d72aeeb90c (patch)
treea9e3e0ee07a81d789c6cf8dd059d9973a9348d47 /src
parent56ccff6386903c3d7465e20d694ebe6833d91e35 (diff)
downloadmongo-5b2fe7d1a17dbee9ab5ce3cf865415d72aeeb90c.tar.gz
SERVER-66864 Add index version checks to versioning protocol
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index 385a2b91b67..bc13cdd914c 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -468,12 +468,21 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt(
const auto& currentMetadata = optCurrentMetadata->get();
+ const auto indexFeatureFlag = feature_flags::gGlobalIndexesShardingCatalog.isEnabled(
+ serverGlobalParams.featureCompatibility);
const auto wantedPlacementVersion = currentMetadata.getShardVersion();
- const auto wantedShardVersion =
- ShardVersion(wantedPlacementVersion, boost::optional<CollectionIndexes>(boost::none));
+ const auto wantedCollectionIndexes =
+ indexFeatureFlag ? getCollectionIndexes(opCtx) : boost::none;
+ const auto wantedIndexVersion = wantedCollectionIndexes
+ ? boost::make_optional(wantedCollectionIndexes->indexVersion())
+ : boost::none;
+ const auto wantedShardVersion = ShardVersion(wantedPlacementVersion, wantedCollectionIndexes);
+
const ChunkVersion receivedPlacementVersion = receivedShardVersion.placementVersion();
+ const boost::optional<Timestamp> receivedIndexVersion = receivedShardVersion.indexVersion();
- if (wantedPlacementVersion.isWriteCompatibleWith(receivedPlacementVersion) ||
+ if ((wantedPlacementVersion.isWriteCompatibleWith(receivedPlacementVersion) &&
+ (!indexFeatureFlag || receivedIndexVersion == wantedIndexVersion)) ||
receivedShardVersion == ShardVersion::IGNORED())
return optCurrentMetadata;
@@ -499,7 +508,13 @@ CollectionShardingRuntime::_getMetadataWithVersionCheckAt(
if (wantedPlacementVersion.majorVersion() != receivedPlacementVersion.majorVersion()) {
// Could be > or < - wanted is > if this is the source of a migration, wanted < if this is
// the target of a migration
- uasserted(std::move(sci), str::stream() << "version mismatch detected for " << _nss.ns());
+ uasserted(std::move(sci),
+ str::stream() << "placement version mismatch detected for " << _nss.ns());
+ }
+
+ if (indexFeatureFlag && wantedIndexVersion != receivedIndexVersion) {
+ uasserted(std::move(sci),
+ str::stream() << "index version mismatch detected for " << _nss.ns());
}
// Those are all the reasons the versions can mismatch