summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2020-03-23 14:12:13 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-23 21:36:52 +0000
commit5b4a8ab051b00579cb8f4957067ee05fbee279c3 (patch)
tree656dce4360da7a38478e42a3457c52d9b997aa30
parent6495df6629097d1cd846056f60cc3b5570be8a10 (diff)
downloadmongo-5b4a8ab051b00579cb8f4957067ee05fbee279c3.tar.gz
SERVER-46593 Use the CatalogCache directly in ShardServerProcessInterface::collectDocumentKeyFieldsForHostedCollection
-rw-r--r--src/mongo/db/pipeline/process_interface/mongo_process_interface.h4
-rw-r--r--src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp43
2 files changed, 17 insertions, 30 deletions
diff --git a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
index 628dc537e8b..7b0be46f8aa 100644
--- a/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
+++ b/src/mongo/db/pipeline/process_interface/mongo_process_interface.h
@@ -323,10 +323,6 @@ public:
* collection is not sharded or no longer exists, returns only _id. Also returns a boolean that
* indicates whether the returned fields of the document key are final and will never change for
* the given collection, either because the collection was dropped or has become sharded.
- *
- * This method is meant to be called from a mongod which owns at least one chunk for this
- * collection. It will inspect the CollectionShardingState, not the CatalogCache. If asked about
- * a collection not hosted on this shard, the answer will be incorrect.
*/
virtual std::pair<std::vector<FieldPath>, bool> collectDocumentKeyFieldsForHostedCollection(
OperationContext* opCtx, const NamespaceString&, UUID) const = 0;
diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp
index 5bde04b25a8..76dc456a92c 100644
--- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp
@@ -36,29 +36,18 @@
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/exec/shard_filterer_impl.h"
-#include "mongo/db/ops/write_ops_exec.h"
-#include "mongo/db/ops/write_ops_gen.h"
#include "mongo/db/pipeline/document_source_internal_shard_filter.h"
#include "mongo/db/pipeline/sharded_agg_helpers.h"
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/rpc/get_status_from_command_result.h"
-#include "mongo/s/catalog_cache.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/cluster_write.h"
namespace mongo {
-using boost::intrusive_ptr;
-using std::shared_ptr;
-using std::string;
-using std::unique_ptr;
-using write_ops::Insert;
-using write_ops::Update;
-using write_ops::UpdateOpEntry;
-
bool ShardServerProcessInterface::isSharded(OperationContext* opCtx, const NamespaceString& nss) {
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
Lock::CollectionLock collLock(opCtx, nss, MODE_IS);
@@ -81,23 +70,25 @@ ShardServerProcessInterface::collectDocumentKeyFieldsForHostedCollection(Operati
UUID uuid) const {
invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);
- const auto collDesc = [opCtx, &nss]() -> ScopedCollectionDescription {
- Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
- Lock::CollectionLock collLock(opCtx, nss, MODE_IS);
- return CollectionShardingState::get(opCtx, nss)->getCollectionDescription();
- }();
-
- if (!collDesc.isSharded() || !collDesc.uuidMatches(uuid)) {
- // An unsharded collection can still become sharded so is not final. If the uuid doesn't
- // match the one stored in the ScopedCollectionDescription, this implies that the collection
- // has been dropped and recreated as sharded. We don't know what the old document key fields
- // might have been in this case so we return just _id.
- return {{"_id"}, false};
+ auto* const catalogCache = Grid::get(opCtx)->catalogCache();
+ auto swCollectionRoutingInfo = catalogCache->getCollectionRoutingInfo(opCtx, nss);
+ if (swCollectionRoutingInfo.isOK()) {
+ auto cm = swCollectionRoutingInfo.getValue().cm();
+ if (cm && cm->uuidMatches(uuid)) {
+ // Unpack the shard key. Collection is now sharded so the document key fields will never
+ // change, mark as final.
+ return {_shardKeyToDocumentKeyFields(cm->getShardKeyPattern().getKeyPatternFields()),
+ true};
+ }
+ } else if (swCollectionRoutingInfo != ErrorCodes::NamespaceNotFound) {
+ uassertStatusOK(std::move(swCollectionRoutingInfo));
}
- // Unpack the shard key. Collection is now sharded so the document key fields will never change,
- // mark as final.
- return {_shardKeyToDocumentKeyFields(collDesc.getKeyPatternFields()), true};
+ // An unsharded collection can still become sharded so is not final. If the uuid doesn't match
+ // the one stored in the ScopedCollectionDescription, this implies that the collection has been
+ // dropped and recreated as sharded. We don't know what the old document key fields might have
+ // been in this case so we return just _id.
+ return {{"_id"}, false};
}
Status ShardServerProcessInterface::insert(const boost::intrusive_ptr<ExpressionContext>& expCtx,