summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/client/scoped_db_conn_test.cpp4
-rw-r--r--src/mongo/db/commands/shutdown.h2
-rw-r--r--src/mongo/db/dbcommands.cpp2
-rw-r--r--src/mongo/db/dbcommands_generic.cpp7
-rw-r--r--src/mongo/db/instance.cpp12
-rw-r--r--src/mongo/db/instance.h2
-rw-r--r--src/mongo/s/commands_admin.cpp2
-rw-r--r--src/mongo/s/server.cpp2
-rw-r--r--src/mongo/shell/dbshell.cpp2
-rw-r--r--src/mongo/unittest/crutch.cpp6
-rw-r--r--src/mongo/util/exit_code.h11
-rw-r--r--src/mongo/util/ntservice_test.cpp2
-rw-r--r--src/mongo/util/signal_handlers.cpp3
13 files changed, 36 insertions, 21 deletions
diff --git a/src/mongo/client/scoped_db_conn_test.cpp b/src/mongo/client/scoped_db_conn_test.cpp
index 5b75263f6a0..ed63eaa2fdb 100644
--- a/src/mongo/client/scoped_db_conn_test.cpp
+++ b/src/mongo/client/scoped_db_conn_test.cpp
@@ -85,6 +85,10 @@ namespace mongo {
::_exit(rc);
}
+ void exitCleanly(ExitCode rc, OperationContext* txn) {
+ dbexit(rc, "");
+ }
+
bool haveLocalShardingInfo(const string& ns) {
return false;
}
diff --git a/src/mongo/db/commands/shutdown.h b/src/mongo/db/commands/shutdown.h
index b782f4c58f6..2a102971e57 100644
--- a/src/mongo/db/commands/shutdown.h
+++ b/src/mongo/db/commands/shutdown.h
@@ -56,7 +56,7 @@ namespace mongo {
BSONObjBuilder& result,
bool fromRepl);
private:
- bool shutdownHelper();
+ static bool shutdownHelper(OperationContext* txn);
};
} // namespace mongo
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 72f6ec883b2..f38db4a747d 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -120,7 +120,7 @@ namespace mongo {
writelocktry wlt(txn->lockState(), 2 * 60 * 1000);
uassert( 13455 , "dbexit timed out getting lock" , wlt.got() );
- return shutdownHelper();
+ return shutdownHelper(txn);
}
class CmdDropDatabase : public Command {
diff --git a/src/mongo/db/dbcommands_generic.cpp b/src/mongo/db/dbcommands_generic.cpp
index 6a466cc0dd4..5ff4089086b 100644
--- a/src/mongo/db/dbcommands_generic.cpp
+++ b/src/mongo/db/dbcommands_generic.cpp
@@ -304,7 +304,7 @@ namespace mongo {
out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
}
- bool CmdShutdown::shutdownHelper() {
+ bool CmdShutdown::shutdownHelper(OperationContext* txn) {
MONGO_FAIL_POINT_BLOCK(crashOnShutdown, crashBlock) {
const std::string crashHow = crashBlock.getData()["how"].str();
if (crashHow == "fault") {
@@ -319,9 +319,8 @@ namespace mongo {
log() << "terminating, shutdown command received" << endl;
- dbexit( EXIT_CLEAN , "shutdown called" ); // this never returns
- verify(0);
- return true;
+ exitCleanly( EXIT_CLEAN, txn ); // this never returns
+ invariant(false);
}
/* for testing purposes only */
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index ef37863a96b..b5886eb5e58 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -1032,7 +1032,7 @@ namespace {
storageEngine->cleanShutdown(txn);
}
- void exitCleanly( ExitCode code ) {
+ void exitCleanly( ExitCode code, OperationContext* txn ) {
shutdownInProgress.store(1);
// Global storage engine may not be started in all cases before we exit
@@ -1042,14 +1042,18 @@ namespace {
repl::getGlobalReplicationCoordinator()->shutdown();
- OperationContextImpl txn;
- Lock::GlobalWrite lk(txn.lockState());
+ if (!txn) {
+ // leaked, but we are exiting so doesn't matter
+ txn = new OperationContextImpl();
+ }
+
+ Lock::GlobalWrite lk(txn->lockState());
log() << "now exiting" << endl;
// Execute the graceful shutdown tasks, such as flushing the outstanding journal
// and data files, close sockets, etc.
try {
- shutdownServer(&txn);
+ shutdownServer(txn);
}
catch (const DBException& ex) {
severe() << "shutdown failed with DBException " << ex;
diff --git a/src/mongo/db/instance.h b/src/mongo/db/instance.h
index df687e40c30..05ed5cd1a0c 100644
--- a/src/mongo/db/instance.h
+++ b/src/mongo/db/instance.h
@@ -141,6 +141,4 @@ namespace mongo {
void maybeCreatePidFile();
- void exitCleanly( ExitCode code );
-
} // namespace mongo
diff --git a/src/mongo/s/commands_admin.cpp b/src/mongo/s/commands_admin.cpp
index 3ad9a3f3cdb..c194d250c85 100644
--- a/src/mongo/s/commands_admin.cpp
+++ b/src/mongo/s/commands_admin.cpp
@@ -1911,7 +1911,7 @@ namespace mongo {
}
bool CmdShutdown::run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
- return shutdownHelper();
+ return shutdownHelper(txn);
}
} // namespace mongo
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 3664a16b9d1..22ae0028e45 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -474,7 +474,7 @@ int main(int argc, char* argv[], char** envp) {
#undef exit
-void mongo::exitCleanly( ExitCode code ) {
+void mongo::exitCleanly( ExitCode code, OperationContext* txn ) {
// TODO: do we need to add anything?
mongo::dbexit( code );
}
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index e313035e454..a2e1938083e 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -177,7 +177,7 @@ namespace mongo {
void Client::initThread(const char *desc, mongo::AbstractMessagingPort *mp) {}
void logProcessDetailsForLogRotate() {}
- void exitCleanly( ExitCode code ) {
+ void exitCleanly( ExitCode code, OperationContext* txn ) {
{
mongo::mutex::scoped_lock lk(mongo::shell_utils::mongoProgramOutputMutex);
mongo::dbexitCalled = true;
diff --git a/src/mongo/unittest/crutch.cpp b/src/mongo/unittest/crutch.cpp
index 6bb07a19d6c..3ed5798d61a 100644
--- a/src/mongo/unittest/crutch.cpp
+++ b/src/mongo/unittest/crutch.cpp
@@ -57,7 +57,11 @@ namespace mongo {
}
void dbexit(ExitCode rc, const char *why) {
- fassertFailed(17250);
+ invariant(!"unittests shouldn't call dbexit");
+ }
+
+ void exitCleanly( ExitCode code, OperationContext* txn ) {
+ invariant(!"unittests shouldn't call exitCleanly");
}
} // namespace mongo
diff --git a/src/mongo/util/exit_code.h b/src/mongo/util/exit_code.h
index 30745d6c1e5..0d0617d92fa 100644
--- a/src/mongo/util/exit_code.h
+++ b/src/mongo/util/exit_code.h
@@ -32,7 +32,10 @@
#pragma once
+#include <cstring>
+
namespace mongo {
+ class OperationContext;
enum ExitCode {
EXIT_CLEAN = 0 ,
@@ -55,4 +58,12 @@ namespace mongo {
EXIT_TEST = 101
};
+ /**
+ * Exit the current executable doing whatever cleanup is necessary.
+ * Defined differently in different executables.
+ *
+ * If txn is NULL, an OperationContext will be constructed if necessary for clean shutdown.
+ */
+ void exitCleanly( ExitCode code, OperationContext* txn = NULL );
+
} // namespace mongo
diff --git a/src/mongo/util/ntservice_test.cpp b/src/mongo/util/ntservice_test.cpp
index 5aee2e9c711..03eecee6a89 100644
--- a/src/mongo/util/ntservice_test.cpp
+++ b/src/mongo/util/ntservice_test.cpp
@@ -114,8 +114,6 @@ TEST(NtService, RegressionSERVER_7252) {
// CRUTCHES!
namespace mongo {
- enum ExitCode;
- void exitCleanly(ExitCode ignored) { std::abort(); }
void Client::initThread(const char* desc, AbstractMessagingPort* mp) {
}
} // namespace mongo
diff --git a/src/mongo/util/signal_handlers.cpp b/src/mongo/util/signal_handlers.cpp
index 0e8acb1d7dc..3ea6328b667 100644
--- a/src/mongo/util/signal_handlers.cpp
+++ b/src/mongo/util/signal_handlers.cpp
@@ -76,9 +76,6 @@ namespace mongo {
*
*/
- // everything provides this, but only header is instance.h
- void exitCleanly(ExitCode exitCode);
-
namespace {
#ifdef _WIN32