src/mongo/shell/replsettest.js
/**
     * Constructor, which initializes the ReplSetTest object by starting new instances.
     */
Constructor, which initializes the ReplSetTest object by starting new instances.
Constructor which initializes the ReplSetTest object by starting new instances .
function _constructStartNewInstances(opts) {
        self.name = opts.name || jsTest.name();
        print('Starting new replica set ' + self.name);
        self.serverless = opts.serverless;
        self.useHostName = opts.useHostName == undefined ? true : opts.useHostName;
        self.host = self.useHostName ? (opts.host || getHostName()) : 'localhost';
        self.oplogSize = opts.oplogSize || 40;
        self.useSeedList = opts.useSeedList || false;
        self.keyFile = opts.keyFile;
        self.clusterAuthMode = undefined;
        if (opts.clusterAuthMode) {
            self.clusterAuthMode = opts.clusterAuthMode;
        }
        self.protocolVersion = opts.protocolVersion;
        self.waitForKeys = opts.waitForKeys;
        self.seedRandomNumberGenerator = opts.hasOwnProperty('seedRandomNumberGenerator')
            ? opts.seedRandomNumberGenerator
            : true;
        self.isConfigServer = opts.isConfigServer;
        _useBridge = opts.useBridge || false;
        _bridgeOptions = opts.bridgeOptions || {};
        _causalConsistency = opts.causallyConsistent || false;
        _configSettings = opts.settings || false;
        self.nodeOptions = {};
        var numNodes;
        if (isObject(opts.nodes)) {
            var len = 0;
            for (var i in opts.nodes) {
                var options = self.nodeOptions["n" + len] =
                    _deepObjectMerge(opts.nodeOptions, opts.nodes[i]);
                if (i.startsWith("a")) {
                    options.arbiter = true;
                }
                len++;
            }
            numNodes = len;
        } else if (Array.isArray(opts.nodes)) {
            for (var i = 0; i < opts.nodes.length; i++) {
                self.nodeOptions["n" + i] = Object.merge(opts.nodeOptions, opts.nodes[i]);
            }
            numNodes = opts.nodes.length;
        } else {
            for (var i = 0; i < opts.nodes; i++) {
                self.nodeOptions["n" + i] = opts.nodeOptions;
            }
            numNodes = opts.nodes;
        }
        for (let i = 0; i < numNodes; i++) {
            if (self.nodeOptions["n" + i] !== undefined &&
                self.nodeOptions["n" + i].clusterAuthMode == "x509") {
                self.clusterAuthMode = "x509";
            }
        }
        if (_useBridge) {
            let makeAllocatePortFn = (preallocatedPorts) => {
                let idxNextNodePort = 0;
                return function() {
                    if (idxNextNodePort >= preallocatedPorts.length) {
                        throw new Error("Cannot use a replica set larger than " +
                                        preallocatedPorts.length + " members with useBridge=true");
                    }
                    const nextPort = preallocatedPorts[idxNextNodePort];
                    ++idxNextNodePort;
                    return nextPort;
                };
            };
            _allocatePortForBridge = makeAllocatePortFn(allocatePorts(MongoBridge.kBridgeOffset));
            _allocatePortForNode = makeAllocatePortFn(allocatePorts(MongoBridge.kBridgeOffset));
        } else {
            _allocatePortForBridge = function() {
                throw new Error("Using mongobridge isn't enabled for this replica set");
            };
            _allocatePortForNode = allocatePort;
        }
        self.nodes = [];
        if (_useBridge) {
            self.ports = Array.from({length: numNodes}, _allocatePortForBridge);
            _unbridgedPorts = Array.from({length: numNodes}, _allocatePortForNode);
            _unbridgedNodes = [];
        } else {
            self.ports = Array.from({length: numNodes}, _allocatePortForNode);
        }
    }
