jstests/sharding/libs/resharding_test_fixture.js
/**
     * Given the shardName, steps up a secondary (chosen at random) to become the new primary of the
     * shard replica set. To force an election on the configsvr rather than a participant shard, use
     * shardName = this.configShardName;
     */
Given the shardName, steps up a secondary (chosen at random) to become the new primary of the
shard replica set. To force an election on the configsvr rather than a participant shard, use
shardName = this.configShardName.
Given the shardName steps up a secondary ( chosen at random ) to become the new primary of the shard replica set . To force an election on the configsvr rather than a participant shard use shardName = this . configShardName .
stepUpNewPrimaryOnShard(shardName) {
        jsTestLog(`ReshardingTestFixture stepping up new primary on shard ${shardName}`);
        const replSet = this.getReplSetForShard(shardName);
        let originalPrimary = replSet.getPrimary();
        let secondaries = replSet.getSecondaries();
        while (secondaries.length > 0) {
            const newPrimaryIdx = Random.randInt(secondaries.length);
            const newPrimary = secondaries[newPrimaryIdx];
            let res;
            try {
                res = newPrimary.adminCommand({replSetStepUp: 1});
            } catch (e) {
                if (!isNetworkError(e)) {
                    throw e;
                }
                jsTest.log(
                    `ReshardingTestFixture got a network error ${tojson(e)} while` +
                    ` attempting to step up secondary ${newPrimary.host}. This is likely due to` +
                    ` the secondary previously having transitioned through ROLLBACK and closing` +
                    ` its user connections. Will retry stepping up the same secondary again`);
                res = newPrimary.adminCommand({replSetStepUp: 1});
            }
            if (res.ok === 1) {
                replSet.awaitNodesAgreeOnPrimary();
                assert.eq(newPrimary, replSet.getPrimary());
                return;
            }
            jsTest.log(`ReshardingTestFixture failed to step up secondary ${newPrimary.host} and` +
                       ` got error ${tojson(res)}. Will retry on another secondary until all` +
                       ` secondaries have been exhausted`);
            secondaries.splice(newPrimaryIdx, 1);
        }
        jsTest.log(`ReshardingTestFixture failed to step up secondaries, trying to step` +
                   ` original primary back up`);
        replSet.stepUp(originalPrimary, {awaitReplicationBeforeStepUp: false});
    }
stepUpNewPrimaryOnShard ( shardName ) { jsTestLog ( ` ${ shardName } ` ) ; const replSet = this . getReplSetForShard ( shardName ) ; let originalPrimary = replSet . getPrimary ( ) ; let secondaries = replSet . getSecondaries ( ) ; while ( secondaries . length > 0 ) { const newPrimaryIdx = Random . randInt ( secondaries . length ) ; const newPrimary = secondaries [ newPrimaryIdx ] ; let res ; try { res = newPrimary . adminCommand ( { replSetStepUp : 1 } ) ; } catch ( e ) { if ( ! isNetworkError ( e ) ) { throw e ; } jsTest . log ( ` ${ tojson ( e ) } ` + ` ${ newPrimary . host } ` + ` ` + ` ` ) ; res = newPrimary . adminCommand ( { replSetStepUp : 1 } ) ; } if ( res . ok === 1 ) { replSet . awaitNodesAgreeOnPrimary ( ) ; assert . eq ( newPrimary , replSet . getPrimary ( ) ) ; return ; } jsTest . log ( ` ${ newPrimary . host } ` + ` ${ tojson ( res ) } ` + ` ` ) ; secondaries . splice ( newPrimaryIdx , 1 ) ; } jsTest . log ( ` ` + ` ` ) ; replSet . stepUp ( originalPrimary , { awaitReplicationBeforeStepUp : false } ) ; }
Given the shardName, steps up a secondary (chosen at random) to become the new primary of the
 shard replica set.
Given the shardName steps up a secondary ( chosen at random ) to become the new primary of the shard replica set .
// Once the primary is terminated/killed/stepped down, write availability is lost. Avoid // long periods where the replica set doesn't have write availability by trying to step // up secondaries until one succeeds.