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

refineShardKey should verify indexes on shards with chunks

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.4.0-rc0, 4.5.1
    • Component/s: Sharding
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Requested:
      v4.4
    • Steps To Reproduce:
      Hide

      const dbName = "test";
       const collName = "foo";
       const ns = dbName + "." + collName;
       let testDB = st.s.getDB(dbName);
       let testColl = testDB.foo;
       
       // Create a sharded collection with one chunk on shard0.
       assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
       assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName}));
       assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));
       
      // After this there's only a chunk on shard 1
      assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 1}, to: st.shard1.shardName}));
       
      // So this only creates an index on shard 1
      assert.commandWorked(st.s.getCollection(ns).createIndex({x: 1, y: 1}));
       
      // But this fails with "InvalidOptions: Please create an index that starts with the proposed shard key before sharding the collection" because it checks indexes on the primary shard (shard 0)
      assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: ns, key: {x: 1, y: 1}}));
      

      Show
      const dbName = "test" ; const collName = "foo" ; const ns = dbName + "." + collName; let testDB = st.s.getDB(dbName); let testColl = testDB.foo;   // Create a sharded collection with one chunk on shard0. assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName})); assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));   // After this there's only a chunk on shard 1 assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 1}, to: st.shard1.shardName}));   // So this only creates an index on shard 1 assert.commandWorked(st.s.getCollection(ns).createIndex({x: 1, y: 1}));   // But this fails with "InvalidOptions: Please create an index that starts with the proposed shard key before sharding the collection" because it checks indexes on the primary shard (shard 0) assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: ns, key: {x: 1, y: 1}}));
    • Sprint:
      Sharding 2020-03-09, Sharding 2020-03-23

      Description

      refineCollectionShardKey verifies shard key indexes by checking the primary shard. createIndex however only creates indexes on shards that own chunks. So even if a user creates the correct indexes, if the primary shard does not own chunks, refineCollectionShardKey can fail. See repro.

        Attachments

          Activity

            People

            Assignee:
            jack.mulrow Jack Mulrow
            Reporter:
            matthew.saltz Matthew Saltz
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: