summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2020-06-22 16:02:00 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-23 17:44:42 +0000
commit3c14c24170a43252ff481c5cffad9014d5a93db2 (patch)
treecc0be9ef6a3a8f575a03538bd9d507303d5313ca /src
parent5958a1302055a6e500ec530fc166c0b7ba4b58bd (diff)
downloadmongo-3c14c24170a43252ff481c5cffad9014d5a93db2.tar.gz
SERVER-48326 Complete TODO listed in SERVER-47701
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/op_observer_sharding_impl.cpp31
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp6
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()) {