function _constructStartNewInstances ( opts ) { self . name = opts . name || jsTest . name ( ) ; print ( 'Starting new replica set ' + self . name ) ; self . serverless = opts . serverless ; self . useHostName = opts . useHostName == undefined ? true : opts . useHostName ; self . host = self . useHostName ? ( opts . host || getHostName ( ) ) : 'localhost' ; self . oplogSize = opts . oplogSize || 40 ; self . useSeedList = opts . useSeedList || false ; self . keyFile = opts . keyFile ; self . clusterAuthMode = undefined ; if ( opts . clusterAuthMode ) { self . clusterAuthMode = opts . clusterAuthMode ; } self . protocolVersion = opts . protocolVersion ; self . waitForKeys = opts . waitForKeys ; self . seedRandomNumberGenerator = opts . hasOwnProperty ( 'seedRandomNumberGenerator' ) ? opts . seedRandomNumberGenerator : true ; self . isConfigServer = opts . isConfigServer ; _useBridge = opts . useBridge || false ; _bridgeOptions = opts . bridgeOptions || { } ; _causalConsistency = opts . causallyConsistent || false ; _configSettings = opts . settings || false ; self . nodeOptions = { } ; var numNodes ; if ( isObject ( opts . nodes ) ) { var len = 0 ; for ( var i in opts . nodes ) { var options = self . nodeOptions [ "n" + len ] = _deepObjectMerge ( opts . nodeOptions , opts . nodes [ i ] ) ; if ( i . startsWith ( "a" ) ) { options . arbiter = true ; } len ++ ; } numNodes = len ; } else if ( Array . isArray ( opts . nodes ) ) { for ( var i = 0 ; i < opts . nodes . length ; i ++ ) { self . nodeOptions [ "n" + i ] = Object . merge ( opts . nodeOptions , opts . nodes [ i ] ) ; } numNodes = opts . nodes . length ; } else { for ( var i = 0 ; i < opts . nodes ; i ++ ) { self . nodeOptions [ "n" + i ] = opts . nodeOptions ; } numNodes = opts . nodes ; } for ( let i = 0 ; i < numNodes ; i ++ ) { if ( self . nodeOptions [ "n" + i ] !== undefined && self . nodeOptions [ "n" + i ] . clusterAuthMode == "x509" ) { self . clusterAuthMode = "x509" ; } } if ( _useBridge ) { let makeAllocatePortFn = ( preallocatedPorts ) => { let idxNextNodePort = 0 ; return function ( ) { if ( idxNextNodePort >= preallocatedPorts . length ) { throw new Error ( "Cannot use a replica set larger than " + preallocatedPorts . length + " members with useBridge=true" ) ; } const nextPort = preallocatedPorts [ idxNextNodePort ] ; ++ idxNextNodePort ; return nextPort ; } ; } ; _allocatePortForBridge = makeAllocatePortFn ( allocatePorts ( MongoBridge . kBridgeOffset ) ) ; _allocatePortForNode = makeAllocatePortFn ( allocatePorts ( MongoBridge . kBridgeOffset ) ) ; } else { _allocatePortForBridge = function ( ) { throw new Error ( "Using mongobridge isn't enabled for this replica set" ) ; } ; _allocatePortForNode = allocatePort ; } self . nodes = [ ] ; if ( _useBridge ) { self . ports = Array . from ( { length : numNodes } , _allocatePortForBridge ) ; _unbridgedPorts = Array . from ( { length : numNodes } , _allocatePortForNode ) ; _unbridgedNodes = [ ] ; } else { self . ports = Array . from ( { length : numNodes } , _allocatePortForNode ) ; } }
Constructor, which initializes the ReplSetTest object by starting new instances.
Constructor which initializes the ReplSetTest object by starting new instances .
// opts.nodeOptions and opts.nodes[i] may contain nested objects that have // the same key, e.g. setParameter. So we need to recursively merge them. // Object.assign and Object.merge do not merge nested objects of the same key.