【问题标题】:Mongodb Sharding not working - what is causing Collection not shardedMongodb 分片不起作用 - 是什么导致 Collection 没有分片
【发布时间】:2014-03-21 15:32:44
【问题描述】:

我正在尝试使用两个节点设置 mongodb 分片。我启用了 3 个配置进程和一个路由器进程。我正在从 SQL 服务器中提取数据(以 50 列 - 650 MB - _id 作为键)并放入 mongodb。在 pentaho 配置中,我启用了“使用所有副本集” 并输入主节点的主机名和端口。当我运行转换时,所有数据都进入主节点,而另一个节点没有获取数据。当我输入 db.table.getShardDistribution() 时,我收到以下消息“Collection not sharded”。

is.BalancerRunning() 的状态也给了我false 的状态。我很确定后台进程平衡器在这里不起作用。

当我尝试插入样本测试记录 10,00,000 条记录并以名称为键时,分片设置工作正常,每个分片都分配了数据。

所以,当我运行 pentaho 转换以在 mongodb 中填充数据时,我遗漏了一些东西或做错了什么。任何帮助表示赞赏。

我的设置


C:\Mongodb\bin\mongod.exe --shardsvr  --port 10001  --dbpath  C:\Mongodb\shard1      > C:\Mongodb\Log\shard1.log
C:\Mongodb\bin\mongod.exe --shardsvr  --port 10002  --dbpath  C:\Mongodb\shard2      > C:\Mongodb\Log\shard2.log
C:\Mongodb\bin\mongod.exe --configsvr --port 20000  --dbpath  C:\Mongodb\configdb    > C:\Mongodb\Log\config.log
C:\Mongodb\bin\mongos.exe --configdb 10.231.34.105:
 --chunkSize 1               > C:\Mongodb\Log\mongos.log


mongos> use admin
switched to dbadmin

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

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

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

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

mongos> use dbTest;

db.cTest.ensureIndex({ Date_D : 1 });```

【问题讨论】:

  • 你能将一个 mongo shell 连接到你的 mongos(路由器)实例,运行 sh.status() 并在此处提供输出吗? sh.status() 将提供您分片设置的摘要。
  • 分片版本:{“_id”:1,“version”:3,“minCompatibleVersion”:3,“currentVersion”:4,“clusterId”:ObjectId(“532c4541d0b378244488e8fa”)}分片:{ “_id”:“shard0000”,“主机”:“10.231.34.105:40001”} {“_id”:“shard0001”,“主机”:“10.231.34.106:40002”}数据库:{“_id”:“管理员", "partitioned" : false, "primary" : "config" } { "_id" : "dbTest", "partitioned" : true, "primary" : "shard0000" } { "_id" : "dTest", "partitioned " : false, "primary" : "shard0001" }
  • 我在这个输出中看不到任何分片集合,假设这是完整的 sh.status() 输出。要尝试的一件事是在尝试对集合进行分片之前在 cTest 上创建索引。这可能是一个要求,具体取决于您运行的 MongoDB 版本。
  • 但是从 shard1 中,如果我使用以下代码填充表 ::myData = "";while ( myData.length

标签: mongodb pentaho sharding


【解决方案1】:

我不确定您是否对数据库和集合进行分片。

设置分片后,您是否为数据库启用了分片。如下所示

db.runCommand({
    enablesharding : "dbname"
});

db.stats()确认。

为集合启用分片后。如下所示。

db.runCommand({
        shardcollection : "collection_name",
        key : {
            shardKey : "hashed"
        }
    });

然后确认db.collections.stats()

【讨论】:

  • 我输入了两个命令。这是 db.collection.stats() "sharded" 的结果:false,"primary":"shard0000","ns":"dbTest.cTest","count":128000,"size":95225584,"avgObjSize “:743.949875,“storageSize”:131043328,“numExtents”:11,“nindexes”:1,“lastExtentSize”:38096896,“paddingFactor”:1,“systemFlags”:1,“userFlags”:0,“totalIndexSize”: 4161584, "indexSizes" : { "id" : 4161584 }, "ok" : 1 }
  • 我可以看到 Sharded Option 给了我错误的结果。在问题中,我已经编辑并添加了我的设置配置
  • 正确选择分片键
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 2012-10-09
相关资源
最近更新 更多