diff options
author | Eric Milkie <milkie@10gen.com> | 2013-04-16 11:37:19 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2013-04-18 10:24:54 -0400 |
commit | 9d5de58e4fb9129ed630e99e732899411249ac6a (patch) | |
tree | feb425bc2c2178fcc76375fd67ec020a30b39514 | |
parent | 63970873031d29f7eafbe1bd3d441578e7f675d3 (diff) | |
download | mongo-9d5de58e4fb9129ed630e99e732899411249ac6a.tar.gz |
SERVER-4739 use a thread for logRotate signal instead of a signal handler
Conflicts:
src/mongo/db/db.cpp
src/mongo/s/server.cpp
-rw-r--r-- | src/mongo/db/db.cpp | 43 | ||||
-rw-r--r-- | src/mongo/db/dbcommands_generic.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/initialize_server_global_state.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 31 | ||||
-rw-r--r-- | src/mongo/util/log.cpp | 6 |
5 files changed, 64 insertions, 25 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 12037d0b6a8..def2e459c70 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -80,8 +80,8 @@ namespace mongo { extern string repairpath; static void setupSignalHandlers(); - static void startInterruptThread(); void startReplication(); + static void startSignalProcessingThread(); void exitCleanly( ExitCode code ); #ifdef _WIN32 @@ -1280,9 +1280,9 @@ static int mongoDbMain(int argc, char* argv[], char **envp) { if (!initializeServerGlobalState()) ::_exit(EXIT_FAILURE); - // Per SERVER-7434, startInterruptThread() must run after any forks + // Per SERVER-7434, startSignalProcessingThread() must run after any forks // (initializeServerGlobalState()) and before creation of any other threads. - startInterruptThread(); + startSignalProcessingThread(); dataFileSync.go(); @@ -1350,15 +1350,27 @@ namespace mongo { } sigset_t asyncSignals; - // The above signals will be processed by this thread only, in order to + // The signals in asyncSignals will be processed by this thread only, in order to // ensure the db and log mutexes aren't held. - void interruptThread() { - int actualSignal; - sigwait( &asyncSignals, &actualSignal ); - log() << "got signal " << actualSignal << " (" << strsignal( actualSignal ) - << "), will terminate after current cmd ends" << endl; - Client::initThread( "interruptThread" ); - exitCleanly( EXIT_CLEAN ); + void signalProcessingThread() { + while (true) { + int actualSignal = 0; + int status = sigwait( &asyncSignals, &actualSignal ); + fassert(16781, status == 0); + switch (actualSignal) { + case SIGUSR1: + // log rotate signal + fassert(16782, rotateLogs()); + break; + default: + // interrupt/terminate signal + Client::initThread( "signalProcessingThread" ); + log() << "got signal " << actualSignal << " (" << strsignal( actualSignal ) + << "), will terminate after current cmd ends" << endl; + exitCleanly( EXIT_CLEAN ); + break; + } + } } // this will be called in certain c++ error cases, for example if there are two active @@ -1399,19 +1411,20 @@ namespace mongo { setupSIGTRAPforGDB(); // asyncSignals is a global variable listing the signals that should be handled by the - // interrupt thread, once it is started via startInterruptThread(). + // interrupt thread, once it is started via startSignalProcessingThread(). sigemptyset( &asyncSignals ); sigaddset( &asyncSignals, SIGHUP ); sigaddset( &asyncSignals, SIGINT ); sigaddset( &asyncSignals, SIGTERM ); + sigaddset( &asyncSignals, SIGUSR1 ); set_terminate( myterminate ); set_new_handler( my_new_handler ); } - void startInterruptThread() { + void startSignalProcessingThread() { verify( pthread_sigmask( SIG_SETMASK, &asyncSignals, 0 ) == 0 ); - boost::thread it( interruptThread ); + boost::thread it( signalProcessingThread ); } #else // WIN32 @@ -1486,7 +1499,7 @@ namespace mongo { _set_purecall_handler( myPurecallHandler ); } - void startInterruptThread() {} + void startSignalProcessingThread() {} #endif // if !defined(_WIN32) diff --git a/src/mongo/db/dbcommands_generic.cpp b/src/mongo/db/dbcommands_generic.cpp index 7b8070d6fac..e4528e605ae 100644 --- a/src/mongo/db/dbcommands_generic.cpp +++ b/src/mongo/db/dbcommands_generic.cpp @@ -230,8 +230,7 @@ namespace mongo { out->push_back(Privilege(AuthorizationManager::SERVER_RESOURCE_NAME, actions)); } virtual bool run(const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - fassert(16175, rotateLogs()); - return 1; + return rotateLogs(); } } logRotateCmd; diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp index 120a733d10d..f439c9e8a79 100644 --- a/src/mongo/db/initialize_server_global_state.cpp +++ b/src/mongo/db/initialize_server_global_state.cpp @@ -193,14 +193,10 @@ namespace mongo { static void ignoreSignal( int sig ) {} - static void rotateLogsOrDie(int sig) { - fassert(16176, rotateLogs()); - } - void setupCoreSignals() { #if !defined(_WIN32) - verify( signal(SIGUSR1 , rotateLogsOrDie ) != SIG_ERR ); verify( signal(SIGHUP , ignoreSignal ) != SIG_ERR ); + verify( signal(SIGUSR2, ignoreSignal ) != SIG_ERR ); #endif } diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index f7e647662f9..165bf7a7ef7 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -163,6 +163,33 @@ namespace mongo { ::_exit(EXIT_ABRUPT); } + sigset_t asyncSignals; + + void signalProcessingThread() { + while (true) { + int actualSignal = 0; + int status = sigwait( &asyncSignals, &actualSignal ); + fassert(16779, status == 0); + switch (actualSignal) { + case SIGUSR1: + // log rotate signal + fassert(16780, rotateLogs()); + break; + default: + // no one else should be here + fassertFailed(16778); + break; + } + } + } + + void startSignalProcessingThread() { +#ifndef _WIN32 + verify( pthread_sigmask( SIG_SETMASK, &asyncSignals, 0 ) == 0 ); + boost::thread it( signalProcessingThread ); +#endif + } + void setupSignalHandlers() { setupSIGTRAPforGDB(); setupCoreSignals(); @@ -183,6 +210,10 @@ namespace mongo { signal( SIGPIPE , SIG_IGN ); #endif + sigemptyset( &asyncSignals ); + sigaddset( &asyncSignals, SIGUSR1 ); + startSignalProcessingThread(); + setWindowsUnhandledExceptionFilter(); set_new_handler( my_new_handler ); } diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp index f69ffbd5450..00845d07da1 100644 --- a/src/mongo/util/log.cpp +++ b/src/mongo/util/log.cpp @@ -141,7 +141,7 @@ namespace mongo { bool rotate() { if ( ! _enabled ) { - cout << "LoggingManager not enabled" << endl; + cout << "logRotate is not possible: loggingManager not enabled" << endl; return true; } @@ -156,7 +156,7 @@ namespace mongo { ss << _path << "." << terseCurrentTime( false ); string s = ss.str(); if (0 != rename(_path.c_str(), s.c_str())) { - error() << "Failed to rename '" << _path + error() << "failed to rename '" << _path << "' to '" << s << "': " << errnoWithDescription() << endl; return false; @@ -187,7 +187,7 @@ namespace mongo { tmp = freopen(_path.c_str(), _append ? "a" : "w", stdout); #endif if ( !tmp ) { - cerr << "can't open: " << _path.c_str() << " for log file" << endl; + error() << "can't open: " << _path.c_str() << " for log file" << endl; return false; } |