📄 main.cpp
字号:
break; case NRT_NoStart_Restart: theConfig->setInitialStart(false); globalData.theRestartFlag = initial_state; break; case NRT_NoStart_InitialStart: theConfig->setInitialStart(true); globalData.theRestartFlag = initial_state; break; case NRT_DoStart_InitialStart: theConfig->setInitialStart(true); globalData.theRestartFlag = perform_start; break; default: error_exit = 1; if(theConfig->stopOnError()){ /** * Error shutdown && stopOnError() */ reportShutdown(theConfig, error_exit, 0); exit(0); } // Fall-through case NRT_DoStart_Restart: theConfig->setInitialStart(false); globalData.theRestartFlag = perform_start; break; } } else { error_exit = 1; if (WIFSIGNALED(status)) { signum = WTERMSIG(status); childReportSignal(signum); } else { signum = 127; g_eventLogger.info("Unknown exit reason. Stopped."); } if(theConfig->stopOnError()){ /** * Error shutdown && stopOnError() */ reportShutdown(theConfig, error_exit, 0); exit(0); } } if (!failed_startup_flag) { // Reset the counter for consecutive failed startups failed_startups = 0; } else if (failed_startups >= MAX_FAILED_STARTUPS && !theConfig->stopOnError()) { /** * Error shutdown && stopOnError() */ g_eventLogger.alert("Ndbd has failed %u consecutive startups. " "Not restarting", failed_startups); reportShutdown(theConfig, error_exit, 0); exit(0); } failed_startup_flag = false; reportShutdown(theConfig, error_exit, 1); g_eventLogger.info("Ndb has terminated (pid %d) restarting", child); theConfig->fetch_configuration(); } if (child >= 0) g_eventLogger.info("Angel pid: %d ndb pid: %d", getppid(), getpid()); else if (child > 0) g_eventLogger.info("Ndb pid: %d", getpid()); else g_eventLogger.info("Ndb started in foreground");#else g_eventLogger.info("Ndb started");#endif theConfig->setupConfiguration(); systemInfo(* theConfig, * theConfig->m_logLevel); // Load blocks globalEmulatorData.theSimBlockList->load(* theConfig); // Set thread concurrency for Solaris' light weight processes int status; status = NdbThread_SetConcurrencyLevel(30); assert(status == 0); #ifdef VM_TRACE // Create a signal logger char *buf= NdbConfig_SignalLogFileName(globalData.ownId); NdbAutoPtr<char> tmp_aptr(buf); FILE * signalLog = fopen(buf, "a"); globalSignalLoggers.setOwnNodeId(globalData.ownId); globalSignalLoggers.setOutputStream(signalLog);#endif catchsigs(false); /** * Do startup */ ErrorReporter::setErrorHandlerShutdownType(NST_ErrorHandlerStartup); switch(globalData.theRestartFlag){ case initial_state: globalEmulatorData.theThreadConfig->doStart(NodeState::SL_CMVMI); break; case perform_start: globalEmulatorData.theThreadConfig->doStart(NodeState::SL_CMVMI); globalEmulatorData.theThreadConfig->doStart(NodeState::SL_STARTING); break; default: assert("Illegal state globalData.theRestartFlag" == 0); } globalTransporterRegistry.startSending(); globalTransporterRegistry.startReceiving(); if (!globalTransporterRegistry.start_service(*globalEmulatorData.m_socket_server)){ ndbout_c("globalTransporterRegistry.start_service() failed"); exit(-1); } // Re-use the mgm handle as a transporter if(!globalTransporterRegistry.connect_client( theConfig->get_config_retriever()->get_mgmHandlePtr())) ERROR_SET(fatal, NDBD_EXIT_INVALID_CONFIG, "Connection to mgmd terminated before setup was complete", "StopOnError missing"); if (!globalTransporterRegistry.start_clients()){ ndbout_c("globalTransporterRegistry.start_clients() failed"); exit(-1); } globalEmulatorData.theWatchDog->doStart(); globalEmulatorData.m_socket_server->startServer(); // theConfig->closeConfiguration(); globalEmulatorData.theThreadConfig->ipControlLoop(); NdbShutdown(NST_Normal); return NRT_Default;}void systemInfo(const Configuration & config, const LogLevel & logLevel){#ifdef NDB_WIN32 int processors = 0; int speed; SYSTEM_INFO sinfo; GetSystemInfo(&sinfo); processors = sinfo.dwNumberOfProcessors; HKEY hKey; if(ERROR_SUCCESS==RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0, KEY_READ, &hKey)) { DWORD dwMHz; DWORD cbData = sizeof(dwMHz); if(ERROR_SUCCESS==RegQueryValueEx(hKey, "~MHz", 0, 0, (LPBYTE)&dwMHz, &cbData)) { speed = int(dwMHz); } RegCloseKey(hKey); }#elif defined NDB_SOLARIS // ok // Search for at max 16 processors among the first 256 processor ids processor_info_t pinfo; memset(&pinfo, 0, sizeof(pinfo)); int pid = 0; while(processors < 16 && pid < 256){ if(!processor_info(pid++, &pinfo)) processors++; } speed = pinfo.pi_clock;#endif if(logLevel.getLogLevel(LogLevel::llStartUp) > 0){ g_eventLogger.info("NDB Cluster -- DB node %d", globalData.ownId); g_eventLogger.info("%s --", NDB_VERSION_STRING); if (config.get_mgmd_host()) g_eventLogger.info("Configuration fetched at %s port %d", config.get_mgmd_host(), config.get_mgmd_port());#ifdef NDB_SOLARIS // ok g_eventLogger.info("NDB is running on a machine with %d processor(s) at %d MHz", processor, speed);#endif } if(logLevel.getLogLevel(LogLevel::llStartUp) > 3){ Uint32 t = config.timeBetweenWatchDogCheck(); g_eventLogger.info("WatchDog timer is set to %d ms", t); }}#define handler_register(signum, handler, ignore)\{\ if (ignore) {\ if(signum != SIGCHLD)\ signal(signum, SIG_IGN);\ } else\ signal(signum, handler);\}void catchsigs(bool ignore){#if !defined NDB_WIN32 && !defined NDB_SOFTOSE && !defined NDB_OSE static const int signals_shutdown[] = {#ifdef SIGBREAK SIGBREAK,#endif SIGHUP, SIGINT,#if defined SIGPWR SIGPWR,#elif defined SIGINFO SIGINFO,#endif SIGQUIT, SIGTERM,#ifdef SIGTSTP SIGTSTP,#endif SIGTTIN, SIGTTOU }; static const int signals_error[] = { SIGABRT, SIGALRM,#ifdef SIGBUS SIGBUS,#endif SIGCHLD, SIGFPE, SIGILL,#ifdef SIGIO SIGIO,#endif#ifdef SIGPOLL SIGPOLL,#endif SIGSEGV }; static const int signals_ignore[] = { SIGPIPE }; size_t i; for(i = 0; i < sizeof(signals_shutdown)/sizeof(signals_shutdown[0]); i++) handler_register(signals_shutdown[i], handler_shutdown, ignore); for(i = 0; i < sizeof(signals_error)/sizeof(signals_error[0]); i++) handler_register(signals_error[i], handler_error, ignore); for(i = 0; i < sizeof(signals_ignore)/sizeof(signals_ignore[0]); i++) handler_register(signals_ignore[i], SIG_IGN, ignore);#ifdef SIGTRAP Configuration* theConfig = globalEmulatorData.theConfiguration; if (! theConfig->getForegroundMode()) handler_register(SIGTRAP, handler_error, ignore);#endif#endif}extern "C"void handler_shutdown(int signum){ g_eventLogger.info("Received signal %d. Performing stop.", signum); childReportError(0); childReportSignal(signum); globalData.theRestartFlag = perform_stop;}extern "C"void handler_error(int signum){ // only let one thread run shutdown static long thread_id= 0; if (thread_id != 0 && thread_id == my_thread_id()) { // Shutdown thread received signal#ifndef NDB_WIN32 signal(signum, SIG_DFL); kill(getpid(), signum);#endif while(true) NdbSleep_MilliSleep(10); } if(theShutdownMutex && NdbMutex_Trylock(theShutdownMutex) != 0) while(true) NdbSleep_MilliSleep(10); thread_id= my_thread_id(); g_eventLogger.info("Received signal %d. Running error handler.", signum); childReportSignal(signum); // restart the system char errorData[64], *info= 0;#ifdef HAVE_STRSIGNAL info= strsignal(signum);#endif BaseString::snprintf(errorData, sizeof(errorData), "Signal %d received; %s", signum, info ? info : "No text for signal available"); ERROR_SET_SIGNAL(fatal, NDBD_EXIT_OS_SIGNAL_RECEIVED, errorData, __FILE__);}extern "C"void handler_sigusr1(int signum){ if (!failed_startup_flag) { failed_startups++; failed_startup_flag = true; } g_eventLogger.info("Angel received ndbd startup failure count %u.", failed_startups);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -