2013-08-23 32 views
0

我已經在本地主機上設置了分片mongo數據庫環境,包含3個配置服務器和2個分片mongo實例以及一個mongos。分片mongodb不會重新分配數據

一旦集羣已經開始了,我運行的命令序列如下:

sh.addShard("127.0.0.1:27010") 
sh.addShard("127.0.0.1:27011") 

a = {"_id" : 1, "value" : 1} 
b = {"_id" : 2, "value" : 2} 
c = {"_id" : 3, "value" : 3} 
d = {"_id" : 4, "value" : 4} 

use foobar; 
db.foo.insert(a); 
db.foo.insert(b); 
db.foo.insert(c); 
db.foo.insert(d); 

的我啓用拆分數據庫,並創建一個索引等

sh.enableSharding("foobar"); 
db.foo.ensureIndex({"value":"hashed"}); 
sh.shardCollection("foobar.foo", { value: "hashed" }) 

所有的結果上述操作是成功的。

但是,一旦我做: db.foo.stats()

我看到所有的數據只是一個碎片沒有被分配結束。運行

db.printShardingStatus(); 

生產:

--- Sharding Status --- 
sharding version: { 
"_id" : 1, 
"version" : 3, 
"minCompatibleVersion" : 3, 
"currentVersion" : 4, 
"clusterId" : ObjectId("52170e8a7633066f09e0c9d3") 
} 
shards: 
{ "_id" : "shard0000", "host" : "127.0.0.1:27010" } 
{ "_id" : "shard0001", "host" : "127.0.0.1:27011" } 
databases: 
{ "_id" : "admin", "partitioned" : false, "primary" : "config" } 
{ "_id" : "foobar", "partitioned" : true, "primary" : "shard0000" } 
    foobar.foo 
     shard key: { "value" : "hashed" } 
     chunks: 
      shard0000 1 
     { "value" : { "$minKey" : 1 } } -->> { "value" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0) 

有趣的是,不過,如果我開始一個空白的收集和有將任何數據之前啓用它分片,結果有很大的不同:

db.foo.stats(); 
{ 
"sharded" : true, 
"ns" : "foobar.foo", 
"count" : 4, 
"numExtents" : 2, 
"size" : 144, 
"storageSize" : 16384, 
"totalIndexSize" : 32704, 
"indexSizes" : { 
    "_id_" : 16352, 
    "value_hashed" : 16352 
}, 
"avgObjSize" : 36, 
"nindexes" : 2, 
"nchunks" : 4, 
"shards" : { 
    "shard0000" : { 
     "ns" : "foobar.foo", 
     "count" : 1, 
     "size" : 36, 
     "avgObjSize" : 36, 
     "storageSize" : 8192, 
     "numExtents" : 1, 
     "nindexes" : 2, 
     "lastExtentSize" : 8192, 
     "paddingFactor" : 1, 
     "systemFlags" : 1, 
     "userFlags" : 0, 
     "totalIndexSize" : 16352, 
     "indexSizes" : { 
      "_id_" : 8176, 
      "value_hashed" : 8176 
     }, 
     "ok" : 1 
    }, 
    "shard0001" : { 
     "ns" : "foobar.foo", 
     "count" : 3, 
     "size" : 108, 
     "avgObjSize" : 36, 
     "storageSize" : 8192, 
     "numExtents" : 1, 
     "nindexes" : 2, 
     "lastExtentSize" : 8192, 
     "paddingFactor" : 1, 
     "systemFlags" : 1, 
     "userFlags" : 0, 
     "totalIndexSize" : 16352, 
     "indexSizes" : { 
      "_id_" : 8176, 
      "value_hashed" : 8176 
     }, 
     "ok" : 1 
    } 
}, 
"ok" : 1 
} 

所以問題是我是否缺少一些東西,如果我分割現有的集合?

回答

0

目前你有這樣一個小數據集,你只有1塊數據。 MongoDB將根據Migration Thresholds來平衡您的數據 - 這樣平衡器的影響就會保持在最低水平。嘗試添加更多數據:)並且平衡器將分割您的數據並隨着時間的推移平衡數據塊。

沒有集合中的數據開始每個分片將被分配一個區塊的範圍,這就是爲什麼你在第二種情況下跨越分片查看數據。