summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrett Nawrocki <brett.nawrocki@mongodb.com>2021-09-13 21:29:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-22 22:21:36 +0000
commitbb887cdeca1bbb61b8a4b39139470b5cd18444d0 (patch)
tree751d39aec3948280f47ded74b327391372e44900 /src
parent16680b2846dfd1c5c4d58de93e5255b3705ad096 (diff)
downloadmongo-bb887cdeca1bbb61b8a4b39139470b5cd18444d0.tar.gz
SERVER-59585 Fix invalid cast on config servers
ReshardingOpObserver is enabled on both --configsvrs and --shardsvrs. However, config servers use CollectionShardingStateStandalone rather than CollectionShardingRuntime and means calling CollectionShardingRuntime::get() on a config server is incorrect. Instead, use CollectionShardingState::get() to retrieve the information without a cast. Also, update test_resharding_test_fixture_detects_unowned_docs.js to specify a shard version when performing its insert so that the collection is considered to be sharded by the ReshardingOpObserver when using the CollectionShardingState interface.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/resharding/resharding_op_observer.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/mongo/db/s/resharding/resharding_op_observer.cpp b/src/mongo/db/s/resharding/resharding_op_observer.cpp
index 0027b9e0d62..5e1449a383e 100644
--- a/src/mongo/db/s/resharding/resharding_op_observer.cpp
+++ b/src/mongo/db/s/resharding/resharding_op_observer.cpp
@@ -70,17 +70,15 @@ void assertCanExtractShardKeyFromDocs(OperationContext* opCtx,
const NamespaceString& nss,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end) {
- const auto metadata = CollectionShardingRuntime::get(opCtx, nss)->getCurrentMetadataIfKnown();
+ const auto collDesc = CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx);
// A user can manually create a 'db.system.resharding.' collection that isn't guaranteed to be
// sharded outside of running reshardCollection.
uassert(ErrorCodes::NamespaceNotSharded,
str::stream() << "Temporary resharding collection " << nss.toString()
<< " is not sharded",
- metadata && metadata->isSharded());
-
- auto chunkManager = *metadata->getChunkManager();
- const auto& shardKeyPattern = chunkManager.getShardKeyPattern();
+ collDesc.isSharded());
+ const ShardKeyPattern shardKeyPattern(collDesc.getKeyPattern());
for (auto it = begin; it != end; ++it) {
shardKeyPattern.extractShardKeyFromDocThrows(it->doc);
}