[SERVER-46004] refineShardKey should verify indexes on shards with chunks Created: 05/Feb/20  Updated: 29/Oct/23  Resolved: 13/Mar/20

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 4.4.0-rc0, 4.7.0

Type: Bug Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: Jack Mulrow
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Steps To Reproduce:

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
Participants:

 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.



 Comments   
Comment by Githook User [ 30/Mar/20 ]

Author:

{'name': 'Jack Mulrow', 'email': 'jack.mulrow@mongodb.com', 'username': 'jsmulrow'}

Message: SERVER-46004 refineCollectionShardKey should verify indexes on a shard with a chunk

(cherry picked from commit 8781a75d17393b9f2c747116ed17a91b734bb2db)
Branch: v4.4
https://github.com/mongodb/mongo/commit/c136056b569ecd11fe98c81312609432b25d9cc6

Comment by Githook User [ 13/Mar/20 ]

Author:

{'username': 'jsmulrow', 'name': 'Jack Mulrow', 'email': 'jack.mulrow@mongodb.com'}

Message: SERVER-46004 refineCollectionShardKey should verify indexes on a shard with a chunk
Branch: master
https://github.com/mongodb/mongo/commit/8781a75d17393b9f2c747116ed17a91b734bb2db

Comment by Jack Mulrow [ 14/Feb/20 ]

We should be able to fix this by running the listIndexes on the shard that owns the minKey chunk (with a shard version), like we do for cluster listIndexes. Technically we could use any shard with a chunk, but it's probably better to be consistent. 

Generated at Thu Feb 08 05:10:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.