[SERVER-19714] config.collections should reflect if the shard key is unique Created: 03/Aug/15  Updated: 06/Dec/22  Resolved: 03/May/18

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

Type: Improvement Priority: Minor - P4
Reporter: Joanna Cheng Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-70489 Building a unique index before shardC... Closed
Assigned Teams:
Sharding
Participants:

 Description   

If you create a unique index to be your shard key index, and then shard without specifying {unique: true}, it shows up as {unique : false} in config.collections

mongos> db.bar.ensureIndex({a:1}, {unique:true})
{
	"raw" : {
		"Joannas-MacBook-Pro.local:22001" : {
			"createdCollectionAutomatically" : true,
			"numIndexesBefore" : 1,
			"numIndexesAfter" : 2,
			"ok" : 1
		}
	},
	"ok" : 1
}
mongos> sh.shardCollection("test.bar", {a:1})
{ "collectionsharded" : "test.bar", "ok" : 1 }
mongos> db.getSiblingDB("config").collections.find()
{ "_id" : "test.bar", "lastmodEpoch" : ObjectId("55bf08d75e8b88faa32aeabb"), "lastmod" : ISODate("1970-02-19T17:02:47.296Z"), "dropped" : false, "key" : { "a" : 1 }, "unique" : false }

It would be good if this correctly reflected whether the shard key has guaranteed uniqueness. Above testing was against 3.1.6



 Comments   
Comment by Kaloian Manassiev [ 03/May/18 ]

Unfortunately it is currently not possible to reliably synchronize the config server-stored metadata with what is on the individual shards.

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