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.
- is related to
-
SERVER-14161 Disallow regex as shard key value
- Closed