2727#include " lasterror.h"
2828#include " security.h"
2929#include " json.h"
30- // #include "reccache.h"
3130#include " replpair.h"
3231#include " ../s/d_logic.h"
3332#include " ../util/file_allocator.h"
3837#endif
3938#include " stats/counters.h"
4039#include " background.h"
40+ #include " dur_journal.h"
4141
4242namespace mongo {
4343
@@ -667,11 +667,8 @@ namespace mongo {
667667 return new DBDirectClient ();
668668 }
669669
670- // void recCacheCloseAll();
671-
672670 mongo::mutex exitMutex (" exit" );
673671 int numExitCalls = 0 ;
674- void shutdown ();
675672
676673 bool inShutdown (){
677674 return numExitCalls > 0 ;
@@ -693,6 +690,52 @@ namespace mongo {
693690 // uh - oh, not sure there is anything else we can do...
694691 }
695692
693+ /* * also called by ntservice.cpp */
694+ void shutdownServer () {
695+
696+ log () << " shutdown: going to close listening sockets..." << endl;
697+ ListeningSockets::get ()->closeAll ();
698+
699+ log () << " shutdown: going to flush oplog..." << endl;
700+ flushDiagLog ();
701+
702+ /* must do this before unmapping mem or you may get a seg fault */
703+ log () << " shutdown: going to close sockets..." << endl;
704+ boost::thread close_socket_thread ( boost::bind (MessagingPort::closeAllSockets, 0 ) );
705+
706+ // wait until file preallocation finishes
707+ // we would only hang here if the file_allocator code generates a
708+ // synchronous signal, which we don't expect
709+ log () << " shutdown: waiting for fs preallocator..." << endl;
710+ theFileAllocator ().waitUntilFinished ();
711+
712+ log () << " shutdown: closing all files..." << endl;
713+ if ( durable ) {
714+ /* is this useful? needed? helpful? perhaps even without _DURABLE. ifdef'd for now just to avoid behavior change short term */
715+ MemoryMappedFile::flushAll (true );
716+ }
717+ stringstream ss3;
718+ MemoryMappedFile::closeAllFiles ( ss3 );
719+ rawOut ( ss3.str () );
720+
721+ if ( durable ) {
722+ log () << " shutdown: journalCleanup..." << endl;
723+ dur::journalCleanup ();
724+ }
725+
726+ #if !defined(_WIN32) && !defined(__sunos__)
727+ if ( lockFile ){
728+ log () << " shutdown: removing fs lock..." << endl;
729+ /* This ought to be an unlink(), but Eliot says the last
730+ time that was attempted, there was a race condition
731+ with acquirePathLock(). */
732+ if ( ftruncate ( lockFile , 0 ) )
733+ log () << " couldn't remove fs lock " << errnoWithDescription () << endl;
734+ flock ( lockFile, LOCK_UN );
735+ }
736+ #endif
737+ }
738+
696739 /* not using log() herein in case we are already locked */
697740 void dbexit ( ExitCode rc, const char *why, bool tryToGetLock ) {
698741
@@ -725,7 +768,7 @@ namespace mongo {
725768 }
726769
727770 try {
728- shutdown (); // gracefully shutdown instance
771+ shutdownServer (); // gracefully shutdown instance
729772 }
730773 catch ( ... ){
731774 tryToOutputFatal ( " shutdown failed with exception" );
@@ -741,45 +784,6 @@ namespace mongo {
741784 ::exit (rc);
742785 }
743786
744- void shutdown () {
745-
746- log () << " shutdown: going to close listening sockets..." << endl;
747- ListeningSockets::get ()->closeAll ();
748-
749- log () << " shutdown: going to flush oplog..." << endl;
750- flushDiagLog ();
751-
752- /* must do this before unmapping mem or you may get a seg fault */
753- log () << " shutdown: going to close sockets..." << endl;
754- boost::thread close_socket_thread ( boost::bind (MessagingPort::closeAllSockets, 0 ) );
755-
756- // wait until file preallocation finishes
757- // we would only hang here if the file_allocator code generates a
758- // synchronous signal, which we don't expect
759- log () << " shutdown: waiting for fs preallocator..." << endl;
760- theFileAllocator ().waitUntilFinished ();
761-
762- log () << " shutdown: closing all files..." << endl;
763- stringstream ss3;
764- MemoryMappedFile::closeAllFiles ( ss3 );
765- rawOut ( ss3.str () );
766-
767- // should we be locked here? we aren't. might be ok as-is.
768- // recCacheCloseAll();
769-
770- #if !defined(_WIN32) && !defined(__sunos__)
771- if ( lockFile ){
772- log () << " shutdown: removing fs lock..." << endl;
773- /* This ought to be an unlink(), but Eliot says the last
774- time that was attempted, there was a race condition
775- with acquirePathLock(). */
776- if ( ftruncate ( lockFile , 0 ) )
777- log () << " couldn't remove fs lock " << errnoWithDescription () << endl;
778- flock ( lockFile, LOCK_UN );
779- }
780- #endif
781- }
782-
783787#if !defined(_WIN32) && !defined(__sunos__)
784788 void writePid (int fd) {
785789 stringstream ss;
0 commit comments