Documents with fields MaxKey() value may not be moved on a chunk migration

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Catalog and Routing
    • ALL
    • Hide
      import {ShardingTest} from "jstests/libs/shardingtest.js";
      
      let st = new ShardingTest({shards: 3});
      
      const db = st.s.getDB("test");
      
      assert.commandWorked(st.s.adminCommand({enableSharding: db.getName(), primaryShard: st.shard0.shardName}));
      
      // Create a sharded collection with:
      //  - shard key pattern: {x:1}
      //  - shard key index: {x:1, y:1}
      assert.commandWorked(db.adminCommand({shardCollection: "test.coll", key: {x: 1}}));
      db.coll.createIndex({x: 1, y: 1});
      db.coll.dropIndex({x: 1});
      
      // Create doc {x: MaxKey(), y:10}
      db.coll.insertOne({x: MaxKey(), y: 10});
      assert.eq(db.coll.find({}).count(), 1);
      
      // Move chunk
      assert.commandWorked(
          db.adminCommand({moveRange: "test.coll", min: {x: 0}, max: {x: MaxKey()}, toShard: st.shard1.shardName}),
      );
      
      // The document {x: MaxKey(), y:10} has not been moved
      // Consequently, we can't fetch it from the mongos
      const docs = db.coll.find().toArray();
      assert.eq(docs.length, 1);
      
      db.coll.drop();
      
      st.stop();
      Show
      import {ShardingTest} from "jstests/libs/shardingtest.js"; let st = new ShardingTest({shards: 3}); const db = st.s.getDB("test"); assert.commandWorked(st.s.adminCommand({enableSharding: db.getName(), primaryShard: st.shard0.shardName})); // Create a sharded collection with: //  - shard key pattern: {x:1} //  - shard key index: {x:1, y:1} assert.commandWorked(db.adminCommand({shardCollection: "test.coll", key: {x: 1}})); db.coll.createIndex({x: 1, y: 1}); db.coll.dropIndex({x: 1}); // Create doc {x: MaxKey(), y:10} db.coll.insertOne({x: MaxKey(), y: 10}); assert.eq(db.coll.find({}).count(), 1); // Move chunk assert.commandWorked(     db.adminCommand({moveRange: "test.coll", min: {x: 0}, max: {x: MaxKey()}, toShard: st.shard1.shardName}), ); // The document {x: MaxKey(), y:10} has not been moved // Consequently, we can't fetch it from the mongos const docs = db.coll.find().toArray(); assert.eq(docs.length, 1); db.coll.drop(); st.stop();
    • CAR Team 2026-03-30
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If a chunk migration uses an index that is longer than the shard key pattern, documents with fields MaxKey() value may not be moved.

      For example:

      • Sharded collection with shard key pattern {x:1}
      • It has the document: {x: MaxKey(), y: 10}
      • A chunk migration uses index {x: 1, y: 1}
      • The chunk migration with a range where max is {x: MaxKey()} will miss that document.

      The upper bound of the range is extended to include all index fields, resulting in {x: MaxKey(), y: MinKey()}. The field y is set to MinKey() because the upper bound is non-inclusive.

            Assignee:
            Unassigned
            Reporter:
            Silvia Surroca
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: