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

moveChunk completes with invalid epoch type

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.7.8
    • Component/s: Sharding
    • ALL
    • Hide
      function moveChunk(st, fromMongod, toMongod, epoch) {
          var chunk = st.s.getDB("config").chunks.findOne({shard: fromMongod.shardName});
          assert(chunk, "no chunks on shard to move");
          epoch = epoch || chunk.lastmodEpoch;
          var cmd = {
              moveChunk: coll + "",
              from: fromMongod.host,
              to: toMongod.host,
              fromShard: fromMongod.shardName,
              toShard: toMongod.shardName,
              min: {x: chunk.min.x},
              max: {x: chunk.max.x},
              maxChunkSizeBytes: 52428800,
              shardId: chunk._id,
              configdb: st.config0.host,
              secondaryThrottle: true,
              waitForDelete: true,
              maxTimeMS: 0,
              epoch: epoch
          };
      
          // moveChunk should fail with epoch that is not the same as the one in the chunk
          //if (!chunk.lastmodEpoch.equals(epoch)) {
              //assert.commandFailed(fromMongod.adminCommand(cmd), "moveChunk failed " + tojson(epoch));
          //} else {
              assert.commandWorked(fromMongod.adminCommand(cmd), "moveChunk worked " + tojson(epoch));
          //}
      }
      
      var st = new ShardingTest({name: "epoch", shards: 2, chunkSize: 1});
      st.stopBalancer();
      
      var configDB = st.s.getDB("config");
      var testDB = st.s.getDB("test");
      var collName = "epoch";
      var coll = testDB[collName];
      configDB.adminCommand({enableSharding: "test"});
      configDB.adminCommand({movePrimary: "test", to: "shard0000"});
      configDB.adminCommand({shardCollection: coll + "", key: {x: 1}});
      
      assert.commandWorked(
          configDB.adminCommand({split: coll + "", middle: {x: 100}}),
          "split");
      assert.commandWorked(
          configDB.adminCommand({moveChunk: coll + "", find: {x: 100}, to: "shard0001"}),
          "moveChunk");
      
      var collectionDoc = configDB.collections.findOne({_id: coll + ""});
      var lastmodEpoch = collectionDoc.lastmodEpoch;
      moveChunk(st, st.d0, st.d1, "abc"); // Works, should fail
      moveChunk(st, st.d1, st.d0, 12345); // Works, should fail
      moveChunk(st, st.d0, st.d1, lastmodEpoch); // Works
      
      st.stop();
      
      Show
      function moveChunk(st, fromMongod, toMongod, epoch) { var chunk = st.s.getDB( "config" ).chunks.findOne({shard: fromMongod.shardName}); assert (chunk, "no chunks on shard to move" ); epoch = epoch || chunk.lastmodEpoch; var cmd = { moveChunk: coll + "", from: fromMongod.host, to: toMongod.host, fromShard: fromMongod.shardName, toShard: toMongod.shardName, min: {x: chunk.min.x}, max: {x: chunk.max.x}, maxChunkSizeBytes: 52428800, shardId: chunk._id, configdb: st.config0.host, secondaryThrottle: true , waitForDelete: true , maxTimeMS: 0, epoch: epoch }; // moveChunk should fail with epoch that is not the same as the one in the chunk // if (!chunk.lastmodEpoch.equals(epoch)) { // assert .commandFailed(fromMongod.adminCommand(cmd), "moveChunk failed " + tojson(epoch)); //} else { assert .commandWorked(fromMongod.adminCommand(cmd), "moveChunk worked " + tojson(epoch)); //} } var st = new ShardingTest({name: "epoch" , shards: 2, chunkSize: 1}); st.stopBalancer(); var configDB = st.s.getDB( "config" ); var testDB = st.s.getDB( "test" ); var collName = "epoch" ; var coll = testDB[collName]; configDB.adminCommand({enableSharding: "test" }); configDB.adminCommand({movePrimary: "test" , to: "shard0000" }); configDB.adminCommand({shardCollection: coll + "", key: {x: 1}}); assert .commandWorked( configDB.adminCommand({split: coll + "", middle: {x: 100}}), "split" ); assert .commandWorked( configDB.adminCommand({moveChunk: coll + "", find: {x: 100}, to: " shard0001"}), "moveChunk" ); var collectionDoc = configDB.collections.findOne({_id: coll + ""}); var lastmodEpoch = collectionDoc.lastmodEpoch; moveChunk(st, st.d0, st.d1, "abc" ); // Works, should fail moveChunk(st, st.d1, st.d0, 12345); // Works, should fail moveChunk(st, st.d0, st.d1, lastmodEpoch); // Works st.stop();

      moveChunk containing an invalid epoch type, non ObjectID type, completes without error. If a mismatching ObjectID is sent, it will correctly fail.

            Assignee:
            randolph@mongodb.com Randolph Tan
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: