[SERVER-11324] Create unique index on colleciton with hashed sharding key Created: 23/Oct/13  Updated: 11/Jul/16  Resolved: 14/Nov/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.4.6
Fix Version/s: 2.5.4

Type: Bug Priority: Major - P3
Reporter: Steffen Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12.04.x LTS
3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux


Attachments: File hash_shard_unique_compound.js    
Issue Links:
Depends
Related
Operating System: ALL
Steps To Reproduce:

create a collection with index

{targetId : 1 ,timestamp: -1}, {unique : true}


shard collection with with key

{ targetId: "hashed"}

drop index

{targetId : 1 ,timestamp: -1}


try to recreate index

 {targetId : 1 ,timestamp: -1}, {unique : true}

Participants:

 Description   

We want to creat a compound index in a sharded collection with a hashed sharding key.

The non hashed shard key is a prefix of the compound index.

If we create the index before we shard the collection, mongodb does not complain about the index.

{
	"err" : "can't use unique indexes with sharding  ns:test.collection key: { targetId: 1.0, timestamp: -1.0 }",
	"code" : 10205,
	"n" : 0,
	"ok" : 1
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 28/Mar/14 ]

No, this has not been back-ported to 2.4.x. This fix will be included in the upcoming 2.6 (stable) release.

Comment by James Blackburn [ 28/Mar/14 ]

Is this fixed in any version of 2.4.x?

Comment by Githook User [ 14/Nov/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-11324: fix for wrong test change
Branch: master
https://github.com/mongodb/mongo/commit/48268f23932ed93e69054eaa7e34b8d9c79a8008

Comment by Githook User [ 14/Nov/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-11324: Allow unique index if prefixed by hashed shard key
Branch: master
https://github.com/mongodb/mongo/commit/423a65720edb43703cca9aef04592c709afbd9b7

Comment by Scott Hernandez (Inactive) [ 23/Oct/13 ]

Steffen, I've added a test showing the current behavior and the inconsistent errors depending on if you create the unique index before or after sharding the collection.

Sorry for missing that detail in the reproduction.

Comment by Eliot Horowitz (Inactive) [ 23/Oct/13 ]

There is at least one issue here that it didn't complain the other way.
You should also be able to create the compound index if you make targetId hashed

Comment by Scott Hernandez (Inactive) [ 23/Oct/13 ]

This is expected behavior based on the sharding system design and restrictions.

Here are the related docs which offer more information and workarounds:

Generated at Thu Feb 08 03:25:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.