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

A collection can't be sharded with zones predefined on a prefix of the shard key

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 6.0.0, 7.0.0, 8.1.0-rc0, 8.0.0, 8.2.0-rc0
    • Component/s: None
    • None
    • Catalog and Routing
    • CAR Team To Be Assigned
    • 3
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Zones for a sharded collection can be created either before or after the collection exists. At the same time, zones can be defined either on the shard key, or a prefix of it.

      However, of those combinations, creating zones on a prefix of the shard key, and before the collection is created, currently fails with an InvalidOptions error, as shardCollection expects the zones to exactly match the shard key:

      > db.adminCommand({updateZoneKeyRange: "test.xyzzy", min: {a:1}, max:{a:10}, zone:"BCN"})
      > db.adminCommand({shardCollection: "test.xyzzy", key: {a:1, b:1}})
      MongoServerError[InvalidOptions]: the proposed shard key { a: 1, b: 1 } does not match with the shard key of the existing zone { a: 1 } -->> { a: 10 }
      

      Inverting the order of the operations works, however, this misses the benefits of the initial chunks being created so that data is distributed according to the zones without balancing:

      > db.adminCommand({shardCollection: "test.foo", key: {a:1, b:1}})
      > db.adminCommand({updateZoneKeyRange: "test.foo", min: {a:1}, max:{a:10}, zone:"BCN"})
      { ok: 1, [...] }
      

       

      We should fix this limitation to avoid usability surprises for users.

            Assignee:
            Unassigned Unassigned
            Reporter:
            joan.bruguera-mico@mongodb.com Joan Bruguera Micó
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: