Hide
Create a shared cluster
Step1: enable sharding for test database
sh.enableSharding("test")
Step2: create index for some colletion
mongos> db.coll.createIndex({x: 1})
{
"raw" : {
"mymongo02/r101072137.sqa.zmf:9665" : {
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1504497721, 2),
"electionId" : ObjectId("58eeece962cc998e3a94975d")
}
}
},
"ok" : 1
}
Shard1 (primary shard for test database)
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1",
"ns" : "test.coll"
}
]
Shard2
Step3: shardCollection for test.coll
sh.shardCollection("test.coll", {x: 1})
{ "collectionsharded" : "test.coll", "ok" : 1 }
Step4: create index again with different option
mongos> db.coll.createIndex({x: 1}, {safe: null})
{
"raw" : {
"mymongo02/r101072137.sqa.zmf:9665" : {
"ok" : 0,
"errmsg" : "Index with name: x_1 already exists with different options",
"code" : 85
},
"mymongo03/r101072137.sqa.zmf:9666" : {
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1504497768, 2),
"electionId" : ObjectId("59acc73aacadfa7926c9cabb")
}
}
},
"code" : 85,
"ok" : 0,
"errmsg" : "{ mymongo02/r101072137.sqa.zmf:9665: \"Index with name: x_1 already exists with different options\" }"
}
Shard1 (primary shard)
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1",
"ns" : "test.coll"
}
]
mymongo02:PRIMARY>
Shard2
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1",
"ns" : "test.coll",
"safe" : null
}
]
Now two shards have the same index with different IndexOption, the migration will never success.
Show
Create a shared cluster
Step1: enable sharding for test database
sh.enableSharding( "test" )
Step2: create index for some colletion
mongos> db.coll.createIndex({x: 1})
{
"raw" : {
"mymongo02/r101072137.sqa.zmf:9665" : {
"createdCollectionAutomatically" : true ,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1504497721, 2),
"electionId" : ObjectId( "58eeece962cc998e3a94975d" )
}
}
},
"ok" : 1
}
Shard1 (primary shard for test database)
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_" ,
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1" ,
"ns" : "test.coll"
}
]
Shard2
db.coll.getIndexes()
[ ]
Step3: shardCollection for test.coll
sh.shardCollection( "test.coll" , {x: 1})
{ "collectionsharded" : "test.coll" , "ok" : 1 }
Step4: create index again with different option
mongos> db.coll.createIndex({x: 1}, {safe: null })
{
"raw" : {
"mymongo02/r101072137.sqa.zmf:9665" : {
"ok" : 0,
"errmsg" : "Index with name: x_1 already exists with different options" ,
"code" : 85
},
"mymongo03/r101072137.sqa.zmf:9666" : {
"createdCollectionAutomatically" : true ,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1504497768, 2),
"electionId" : ObjectId( "59acc73aacadfa7926c9cabb" )
}
}
},
"code" : 85,
"ok" : 0,
"errmsg" : "{ mymongo02/r101072137.sqa.zmf:9665: \" Index with name: x_1 already exists with different options\ " }"
}
Shard1 (primary shard)
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_" ,
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1" ,
"ns" : "test.coll"
}
]
mymongo02:PRIMARY>
Shard2
db.coll.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_" ,
"ns" : "test.coll"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1" ,
"ns" : "test.coll" ,
"safe" : null
}
]
Now two shards have the same index with different IndexOption, the migration will never success.