简体   繁体   中英

Set smallfiles in 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})

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!

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.

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

Eg, you could set smallFiles for two shards as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM