diff options
Diffstat (limited to 'jstests/replsets/disallow_adding_initialized_node1.js')
-rw-r--r-- | jstests/replsets/disallow_adding_initialized_node1.js | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/jstests/replsets/disallow_adding_initialized_node1.js b/jstests/replsets/disallow_adding_initialized_node1.js index 910e71c7d8c..7123070bf92 100644 --- a/jstests/replsets/disallow_adding_initialized_node1.js +++ b/jstests/replsets/disallow_adding_initialized_node1.js @@ -5,79 +5,78 @@ // detecting an inconsistent replica set ID in the heartbeat response metadata from B_0. (function() { - 'use strict'; - load("jstests/libs/check_log.js"); +'use strict'; +load("jstests/libs/check_log.js"); - var name = 'disallow_adding_initialized_node1'; - var replSetA = new ReplSetTest({ - name: name, - nodes: [ - {rsConfig: {_id: 10}}, - ] - }); - replSetA.startSet({dbpath: "$set-A-$node"}); - replSetA.initiate(); +var name = 'disallow_adding_initialized_node1'; +var replSetA = new ReplSetTest({ + name: name, + nodes: [ + {rsConfig: {_id: 10}}, + ] +}); +replSetA.startSet({dbpath: "$set-A-$node"}); +replSetA.initiate(); - var replSetB = new ReplSetTest({ - name: name, - nodes: [ - {rsConfig: {_id: 20}}, - ] - }); - replSetB.startSet({dbpath: "$set-B-$node"}); - replSetB.initiate(); +var replSetB = new ReplSetTest({ + name: name, + nodes: [ + {rsConfig: {_id: 20}}, + ] +}); +replSetB.startSet({dbpath: "$set-B-$node"}); +replSetB.initiate(); - var primaryA = replSetA.getPrimary(); - var primaryB = replSetB.getPrimary(); - jsTestLog('Before merging: primary A = ' + primaryA.host + '; primary B = ' + primaryB.host); +var primaryA = replSetA.getPrimary(); +var primaryB = replSetB.getPrimary(); +jsTestLog('Before merging: primary A = ' + primaryA.host + '; primary B = ' + primaryB.host); - var configA = assert.commandWorked(primaryA.adminCommand({replSetGetConfig: 1})).config; - var configB = assert.commandWorked(primaryB.adminCommand({replSetGetConfig: 1})).config; - assert(configA.settings.replicaSetId instanceof ObjectId); - assert(configB.settings.replicaSetId instanceof ObjectId); - jsTestLog('Replica set A ID = ' + configA.settings.replicaSetId); - jsTestLog('Replica set B ID = ' + configB.settings.replicaSetId); - assert.neq(configA.settings.replicaSetId, configB.settings.replicaSetId); +var configA = assert.commandWorked(primaryA.adminCommand({replSetGetConfig: 1})).config; +var configB = assert.commandWorked(primaryB.adminCommand({replSetGetConfig: 1})).config; +assert(configA.settings.replicaSetId instanceof ObjectId); +assert(configB.settings.replicaSetId instanceof ObjectId); +jsTestLog('Replica set A ID = ' + configA.settings.replicaSetId); +jsTestLog('Replica set B ID = ' + configB.settings.replicaSetId); +assert.neq(configA.settings.replicaSetId, configB.settings.replicaSetId); - jsTestLog("Adding replica set B's primary " + primaryB.host + " to replica set A's config"); - configA.version++; - configA.members.push({_id: 11, host: primaryB.host}); - var reconfigResult = - assert.commandFailedWithCode(primaryA.adminCommand({replSetReconfig: configA}), - ErrorCodes.NewReplicaSetConfigurationIncompatible); - var msgA = 'Our replica set ID of ' + configA.settings.replicaSetId + - ' did not match that of ' + primaryB.host + ', which is ' + configB.settings.replicaSetId; - assert.neq(-1, reconfigResult.errmsg.indexOf(msgA)); +jsTestLog("Adding replica set B's primary " + primaryB.host + " to replica set A's config"); +configA.version++; +configA.members.push({_id: 11, host: primaryB.host}); +var reconfigResult = + assert.commandFailedWithCode(primaryA.adminCommand({replSetReconfig: configA}), + ErrorCodes.NewReplicaSetConfigurationIncompatible); +var msgA = 'Our replica set ID of ' + configA.settings.replicaSetId + ' did not match that of ' + + primaryB.host + ', which is ' + configB.settings.replicaSetId; +assert.neq(-1, reconfigResult.errmsg.indexOf(msgA)); - var newPrimaryA = replSetA.getPrimary(); - var newPrimaryB = replSetB.getPrimary(); - jsTestLog('After merging: primary A = ' + newPrimaryA.host + '; primary B = ' + - newPrimaryB.host); - assert.eq(primaryA, newPrimaryA); - assert.eq(primaryB, newPrimaryB); +var newPrimaryA = replSetA.getPrimary(); +var newPrimaryB = replSetB.getPrimary(); +jsTestLog('After merging: primary A = ' + newPrimaryA.host + '; primary B = ' + newPrimaryB.host); +assert.eq(primaryA, newPrimaryA); +assert.eq(primaryB, newPrimaryB); - // Mismatch replica set IDs in heartbeat responses should be logged. - var msgB = "replica set IDs do not match, ours: " + configB.settings.replicaSetId + - "; remote node's: " + configA.settings.replicaSetId; - checkLog.contains(primaryB, msgB); +// Mismatch replica set IDs in heartbeat responses should be logged. +var msgB = "replica set IDs do not match, ours: " + configB.settings.replicaSetId + + "; remote node's: " + configA.settings.replicaSetId; +checkLog.contains(primaryB, msgB); - var statusA = assert.commandWorked(primaryA.adminCommand({replSetGetStatus: 1})); - var statusB = assert.commandWorked(primaryB.adminCommand({replSetGetStatus: 1})); - jsTestLog('After merging: replica set status A = ' + tojson(statusA)); - jsTestLog('After merging: replica set status B = ' + tojson(statusB)); +var statusA = assert.commandWorked(primaryA.adminCommand({replSetGetStatus: 1})); +var statusB = assert.commandWorked(primaryB.adminCommand({replSetGetStatus: 1})); +jsTestLog('After merging: replica set status A = ' + tojson(statusA)); +jsTestLog('After merging: replica set status B = ' + tojson(statusB)); - // Replica set A's config should remain unchanged due to failed replSetReconfig command. - assert.eq(1, statusA.members.length); - assert.eq(10, statusA.members[0]._id); - assert.eq(primaryA.host, statusA.members[0].name); - assert.eq(ReplSetTest.State.PRIMARY, statusA.members[0].state); +// Replica set A's config should remain unchanged due to failed replSetReconfig command. +assert.eq(1, statusA.members.length); +assert.eq(10, statusA.members[0]._id); +assert.eq(primaryA.host, statusA.members[0].name); +assert.eq(ReplSetTest.State.PRIMARY, statusA.members[0].state); - // Replica set B's config should remain unchanged. - assert.eq(1, statusB.members.length); - assert.eq(20, statusB.members[0]._id); - assert.eq(primaryB.host, statusB.members[0].name); - assert.eq(ReplSetTest.State.PRIMARY, statusB.members[0].state); +// Replica set B's config should remain unchanged. +assert.eq(1, statusB.members.length); +assert.eq(20, statusB.members[0]._id); +assert.eq(primaryB.host, statusB.members[0].name); +assert.eq(ReplSetTest.State.PRIMARY, statusB.members[0].state); - replSetB.stopSet(); - replSetA.stopSet(); +replSetB.stopSet(); +replSetA.stopSet(); })(); |