[SERVER-3718] Trying to shard a collection succeeds even without a unique index Created: 29/Aug/11  Updated: 11/Jul/16  Resolved: 04/Oct/11

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Sharding
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Bug Priority: Major - P3
Reporter: Spencer Brody (Inactive) Assignee: Greg Studer
Resolution: Done Votes: 0
Labels: indexing, sharding
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   

> use sharded
> db.unique.drop()
true
> db.adminCommand( { shardcollection : "sharded.unique", key:{a:1}})

{ "collectionsharded" : "sharded.unique", "ok" : 1 }

> db.system.indexes.find()
{ "name" : "id", "ns" : "sharded.foo", "key" :

{ "_id" : 1 }

, "v" : 0 }
{ "v" : 1, "key" :

{ "_id" : 1 }

, "ns" : "sharded.unique", "name" : "id" }
{ "v" : 1, "key" :

{ "a" : 1 }

, "ns" : "sharded.unique", "name" : "a_1" }

Sharding the collection succeeds and creates two non-unique indexes, one on _id and one on the shard key. It should fail, saying that a unique index is necessary.



 Comments   
Comment by auto [ 29/Sep/11 ]

Author:

{u'login': u'gregstuder', u'name': u'gregs', u'email': u'greg@10gen.com'}

Message: better msging / tests when sharding collection with diff types of indexes SERVER-3718
Branch: master
https://github.com/mongodb/mongo/commit/f17810799b107bebdfe3fd1d3a4780f72d10f246

Comment by Spencer Brody (Inactive) [ 02/Sep/11 ]

After further discussion with Greg, we realized that this is the correct behavior when not using "unique:true" to the shardCollection command. If you use "unique:true" to try to enforce that the shard key be unique, however, then the command should fail if there isn't a usable unique index for the shard key.

Comment by auto [ 02/Sep/11 ]

Author:

{u'login': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@10gen.com'}

Message: Update test to reflect desired behavior. SERVER-3718
Branch: master
https://github.com/mongodb/mongo/commit/fcf97ff30ec7113e3f2a7669ba17e8df46841a40

Comment by auto [ 30/Aug/11 ]

Author:

{u'login': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@10gen.com'}

Message: Add more tests for SERVER-2326 & SERVER-3718.
Branch: master
https://github.com/mongodb/mongo/commit/ad830c9c07b7e99187719ae8d099835fb684d0a4

Comment by auto [ 29/Aug/11 ]

Author:

{u'login': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@10gen.com'}

Message: Fix sharding index creation tests. Now can catch SERVER-3718.
Branch: master
https://github.com/mongodb/mongo/commit/ae3201b73d06f139912aca4573994f1ed0c68d7b

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