2013-04-17 2 views
2

sharded mongo 환경에서 모의 ​​테스트를 수행했지만 샤드 키 값이 작은 경우 콜렉션이 배포되지 않았지만 샤드 키가 크면 int , 그것의 일 벌금. 다음을 읽어보십시오 ...샤드 키가 작은 int 인 경우 Mongo 샤드 컬렉션이 배포되지 않음

mongos 셸에서 레코드를 삽입하는 데 사용되는 코드입니다.

var shId = 15; 
for (var i = 0; i < 100; i++) { 
    if(i%50 == 0){ 
     shId = shId + 1; 
    } 
    db.Foo.insert({ shKeyId : shId , text:"this is a test" }); 
} 

shId = 15 인 경우 Foo 컬렉션이 두 개의 샤드로 분할되지 않았습니다.

환경 : 2 개의 샤드, 1 차 샤드와 2 차 mongod 인스턴스 2 개. Mongo config가 샤드 중 하나에서 실행 중입니다.

샤드 해시 키로 shKeyId에 의해 'Foo'컬렉션에서 샤딩이 활성화되었습니다. db.runCommand ({shardcollection : "test.Foo", key : {shKeyId : "hashed"}}));

sh.status() 출력

mongos> sh.status(); 
--- Sharding Status --- 
    sharding version: { 
    "_id" : 1, 
    "version" : 3, 
    "minCompatibleVersion" : 3, 
    "currentVersion" : 4, 
    "clusterId" : ObjectId("516ea48e979736fd306973c9") 
} 
    shards: 
    { "_id" : "mongo-perf-shrd1", "host" : "mongo-perf-shrd1/sh1-prim-ip:27017,sh1-sec1-ip:27017,sh1-sec2-ip:27017" } 
    { "_id" : "mongo-perf-shrd2", "host" : "mongo-perf-shrd2/sh2-prim-ip:27017,sh2-sec1-ip:27017,sh2-sec2-ip:27017" } 
    databases: 
    { "_id" : "admin", "partitioned" : false, "primary" : "config" } 

    { "_id" : "test", "partitioned" : true, "primary" : "mongo-perf-shrd2" } 
     test.Foo 
      shard key: { "shKeyId" : "hashed" } 
      chunks: 
       mongo-perf-shrd2 2 
       mongo-perf-shrd1 2 
      { "shKeyId" : { "$minKey" : 1 } } -->> { "shKeyId" : NumberLong("-4611686018427387902") } on : mongo-perf-shrd2 { "t" : 2, "i" : 2 } 
      { "shKeyId" : NumberLong("-4611686018427387902") } -->> { "shKeyId" : NumberLong(0) } on : mongo-perf-shrd2 { "t" : 2, "i" : 3 } 
      { "shKeyId" : NumberLong(0) } -->> { "shKeyId" : NumberLong("4611686018427387902") } on : mongo-perf-shrd1 { "t" : 2, "i" : 4 } 
      { "shKeyId" : NumberLong("4611686018427387902") } -->> { "shKeyId" : { "$maxKey" : 1 } } on : mongo-perf-shrd1 { "t" : 2, "i" : 5 } 

파편 배포 출력 그냥 단조 파편 키가

mongos> db.Foo.getShardDistribution(); 

Shard mongo-perf-shrd1 at mongo-perf-shrd1/ip1:27017,ip2,ip3:27017 
data : 6KiB docs : 100 chunks : 2 
estimated data per chunk : 3KiB 
estimated docs per chunk : 50 

Shard mongo-perf-shrd2 at mongo-perf-shrd2/ip4:27017,ip5:27017,ip6:27017 
data : 0B docs : 0 chunks : 2 
estimated data per chunk : 0B 
estimated docs per chunk : 0 

Totals 
data : 6KiB docs : 100 chunks : 4 
Shard mongo-perf-shrd1 contains 100% data, 100% docs in cluster, avg obj size on shard : 64B 
Shard mongo-perf-shrd2 contains 0% data, 0% docs in cluster, avg obj size on shard : NaNGiB 
+0

"샤딩이 효과가 없다"는 것이 무슨 뜻인지 설명해 주시겠습니까? – shelman

+0

50 레코드가 샤드 1에 들어가고 다른 50 레코드가 샤드 2에 들어갈 것으로 예상했습니다. 하지만 shard1에 저장된 100 개의 레코드들 모두 – Samba

+0

mongos에서 실행되는'sh.status()'의 결과를 게시 할 수 있습니까? – shelman

답변

0

, 이 좋은 해결책이되지 않습니다 : 단지에 대한 http://docs.mongodb.org/manual/core/sharded-cluster-internals/

모의 테스트를 거쳐 기본적으로 샤드 키를 선택할 수 있음 _id 필드

+2

http://docs.mongodb.org/manual/core/sharded-clusters/#shard-keys "해시 된 키는 단조롭게 증가하는 필드와 잘 작동합니다" – Samba