[SERVER-13702] Commands without optional query may target to wrong shards on mongos Created: 23/Apr/14  Updated: 19/Jun/15  Resolved: 18/Sep/14

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 2.6.5, 2.7.7

Type: Bug Priority: Major - P3
Reporter: Siyuan Zhou Assignee: Siyuan Zhou
Resolution: Done Votes: 0
Labels: cap-ticket-needed
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File sh_count.js     File sh_mr.js    
Issue Links:
Related
related to SERVER-13656 Use new query framework in getShardsF... Closed
Tested
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

Run attached script for count and mapReduce

Participants:

 Description   

On mongos, for commands allowing optional query, e.g. count, mapreduce, if the optional query is not given, the command will use the command BSONObj itself as the query to target shards, which could return wrong shards if the shard key happens to be one of the field in the command object.

This is because if the optional query is not given, commands call Strategy::commandOp with an empty targetingQuery parameter. The targetingQuery parameter is passed to ParallelSortClusteredCursor as CommandInfo.cmdFilter. An empty cmdFilter will be interpreted as using the command/query as a whole to target shards.



 Comments   
Comment by Githook User [ 18/Sep/14 ]

Author:

{u'username': u'visualzhou', u'name': u'Siyuan Zhou', u'email': u'siyuan.zhou@mongodb.com'}

Message: SERVER-13702 Commands without optional query may target to wrong shards on mongos

(cherry picked from commit bd1a02385378ee50a33db7c255217c050cc74192)

SERVER-13702 Add JS tests for shard targeting.

(cherry picked from commit e986b037f1301fae63938dc9bd933ff8ac25b7d6)
Branch: v2.6
https://github.com/mongodb/mongo/commit/0cf60aa0af55a673786d4950c4b5524c1d671e6e

Comment by Githook User [ 18/Sep/14 ]

Author:

{u'username': u'visualzhou', u'name': u'Siyuan Zhou', u'email': u'siyuan.zhou@mongodb.com'}

Message: SERVER-13702 Commands without optional query may target to wrong shards on mongos

(cherry picked from commit bd1a02385378ee50a33db7c255217c050cc74192)

SERVER-13702 Add JS tests for shard targeting.

(cherry picked from commit e986b037f1301fae63938dc9bd933ff8ac25b7d6)
Branch: v2.6
https://github.com/mongodb/mongo/commit/0cf60aa0af55a673786d4950c4b5524c1d671e6e

Comment by Githook User [ 17/Sep/14 ]

Author:

{u'username': u'visualzhou', u'name': u'Siyuan Zhou', u'email': u'siyuan.zhou@mongodb.com'}

Message: SERVER-13702 Add JS tests for shard targeting.
Branch: master
https://github.com/mongodb/mongo/commit/e986b037f1301fae63938dc9bd933ff8ac25b7d6

Comment by Siyuan Zhou [ 15/Sep/14 ]

greg_10gen, I am working on the JS tests. Sorry for missing it at the first time. I forgot why we don't backport this issue to 2.6, but v2.6 has the same bug.

Comment by Githook User [ 28/Apr/14 ]

Author:

{u'username': u'visualzhou', u'name': u'Siyuan Zhou', u'email': u'siyuan.zhou@mongodb.com'}

Message: SERVER-13702 Commands without optional query may target to wrong shards on mongos
Branch: master
https://github.com/mongodb/mongo/commit/bd1a02385378ee50a33db7c255217c050cc74192

Generated at Thu Feb 08 03:32:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.