我添加了两个分片,如下所示:
shards:
{ "_id" : "rs0", "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
{ "_id" : "rs1", "host" : "rs1/serv3:27017,serv4:27017,serv5:27017" }
我已将我的收藏帖子分片如下:
数据库:
{ "_id" : "mypost", "partitioned" : true, "primary" : "rs0" }
mypost.posts
shard key: { "_id" : "hashed" }
chunks:
rs0 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)
我的问题是,即使我在 _id 上使用散列键并插入了 34MB 的数据,为什么始终只从分片 1 获取数据,而没有将任何块移动到分片 2。
当我做
db.posts.find().explain() i get:
{
"clusteredType" : "ParallelSort",
"shards" : {
"rs0/serv1:27017,serv2:27017,serv3:27017" : [
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 1000,
"nscannedObjects" : 1000,
"nscanned" : 1000,
"nscannedObjectsAllPlans" : 1000,
"nscannedAllPlans" : 1000,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 4,
"indexBounds" : {
},
"server" : "serv1:27017"
}
]
},
"cursor" : "BasicCursor",
"n" : 1000,
"nChunkSkips" : 0,
"nYields" : 0,
"nscanned" : 1000,
"nscannedAllPlans" : 1000,
"nscannedObjects" : 1000,
"nscannedObjectsAllPlans" : 1000,
"millisShardTotal" : 4,
"millisShardAvg" : 4,
"numQueries" : 1,
"numShards" : 1,
"indexBounds" : {
},
"millis" : 5
}
我的数据如何自动发送到两个分片。
sh.status()
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("50fde9a8552b8ce5c47c8ead")
}
shards:
{ "_id" : "rs0", "host" : "rs0/serv1:27017,serv2:27017,serv3:27017" }
{ "_id" : "rs1", "host" : "rs1/serv4:27017,serv5:27017,serv6:27017" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "myposts", "partitioned" : true, "primary" : "rs0" }
myposts.posts
shard key: { "_id" : "hashed" }
chunks:
rs0 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0)
删除集合后的状态---------
{ "_id" : "myposts", "partitioned" : true, "primary" : "rs0" }
myposts.posts
shard key: { "_id" : "hashed" }
chunks:
rs0 2
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : rs0 Timestamp(1, 0)
{ "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 1)