【问题标题】:mongoDB sharding examplemongoDB分片示例
【发布时间】:2011-12-18 13:55:53
【问题描述】:

在 windows 上使用 mongo 2.0.1 32 位的新手尝试如下测试分片:

(4) 进程:2 个分片 + config srver + mongos w tiny chunksize

mongod.exe --shardsvr  --port 10001  --dbpath <folder1>       > shard1.log
mongod.exe --shardsvr  --port 10002  --dbpath <folder2>       > shard2.log
mongod.exe --configsvr --port 20000  --dbpath <configfolder>  > config.log
mongos.exe --configdb localhost:20000 --chunkSize 1           > mongos.log

我运行了 shell 并设置了 2 个分片:

mongos> use admin
switched to dbadmin

mongos> db.runCommand( { addshard : "localhost:10001" } );
{ "shardAdded" : "shard0000", "ok" : 1 }

mongos> db.runCommand( { addshard : "localhost:10002" } );
{ "shardAdded" : "shard0001", "ok" : 1 }

然后我为测试数据库 (dbTest) 和集合 (cTest) 启用分片:

mongos> db.runCommand( { enablesharding  : "dbTest" } );
{ "ok" : 1 }

mongos> db.runCommand( { shardcollection : "dbTest.cTest", key : { Name : 1 } } );
{ "collectionssharded" : "dbTest.cTest", "ok" : 1 }

最后我用 1,000,005 条样本记录填充了 cTest 集合(按名称索引):

mongos> use dbTest
switched to db dbTest

db.cTest.drop();
db.cTest.ensureIndex({ Name : 1 });
db.cTest.save({Name: "Frank", Age:56, Job: "Accountant", State: "NY"});
db.cTest.save({Name: "Bill" , Age:23,                    State: "CA"});
db.cTest.save({Name: "Janet", Age:34, Job: "Dancer"                 });
db.cTest.save({Name: "Andy",  Age:44                                });
db.cTest.save({Name: "Zach",  Age:23, Job: "Fireman",    State: "CA"});
i=1;
while(i<=1000) 
{ 
  j=1;
  while (j<=1000) 
  { 
    db.cTest.save({Name:"Person("+i+","+j+")", Age:i+j}); 
    j = j+1
  }; 
  i=i+1; 
};

然而……

看起来实际上没有任何东西被分片。在配置数据库中,db.chunks.count() 为零,我可以从 Windows 资源管理器文件大小中看到,所有数据都进入了第一个分片的物理文件设置设置,而没有进入第二个分片。

谁能发现我做错了什么,并提供一些关于如何管理和调试这类事情并查看发生了什么的提示?

谢谢

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    一旦你“shardcollection”,就不要放弃它。它将删除有关分片集合的元数据。

    【讨论】:

    • 谢谢,Nat 就是这样。 (我可能会连续几天盯着它看!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2013-03-26
    • 2013-05-08
    相关资源
    最近更新 更多