[SERVER-14138] mongos incorrectly targets multiple shards for nested field shard key predicates Created: 03/Jun/14  Updated: 11/Mar/15  Resolved: 05/Jun/14

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.6.1
Fix Version/s: 2.6.2, 2.7.2

Type: Bug Priority: Critical - P2
Reporter: Norman Graham Assignee: Greg Studer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File upsertTest.js    
Issue Links:
Depends
Related
is related to SERVER-14161 Disallow regex as shard key value Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

Create a 4 shard cluster with shards named "a", "b", "c", and "d". Then run the attached javascript functions.

Participants:

 Description   
Issue Status as of Jun 09, 2014

ISSUE SUMMARY
On sharded collections using nested shard keys, some targeted operations fail to target the right shard and are broadcast instead. This issue only affects collections which are sharded over a nested shard key field (e.g. 'a.b') where the predicates are specified in object notation (e.g. {a: {b: 1}}) instead of dot notation (e.g. {"a.b": 1}), and only on limited updates/deletes – i.e. single deletes, non-multi updates, and upserts.

USER IMPACT
For upserts, orphaned documents may be created on all shards of a collection; these orphaned documents may cause write errors if using uniquely indexed fields (i.e. _id) in the query. Upserts not containing uniquely indexed fields can result in growing numbers of orphaned documents.

For single/non-multi deletes and updates there may be a performance impact, and updates to orphaned documents may be unexpectedly reported, resulting in incorrect write statistics. Also, there may be rare cases where the update applies an incorrect number of times despite being limited – disable balancing on affected collections as a workaround for this specific case.

WORKAROUNDS
Change the nested shard key to use dot notation (see example above).

AFFECTED VERSIONS
MongoDB 2.6.0 and 2.6.1 are affected by this issue.

FIX VERSION
The fix is included in the 2.6.2 production release.

RESOLUTION DETAILS
Explicitly look up the documents to update/delete in the ChunkManager.

Original description

In a sharded collection, upserts resulting from a save() have different behaviors depending on the shape of the shard key. When the shard key is a simple key or a compound key composed of top-level fields, behavior is consistent with 2.4.10, i.e. upserts are targeted. However, with a compound shard key composed of fields from an embedded document, the upserts are broadcast to all shards.

In the insert case of upsert, the broadcast upsert inserts a document on all shards. In the update case of upsert, the broadcast upsert updates the document on the chunk-owning shard and generates a duplicate key error on all remaining shards.

Chunks must be distributed across multiple shards to observe the effect.



 Comments   
Comment by Daniel Pasette (Inactive) [ 13/Jun/14 ]

2.6.2 is currently planned for general availability on Monday.

Comment by Leo Torbochkin [ 12/Jun/14 ]

Thanks for the update Greg! I was wondering how long the testing usually takes? Trying to determine if we can expect the RHEL RPM today/tomorrow or Monday?

Comment by Greg Studer [ 11/Jun/14 ]

Yep, we're currently re-testing the -rc1 build. Assuming there are no issues found which require another rc, we will release after the testing completes.

Comment by Leo Torbochkin [ 11/Jun/14 ]

Thanks for looking into this!

I saw the 2.6.2 release was slated to release yesterday and there was a release candidate available. We are specifically looking to use the RHEL RPM and were looking for the 2.6.2 version here:

http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/RPMS/

Are you expecting the official release 2.6.2 shortly?

Thanks!

Comment by Githook User [ 06/Jun/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-14138 fix shard key targeting tests backported from v2.7
Branch: v2.6
https://github.com/mongodb/mongo/commit/90d6761433af542814185a8ec45a11208df9fe6f

Comment by Githook User [ 05/Jun/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-14138 mongos incorrectly targets multiple shards for nested field shard keys
(cherry picked from commit 777de742ee578b62b12ded8381aadf98dfa9fa5f)

Conflicts:
jstests/sharding/hash_regex_targetting.js
Branch: v2.6
https://github.com/mongodb/mongo/commit/03c83b974897ce58d7cd6f69e27cae7bc1433e2f

Comment by Githook User [ 05/Jun/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-14138 mongos incorrectly targets multiple shards for nested field shard keys
Branch: master
https://github.com/mongodb/mongo/commit/777de742ee578b62b12ded8381aadf98dfa9fa5f

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