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

Can't add tag ranges when sharding on subdocument fields

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL

      Enable sharding, shard a collection with a subdocument field, add tag range, tag a shard:

      sh.enableSharding("test")
      sh.shardCollection("test.foo", {"a.b": 1})
      sh.addTagRange("test.foo", {a: {b: "AP"}}, {a: {b: "AQ"}}, "AP")
      sh.addShardTag("shard0002", "AP") // or pick a shard that's NOT the primary shard
      

      This gives an error in the logs

      Wed Apr 23 12:03:52.252 [Balancer] Assertion: 16634:field names of bound { a: { b: "AP" } } do not match those of keyPattern { a.b: 1.0 }
      0x1002a106b 0x10027d71e 0x10027d7dd 0x1000f256e 0x10016216e 0x10015fae6 0x10027edb5 0x10027f4ea 0x10027f5b6 0x10027f676 0x1002d39e5 0x7fff91189899 0x7fff9118972a 0x7fff9118dfc9
      

      As this error suggests, this doesn't work:

      db.foo.insert({a: {b: "AP"}, i:1})
      sh.status() // shows chunk still on primary shard, not tagged shard
      

      We can't make the shard tag match the shard key:

      > sh.addTagRange("test.foo", {"a.b": "AP"}, {"a.b": "AQ"}, "AP")
      Wed Apr 23 12:06:41.756 JavaScript execution failed: can't have . in field names [a.b] at src/mongo/shell/collection.js:L143
      

      This is because sh.addTagRange() is basically doing this:

      use config
      db.tags.insert({ "_id" : { "ns" : "test.foo", "min" : { "a.b" : "AP" }  }, "ns" : "test.foo", "min" : { "a.b" : "AP" }, "max" : { "a.b" : "AQ"  }, "tag" : "AP" })
      

      And although these are valid javascript and JSON field names, they are not valid for MongoDB (https://docs.mongodb.org/manual/reference/limits/#Restrictions-on-Field-Names)

      We also can't change the shard key format:

      > sh.shardCollection("test.bar", {a: {b:1}})
      {
      	"ok" : 0,
      	"errmsg" : "Unsupported shard key pattern.  Pattern must either be a single hashed field, or a list of ascending fields."
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            joanna.cheng@mongodb.com Joanna Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: