static void shutdownServer() { log() << "shutdown: going to close listening sockets..." << endl; ListeningSockets::get()->closeAll(); log() << "shutdown: going to flush diaglog..." << endl; _diaglog.flush(); /* must do this before unmapping mem or you may get a seg fault */ log() << "shutdown: going to close sockets..." << endl; boost::thread close_socket_thread( boost::bind(MessagingPort::closeAllSockets, 0) ); { LOCK_REASON(lockReason, "shutting down"); Lock::GlobalWrite lk(lockReason); log() << "shutdown: going to close databases..." << endl; dbHolderW().closeDatabases(dbpath); log() << "shutdown: going to unload all plugins..." << endl; plugins::loader->shutdown(); log() << "shutdown: going to shutdown TokuMX..." << endl; storage::shutdown(); } #if !defined(__sunos__) if ( lockFile ) { log() << "shutdown: removing fs lock..." << endl; /* This ought to be an unlink(), but Eliot says the last time that was attempted, there was a race condition with acquirePathLock(). */ #ifdef _WIN32 if( _chsize( lockFile , 0 ) ) log() << "couldn't remove fs lock " << WSAGetLastError() << endl; CloseHandle(lockFileHandle); #else if( ftruncate( lockFile , 0 ) ) log() << "couldn't remove fs lock " << errnoWithDescription() << endl; flock( lockFile, LOCK_UN ); #endif } #endif }
void testing (ACE_Reactor *reactor, int make_invocations, int run_event_loop_thread, int run_purger_thread, int run_receiver_thread, int nested_upcalls) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n(%t) Configuration:\n") ACE_TEXT ("\tInvocation thread = %d\n") ACE_TEXT ("\tEvent Loop thread = %d\n") ACE_TEXT ("\tPurger thread = %d\n") ACE_TEXT ("\tReceiver thread = %d\n") ACE_TEXT ("\tNested Upcalls = %d\n\n"), make_invocations, run_event_loop_thread, run_purger_thread, run_receiver_thread, nested_upcalls)); ACE_Thread_Manager thread_manager; int result = 0; // Create the connection cache. Connection_Cache connection_cache; ACE_Auto_Event new_connection_event; // Create the invocation thread. Invocation_Thread invocation_thread (thread_manager, *reactor, connection_cache, new_connection_event, make_invocations, run_receiver_thread, nested_upcalls); result = invocation_thread.activate (); ACE_TEST_ASSERT (result == 0); // Create the thread for closing the server socket. Close_Socket_Thread close_socket_thread (thread_manager, *reactor, new_connection_event, make_invocations, run_receiver_thread); result = close_socket_thread.activate (); ACE_TEST_ASSERT (result == 0); global_event_loop_thread_variable = 0; // Create a thread to run the event loop. Event_Loop_Thread event_loop_thread (thread_manager, *reactor); if (run_event_loop_thread) { global_event_loop_thread_variable = &event_loop_thread; result = event_loop_thread.activate (); ACE_TEST_ASSERT (result == 0); } // Create a thread to run the purger. Purger_Thread purger_thread (thread_manager, *reactor, connection_cache); if (run_purger_thread) { result = purger_thread.activate (); ACE_TEST_ASSERT (result == 0); } // Wait for threads to exit. result = thread_manager.wait (); ACE_TEST_ASSERT (result == 0); // Set the global variable to zero again because the // event_loop_thread exists on the stack and now // gets destructed. global_event_loop_thread_variable = 0; }
static void shutdownServer() { log() << "shutdown: going to close listening sockets..." << endl; ListeningSockets::get()->closeAll(); log() << "shutdown: going to flush diaglog..." << endl; _diaglog.flush(); /* must do this before unmapping mem or you may get a seg fault */ log() << "shutdown: going to close sockets..." << endl; boost::thread close_socket_thread( boost::bind(MessagingPort::closeAllSockets, 0) ); // wait until file preallocation finishes // we would only hang here if the file_allocator code generates a // synchronous signal, which we don't expect log() << "shutdown: waiting for fs preallocator..." << endl; FileAllocator::get()->waitUntilFinished(); if( cmdLine.dur ) { log() << "shutdown: lock for final commit..." << endl; { int n = 10; while( 1 ) { // we may already be in a read lock from earlier in the call stack, so do read lock here // to be consistent with that. readlocktry w(20000); if( w.got() ) { log() << "shutdown: final commit..." << endl; getDur().commitNow(); break; } if( --n <= 0 ) { log() << "shutdown: couldn't acquire write lock, aborting" << endl; mongoAbort("couldn't acquire write lock"); } log() << "shutdown: waiting for write lock..." << endl; } } MemoryMappedFile::flushAll(true); } log() << "shutdown: closing all files..." << endl; stringstream ss3; MemoryMappedFile::closeAllFiles( ss3 ); log() << ss3.str() << endl; if( cmdLine.dur ) { dur::journalCleanup(true); } #if !defined(__sunos__) if ( lockFile ) { log() << "shutdown: removing fs lock..." << endl; /* This ought to be an unlink(), but Eliot says the last time that was attempted, there was a race condition with acquirePathLock(). */ #ifdef _WIN32 if( _chsize( lockFile , 0 ) ) log() << "couldn't remove fs lock " << errnoWithDescription(_doserrno) << endl; CloseHandle(lockFileHandle); #else if( ftruncate( lockFile , 0 ) ) log() << "couldn't remove fs lock " << errnoWithDescription() << endl; flock( lockFile, LOCK_UN ); #endif } #endif }