SERVER-27549 Print message on intentional server crash.

This commit is contained in:
Robert Guo 2017-05-08 12:29:50 -04:00
parent 7c53bb196f
commit df10adbfe5
94 changed files with 228 additions and 231 deletions

View File

@ -4,6 +4,10 @@ selector:
- jstests/disk/*.js
exclude_files:
- jstests/disk/repair2.js # SERVER-18256
# The following tests require a dedicated disk partition to be set up. Otherwise they will
# silently be no-ops.
- jstests/disk/repair3.js
- jstests/disk/repair4.js
executor:
js_test:

View File

@ -36,7 +36,7 @@ assert.commandWorked(db.adminCommand('serverStatus'));
jsTest.log('repeat without config server');
// shut down only config server
MongoRunner.stopMongod(config.port, /*signal*/ 15);
MongoRunner.stopMongod(config);
// open a new connection to mongos (unauthorized)
var conn2 = new Mongo(mongos.host);

View File

@ -296,7 +296,7 @@ function runTest(conn) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -486,7 +486,7 @@ var runTests = function(conn) {
var conn = MongoRunner.runMongod({auth: ''});
runTests(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 1, keyFile: 'jstests/libs/key1'});

View File

@ -57,7 +57,7 @@ function runTest(admindb) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
runTest(conn.getDB("admin"));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -78,7 +78,7 @@ function ClusterSpawnHelper(clusterType, startWithAuth, startWithTransitionToAut
} else if (clusterType === "repl") {
replSetTest.stopSet();
} else {
MongoRunner.stopMongod(this.conn.port);
MongoRunner.stopMongod(this.conn);
}
};
}

View File

@ -226,9 +226,9 @@
}
// Run the test on a standalone.
let mongod = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
runTest(mongod);
MongoRunner.stopMongod(mongod);
let conn = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
runTest(conn);
MongoRunner.stopMongod(conn);
// Run the test on a sharded cluster.
let cluster = new ShardingTest(

View File

@ -149,9 +149,9 @@
assert.lt(diff, 30000, "Start: " + start + "; end: " + end + "; diff: " + diff);
}
var m = MongoRunner.runMongod({auth: ""});
runTest(m);
MongoRunner.stopMongod(m);
var conn = MongoRunner.runMongod({auth: ""});
runTest(conn);
MongoRunner.stopMongod(conn);
// TODO: This feature is currently not supported on sharded clusters.
/*var st =

View File

@ -120,7 +120,7 @@ var authenticate = function(mongo) {
var shutdown = function(conn) {
print("============ shutting down.");
MongoRunner.stopMongod(conn.port, /*signal*/ false, {auth: {user: username, pwd: password}});
MongoRunner.stopMongod(conn, /*signal*/ false, {auth: {user: username, pwd: password}});
};
var runTest = function(useHostName) {

View File

@ -248,9 +248,9 @@ if (0) {
})();
};
var mongo = MongoRunner.runMongod({verbose: 5, setParameter: 'logUserIds=1'});
doTest(mongo, new Mongo(mongo.host));
MongoRunner.stopMongod(mongo.port);
var conn = MongoRunner.runMongod({verbose: 5, setParameter: 'logUserIds=1'});
doTest(conn, new Mongo(conn.host));
MongoRunner.stopMongod(conn);
var st = new ShardingTest(
{shards: 1, verbose: 5, other: {mongosOptions: {setParameter: 'logUserIds=1'}}});

View File

@ -32,7 +32,7 @@ var doTest = function(mongo, callSetParam) {
var mongo = MongoRunner.runMongod({verbose: 5});
doTest(mongo);
MongoRunner.stopMongod(mongo.port);
MongoRunner.stopMongod(mongo);
var st = new ShardingTest({shards: 1, verbose: 5});
doTest(st.s);

View File

@ -117,7 +117,7 @@ function runTest(conn) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3});

View File

@ -187,7 +187,7 @@ function runTest(conn) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -376,7 +376,7 @@ function runTest(conn) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -5,5 +5,5 @@
var conn = MongoRunner.runMongod({auth: '', useHostname: false});
runAllRoleManagementCommandsTests(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
})();

View File

@ -28,7 +28,7 @@ function withMongod(extraMongodArgs, operation) {
try {
operation(mongod);
} finally {
MongoRunner.stopMongod(mongod.port);
MongoRunner.stopMongod(mongod);
}
}

View File

@ -142,7 +142,7 @@ function runTest(conn) {
jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -279,7 +279,7 @@ jsTest.log('Test standalone');
var conn = MongoRunner.runMongod({auth: ''});
conn.getDB('admin').runCommand({setParameter: 1, newCollectionsUsePowerOf2Sizes: false});
runTest(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log('Test sharding');
var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});

View File

@ -5,5 +5,5 @@
var conn = MongoRunner.runMongod({auth: '', useHostname: false});
runAllUserManagementCommandsTests(conn);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
})();

View File

