summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-02-18 15:58:06 -0500
committerBenety Goh <benety@mongodb.com>2016-02-19 10:09:02 -0500
commit2df600bee60bfdc996c632ffddbb1a8491a6577c (patch)
treea328ea77151deb2159706afcdb0739d198c2ec48 /jstests
parent626080cb8eb8b336b660ebafc460b79aa8447685 (diff)
downloadmongo-2df600bee60bfdc996c632ffddbb1a8491a6577c.tar.gz
SERVER-22731 allow replSetInitiate on nodes started with --configsvr but not --replSet
(cherry picked from commit 0e6d01cb63688d9f130756bccb56baaa4de07170)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/initiate_without_replset_name_at_startup.js46
1 files changed, 38 insertions, 8 deletions
diff --git a/jstests/replsets/initiate_without_replset_name_at_startup.js b/jstests/replsets/initiate_without_replset_name_at_startup.js
index 8db76862088..4deac03ca0b 100644
--- a/jstests/replsets/initiate_without_replset_name_at_startup.js
+++ b/jstests/replsets/initiate_without_replset_name_at_startup.js
@@ -1,8 +1,8 @@
/**
- * If a node is started without --replSet, and it has neither an oplog nor a local replica set
- * config document, the operator should be able to run replSetInitiate to create a single-node
- * replica set configuration and to prime the oplog. Then, on restart if the operator adds
- * --replSet to the startup configuration directives, the node can immediately transition into
+ * If a node is started with --configsvr but without --replSet, and it has neither an oplog nor a
+ * local replica set config document, the operator should be able to run replSetInitiate to create
+ * a single-node replica set configuration and to prime the oplog. Then, on restart if the operator
+ * adds --replSet to the startup configuration directives, the node can immediately transition into
* PRIMARY rather than waiting in STARTUP for the operator to run replSetInitiate. This should
* only be allowed for single-node replica set configurations.
*
@@ -12,6 +12,7 @@
*/
(function () {
"use strict";
+
var baseName = 'testInitiateWithoutReplSetNameAtStartup';
var port = allocatePorts(1)[0];
var dbpath = MongoRunner.dataPath + baseName + '/';
@@ -27,6 +28,33 @@
{_id: 0, host: mongod.name},
],
};
+
+ var result = assert.commandFailedWithCode(
+ mongod.getDB('admin').runCommand({replSetInitiate: config}),
+ ErrorCodes.NoReplicationEnabled,
+ 'replSetInitiate should fail when both --configsvr and --replSet are missing.');
+ assert(
+ result.errmsg.match(/This node was not started with the replSet option/),
+ 'unexpected error message when both --configsvr and --replSet are missing. ' +
+ 'configuration: ' + tojson(result));
+
+ // The rest of this test can only be run if the storageEngine supports committed reads.
+ var supportsCommittedReads =
+ mongod.getDB('admin').serverStatus().storageEngine.supportsCommittedReads;
+
+ MongoRunner.stopMongod(port);
+
+ if (!supportsCommittedReads) {
+ jsTestLog('Skipping rest of test because storage engine does not support committed reads');
+ return;
+ }
+
+ mongod = MongoRunner.runMongod({
+ configsvr: '',
+ dbpath: dbpath,
+ port: port,
+ restart: true});
+
assert.commandWorked(
mongod.getDB('admin').runCommand({replSetInitiate: config}),
'replSetInitiate should not fail when given a valid configuration');
@@ -41,7 +69,7 @@
'config passed to replSetInitiate (left side) does not match config saved in ' +
systemReplsetCollection.getFullName() + ' (right side)');
- var result = assert.commandFailedWithCode(
+ result = assert.commandFailedWithCode(
mongod.getDB('admin').runCommand({replSetInitiate: {
_id: baseName + '-2',
version: 1,
@@ -49,7 +77,7 @@
{_id: 0, host: mongod.name},
],
}}),
- 23, // AlreadyInitialized
+ ErrorCodes.AlreadyInitialized,
'expected AlreadyInitialized error code when configuration already exists in ' +
systemReplsetCollection.getFullName());
assert(result.errmsg.match(/already initialized/),
@@ -78,6 +106,7 @@
// Restart server and attempt to save a different config.
mongod = MongoRunner.runMongod({
+ configsvr: '',
dbpath: dbpath,
port: port,
restart: true});
@@ -89,7 +118,7 @@
{_id: 0, host: mongod.name},
],
}}),
- 23, // AlreadyInitialized
+ ErrorCodes.AlreadyInitialized,
'expected AlreadyInitialized error code when configuration already exists in ' +
systemReplsetCollection.getFullName() + ' after restarting');
assert(result.errmsg.match(/already initialized/),
@@ -105,6 +134,7 @@
// Restart server with --replSet and check own replica member state.
mongod = MongoRunner.runMongod({
+ configsvr: '',
dbpath: dbpath,
port: port,
replSet: config._id,
@@ -127,7 +157,7 @@
1000);
// Write/read a single document to ensure basic functionality.
- var t = mongod.getDB('test').getCollection(baseName);
+ var t = mongod.getDB('config').getCollection(baseName);
var doc = {_id: 0};
assert.soon(
function() {