Set smallfiles in ShardingTest

一世执手 提交于 2020-01-02 05:39:09

问题


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})

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})

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


回答1:


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

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 } }

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:''}}})

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

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




回答2:


A thorough explanation of the invoking modes of ShardingTest() is to be found in the source code of the function itself.

E.g., you could set smallFiles for two shards as follows:

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


来源:https://stackoverflow.com/questions/23973077/set-smallfiles-in-shardingtest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!