summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2023-02-17 16:38:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-21 15:51:33 +0000
commit3dfde12941d33555ee44d935f5d55fd143d41801 (patch)
tree3be50315820dd9effd1cc13b5f8ca5c21ea574b2 /src
parent1494cea315e785cebecdd63c562728957792a145 (diff)
downloadmongo-3dfde12941d33555ee44d935f5d55fd143d41801.tar.gz
SERVER-74097 Populate `CollectionUUIDMismatch` via `listCollections` for sharded find
(cherry picked from commit 4c670108b0aa1f5903ddb0c4e74ab0cee518b151)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/s/query/cluster_find.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp
index 2709b80f648..ffb745e8b4a 100644
--- a/src/mongo/s/query/cluster_find.cpp
+++ b/src/mongo/s/query/cluster_find.cpp
@@ -61,6 +61,7 @@
#include "mongo/s/client/num_hosts_targeted_metrics.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
+#include "mongo/s/collection_uuid_mismatch.h"
#include "mongo/s/grid.h"
#include "mongo/s/query/async_results_merger.h"
#include "mongo/s/query/cluster_client_cursor_impl.h"
@@ -300,19 +301,6 @@ CursorId runQueryWithoutRetrying(OperationContext* opCtx,
"tailable cursor unexpectedly has a sort",
sortComparatorObj.isEmpty() || !findCommand.getTailable());
- auto establishCursorsOnShards = [&](const std::set<ShardId>& shardIds) {
- return establishCursors(
- opCtx,
- Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(),
- query.nss(),
- readPref,
- // Construct the requests that we will use to establish cursors on the targeted shards,
- // attaching the shardVersion and txnNumber, if necessary.
- constructRequestsForShards(
- opCtx, cri, shardIds, query, sampleId, appendGeoNearDistanceProjection),
- findCommand.getAllowPartialResults());
- };
-
try {
// Establish the cursors with a consistent shardVersion across shards.
@@ -331,23 +319,29 @@ CursorId runQueryWithoutRetrying(OperationContext* opCtx,
"deadline"_attr = deadline);
}
- // The call to establishCursorsOnShards has its own timeout mechanism that is controlled
- // by the opCtx, so we don't expect runWithDeadline to throw a timeout at this level. We
- // use runWithDeadline because it has the side effect of pushing a temporary
- // (artificial) deadline onto the opCtx used by establishCursorsOnShards.
+ // The call to establishCursors has its own timeout mechanism that is controlled by the
+ // opCtx, so we don't expect runWithDeadline to throw a timeout at this level. We use
+ // runWithDeadline because it has the side effect of pushing a temporary (artificial)
+ // deadline onto the opCtx used by establishCursors.
opCtx->runWithDeadline(deadline, ErrorCodes::MaxTimeMSExpired, [&]() -> void {
- params.remotes = establishCursorsOnShards(shardIds);
+ params.remotes = establishCursors(
+ opCtx,
+ Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(),
+ query.nss(),
+ readPref,
+ // Construct the requests that we will use to establish cursors on the targeted
+ // shards, attaching the shardVersion and txnNumber, if necessary.
+ constructRequestsForShards(
+ opCtx, cri, shardIds, query, sampleId, appendGeoNearDistanceProjection),
+ findCommand.getAllowPartialResults());
});
} catch (const DBException& ex) {
if (ex.code() == ErrorCodes::CollectionUUIDMismatch &&
!ex.extraInfo<CollectionUUIDMismatchInfo>()->actualCollection() &&
!shardIds.count(cm.dbPrimary())) {
- // We received CollectionUUIDMismatchInfo but it does not contain the actual
- // namespace, and we did not attempt to establish a cursor on the primary shard.
- // Attempt to do so now in case the collection corresponding to the provided UUID is
- // unsharded. This should throw CollectionUUIDMismatchInfo, StaleShardVersion, or
- // StaleDbVersion.
- establishCursorsOnShards({cm.dbPrimary()});
+ // We received CollectionUUIDMismatch but it does not contain the actual namespace, and
+ // we did not attempt to establish a cursor on the primary shard.
+ uassertStatusOK(populateCollectionUUIDMismatch(opCtx, ex.toStatus()));
MONGO_UNREACHABLE;
}
throw;