在ShardingTest中设置小文件 [英] Set smallfiles in ShardingTest

查看:151
本文介绍了在ShardingTest中设置小文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个ShardingTest()对象可用于创建测试分片环境(请参见

I know there is a ShardingTest() object that can be used to create a testing sharding environment (see https://serverfault.com/questions/590576/installing-multiple-mongodb-versions-on-the-same-server), eg:

mongo --nodb
cluster = new ShardingTest({shards : 3, rs : false})

但是,考虑到我的测试机中的磁盘空间有限,并且在使用上述命令时出现日志文件的可用空间不足"错误,因此我想设置smallfiles选项.我已经尝试了以下方法而没有运气:

However, given that the disk space in my testing machine is limited and I'm getting "Insufficient free space for journal files" errors when using the above command, I'd like to set the smallfiles option. I have tried with the following with no luck:

cluster = new ShardingTest({shards : 3, rs : false, smallfiles: true})

请问如何为分片测试启用smallfile?谢谢!

How smallfiles can be enabled for a sharding test, please? Thanks!

推荐答案

确定如何使用MongoDB shell命令的一种好方法是在命令行中键入不带括号的命令,而不是运行它将打印源代码用于命令.因此,如果您运行

A good way to determine how to use a MongoDB shell command is to type the command without the parentheses into the shell and instead of running it will print the source code for the command. So if you run

ShardingTest

在命令提示符下,您将看到所有源代码.在第30行附近,您会看到以下评论:

at the command prompt you will see all of the source code. Around line 30 you'll see this comment:

    // Allow specifying options like :
    // { mongos : [ { noprealloc : "" } ], config : [ { smallfiles : "" } ], shards : { rs : true, d : true } }

为您提供正确的语法,以传递mongos,config和shard的配置参数(适用于所有分片的非副本集mongod).就是说,您无需为分片指定数字,而可以传入对象.在代码中进一步挖掘:

which gives you the correct syntax to pass configuration parameters for mongos, config and shards (which apply to the non replicaset mongods for all the shards). That is, instead of specifying a number for shards you pass in an object. Digging further in the code:

else if( isObject( numShards ) ){
            tempCount = 0;
            for( var i in numShards ) {
                otherParams[ i ] = numShards[i];
                tempCount++;
            }

            numShards = tempCount;

这将获取一个对象,并将该对象内的子文档用作每个分片的选项参数.使用您的示例,这将导致:

This will take an object and use the subdocuments within the object as option parameters for each shard. This leads to, using your example:

cluster = new ShardingTest({shards : {d0:{smallfiles:''}, d1:{smallfiles:''}, d2:{smallfiles:''}}})

从输出中我可以看到,它是以--smallfiles开头的分片:

which from the output I can see is starting the shards with --smallfiles:

shell: started program mongod --port 30000 --dbpath /data/db/test0 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30001 --dbpath /data/db/test1 --smallfiles --setParameter enableTestCommands=1 
shell: started program mongod --port 30002 --dbpath /data/db/test2 --smallfiles --setParameter enableTestCommands=1

或者,由于您现在已经拥有源代码,因此您可以修改javascript以默认情况下传入小文件.

Alternatively, since you now have the source code in front of you, you could modify the javascript to pass in smallfiles by default.

这篇关于在ShardingTest中设置小文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