Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9620

Index can be made multikey if a prefix of it is a shard key (splitVectors fail)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc0
    • Affects Version/s: 2.2.4, 2.4.3
    • Component/s: Sharding
    • None
    • ALL

      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
      1. Set up sharded cluster
      2. Connect to mongos, insert a document into a collection:
        > db.docs.insert({a:1, b:2, c:3, d:4})
        
      3. Create index on all 4 fields:
        > db.docs.ensureIndex({a:1, b:1, c:1, d:1})
        
      4. Enable sharding and shard collection on a prefix of the index:
        > sh.enableSharding('test')
        > sh.shardCollection('test.docs', {a:1, b:1})
        
      5. Now insert a document that contains an array for c:
        > db.docs.insert({a:5, b:6, c:[1, 2, 3], d:7})
        
      6. 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.

            Assignee:
            randolph@mongodb.com Randolph Tan
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: