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

collMod command not sent to all shards for a sharded collection if no chunks have been received

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Sharding
    • Sharding EMEA
    • ALL
    • Sharding 2022-03-07, Sharding NYC 2022-03-21, Sharding NYC 2022-04-04, Sharding NYC 2022-05-30, Sharding 2022-06-27, Sharding EMEA 2023-06-12
    • 3

      This ticket is an extension of SERVER-62272 and uses the same reproduction code. Once the sharding has been enabled for a collection that contains schema validation failures if no chunks have moved from the donor shard to a recipient shard, the recipient shard's collection info cannot be modified using collMod.

      For example, given a 2 shard sharded cluster:

      MongoDB Enterprise mongos> sh.status()
      --- Sharding Status ---
        sharding version: {
              "_id" : 1,
              "minCompatibleVersion" : 5,
              "currentVersion" : 6,
              "clusterId" : ObjectId("61ccb31408be338b6e44a5c0")
        }
        shards:
              {  "_id" : "shard01",  "host" : "shard01/localhost:27018,localhost:27019,localhost:27020",  "state" : 1 }
              {  "_id" : "shard02",  "host" : "shard02/localhost:27021,localhost:27022,localhost:27023",  "state" : 1 }
        active mongoses:
              "4.4.10" : 1
        autosplit:
              Currently enabled: yes
        balancer:
              Currently enabled:  yes
              Currently running:  no
              Failed balancer rounds in last 5 attempts:  0
              Migration Results for the last 24 hours:
                      18 : Failed with error 'aborted', from shard01 to shard02
        databases:
              {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
              {  "_id" : "test",  "primary" : "shard01",  "partitioned" : true,  "version" : {  "uuid" : UUID("776a14de-913b-4ed4-a1c1-6533fbbf1ab7"),  "lastMod" : 1 } }
                      test.c3
                              shard key: { "_id" : 1 }
                              unique: false
                              balancing: true
                              chunks:
                                      shard01 17
      

      If we issue a collMod while connected to the cluster via a mongos the primary shard will be updated, but any other shards that had this collection created via the shardCollection command will not.

      For example, if we send the following command we would expect the validationLevel to be updated to off from the default of strict:

      MongoDB Enterprise mongos> db.getSiblingDB("test").runCommand({
      ...   collMod: "c3",
      ...   validator: { $jsonSchema: {
      ...      bsonType: "object",
      ...      properties: {
      ...         i: {
      ...            bsonType: "string",
      ...            description: "must be a string"
      ...         },
      ...      }
      ...   } } ,
      ...   "validationLevel" : "off"
      ... })
      {
              "raw" : {
                      "shard01/localhost:27018,localhost:27019,localhost:27020" : {
                              "ok" : 1
                      }
              },
              "ok" : 1,
              "operationTime" : Timestamp(1640805401, 1),
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1640805401, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              }
      }
      

      If we connect to each shard individually now and run db.getCollectionInfos() the result is that shard01 in our cluster has the updated collection metadata whereas shard02 doesn't:

      MongoDB Enterprise mongos> var db1 = new Mongo(db.getSiblingDB("config").shards.findOne({ _id: "shard01" }).host)
      MongoDB Enterprise mongos> db1.getDB("test").getCollectionInfos()
      [
              {
                      "name" : "c3",
                      "type" : "collection",
                      "options" : {
                              "validator" : {
                                      "$jsonSchema" : {
                                              "bsonType" : "object",
                                              "properties" : {
                                                      "i" : {
                                                              "bsonType" : "string",
                                                              "description" : "must be a string"
                                                      }
                                              }
                                      }
                              },
                              "validationLevel" : "off",
                              "validationAction" : "error"
                      },
                      "info" : {
                              "readOnly" : false,
                              "uuid" : UUID("2669f807-557f-4cb9-8d21-3ca5d1bc744f")
                      },
                      "idIndex" : {
                              "v" : 2,
                              "key" : {
                                      "_id" : 1
                              },
                              "name" : "_id_"
                      }
              }
      ]
      
      MongoDB Enterprise mongos> var db2 = new Mongo(db.getSiblingDB("config").shards.findOne({ _id: "shard02" }).host)
      MongoDB Enterprise mongos> db2.getDB("test").getCollectionInfos()
      [
              {
                      "name" : "c3",
                      "type" : "collection",
                      "options" : {
                              "validator" : {
                                      "$jsonSchema" : {
                                              "bsonType" : "object",
                                              "properties" : {
                                                      "i" : {
                                                              "bsonType" : "string",
                                                              "description" : "must be a string"
                                                      }
                                              }
                                      }
                              },
                              "validationLevel" : "strict",
                              "validationAction" : "error"
                      },
                      "info" : {
                              "readOnly" : false,
                              "uuid" : UUID("2669f807-557f-4cb9-8d21-3ca5d1bc744f")
                      },
                      "idIndex" : {
                              "v" : 2,
                              "key" : {
                                      "_id" : 1
                              },
                              "name" : "_id_"
                      }
              }
      ]
      

            Assignee:
            enrico.golfieri@mongodb.com Enrico Golfieri
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: