Currently, the distinct command's behavior (with respect to whether it does shard versioning or not) is nondeterministic.
The distinct command on mongos uses ShardConnection with a namespace, but without a ChunkManager.
So, if the connection retrieved from the sharded connection pool happens to be as fresh as the mongos's routing table cache, setShardVersion will not be sent over the connection.
If the connection is staler than the mongos's routing table cache, setShardVersion will be sent over the connection, and if the mongos's routing table cache was staler than the authoritative routing table, the mongos will receive a stale version error.
Then, mongos will refresh its routing table cache and retry the distinct command, which will now get routed to the correct shard.
https://github.com/mongodb/mongo/blob/r3.5.11/src/mongo/s/client/version_manager.cpp#L332-L339
This ticket should make the distinct command use scatterGather() rather than ShardConnection, so that it always has versioned behavior.
- has to be done before
-
SERVER-30595 Do not use chunk metadata to filter results for read concern 'available' requests
- Closed
- is related to
-
SERVER-30734 make the distinct command versioned on mongos for unsharded collections
- Closed