diff options
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_impl.cpp | 31 | ||||
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.cpp | 6 |
2 files changed, 18 insertions, 19 deletions
diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index dcc5d398dc0..08d745dd117 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -50,23 +50,16 @@ const auto getIsMigrating = OperationContext::declareDecoration<bool>(); * restarted. */ void assertIntersectingChunkHasNotMoved(OperationContext* opCtx, - CollectionShardingRuntime* csr, + CollectionMetadata const& metadata, const BSONObj& doc) { const auto atClusterTime = repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime(); if (!atClusterTime) return; - // TODO (SERVER-47701): As part of enabling transition from a replica-set to sharded cluster, - // without requiring application downtime, these checks need to be revisited. Ideally this code - // should not be reached upon direct writes to a shard. - auto metadata = csr->getCurrentMetadataIfKnown(); - if (!metadata || !metadata->isSharded()) - return; - - auto shardKey = metadata->getShardKeyPattern().extractShardKeyFromDoc(doc); + auto shardKey = metadata.getShardKeyPattern().extractShardKeyFromDoc(doc); // We can assume the simple collation because shard keys do not support non-simple collations. - ChunkManager chunkManagerAtClusterTime(metadata->getChunkManager()->getRoutingHistory(), + ChunkManager chunkManagerAtClusterTime(metadata.getChunkManager()->getRoutingHistory(), atClusterTime->asTimestamp()); auto chunk = chunkManagerAtClusterTime.findIntersectingChunkWithSimpleCollation(shardKey); @@ -110,8 +103,12 @@ void OpObserverShardingImpl::shardObserveInsertOp(OperationContext* opCtx, auto* const csr = CollectionShardingRuntime::get(opCtx, nss); csr->checkShardVersionOrThrow(opCtx); + auto metadata = csr->getCurrentMetadataIfKnown(); + if (!metadata || !metadata->isSharded()) + return; + if (inMultiDocumentTransaction) { - assertIntersectingChunkHasNotMoved(opCtx, csr, insertedDoc); + assertIntersectingChunkHasNotMoved(opCtx, *metadata, insertedDoc); return; } @@ -132,8 +129,12 @@ void OpObserverShardingImpl::shardObserveUpdateOp(OperationContext* opCtx, auto* const csr = CollectionShardingRuntime::get(opCtx, nss); csr->checkShardVersionOrThrow(opCtx); + auto metadata = csr->getCurrentMetadataIfKnown(); + if (!metadata || !metadata->isSharded()) + return; + if (inMultiDocumentTransaction) { - assertIntersectingChunkHasNotMoved(opCtx, csr, postImageDoc); + assertIntersectingChunkHasNotMoved(opCtx, *metadata, postImageDoc); return; } @@ -153,8 +154,12 @@ void OpObserverShardingImpl::shardObserveDeleteOp(OperationContext* opCtx, auto* const csr = CollectionShardingRuntime::get(opCtx, nss); csr->checkShardVersionOrThrow(opCtx); + auto metadata = csr->getCurrentMetadataIfKnown(); + if (!metadata || !metadata->isSharded()) + return; + if (inMultiDocumentTransaction) { - assertIntersectingChunkHasNotMoved(opCtx, csr, documentKey); + assertIntersectingChunkHasNotMoved(opCtx, *metadata, documentKey); return; } diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index a63318262b6..5190133a690 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -235,9 +235,6 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx, std::vector<InsertStatement>::const_iterator begin, std::vector<InsertStatement>::const_iterator end, bool fromMigrate) { - // TODO (SERVER-47701): As part of enabling transition from a replica-set to sharded cluster, - // without requiring application downtime, these checks need to be revisited. Ideally this code - // should not be reached upon direct writes to a shard. const auto metadata = CollectionShardingRuntime::get(opCtx, nss)->getCurrentMetadataIfKnown(); for (auto it = begin; it != end; ++it) { @@ -392,9 +389,6 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE } } - // TODO (SERVER-47701): As part of enabling transition from a replica-set to sharded cluster, - // without requiring application downtime, these checks need to be revisited. Ideally this code - // should not be reached upon direct writes to a shard. auto* const csr = CollectionShardingRuntime::get(opCtx, args.nss); const auto metadata = csr->getCurrentMetadataIfKnown(); if (metadata && metadata->isSharded()) { |