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

Arrays along shard key path are not correctly rejected

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Sharding 2019-11-04, Sharding 2019-11-18

      After SERVER-42390, we are allowing missing shard keys on mongos. Since we consider an array at any point along the shard key path as 'missing', we are accidentally allowing documents containing arrays to be sent to the shards. In this case we are targeting using the 'missing' field logic here.

      We should reject any array fields along the shard key path. A simple repo script below.

      mongos> sh.enableSharding("db")
      mongos> sh.shardCollection("db.col" ,  {"a.b": 1})
      {
      	"collectionsharded" : "db.col",
      	"collectionUUID" : UUID("75116042-38b2-477f-8428-443bad3dc983"),
      	"ok" : 1,
      	"operationTime" : Timestamp(1571847436, 14),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1571847436, 14),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      mongos> sh.splitAt("db.col", {"a.b" : 1})
      {
      	"ok" : 1,
      	"operationTime" : Timestamp(1571847448, 1),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1571847450, 4),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      mongos> sh.moveChunk("db.col", {"a.b": 1}, "shard01")
      {
      	"millis" : 91,
      	"ok" : 1,
      	"operationTime" : Timestamp(1571847525, 5),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1571847525, 5),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      mongos> use db
      switched to db db
      mongos> db.col.insert({a : [{b: -5}, {b: 5}]}) // Should fail.
      mongos> db.col.find({"a.b" : 5}) // Query gets targeted to wrong shard.
      mongos> db.col.find({"a.b" : -5})
      { "_id" : ObjectId("5db07dea8e9b60349f227f70"), "a" : [ { "b" : -5 }, { "b" : 5 } ] }
      mongos> db.col.insert({a: {b: [1]}}) // Doesn't return the correct error message.
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 82,
      		"errmsg" : "no progress was made executing batch write op in db.col after 5 rounds (0 ops completed in 6 rounds total)"
      	}
      })
      

            Assignee:
            blake.oler@mongodb.com Blake Oler
            Reporter:
            arun.banala@mongodb.com Arun Banala
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: