[SERVER-15989] moveChunk completes with invalid epoch type Created: 06/Nov/14  Updated: 19/Oct/15  Resolved: 19/Oct/15

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.7.8
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Jonathan Abrahams Assignee: Randolph Tan
Resolution: Won't Fix Votes: 0
Labels: 28qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-15007 Add epoch check for split and moveChunk Closed
Operating System: ALL
Steps To Reproduce:

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();

Participants:

 Description   

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



 Comments   
Comment by Andy Schwerin [ 19/Oct/15 ]

Only the cluster user can issue this command to mongod when auth is enabled; it is fully internal.

Comment by Jonathan Abrahams [ 06/Nov/14 ]

Split chunk also exhibits the same behavior, with an invalid tepoch ype:

 m30001| 2014-11-06T10:55:59.435-0500 I SHARDING [conn1] received splitChunk request: { splitChunk: "test.epoch", keyPattern: { x: 1.0 }, min: { x: 1000.0 }, max: { x: MaxKey }, from: "shard0001", splitKeys: [ { x: 1200.0 } ], shardId: "test.epoch-x_1000.0", configdb: "localhost:30000", epoch: "abc" }
 m30001| 2014-11-06T10:55:59.437-0500 I SHARDING [conn1] distributed lock 'test.epoch/Jonathans-MacBook-Pro.local:30001:1415289359:144108271' acquired, ts : 545b9a0f7a14175eaac98700
 m30001| 2014-11-06T10:55:59.437-0500 I SHARDING [conn1] remotely refreshing metadata for test.epoch based on current shard version 2|0||545b9a0f63d8a811810a592b, current metadata version is 2|1||545b9a0f63d8a811810a592b
 m30001| 2014-11-06T10:55:59.437-0500 I SHARDING [conn1] metadata of collection test.epoch already up to date (shard version : 2|0||545b9a0f63d8a811810a592b, took 0ms)
 m30001| 2014-11-06T10:55:59.437-0500 I SHARDING [conn1] splitChunk accepted at version 2|0||545b9a0f63d8a811810a592b
 m30001| 2014-11-06T10:55:59.438-0500 I SHARDING [conn1] about to log metadata event: { _id: "Jonathans-MacBook-Pro.local-2014-11-06T15:55:59-545b9a0f7a14175eaac98701", server: "Jonathans-MacBook-Pro.local", clientAddr: "127.0.0.1:55484", time: new Date(1415289359438), what: "split", ns: "test.epoch", details: { before: { min: { x: 1000.0 }, max: { x: MaxKey } }, left: { min: { x: 1000.0 }, max: { x: 1200.0 }, lastmod: Timestamp 2000|2, lastmodEpoch: ObjectId('545b9a0f63d8a811810a592b') }, right: { min: { x: 1200.0 }, max: { x: MaxKey }, lastmod: Timestamp 2000|3, lastmodEpoch: ObjectId('545b9a0f63d8a811810a592b') } } }

Generated at Thu Feb 08 03:39:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.