@ -27,7 +27,7 @@ function check() {
assert.eq.automsg("1", "db[ baseName ].count()");
}
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
m = MongoRunner.runMongod({
@ -38,7 +38,7 @@ m = MongoRunner.runMongod({
db = m.getDB(baseName);
assert.commandWorked(db.runCommand({repairDatabase: 1}));
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
rc = runMongoProgram(
@ -51,7 +51,7 @@ m = MongoRunner.runMongod({
});
db = m.getDB(baseName);
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
rc = runMongoProgram("mongod", "--repair", "--port", m.port, "--dbpath", dbpath);

View File

@ -48,7 +48,7 @@ for (f in files) {
assert(fileCount > 0, "Expected more than zero nondirectory files in the database directory");
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
m = MongoRunner.runMongod({
@ -60,7 +60,7 @@ m = MongoRunner.runMongod({
db = m.getDB(baseName);
assert.commandWorked(db.runCommand({repairDatabase: 1}));
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Test long database names
resetDbpath(repairpath);
@ -73,7 +73,7 @@ m = MongoRunner.runMongod({
db = m.getDB(longDBName);
assert.writeOK(db[baseName].save({}));
assert.commandWorked(db.runCommand({repairDatabase: 1}));
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Test long repairPath
resetDbpath(longRepairPath);
@ -87,7 +87,7 @@ m = MongoRunner.runMongod({
db = m.getDB(longDBName);
assert.commandWorked(db.runCommand({repairDatabase: 1, backupOriginalFiles: true}));
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Test database name and repairPath with --repair
resetDbpath(longRepairPath);
@ -109,7 +109,7 @@ m = MongoRunner.runMongod({
});
db = m.getDB(longDBName);
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
returnCode = runMongoProgram("mongod",
@ -131,7 +131,7 @@ m = MongoRunner.runMongod({
});
db = m.getDB(baseName);
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
returnCode =

View File

@ -47,7 +47,7 @@ if (doIt) {
}
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
resetDbpath(repairpath);
var rc = runMongoProgram("mongod",
@ -73,5 +73,5 @@ if (doIt) {
});
db = m.getDB(baseName);
check();
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
}

View File

@ -49,5 +49,5 @@ if (doIt) {
}
check();
MongoRunner.stopMongod(port);
MongoRunner.stopMongod(m);
}

View File

@ -83,7 +83,7 @@ sleep(8000);
// kill the process hard
tst.log("kill -9 mongod");
MongoRunner.stopMongod(conn.port, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -3,27 +3,6 @@
var testname = "dur_checksum";
var path = MongoRunner.dataPath + testname;
if (0) {
// This is used to create the prototype journal file.
jsTest.log("Just creating prototype journal, not testing anything");
var conn = MongoRunner.runMongod({dbpath: path, journal: ""});
var db = conn.getDB("test");
// each insert is in it's own commit.
db.foo.insert({a: 1});
db.runCommand({getlasterror: 1, j: 1});
db.foo.insert({a: 2});
db.runCommand({getlasterror: 1, j: 1});
MongoRunner.stopMongod(conn.port, /*signal*/ 9);
jsTest.log("Journal file left at " + path + "/journal/j._0");
quit();
// A hex editor must be used to replace the checksums of specific journal sections with
// "0BADC0DE 1BADC0DE 2BADC0DE 3BADCD0E"
}
function startMongodWithJournal() {
return MongoRunner.runMongod({
restart: true,
@ -42,7 +21,7 @@ copyFile("jstests/libs/dur_checksum_good.journal", path + "/journal/j._0");
var conn = startMongodWithJournal();
var db = conn.getDB('test');
assert.eq(db.foo.count(), 2);
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
// dur_checksum_bad_last.journal is good.journal with the bad checksum on the last section.
jsTest.log("Starting with bad_last.journal");
@ -52,7 +31,7 @@ copyFile("jstests/libs/dur_checksum_bad_last.journal", path + "/journal/j._0");
conn = startMongodWithJournal();
var db = conn.getDB('test');
assert.eq(db.foo.count(), 1); // 2nd insert "never happened"
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
// dur_checksum_bad_first.journal is good.journal with the bad checksum on the prior section.
// This means there is a good commit after the bad one. We currently ignore this, but a future
@ -64,7 +43,7 @@ copyFile("jstests/libs/dur_checksum_bad_first.journal", path + "/journal/j._0");
conn = startMongodWithJournal();
var db = conn.getDB('test');
assert.eq(db.foo.count(), 0); // Neither insert happened.
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
// If we detect an error in a non-final journal file, that is considered an error.
jsTest.log("Starting with bad_last.journal followed by good.journal");

View File

@ -125,7 +125,7 @@ verify();
// kill the process hard
log("kill 9");
MongoRunner.stopMongod(conn.port, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -111,7 +111,7 @@ printjson(conn.getDB('admin').runCommand({getlasterror: 1, fsync: 1}));
// kill the process hard
log("kill 9");
MongoRunner.stopMongod(conn.port, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -111,7 +111,7 @@ printjson(conn.getDB('admin').runCommand({getlasterror: 1, fsync: 1}));
// kill the process hard
log("kill 9");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -82,7 +82,7 @@ conn = MongoRunner.runMongod({
work();
log("kill -9");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard
assert(listFiles(path + "/journal/").length > 0,

View File

@ -94,7 +94,7 @@ log("wait a while for a sync and an lsn write");
sleep(14); // wait for lsn write
log("kill mongod -9");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -146,7 +146,7 @@ for (var i = 0; i < 3; ++i) {
// kill the process hard
log("hard kill");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
sleep(5000);
}
@ -204,7 +204,7 @@ for (var i = 0; i < 5; ++i) {
// kill the process hard
log("hard kill");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
sleep(5000);
}

View File

@ -127,7 +127,7 @@ work();
printjson(conn.getDB('admin').runCommand({getlasterror: 1, fsync: 1}));
// kill the process hard
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// journal file should be present, and non-empty as we killed hard

View File

@ -69,7 +69,7 @@ var runTest = function(adminDB) {
var conn = MongoRunner.runMongod();
runTest(conn.getDB('admin'));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
///////////////////////////////////////////////////////////
// Test mongos

View File

@ -52,7 +52,7 @@ function testGetCmdLineOptsMongod(mongoRunnerConfig, expectedResult) {
var getCmdLineOptsBaseMongod = baseMongod.adminCommand("getCmdLineOpts");
// Stop the mongod we used to get the options
MongoRunner.stopMongod(baseMongod.port);
MongoRunner.stopMongod(baseMongod);
return getCmdLineOptsBaseMongod;
}
@ -114,7 +114,7 @@ function testGetCmdLineOptsMongod(mongoRunnerConfig, expectedResult) {
// Cleanup
mongod.getDB("admin").logout();
MongoRunner.stopMongod(mongod.port);
MongoRunner.stopMongod(mongod);
}
// Test that the parsed result of setting certain command line options has the correct format in

View File

@ -74,7 +74,8 @@ SSLTest.prototype.connectWorked = function() {
var serverPID = _startMongoProgram.apply(null, serverArgv);
try {
assert.soon(function() {
return checkProgram(serverPID) && (0 === _runMongoProgram.apply(null, clientArgv));
return checkProgram(serverPID).alive &&
(0 === _runMongoProgram.apply(null, clientArgv));
}, "connect failed", connectTimeoutMillis);
} catch (ex) {
return false;

View File

@ -95,7 +95,7 @@ function multiVersionDumpRestoreTest(configObj) {
host: serverSource.host,
db: testBaseName
});
MongoRunner.stopMongod(serverSource.port);
MongoRunner.stopMongod(serverSource);
} else { /* "mongos" */
MongoRunner.runMongoTool("mongodump", {
out: configObj.dumpDir,
@ -161,7 +161,7 @@ function multiVersionDumpRestoreTest(configObj) {
if (configObj.restoreType === "mongos") {
shardingTest.stop();
} else {
MongoRunner.stopMongod(serverDest.port);
MongoRunner.stopMongod(serverDest);
}
}

View File

@ -121,7 +121,7 @@
assert.eq(0, ret);
// stop previous mongod
MongoRunner.stopMongod(toolTest.port);
MongoRunner.stopMongod(toolTest.m);
// clear old node configuration info
toolTest.m = null;

View File

@ -32,7 +32,7 @@
output = JSON.parse(output);
assert.eq(output.compression, expected);
MongoRunner.stopMongod(mongo.port);
MongoRunner.stopMongod(mongo);
};
assert.isnull(MongoRunner.runMongod({networkMessageCompressors: "snappy,disabled"}));

View File

@ -13,7 +13,7 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired
assert(listFiles(dbpath + "/foo/index").length > 0);
assert(listFiles(dbpath + "/foo/collection").length > 0);
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Subsequent attempts to start server using same dbpath but different
// wiredTigerDirectoryForIndexes and directoryperdb options should fail.

View File

@ -39,7 +39,7 @@
files = listFiles(files[0].name);
assert(files.length > 0);
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Subsequent attempt to start server using same dbpath without directoryperdb should fail.
assert.isnull(MongoRunner.runMongod({dbpath: dbpath, restart: true}));

View File

@ -32,7 +32,7 @@
assert.commandWorked(viewsDB.runCommand({drop: "view1", writeConcern: {j: 1}}));
// Hard kill the mongod to ensure the data was indeed synced to durable storage.
MongoRunner.stopMongod(conn, 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// Restart the mongod.
conn = MongoRunner.runMongod(mongodArgs);

View File

@ -48,7 +48,7 @@
crashFn(conn);
checkOutput();
} finally {
launcher.stop(conn, undefined, {allowedExitCodes: [expectedExitCode]});
launcher.stop(conn, undefined, {allowedExitCode: expectedExitCode});
}
}

View File

@ -60,5 +60,5 @@
var indexes = t.getIndexes();
assert.eq(1, indexes.length, 'unfinished indexes in listIndexes result: ' + tojson(indexes));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
}());

View File

@ -61,5 +61,5 @@
indexes.length,
'unexpected number of indexes in listIndexes result: ' + tojson(indexes));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
}());

View File

@ -347,9 +347,16 @@ var BackupRestoreTest = function(options) {
rst.waitForState(hiddenNode, [ReplSetTest.State.RECOVERING, ReplSetTest.State.SECONDARY]);
// Stop CRUD client and FSM client.
assert(checkProgram(crudPid), testName + ' CRUD client was not running at end of test');
assert(checkProgram(fsmPid), testName + ' FSM client was not running at end of test');
var crudStatus = checkProgram(crudPid);
assert(crudStatus.alive,
testName + ' CRUD client was not running at end of test and exited with code: ' +
crudStatus.exitCode);
stopMongoProgramByPid(crudPid);
var fsmStatus = checkProgram(fsmPid);
assert(fsmStatus.alive,
testName + ' FSM client was not running at end of test and exited with code: ' +
fsmStatus.exitCode);
stopMongoProgramByPid(fsmPid);
// Wait up to 5 minutes until the new hidden node is in state SECONDARY.

View File

@ -90,4 +90,4 @@ assert.soon(function() {
'it does not contain the necessary operations for us to reach a consistent state');
});
replTest.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]});
replTest.stopSet();

View File

@ -58,6 +58,6 @@ ensureSetParameterFailure(dbConn, "journalCommitInterval", 0);
ensureSetParameterFailure(dbConn, "syncdelay", 10 * 1000 * 1000);
ensureSetParameterFailure(dbConn, "syncdelay", -10 * 1000 * 1000);
MongoRunner.stopMongod(dbConn.port);
MongoRunner.stopMongod(dbConn);
jsTest.log("noPassthrough_parameters_test succeeded!");

View File

@ -13,7 +13,7 @@ if (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wired
assert(listFiles(dbpath + "/index").length > 0);
assert(listFiles(dbpath + "/collection").length > 0);
MongoRunner.stopMongod(m.port);
MongoRunner.stopMongod(m);
// Subsequent attempts to start server using same dbpath but different
// wiredTigerDirectoryForIndexes and directoryperdb options should fail.

View File

@ -20,7 +20,7 @@
// Now connect to the mongod, do a journaled write and abruptly stop the server.
var testDB = conn.getDB('test');
assert.writeOK(testDB.synced.insert({synced: true}, {writeConcern: {j: true}}));
MongoRunner.stopMongod(conn, 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// Restart the mongod.
conn = MongoRunner.runMongod(mongodArgs);

View File

@ -18,7 +18,7 @@ function writeDataAndRestart(doFsync) {
}
jsTestLog("kill -9");
MongoRunner.stopMongod(conn, /*signal*/ 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
jsTestLog("restart node");
conn = MongoRunner.runMongod({

View File

@ -61,7 +61,7 @@ if (jsTest.options().storageEngine && jsTest.options().storageEngine !== "wiredT
assert.commandWorked(secondary1.getDB("admin").runCommand({fsync: 1}));
jsTestLog("kill -9 secondary 1");
MongoRunner.stopMongod(secondary1.port, /*signal*/ 9);
MongoRunner.stopMongod(secondary1, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
jsTestLog("add some data to a new collection bar");
for (var i = 0; i < 100; i++) {

View File

@ -51,7 +51,7 @@
function() {
var count = conn.getDB('test').nojournal.count({journaled: {$exists: true}});
if (count >= 100) {
MongoRunner.stopMongod(conn, 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
return true;
}
return false;

View File

@ -60,7 +60,7 @@
// do an extra journaled write to make all visible commits durable, before killing
// the mongod.
assert.writeOK(testDB.nojournal.insert({final: true}, {writeConcern: {j: true}}));
MongoRunner.stopMongod(conn, 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
return true;
}
return false;

View File

@ -83,7 +83,7 @@ load('jstests/libs/parallelTester.js'); // For ScopedThread
// Mongod needs an unclean shutdown so that WT recovery is forced on restart and we can detect
// any missing records.
MongoRunner.stopMongod(conn, 9);
MongoRunner.stopMongod(conn, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
// Retrieve the start and end data from each thread.
var retData = [];

View File

@ -27,8 +27,6 @@
var master = replTest.getPrimary();
var second = replTest.getSecondary();
var secondId = replTest.getNodeId(second);
var masterDB = master.getDB('bgIndexSec');
var secondDB = second.getDB('bgIndexSec');
@ -60,7 +58,9 @@
// the oplog entry so it isn't replayed. If (A) is present without (B), then there are two ways
// that the index can be rebuilt on startup and this test is only for the one triggered by (A).
secondDB.adminCommand({fsync: 1});
replTest.restart(secondId, {}, /*signal=*/9, /*wait=*/true);
MongoRunner.stopMongod(second, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
replTest.start(second, {}, /*restart=*/true, /*wait=*/true);
// Make sure secondary comes back.
assert.soon(function() {

View File

@ -26,8 +26,6 @@
var master = replTest.getPrimary();
var second = replTest.getSecondary();
var secondId = replTest.getNodeId(second);
var masterDB = master.getDB('bgIndexNoRetrySec');
var secondDB = second.getDB('bgIndexNoRetrySec');
@ -58,7 +56,8 @@
// the oplog entry so it isn't replayed. If (A) is present without (B), then there are two ways
// that the index can be rebuilt on startup and this test is only for the one triggered by (A).
secondDB.adminCommand({fsync: 1});
replTest.restart(secondId, {}, /*signal=*/9, /*wait=*/true);
replTest.stop(second, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL});
replTest.start(second, {}, /*restart*/ true, /*wait=*/true);
// Make sure secondary comes back.
assert.soon(function() {

View File

@ -57,7 +57,7 @@ var m = MongoRunner.runMongod({port: port[0], dbpath: dbdir, logpath: logdir + l
// log should now exist (and no rotations should exist)
assert.eq(logCount(logs[0], true), 1);
MongoRunner.stopMongod(port[0]);
MongoRunner.stopMongod(m /*port[0]*/);
print("------ Start mongod with logpath set to existing file");
m = MongoRunner.runMongod({port: port[1], dbpath: dbdir, logpath: logdir + logs[0]});
@ -69,7 +69,7 @@ assert.eq(logCount(logs[0]), 1);
assert.eq(logCount(logs[0], true), 2);
cleanupFiles();
MongoRunner.stopMongod(port[1]);
MongoRunner.stopMongod(m /*port[1]*/);
// Blocking on SERVER-5117:
// MongoRunner currently hangs if mongod fails to start so these tests don't work
@ -85,7 +85,7 @@ if (false) {
// log should now exist (and no rotations should exist)
assert.eq(logCount(logs[1], true), 1);
MongoRunner.stopMongod(port[2]);
MongoRunner.stopMongod(m /*port[2]*/);
print("------ Start mongod with logpath set to existing file, fork");
m = MongoRunner.runMongod(
@ -98,7 +98,7 @@ if (false) {
assert.eq(logCount(logs[1], true), 2);
cleanupFiles();
MongoRunner.stopMongod(port[3]);
MongoRunner.stopMongod(m /*port[3]*/);
}
// the following tests depend on undefined behavior; assume that MongoRunner raises exception on

View File

@ -33,5 +33,5 @@ if (ss.storageEngine.name !== "wiredTiger") {
assert.commandFailed(reconfigure("eviction_target=a"));
assert.commandFailed(reconfigure("fake_config_key=1"));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
}

View File

@ -37,7 +37,7 @@ var conn = MongoRunner.runMongod({});
for (i in testOnlyCommands) {
assertCmdNotFound(conn.getDB('test'), testOnlyCommands[i]);
}
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
// Now enable the commands
jsTest.setOption('enableTestCommands', true);
@ -46,4 +46,4 @@ var conn = MongoRunner.runMongod({});
for (i in testOnlyCommands) {
assertCmdFound(conn.getDB('test'), testOnlyCommands[i]);
}
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);

View File

@ -19,7 +19,7 @@ var primeSystemReplset = function() {
};
var restartWithConfig = function() {
MongoRunner.stopMongod(conn.port, 15);
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: true, cleanData: false, dbpath: conn.dbpath});
testDB = conn.getDB("test");
var n = 100;
@ -37,7 +37,7 @@ var restartWithoutConfig = function() {
var localDB = conn.getDB("local");
assert.writeOK(localDB.system.replset.remove({}));
MongoRunner.stopMongod(conn.port, 15);
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: true, cleanData: false, dbpath: conn.dbpath});
@ -45,7 +45,7 @@ var restartWithoutConfig = function() {
return conn.getDB("test").foo.count() < 100;
}, "never deleted", 75000);
MongoRunner.stopMongod(conn.port, 15);
MongoRunner.stopMongod(conn);
};
print("Create a TTL collection and put doc in local.system.replset");

View File

@ -40,7 +40,6 @@ load("jstests/replsets/rslib.js");
print("should fail with wrong permissions");
assert.eq(
m, _isWindows() ? 100 : 1, "mongod should exit w/ 1 (EXIT_FAILURE): permissions too open");
MongoRunner.stopMongod(port[0]);
// Pre-populate the data directory for the first replica set node, to be started later, with
// a user's credentials.

View File

@ -117,7 +117,7 @@
'cloneDatabase from standalone to SECONDARY succeeded and should not accept writes');
jsTest.log("Shut down replica set and standalone server");
MongoRunner.stopMongod(standalone.port);
MongoRunner.stopMongod(standalone);
replTest.stopSet();
}

View File

@ -22,7 +22,7 @@
{createIndexes: "test", indexes: [{v: 2, name: "x_1", key: {x: 1}, invalidOption: 1}]}));
// Add another node to the replica set to allow an initial sync to occur.
replTest.add();
var init_sync_node = replTest.add();
clearRawMongoProgramOutput();
reInitiateWithoutThrowingOnAbortedMember(replTest);
@ -36,8 +36,7 @@
};
assert.soon(assertFn, "Initial sync should have aborted on invalid index specification");
replTest.stopSet(undefined,
undefined,
{allowedExitCodes: [MongoRunner.EXIT_ABRUPT, MongoRunner.EXIT_ABORT]});
replTest.stop(init_sync_node, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();
})();

View File

@ -19,7 +19,7 @@ function testInitialSyncAbortsWithUnsupportedAuthSchema(schema) {
assert.writeOK(res);
// Add another node to the replica set to allow an initial sync to occur
rst.add();
var init_sync_node = rst.add();
clearRawMongoProgramOutput();
reInitiateWithoutThrowingOnAbortedMember(rst);
@ -45,9 +45,8 @@ function testInitialSyncAbortsWithUnsupportedAuthSchema(schema) {
' authSchema version: ' + tojson(schema),
60000);
rst.stopSet(undefined,
undefined,
{allowedExitCodes: [MongoRunner.EXIT_ABRUPT, MongoRunner.EXIT_ABORT]});
rst.stop(init_sync_node, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
rst.stopSet();
}
function testInitialSyncAbortsWithExistingUserAndNoAuthSchema() {
@ -66,7 +65,7 @@ function testInitialSyncAbortsWithExistingUserAndNoAuthSchema() {
assert.writeOK(res);
// Add another node to the replica set to allow an initial sync to occur
rst.add();
var init_sync_node = rst.add();
clearRawMongoProgramOutput();
reInitiateWithoutThrowingOnAbortedMember(rst);
@ -88,9 +87,8 @@ function testInitialSyncAbortsWithExistingUserAndNoAuthSchema() {
' a missing auth schema',
60000);
rst.stopSet(undefined,
undefined,
{allowedExitCodes: [MongoRunner.EXIT_ABRUPT, MongoRunner.EXIT_ABORT]});
rst.stop(init_sync_node, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
rst.stopSet();
}
testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema'});

View File

@ -38,8 +38,6 @@
};
assert.soon(assertFn, "Replication should have aborted on invalid index specification", 60000);
replTest.stopSet(undefined,
undefined,
{allowedExitCodes: [MongoRunner.EXIT_ABRUPT, MongoRunner.EXIT_ABORT]});
replTest.stop(replTest.getSecondary(), undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();
})();

View File

@ -61,5 +61,5 @@
"If the Timestamps differ, the server may be filling in the null timestamps");
assert.throws(() => rst.restart(0)); // Restart in replSet mode again.
print('\n\n\t\t^^^^^^^^ This was supposed to fassert ^^^^^^^^^^^\n\n');
rst.stopSet();
})();

View File

@ -74,4 +74,5 @@ assert.soon(function() {
return rawMongoProgramOutput().match(msg);
}, "Did not see a log entry about skipping the nonrollbackable command during rollback");
replTest.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]});
replTest.stop(BID, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();

View File

@ -64,4 +64,5 @@ assert.soon(function() {
return rawMongoProgramOutput().match("cannot rollback a collMod command");
}, "B failed to fassert");
replTest.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]});
replTest.stop(BID, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();

View File

@ -64,4 +64,5 @@ assert.soon(function() {
"rollback : can't rollback drop database full resync will be required");
}, "B failed to fassert");
replTest.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]});
replTest.stop(BID, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();

View File

@ -66,6 +66,6 @@
}
}, "node C failed to fassert", 60 * 1000);
replTest.stopSet(undefined, undefined, {allowedExitCodes: [MongoRunner.EXIT_ABRUPT]});
replTest.stop(CID, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
replTest.stopSet();
}());

View File

@ -19,10 +19,11 @@ load('jstests/replsets/rslib.js');
rst.initiate(conf);
rst.awaitReplication();
let id = rst.getNodeId(rst.getSecondary());
rst.stop(id);
let secondary = rst.getSecondary();
rst.stop(secondary);
let program = rst.start(
id, {waitForConnect: false, setParameter: "failpoint.shutdownAtStartup={mode:'alwaysOn'}"});
secondary,
{waitForConnect: false, setParameter: "failpoint.shutdownAtStartup={mode:'alwaysOn'}"});
// mongod should exit automatically, since failpoint was set.
let exitCode = waitProgram(program.pid);
assert.eq(0, exitCode);

View File

@ -17,7 +17,7 @@
// Kill all secondaries, forcing the current primary to step down.
st.configRS.getSecondaries().forEach(function(secondaryConn) {
MongoRunner.stopMongod(secondaryConn.port);
MongoRunner.stopMongod(secondaryConn);
});
// Test authenticate through a fresh connection.

View File

@ -88,7 +88,7 @@
return res.state == 'completed';
});
MongoRunner.stopMongod(newMongod.port);
MongoRunner.stopMongod(newMongod);
checkBasicCRUD(st.s.getDB('test').unsharded);
checkBasicCRUD(st.s.getDB('test').sharded);

View File

@ -40,7 +40,7 @@
assert.neq(null, configDB.databases.findOne({_id: 'unshardedDB'}));
MongoRunner.stopMongod(newShardConn.port);
MongoRunner.stopMongod(newShardConn);
st.stop();
})();

View File

@ -26,7 +26,7 @@
assert.writeOK(st.getDB('config').TestConfigColl.insert({TestKey: 'Test value'}));
st.configRS.stopMaster();
MongoRunner.stopMongod(configSecondaryToKill.port);
MongoRunner.stopMongod(configSecondaryToKill);
// Clears all cached info so mongos will be forced to query from the config.
st.s.adminCommand({flushRouterConfig: 1});

View File

@ -35,7 +35,7 @@
} else {
assert.commandFailed(res, "Add shard");
}
return m.port;
return m;
};
var findEmptyShard = function(st, ns) {
@ -201,22 +201,22 @@
// information. Therefore, we'll do this manually for now.
for (var i = 0; i < st._mongos.length; i++) {
var port = st["s" + i].port;
MongoRunner.stopMongos(port,
var conn = st["s" + i];
MongoRunner.stopMongos(conn,
/*signal*/ false,
{auth: {user: username, pwd: password}});
}
for (var i = 0; i < st._connections.length; i++) {
var port = st["shard" + i].port;
MongoRunner.stopMongod(port,
var conn = st["shard" + i];
MongoRunner.stopMongod(conn,
/*signal*/ false,
{auth: {user: username, pwd: password}});
}
for (var i = 0; i < st._configServers.length; i++) {
var c = st["config" + i].port;
MongoRunner.stopMongod(port,
var conn = st["config" + i];
MongoRunner.stopMongod(conn,
/*signal*/ false,
{auth: {user: username, pwd: password}});
}

View File

@ -37,14 +37,14 @@
var restartAndFixShardIdentityDoc = function(startOptions) {
var options = Object.extend({}, startOptions);
delete options.shardsvr;
mongodConn = MongoRunner.runMongod(options);
var mongodConn = MongoRunner.runMongod(options);
waitForMaster(mongodConn);
var res = mongodConn.getDB('admin').system.version.update({_id: 'shardIdentity'},
shardIdentityDoc);
assert.eq(1, res.nModified);
MongoRunner.stopMongod(mongodConn.port);
MongoRunner.stopMongod(mongodConn);
newMongodOptions.shardsvr = '';
mongodConn = MongoRunner.runMongod(newMongodOptions);
@ -87,8 +87,7 @@
//
var newMongodOptions = Object.extend(mongodConn.savedOptions, {restart: true});
MongoRunner.stopMongod(mongodConn.port);
MongoRunner.stopMongod(mongodConn);
mongodConn = MongoRunner.runMongod(newMongodOptions);
waitForMaster(mongodConn);
@ -104,7 +103,7 @@
//
// Note: modification of the shardIdentity is allowed only when not running with --shardsvr
MongoRunner.stopMongod(mongodConn.port);
MongoRunner.stopMongod(mongodConn);
delete newMongodOptions.shardsvr;
mongodConn = MongoRunner.runMongod(newMongodOptions);
waitForMaster(mongodConn);
@ -112,7 +111,7 @@
assert.writeOK(mongodConn.getDB('admin').system.version.update(
{_id: 'shardIdentity'}, {_id: 'shardIdentity', shardName: 'x', clusterId: ObjectId()}));
MongoRunner.stopMongod(mongodConn.port);
MongoRunner.stopMongod(mongodConn);
newMongodOptions.shardsvr = '';
assert.throws(function() {
@ -124,14 +123,10 @@
// Test that it is possible to fix the invalid shardIdentity doc by not passing --shardsvr
//
try {
// The server was terminated not by calling stopMongod earlier, this will cleanup
// the process from registry in shell_utils_launcher.
MongoRunner.stopMongod(newMongodOptions.port);
} catch (ex) {
if (!(ex instanceof (MongoRunner.StopError))) {
throw ex;
}
// If mongodConn is not null, the server terminated after MongoRunner.runMongod() had
// returned. So we call stopMongod again to clean up the registry in shell_util_launcher.cpp
if (mongodConn) {
MongoRunner.stopMongod(mongodConn);
}
mongodConn = restartAndFixShardIdentityDoc(newMongodOptions);
@ -145,7 +140,7 @@
runTest(mongod, st.configRS.getURL());
MongoRunner.stopMongod(mongod.port);
MongoRunner.stopMongod(mongod);
var replTest = new ReplSetTest({nodes: 1});
replTest.startSet({shardsvr: ''});

View File

@ -44,7 +44,7 @@
checkShardingStateInitialized(standaloneConn, st.configRS.getURL(), newShardName, clusterId);
checkShardMarkedAsShardAware(st.s, newShardName);
MongoRunner.stopMongod(standaloneConn.port);
MongoRunner.stopMongod(standaloneConn);
// Add a shard that is a replica set.

View File

@ -73,7 +73,7 @@
st.rs0.stop(0);
st.rs0.stop(1);
MongoRunner.stopMongod(newNode.port);
MongoRunner.stopMongod(newNode);
replConfig = st.configRS.getReplSetConfigFromNode();
replConfig.version += 1;

View File

@ -57,7 +57,9 @@ for (var test = 0; test < 2; test++) {
// Flush writes to disk, since sometimes we're killing uncleanly
assert(mongos.getDB("admin").runCommand({fsync: 1}).ok);
MongoRunner.stopMongod(st.shard0, killWith);
var exitCode = killWith === 9 ? MongoRunner.EXIT_SIGKILL : MongoRunner.EXIT_CLEAN;
MongoRunner.stopMongod(st.shard0, killWith, {allowedExitCode: exitCode});
jsTest.log("Restart shard...");

View File

@ -50,7 +50,7 @@ var replShouldFail = function(name, opt1, opt2) {
assert.throws(load, [replSetTestFile], "This setup should have failed");
// clean up to continue running...
if (replTest) {
replTest.stopSet(15);
replTest.stopSet();
}
};

View File

@ -13,7 +13,7 @@ function testSSLTransition(oldMode, newMode, shouldSucceed) {
var res = adminDB.runCommand({"setParameter": 1, "sslMode": newMode});
assert(res["ok"] == shouldSucceed, tojson(res));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
}
function testAuthModeTransition(oldMode, newMode, sslMode, shouldSucceed) {
@ -30,7 +30,7 @@ function testAuthModeTransition(oldMode, newMode, sslMode, shouldSucceed) {
var res = adminDB.runCommand({"setParameter": 1, "clusterAuthMode": newMode});
assert(res["ok"] == shouldSucceed, tojson(res));
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
}
testSSLTransition("allowSSL", "invalid", false);

View File

@ -168,6 +168,6 @@ assert.eq(md5, md5_stored, "hash of stored file does not match the expected valu
if (!_isWindows()) {
// Stop the server
var exitCode = MongoRunner.stopMongod(md.port, 15);
var exitCode = MongoRunner.stopMongod(md);
assert(exitCode == 0);
}

View File

@ -58,7 +58,7 @@ function testCombination(certPath, allowInvalidHost, allowInvalidCert, shouldSuc
assert.eq(
1, mongo, "Connection attempt succeeded when it should fail certPath: " + certPath);
}
MongoRunner.stopMongod(mongod.port);
MongoRunner.stopMongod(mongod);
}
// 1. Test client connections with different server certificates

View File

@ -36,6 +36,6 @@ assert.eq(getCmdLineOptsResult.parsed.net.ssl.clusterPassword,
"<password>",
"Password not properly censored: " + tojson(getCmdLineOptsResult));
MongoRunner.stopMongod(mongodSource.port);
MongoRunner.stopMongod(mongodSource);
print(baseName + " succeeded.");

View File

@ -31,7 +31,7 @@
var exitStatus = runMongoProgram.apply(null, argv);
assert.eq(exitStatus, 0, "successfully connected with SSL");
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
};
assert.throws(function() {

View File

@ -32,7 +32,7 @@ var exitStatus = runMongoProgram('mongo',
assert.eq(exitStatus, 0, "authentication via MONGODB-X509 without CA succeeded");
MongoRunner.stopMongod(conn.port);
MongoRunner.stopMongod(conn);
jsTest.log("Assert mongod doesn\'t start with CA file missing and clusterAuthMode=x509.");

View File

@ -88,7 +88,7 @@ var x509_options = {sslMode: "requireSSL", sslPEMKeyFile: SERVER_CERT, sslCAFile
var mongo = MongoRunner.runMongod(Object.merge(x509_options, {auth: ""}));
authAndTest(mongo);
MongoRunner.stopMongod(mongo.port);
MongoRunner.stopMongod(mongo);
print("2. Testing x.509 auth to mongos");

View File

@ -7,12 +7,14 @@ function testTransition(newSSLMode, newClusterAuthMode) {
// If no parameters are given sslMode defaults to disabled
var conn = MongoRunner.runMongod({clusterAuthMode: "keyFile"});
var adminDB = conn.getDB("admin");
adminDB.createUser({user: "root", pwd: "pwd", roles: ["root"]});
adminDB.auth("root", "pwd");
var res = adminDB.runCommand({"setParameter": 1, "sslMode": newSSLMode});
assert(!res["ok"]);
assert.commandFailedWithCode(res, ErrorCodes.BadValue);
var res = adminDB.runCommand({"setParameter": 1, "clusterAuthMode": newClusterAuthMode});
assert(!res["ok"]);
MongoRunner.stopMongod(conn.port);
assert.commandFailedWithCode(res, ErrorCodes.BadValue);
MongoRunner.stopMongod(conn);
}
testTransition("allowSSL", "sendKeyFile");

View File

@ -114,7 +114,7 @@ destDB.dropDatabase();
// times, but that is not tested here because right now MongoRunners can only be configured using
// javascript objects which do not allow duplicate keys. See SERVER-14220.
MongoRunner.stopMongod(mongodDest.port);
MongoRunner.stopMongod(mongodSource.port);
MongoRunner.stopMongod(mongodDest);
MongoRunner.stopMongod(mongodSource);
print(testBaseName + " success!");

View File

@ -81,7 +81,7 @@ function MongoBridge(options) {
this.connectToBridge = function connectToBridge() {
var failedToStart = false;
assert.soon(() => {
if (!checkProgram(pid)) {
if (!checkProgram(pid).alive) {
failedToStart = true;
return true;
}

View File

@ -1715,11 +1715,11 @@ var ReplSetTest = function(opts) {
n = this.getNodeId(n);
var port = _useBridge ? _unbridgedPorts[n] : this.ports[n];
print('ReplSetTest stop *** Shutting down mongod in port ' + port + ' ***');
var ret = MongoRunner.stopMongod(port, signal, opts);
var conn = _useBridge ? _unbridgedNodes[n] : this.nodes[n];
print('ReplSetTest stop *** Shutting down mongod in port ' + conn.port + ' ***');
var ret = MongoRunner.stopMongod(conn, signal, opts);
print('ReplSetTest stop *** Mongod in port ' + port + ' shutdown with code (' + ret +
print('ReplSetTest stop *** Mongod in port ' + conn.port + ' shutdown with code (' + ret +
') ***');
if (_useBridge) {

View File

@ -6,6 +6,11 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
var shellVersion = version;
// Record the exit codes of mongod and mongos processes that crashed during startup keyed by
// pid. This map is cleared when MongoRunner._startWithArgs and MongoRunner.stopMongod/s are
// called.
var serverExitCodeMap = {};
var _parsePath = function() {
var dbpath = "";
for (var i = 0; i < arguments.length; ++i)
@ -788,10 +793,10 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
return mongos;
};
MongoRunner.StopError = function(message, returnCode) {
MongoRunner.StopError = function(returnCode) {
this.name = "StopError";
this.returnCode = returnCode || "non-zero";
this.message = message || "MongoDB process stopped with exit code: " + this.returnCode;
this.returnCode = returnCode;
this.message = "MongoDB process stopped with exit code: " + this.returnCode;
this.stack = this.toString() + "\n" + (new Error()).stack;
};
@ -805,6 +810,9 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
MongoRunner.EXIT_REPLICATION_ERROR = 3;
MongoRunner.EXIT_NEED_UPGRADE = 4;
MongoRunner.EXIT_SHARDING_ERROR = 5;
// SIGKILL is translated to TerminateProcess() on Windows, which causes the program to
// terminate with exit code 1.
MongoRunner.EXIT_SIGKILL = _isWindows() ? 1 : -9;
MongoRunner.EXIT_KILL = 12;
MongoRunner.EXIT_ABRUPT = 14;
MongoRunner.EXIT_NTSERVICE_ERROR = 20;
@ -822,7 +830,7 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
/**
* Kills a mongod process.
*
* @param {number} port the port of the process to kill
* @param {Mongo} conn the connection object to the process to kill
* @param {number} signal The signal number to use for killing
* @param {Object} opts Additional options. Format:
* {
@ -835,44 +843,38 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
* Note: The auth option is required in a authenticated mongod running in Windows since
* it uses the shutdown command, which requires admin credentials.
*/
MongoRunner.stopMongod = function(port, signal, opts) {
if (!port) {
print("Cannot stop mongo process " + port);
return null;
MongoRunner.stopMongod = function(conn, signal, opts) {
if (!conn.pid) {
throw new Error("first arg must have a `pid` property; " +
"it is usually the object returned from MongoRunner.runMongod/s");
}
signal = parseInt(signal) || 15;
opts = opts || {};
var allowedExitCodes = [MongoRunner.EXIT_CLEAN];
var allowedExitCode = MongoRunner.EXIT_CLEAN;
if (_isWindows()) {
// Return code of processes killed with TerminateProcess on Windows
allowedExitCodes.push(1);
if (opts.allowedExitCode) {
allowedExitCode = opts.allowedExitCode;
}
var port = parseInt(conn.port);
var pid = conn.pid;
// If the return code is in the serverExitCodeMap, it means the server crashed on startup.
// We just use the recorded return code instead of stopping the program.
var returnCode;
if (pid in serverExitCodeMap) {
returnCode = serverExitCodeMap[pid];
delete serverExitCodeMap[pid];
} else {
// Return code of processes killed with SIGKILL on POSIX systems
allowedExitCodes.push(-9);
returnCode = _stopMongoProgram(port, signal, opts);
}
if (opts.allowedExitCodes) {
allowedExitCodes = allowedExitCodes.concat(opts.allowedExitCodes);
}
if (port.port)
port = parseInt(port.port);
if (port instanceof ObjectId) {
var opts = MongoRunner.savedOptions(port);
if (opts)
port = parseInt(opts.port);
}
var returnCode = _stopMongoProgram(parseInt(port), signal, opts);
if (!Array.contains(allowedExitCodes, returnCode)) {
throw new MongoRunner.StopError(
`MongoDB process on port ${port} exited with error code ${returnCode}`, returnCode);
if (allowedExitCode !== returnCode) {
throw new MongoRunner.StopError(returnCode);
} else if (returnCode !== MongoRunner.EXIT_CLEAN) {
print("MongoDB process on port " + port + " intentionally exited with error code ",
returnCode);
}
return returnCode;
@ -1130,6 +1132,7 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
pid = _startMongoProgram({args: argArray, env: env});
}
delete serverExitCodeMap[pid];
if (!waitForConnect) {
return {
pid: pid,
@ -1143,10 +1146,10 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
conn.pid = pid;
return true;
} catch (e) {
if (!checkProgram(pid)) {
var res = checkProgram(pid);
if (!res.alive) {
print("Could not start mongo program at " + port + ", process ended");
// Break out
serverExitCodeMap[pid] = res.exitCode;
return true;
}
}
@ -1178,9 +1181,10 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
assert.soon(function() {
try {
m = new Mongo("127.0.0.1:" + port);
m.pid = pid;
return true;
} catch (e) {
if (!checkProgram(pid)) {
if (!checkProgram(pid).alive) {
print("Could not start mongo program at " + port + ", process ended");
// Break out

View File

@ -745,8 +745,12 @@ BSONObj ClearRawMongoProgramOutput(const BSONObj& args, void* data) {
BSONObj CheckProgram(const BSONObj& args, void* data) {
ProcessId pid = ProcessId::fromNative(singleArg(args).numberInt());
bool isDead = wait_for_pid(pid, false);
return BSON(string("") << (!isDead));
int exit_code = -123456; // sentinel value
bool isDead = wait_for_pid(pid, false, &exit_code);
if (!isDead) {
return BSON("" << BSON("alive" << true));
}
return BSON("" << BSON("alive" << false << "exitCode" << exit_code));
}
BSONObj WaitProgram(const BSONObj& a, void* data) {
@ -1002,8 +1006,8 @@ BSONObj getStopMongodOpts(const BSONObj& a) {
/** stopMongoProgram(port[, signal]) */
BSONObj StopMongoProgram(const BSONObj& a, void* data) {
int nFields = a.nFields();
verify(nFields >= 1 && nFields <= 3);
uassert(15853, "stopMongo needs a number", a.firstElement().isNumber());
uassert(ErrorCodes::FailedToParse, "wrong number of arguments", nFields >= 1 && nFields <= 3);
uassert(ErrorCodes::BadValue, "stopMongoProgram needs a number", a.firstElement().isNumber());
int port = int(a.firstElement().number());
int code = killDb(port, ProcessId::fromNative(0), getSignal(a), getStopMongodOpts(a));
log() << "shell: stopped mongo program on port " << port;
@ -1011,11 +1015,13 @@ BSONObj StopMongoProgram(const BSONObj& a, void* data) {
}
BSONObj StopMongoProgramByPid(const BSONObj& a, void* data) {
verify(a.nFields() == 1 || a.nFields() == 2);
uassert(15852, "stopMongoByPid needs a number", a.firstElement().isNumber());
int nFields = a.nFields();
uassert(ErrorCodes::FailedToParse, "wrong number of arguments", nFields >= 1 && nFields <= 3);
uassert(
ErrorCodes::BadValue, "stopMongoProgramByPid needs a number", a.firstElement().isNumber());
ProcessId pid = ProcessId::fromNative(int(a.firstElement().number()));
int code = killDb(0, pid, getSignal(a));
log() << "shell: stopped mongo program on pid " << pid;
int code = killDb(0, pid, getSignal(a), getStopMongodOpts(a));
log() << "shell: stopped mongo program with pid " << pid;
return BSON("" << (double)code);
}