-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 7.0.0, 8.0.0, 8.3.0, 9.1.0-rc0, 9.0.0
-
Component/s: Sharding
-
Catalog and Routing
-
ALL
-
2
-
🟥 DDL
-
None
-
None
-
None
-
None
-
None
-
None
Issue
In a sharded cluster the following commands create a CollectionOptionsMismatch inconsistency:
use test
db.adminCommand({enableSharding: "test", primaryShard: "shard1"})
db.adminCommand({shardCollection: "test.foo", key: {x: 1}})
db.adminCommand({split: "test.foo", middle: {x: 0}})
db.adminCommand({moveChunk: "test.foo", find: {x: 0}, to: "shard2"})
db.foo.insertMany([{x: -1}, {x: 1}, {x: 1}])
db.foo.createIndex({x: 1, y: 1}, {unique: true}) // Fails with DuplicateKey.
db.runCommand({ // Fails with IndexNotFound.
  collMod: "foo",
  index: {keyPattern: {x: 1, y: 1}, hidden: true},
  validator: {x: {$type: "number"}}
})
db.checkMetadataConsistency().toArray() // Finds CollectionOptionsMismatch.
Â
The problem is that:
- The {x:1, y:1} index is only built on shard1, because shard2 violates the unique constraint. The {x: 1, y: 1}Â stays on shard1 after the DuplicateKey failure.
- The collMod command is both a collection options (validator) and index (hidden) change. collMod first successfully commits the options+index change to shard1, but then it fails to commit to shard2.
- This has made the options (validator) inconsistent across shards, so checkMetadataConsistency reports it as a CollectionOptionsMismatch inconsistency.
Â
(This is a non-timeseries variant of SERVER-108801)
Â
Potential fixes
- (Short term) Disallow mixed options+index collMod: Note it's a breaking change.
- (Medium-long term) Make collMod follow 2PC: make collMod first check the feasibility of the commit (prepare-commit), to resolves an entire class of collMod inconsistency issues (see SERVER-131459,Â
SERVER-108801, SERVER-125922, ...). - (Medium-long term) Ensure indexes are created consistently in all shards (implement create indexes coordinator - SERVER-75675).
Â