The index used for a shard key cannot be a multikey.
Hence inserts into a sharded collection that would turn the relevant index into a multi-key index are prevented, but only if the index is identical with the shard key:
tried to insert object with no valid shard key for { a: 1.0, b: 1.0 } : { _id: ObjectId('518a5fe33c631895e210858a'), a: 1.0, b: [ 1.0, 2.0, 3.0 ] }
If the shard key is instead only a prefix of the index, we do not prevent such inserts for other fields. This causes the index to turn into a multikey index and splitVectors will fail.
Steps to reproduce
- Set up sharded cluster
- Connect to mongos, insert a document into a collection:
> db.docs.insert({a:1, b:2, c:3, d:4})
- Create index on all 4 fields:
> db.docs.ensureIndex({a:1, b:1, c:1, d:1})
- Enable sharding and shard collection on a prefix of the index:
> sh.enableSharding('test') > sh.shardCollection('test.docs', {a:1, b:1})
- Now insert a document that contains an array for c:
> db.docs.insert({a:5, b:6, c:[1, 2, 3], d:7})
- Switch to mongod and run a splitVector command
> db.adminCommand({splitVector: 'test.docs', keyPattern: {a:1, b:1}, maxChunkSize: 1}) { "errmsg" : "couldn't find index over splitting key { a: 1.0, b: 1.0 }", "ok" : 0 }
Proposed behavior
Any insert turning the index into a multikey index should fail with an error, as it does when the index pattern is identical to the shard key.
- is duplicated by
-
SERVER-6095 make multikey indices useful for sharding
- Closed