Skip to content

Commit 1ba6be5

Browse files
committed
WL#4523 Run ndbd as Windows Service
- Move NdbShutdown to ndbd.hpp/.cpp - Remove duplicate defined of NdbRestartType - Make all childReport* functions static and remove the extren definitions of them
1 parent 2467c57 commit 1ba6be5

File tree

10 files changed

+238
-265
lines changed

10 files changed

+238
-265
lines changed

storage/ndb/src/kernel/angel.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <signal.h>
2020

2121
#include "angel.hpp"
22+
#include "ndbd.hpp"
2223

2324
#include <NdbConfig.h>
2425
#include <NdbAutoPtr.hpp>
@@ -353,16 +354,6 @@ configure(const ndb_mgm_configuration* conf, NodeId nodeid)
353354
}
354355

355356

356-
// Temporary duplicate define
357-
enum NdbRestartType {
358-
NRT_Default = 0,
359-
NRT_NoStart_Restart = 1, // -n
360-
NRT_DoStart_Restart = 2, //
361-
NRT_NoStart_InitialStart = 3, // -n -i
362-
NRT_DoStart_InitialStart = 4 // -i
363-
};
364-
365-
366357
void
367358
angel_run(const BaseString& original_args,
368359
const char* connect_str,

storage/ndb/src/kernel/error/ErrorReporter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <NdbConfig.h>
2929
#include <Configuration.hpp>
3030
#include "EventLogger.hpp"
31+
extern EventLogger * g_eventLogger;
32+
33+
#include "TimeModule.hpp"
3134

3235
#include <NdbAutoPtr.hpp>
3336

@@ -43,7 +46,7 @@ static void dumpJam(FILE* jamStream,
4346
const Uint32 thrdTheEmulatedJam[],
4447
Uint32 aBlockNumber);
4548

46-
extern EventLogger * g_eventLogger;
49+
4750
const char*
4851
ErrorReporter::formatTimeStampString(){
4952
TimeModule DateTime; /* To create "theDateTimeString" */

storage/ndb/src/kernel/error/ErrorReporter.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
#include <ndb_global.h>
2323
#include <ndbd_exit_codes.h>
2424

25-
#include "TimeModule.hpp"
26-
#include <Emulator.hpp>
25+
#include "../ndbd.hpp"
2726

2827
class ErrorReporter
2928
{

storage/ndb/src/kernel/ndbd.cpp

Lines changed: 198 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ childReportSignal(int signum)
359359
writeChildInfo("signal", signum);
360360
}
361361

362-
void
362+
static void
363363
childExit(int error_code, int exit_code, Uint32 currentStartPhase)
364364
{
365365
writeChildInfo("error", error_code);
@@ -369,7 +369,7 @@ childExit(int error_code, int exit_code, Uint32 currentStartPhase)
369369
ndbd_exit(exit_code);
370370
}
371371

372-
void
372+
static void
373373
childAbort(int error_code, int exit_code, Uint32 currentStartPhase)
374374
{
375375
#ifndef NDB_WIN
@@ -657,3 +657,199 @@ ndbd_run(bool foreground, int report_fd,
657657

658658
ndbd_exit(0);
659659
}
660+
661+
662+
extern "C" my_bool opt_core;
663+
664+
// instantiated and updated in NdbcntrMain.cpp
665+
extern Uint32 g_currentStartPhase;
666+
667+
int simulate_error_during_shutdown= 0;
668+
669+
void
670+
NdbShutdown(int error_code,
671+
NdbShutdownType type,
672+
NdbRestartType restartType)
673+
{
674+
if(type == NST_ErrorInsert)
675+
{
676+
type = NST_Restart;
677+
restartType = (NdbRestartType)
678+
globalEmulatorData.theConfiguration->getRestartOnErrorInsert();
679+
if(restartType == NRT_Default)
680+
{
681+
type = NST_ErrorHandler;
682+
globalEmulatorData.theConfiguration->stopOnError(true);
683+
}
684+
}
685+
686+
if((type == NST_ErrorHandlerSignal) || // Signal handler has already locked mutex
687+
(NdbMutex_Trylock(theShutdownMutex) == 0)){
688+
globalData.theRestartFlag = perform_stop;
689+
690+
bool restart = false;
691+
692+
if((type != NST_Normal &&
693+
globalEmulatorData.theConfiguration->stopOnError() == false) ||
694+
type == NST_Restart)
695+
{
696+
restart = true;
697+
}
698+
699+
const char * shutting = "shutting down";
700+
if(restart)
701+
{
702+
shutting = "restarting";
703+
}
704+
705+
switch(type){
706+
case NST_Normal:
707+
g_eventLogger->info("Shutdown initiated");
708+
break;
709+
case NST_Watchdog:
710+
g_eventLogger->info("Watchdog %s system", shutting);
711+
break;
712+
case NST_ErrorHandler:
713+
g_eventLogger->info("Error handler %s system", shutting);
714+
break;
715+
case NST_ErrorHandlerSignal:
716+
g_eventLogger->info("Error handler signal %s system", shutting);
717+
break;
718+
case NST_Restart:
719+
g_eventLogger->info("Restarting system");
720+
break;
721+
default:
722+
g_eventLogger->info("Error handler %s system (unknown type: %u)",
723+
shutting, (unsigned)type);
724+
type = NST_ErrorHandler;
725+
break;
726+
}
727+
728+
const char * exitAbort = 0;
729+
#ifndef NDB_WIN
730+
if (opt_core)
731+
exitAbort = "aborting";
732+
else
733+
#endif
734+
exitAbort = "exiting";
735+
736+
if(type == NST_Watchdog)
737+
{
738+
/**
739+
* Very serious, don't attempt to free, just die!!
740+
*/
741+
g_eventLogger->info("Watchdog shutdown completed - %s", exitAbort);
742+
#ifndef NDB_WIN
743+
if (opt_core)
744+
{
745+
childAbort(error_code, -1,g_currentStartPhase);
746+
}
747+
else
748+
#endif
749+
{
750+
childExit(error_code, -1,g_currentStartPhase);
751+
}
752+
}
753+
754+
#ifndef NDB_WIN32
755+
if (simulate_error_during_shutdown)
756+
{
757+
kill(getpid(), simulate_error_during_shutdown);
758+
while(true)
759+
NdbSleep_MilliSleep(10);
760+
}
761+
#endif
762+
763+
globalEmulatorData.theWatchDog->doStop();
764+
765+
#ifdef VM_TRACE
766+
FILE * outputStream = globalSignalLoggers.setOutputStream(0);
767+
if(outputStream != 0)
768+
fclose(outputStream);
769+
#endif
770+
771+
#ifndef NDB_WIN32
772+
#define UNLOAD (type == NST_ErrorInsert && opt_core)
773+
#else
774+
#define UNLOAD (0)
775+
#endif
776+
/**
777+
* Don't touch transporter here (yet)
778+
* cause with ndbmtd, there are locks and nasty stuff
779+
* and we don't know which we are holding...
780+
*/
781+
#if NOT_YET
782+
783+
/**
784+
* Stop all transporter connection attempts and accepts
785+
*/
786+
globalEmulatorData.m_socket_server->stopServer();
787+
globalEmulatorData.m_socket_server->stopSessions();
788+
globalTransporterRegistry.stop_clients();
789+
790+
/**
791+
* Stop transporter communication with other nodes
792+
*/
793+
globalTransporterRegistry.stopSending();
794+
globalTransporterRegistry.stopReceiving();
795+
796+
/**
797+
* Remove all transporters
798+
*/
799+
globalTransporterRegistry.removeAll();
800+
#endif
801+
802+
if(UNLOAD)
803+
{
804+
globalEmulatorData.theSimBlockList->unload();
805+
NdbMutex_Unlock(theShutdownMutex);
806+
globalEmulatorData.destroy();
807+
}
808+
809+
if(type != NST_Normal && type != NST_Restart)
810+
{
811+
g_eventLogger->info("Error handler shutdown completed - %s", exitAbort);
812+
#ifndef NDB_WIN
813+
if (opt_core)
814+
{
815+
childAbort(error_code, -1,g_currentStartPhase);
816+
}
817+
else
818+
#endif
819+
{
820+
childExit(error_code, -1,g_currentStartPhase);
821+
}
822+
}
823+
824+
/**
825+
* This is a normal restart, depend on angel
826+
*/
827+
if(type == NST_Restart){
828+
childExit(error_code, restartType,g_currentStartPhase);
829+
}
830+
831+
g_eventLogger->info("Shutdown completed - exiting");
832+
}
833+
else
834+
{
835+
/**
836+
* Shutdown is already in progress
837+
*/
838+
839+
/**
840+
* If this is the watchdog, kill system the hard way
841+
*/
842+
if (type== NST_Watchdog)
843+
{
844+
g_eventLogger->info("Watchdog is killing system the hard way");
845+
#if defined VM_TRACE
846+
childAbort(error_code, -1,g_currentStartPhase);
847+
#else
848+
childExit(error_code, -1, g_currentStartPhase);
849+
#endif
850+
}
851+
852+
while(true)
853+
NdbSleep_MilliSleep(10);
854+
}
855+
}

storage/ndb/src/kernel/ndbd.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,37 @@ ndbd_run(bool foreground, int report_fd,
2222
bool no_start, bool initial, bool initialstart,
2323
unsigned allocated_nodeid);
2424

25+
enum NdbShutdownType {
26+
NST_Normal,
27+
NST_Watchdog,
28+
NST_ErrorHandler,
29+
NST_ErrorHandlerSignal,
30+
NST_Restart,
31+
NST_ErrorInsert
32+
};
33+
34+
enum NdbRestartType {
35+
NRT_Default = 0,
36+
NRT_NoStart_Restart = 1, // -n
37+
NRT_DoStart_Restart = 2, //
38+
NRT_NoStart_InitialStart = 3, // -n -i
39+
NRT_DoStart_InitialStart = 4 // -i
40+
};
41+
42+
/**
43+
* Shutdown/restart Ndb
44+
*
45+
* @param error_code - The error causing shutdown/restart
46+
* @param type - Type of shutdown/restart
47+
* @param restartType - Type of restart (only valid if type == NST_Restart)
48+
*
49+
* NOTE! never returns
50+
*/
51+
void
52+
NdbShutdown(int error_code,
53+
NdbShutdownType type,
54+
NdbRestartType restartType = NRT_Default);
55+
56+
57+
2558
#endif

storage/ndb/src/kernel/vm/DynArr256.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -991,16 +991,6 @@ Uint32 g_currentStartPhase;
991991
Uint32 g_start_type;
992992
NdbNodeBitmask g_nowait_nodes;
993993

994-
void childExit(int code, Uint32 currentStartPhase)
995-
{
996-
abort();
997-
}
998-
999-
void childAbort(int code, Uint32 currentStartPhase)
1000-
{
1001-
abort();
1002-
}
1003-
1004994
void
1005995
UpgradeStartup::sendCmAppChg(Ndbcntr& cntr, Signal* signal, Uint32 startLevel){
1006996
}

0 commit comments

Comments
 (0)