【Mongo】mongos shard 唯一索引的問題
1.已經被sharding的文件建立唯一索引
-
mongos> db.testmongo.ensureIndex({'age':1,'name':1},{"unique":1})
-
{
-
"raw" : {
-
"shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 1,
-
"ok" : 0,
-
"errmsg" : "cannot create unique index over { age: 1.0, name: 1.0 } with shard key pattern { _id: 1.0 }",
-
"code" : 67,
-
"codeName" : "CannotCreateIndex",
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656402, 42),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
},
-
"shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
-
"createdCollectionAutomatically" : true,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656406, 2),
-
"t" : NumberLong(7)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000007")
-
}
-
},
-
"shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
-
"createdCollectionAutomatically" : true,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656406, 2),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
}
-
},
-
"code" : 67,
-
"ok" : 0,
-
"errmsg" : "{ shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001: \"cannot create unique index over { age: 1.0, name: 1.0 } with shard key pattern { _id: 1.0 }\" }"
-
}
-
mongos> db.testmongo.ensureIndex({'_id':1,'age':1,'name':1},{"unique":1})
-
{
-
"raw" : {
-
"shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
},
-
"shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 2,
-
"numIndexesAfter" : 3,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(7)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000007")
-
}
-
},
-
"shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 2,
-
"numIndexesAfter" : 3,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
}
-
},
-
"ok" : 1
- }
已經被shard的collection 唯一索引的字首必須是分片健
2.已經建立唯一索引的collection去shard
-
mongos> db.testtt.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "welike_mongo.testtt"
},
{
"v" : 2,
"unique" : true,
"key" : {
"age" : 1,
"name" : 1
},
"name" : "age_1_name_1",
"ns" : "welike_mongo.testtt"
}
]
-
mongos> sh.shardCollection("welike_mongo.testtt",{_id:1})
-
{
-
"ok" : 0,
-
"errmsg" : "can't shard collection 'welike_mongo.testtt' with unique index on { age: 1.0, name: 1.0 } and proposed shard key { _id: 1.0 }. Uniqueness can't be maintained unless shard key is a prefix"
-
}
-
mongos> sh.shardCollection("welike_mongo.testtt",{'name':1})
-
{
-
"ok" : 0,
-
"errmsg" : "can't shard collection 'welike_mongo.testtt' with unique index on { age: 1.0, name: 1.0 } and proposed shard key { name: 1.0 }. Uniqueness can't be maintained unless shard key is a prefix"
-
}
-
mongos> sh.shardCollection("welike_mongo.testtt",{'age':1})
- { "collectionsharded" : "welike_mongo.testtt", "ok" : 1 }
已建立唯一索引的collect 去shard 。分片欄位必須是唯一索引的字首
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2156524/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料庫表的唯一索引問題資料庫索引
- mongo 索引解析Go索引
- 管理索引mongo索引Go
- MyBatisPlus解決邏輯刪除與唯一索引的相容問題MyBatis索引
- 唯一索引索引
- 【Mongo】MongoDB索引管理-索引的建立、檢視、刪除MongoDB索引
- 唯一索引和普通索引的選擇索引
- spring data mongo @Field 失效問題SpringGo
- MySQL <唯一索引>MySql索引
- MySQL 唯一索引和普通索引MySql索引
- 一條唯一索引索引
- Matlab轉python的索引問題MatlabPython索引
- ES ElasticSearch 7.x 下動態擴大索引的shard數量Elasticsearch索引
- 主鍵約束、唯一約束和唯一索引索引
- mysql唯一索引是什麼MySql索引
- MySQL實戰45講——普通索引和唯一索引MySql索引
- mysql的唯一索引不會利用change bufferMySql索引
- Mysql索引失效問題demoMySql索引
- 筆記 mongo查詢慢日誌,建立索引筆記Go索引
- 效能測試中的唯一標識問題研究
- 普通索引和唯一索引,應該怎麼選擇?索引
- [20211105]索引分裂塊清除日誌增加(唯一索引).txt索引
- 聊一聊MySQL索引失效的問題MySql索引
- 不能建立降序索引的問題的解決索引
- [20180509]函式索引問題.txt函式索引
- mongo 建立使用者 建hash 分割槽 建索引Go索引
- 如何選擇普通索引和唯一索引《死磕MySQL系列 五》索引MySql
- [20211108]索引分裂塊清除日誌增加(唯一索引)2.txt索引
- mongodb之shard分片MongoDB
- 資料庫聚簇索引——not null條件對唯一鍵索引成為聚簇索引的影響資料庫索引Null
- [20181123]關於降序索引問題.txt索引
- 資料庫索引分裂 問題分析資料庫索引
- Oracle一次“選錯索引”問題的分析Oracle索引
- mysql 新增時,唯一索引衝突時更新MySql索引
- Oracle與GreatSQL差異:更改唯一索引列OracleSQL索引
- 技術分享 | MySQL 大表新增唯一索引的總結MySql索引
- 如何優雅的向MySQL唯一索引列增加值MySql索引
- Python—關於Pandas缺失值問題(國內唯一)Python