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

refineShardKey should verify indexes on shards with chunks

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.4.0-rc0, 4.7.0
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • v4.4
    • 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}}));
    • Sharding 2020-03-09, Sharding 2020-03-23

      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.

            Assignee:
            jack.mulrow@mongodb.com Jack Mulrow
            Reporter:
            matthew.saltz@mongodb.com Matthew Saltz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: