diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2020-06-22 16:02:00 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-23 17:44:42 +0000 |
commit | 3c14c24170a43252ff481c5cffad9014d5a93db2 (patch) | |
tree | cc0be9ef6a3a8f575a03538bd9d507303d5313ca /src/mongo/db/s/op_observer_sharding_impl.cpp | |
parent | 5958a1302055a6e500ec530fc166c0b7ba4b58bd (diff) | |
download | mongo-3c14c24170a43252ff481c5cffad9014d5a93db2.tar.gz |
SERVER-48326 Complete TODO listed in SERVER-47701
Diffstat (limited to 'src/mongo/db/s/op_observer_sharding_impl.cpp')
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_impl.cpp | 31 |
1 files changed, 18 insertions, 13 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; } |