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

Building a unique index before shardCollection shows inconsistent index status

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Sharding EMEA
    • ALL
    • Hide

      First create a unique index.

      sh.enableSharding("testdb")
      use testdb
      db.testcoll.createIndex({a:1}, {unique:true})
      db.testcoll.getIndexes()
      [
              {
                      "v" : 2,
                      "key" : {
                              "_id" : 1
                      },
                      "name" : "_id_"
              },
              {
                      "v" : 2,
                      "key" : {
                              "a" : 1
                      },
                      "name" : "a_1",
                      "unique" : true
              }
      ]
      

      Then shard the collection, but do not specify a unique index.

       sh.shardCollection("testdb.testcoll", {a:1})
      

      Finally, it shows that it is not a unique index in the config.collections table, but when I run getIndexes command, it shows that it is a unique index, and the status is inconsistent.

      use config
      db.collections.find({_id:"testdb.testcoll"})
      { "_id" : "testdb.testcoll", "lastmodEpoch" : ObjectId("63467fa468689fc229d184b2"), "lastmod" : ISODate("2022-10-12T08:49:40.375Z"), "timestamp" : Timestamp(1665564579, 6), "uuid" : UUID("e6eb4a14-60ee-4c00-acb3-355da36b59eb"), "key" : { "a" : 1 }, "unique" : false, "noBalance" : false }
      
      Show
      First create a unique index. sh.enableSharding( "testdb" ) use testdb db.testcoll.createIndex({a:1}, {unique: true }) db.testcoll.getIndexes() [ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" }, { "v" : 2, "key" : { "a" : 1 }, "name" : "a_1" , "unique" : true } ] Then shard the collection, but do not specify a unique index. sh.shardCollection( "testdb.testcoll" , {a:1}) Finally, it shows that it is not a unique index in the config.collections table, but when I run getIndexes command, it shows that it is a unique index, and the status is inconsistent. use config db.collections.find({_id: "testdb.testcoll" }) { "_id" : "testdb.testcoll" , "lastmodEpoch" : ObjectId( "63467fa468689fc229d184b2" ), "lastmod" : ISODate( "2022-10-12T08:49:40.375Z" ), "timestamp" : Timestamp(1665564579, 6), "uuid" : UUID( "e6eb4a14-60ee-4c00-acb3-355da36b59eb" ), "key" : { "a" : 1 }, "unique" : false , "noBalance" : false }

      For a sharded cluster, first create a unique index, but do not specify the relevant field as a unique index when shardColleciton. Finally, the config.collections table shows that the corresponding index is not a unique index.
      Is this expected behavior?
      When running the shardCollection command without specifying unique equal to true bug finding that the corresponding index has been built as a unique index, should it return a failure?

            Assignee:
            backlog-server-sharding-emea [DO NOT USE] Backlog - Sharding EMEA
            Reporter:
            1321280378feng@gmail.com Chao Yin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: