Module: utils/mongoshell

Util functions to be used as mongo shell rc file

Source:

Methods

(inner) createJob(func, arg1, arg2) → {array}

Convert a function call into a job. The first parameter to createJob is the function to call. The remaining arguments are the parameters to the function. For example: var job = createJob(print, "hello ", "world") var job = createJob(sh.status,true)

An arbitrary number of parameters can be passed, so the following example is also valid: var job = createJob(print, "hello"," ", "world", " ", ", this is a longer example")

Parameters:
Name Type Description
func function

the function to be called as a job in a thread.

arg1 any

the first argument.

arg2 any

the second argument.

Source:
Returns:

the job to be invoked.

Type
array

(inner) doFSync(targetDBopt)

Helper function to flush to disk. targetDB can be a standalone mongod, a replica set member or a mongos process. The appropriate actions will be performed based on the values returned by sharded_cluster() and isReplSet().

Parameters:
Name Type Attributes Default Description
targetDB object <optional>
db

a database reference to a mongo process.

Source:
See:
  • sharded_cluster
  • isReplSet

(inner) doFSyncReplicaSet(replSetDBopt)

Perform an fsync on each member of a replica set if the replset was initiated. If replSetDB is not yet initialized then it just fsync's that node Otherwise raise an exception.

Parameters:
Name Type Attributes Default Description
replSetDB object <optional>
db

the database reference to a replica set member.

Source:

(inner) doFSyncSharded(targetDBopt)

For a sharded cluster, iterate through all the data bearing hosts and call fsync on each of them.

Parameters:
Name Type Attributes Default Description
targetDB object <optional>
db

the database reference to a mongos process.

Source:

(inner) getAdminDB()

Attempt to establish a new Mongo connection to mongod instance running on the specified host, with multiple retries.

Returns a reference to admin Database, upon successful connnection. If connection cannot be established after 2 retries, throws an exception.

Source:

(inner) hostWithPort()

Returns a string of format <host_addr>:

Source:

(inner) isReplSet()

Check if isRepl is set.

Source:
Returns:

true if isRepl is defined and true

(inner) keepAliveStartifNeeded()

Starts a keep-alive thread which runs "printMsgFnCbk" callback function with the provided cbkArgs, for every specified intervalMillis.

Source:

(inner) keepAliveStop()

Stops the keep-alive thread.

Source:

(inner) localize(number, separatoropt) → {string}

Much simplified version of toLocaleString. It only support US / EN format.

Parameters:
Name Type Attributes Default Description
number integer

a numeric object (it is converted with toString before being processed).

separator string <optional>
,

the separator to use between strings of digits (defaults to ',').

Source:
Returns:

a language sensitive representation of this number. For example, 1000 will result in the string "1,000"

Type
string

(inner) quiesceSystem(targetDBopt)

Helper function to quiesce the system between tests. targetDB can be a standalone mongod, a replica set member or a mongos process. The appropriate actions will be performed based on the values returned by sharded_cluster() and isReplSet().

Parameters:
Name Type Attributes Default Description
targetDB object <optional>
db

a database reference to a mongo process.

Source:
See:
  • sharded_cluster
  • isReplSet

(inner) runCmd()

Runs a command in the bash shell.

Source:

(inner) runCmdOnTarget()

Runs a list of semicolon separated bash commands on the specified host.

Source:

(inner) runWorkloadInParallel()

Helper function to run a workload in parallel.

Input: numThread: number of threads. workload: a function that runs a workload.

Output: returns an array of run times for each thread

Source:

(inner) shard_collections()

Check if isShardCollections is set.

Source:
Returns:

true if isShardCollections is defined and true

(inner) sharded_cluster()

Check if isSharded is set.

Source:
Returns:

true if isSharded is defined and true

(inner) waitForStates(_db, time_limit_millisopt, …statesopt)

waitForStates blocks until all nodes in a replset reach one of the desired states or a time limit is reached. This function calls replSetGetStatus.

Errors / Exceptions are ignored, the function will continue to wait. This case covers the scenario where the process represented by _db has not yet been added to the replica set.

This function can be used to wait for the primary to discover that all other members of the replica set are in the correct state. For example, workloads/initialsync.js uses this method to block at the end of the test. Otherwise the final tests may fail.

Parameters:
Name Type Attributes Default Description
_db object

A database reference to a replica set member.

time_limit_millis int <optional>
3600000

The minimum amount of time to wait. The floor value is 1.1 seconds.

states string <optional>
<repeatable>
["PRIMARY", "SECONDARY", "ARBITER"]

Zero or more states.

Source:
Returns:

the amount of time the function waited in millis.

(inner) waitOplog(replSetDBopt)

waitOplog wait for secondary to catch up with the primary. This function calls replSetGetStatus. If there are no members returned then this function will return without waiting. It is likely that this case will cover the scenario where the process represented by replSetDB has not yet been added to the replica set.

Parameters:
Name Type Attributes Default Description
replSetDB object <optional>
db

a database reference to a replica set member.

Source:

(inner) waitOplogCheck(replSetDBopt)

wait for the oplog to catch up. On Error this function will perform a single retry. This function will call waitOplogSharded() or waitOplog() based on the return values of sharded_cluster() and isReplSet()

Parameters:
Name Type Attributes Default Description
replSetDB object <optional>
db

the database reference to a mongo process.

Source:
See:
  • waitOplogSharded
  • waitOplog
  • sharded_cluster
  • isReplSet

(inner) waitOplogSharded(targetDBopt)

waitOplogSharded wait for each shard to catch up with the primary.

Parameters:
Name Type Attributes Default Description
targetDB object <optional>
db

a database reference to a mongos process.

Source: