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

sh.addShardToZone() allows unusual (invalid?) chunks to be created

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.2
    • Affects Version/s: 3.4.9, 3.7.1
    • Component/s: Sharding
    • None
    • Major Change
    • ALL
    • Hide

      Spin up a simple shared cluster with mlaunch:

      mlaunch --sharded 1 --single
      

      Then run the following commands from the mongo shell:

      sh.enableSharding("foo")
      sh.shardCollection("foo.bar", { "key" : 1 })
      
      sh.addShardToZone("shard01", "zone")
      
      # This fails as expected
      sh.updateZoneKeyRange("foo.bar", { "key": MaxKey }, { "key": MinKey }, "zone")
      
      # But this succeeds and creates odd chunks in the chunks collection
      sh.updateZoneKeyRange("foo.bar", { "key": { "$maxKey": 1 } }, { "key": { "$minKey": 1 } }, "zone")
      
      Show
      Spin up a simple shared cluster with mlaunch : mlaunch --sharded 1 --single Then run the following commands from the mongo shell: sh.enableSharding("foo") sh.shardCollection("foo.bar", { "key" : 1 }) sh.addShardToZone("shard01", "zone") # This fails as expected sh.updateZoneKeyRange("foo.bar", { "key": MaxKey }, { "key": MinKey }, "zone") # But this succeeds and creates odd chunks in the chunks collection sh.updateZoneKeyRange("foo.bar", { "key": { "$maxKey": 1 } }, { "key": { "$minKey": 1 } }, "zone")
    • Sharding 2018-02-12

      (This issue may be related to SERVER-10987)

      Normally it's not possible to create a key which includes a $ symbol but the following somewhat bizarre (and admittedly contrived) command is accepted and generates really odd chunks:

      sh.updateZoneKeyRange("foo.bar", { "key": { "$maxKey": 1 } }, { "key": { "$minKey": 1 } }, "zone")
      

      What was meant of course was the following:

      sh.updateZoneKeyRange("foo.bar", { "key": MaxKey }, { "key": MinKey }, "zone")
      

      This second form fails as expected as MaxKey is greater than MinKey, but the first form matches more closely how chunks referencing MinKey and MaxKey are shown in, for example, the output of sh.status()

      Running the commands in the 'steps to reproduce' section results in the following 3 chunks being created:

      mongos> db.chunks.find({},{_id:0,lastmod:0,lastmodEpoch:0})
      { "ns" : "foo.bar", "min" : { "key" : { "$minKey" : 1 } }, "max" : { "key" : { "$maxKey" : 1 } }, "shard" : "shard01" }
      { "ns" : "foo.bar", "min" : { "key" : { "$maxKey" : 1 } }, "max" : { "key" : { "$minKey" : 1 } }, "shard" : "shard01" }
      { "ns" : "foo.bar", "min" : { "key" : { "$minKey" : 1 } }, "max" : { "key" : { "$maxKey" : 1 } }, "shard" : "shard01" }
      

      And the output of sh.status() is as follows:

      [...]
        databases:
      	{  "_id" : "foo",  "primary" : "shard01",  "partitioned" : true }
      		foo.bar
      			shard key: { "key" : 1 }
      			unique: false
      			balancing: true
      			chunks:
      				shard01	3
      			{ "key" : { "$minKey" : 1 } } -->> { "key" : { "$maxKey" : 1 } } on : shard01 Timestamp(1, 1)
      			{ "key" : { "$maxKey" : 1 } } -->> { "key" : { "$minKey" : 1 } } on : shard01 Timestamp(1, 2)
      			{ "key" : { "$minKey" : 1 } } -->> { "key" : { "$maxKey" : 1 } } on : shard01 Timestamp(1, 3)
      			 tag: zone  { "key" : { "$maxKey" : 1 } } -->> { "key" : { "$minKey" : 1 } }
      

      I have no idea how the balancer will react if it sees these chunk ranges...

      Another interesting aspect is the following:

      mongos> sh.updateZoneKeyRange("foo.bar", { "key": { "$minKey": 1 } }, { "key": { "$maxKey": 1 } }, "zone")
      {
      	"code" : 9,
      	"ok" : 0,
      	"errmsg" : "min: { key: { $minKey: 1.0 } } should be less than max: { key: { $maxKey: 1.0 } }"
      }
      

      In this case we're trying to set the range to MinKey -->> MaxKey but the validator rejects it (presumably because the min and max values are documents which are being compared in a binary manner and $minKey is alphabetically greater than $maxKey??)

      All of the above tested on MongoDB 3.4.9

            Assignee:
            blake.oler@mongodb.com Blake Oler
            Reporter:
            ronan.bohan@mongodb.com Ronan Bohan
            Votes:
            1 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: