Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14138

mongos incorrectly targets multiple shards for nested field shard key predicates

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.6.2, 2.7.2
    • Affects Version/s: 2.6.1
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • Hide

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

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

      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.

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            norman.graham@mongodb.com Norman Graham (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: