19 #include <ndb_global.h>
21 #include <ndbd_exit_codes.h>
22 #include "ErrorReporter.hpp"
24 #include <FastScheduler.hpp>
25 #include <DebuggerNames.hpp>
27 #include <NdbConfig.h>
28 #include <Configuration.hpp>
29 #include "EventLogger.hpp"
32 #include "TimeModule.hpp"
34 #include <NdbAutoPtr.hpp>
36 #define MESSAGE_LENGTH 500
38 static int WriteMessage(
int thrdMessageID,
39 const char* thrdProblemData,
40 const char* thrdObjRef,
41 NdbShutdownType & nst);
43 static void dumpJam(FILE* jamStream,
44 Uint32 thrdTheEmulatedJamIndex,
45 const Uint32 thrdTheEmulatedJam[],
50 ErrorReporter::formatTimeStampString(){
53 static char theDateTimeString[39];
57 DateTime.setTimeStamp();
60 DateTime.getDayName(), DateTime.getDayOfMonth(),
61 DateTime.getMonthName(), DateTime.getYear(), DateTime.getHour(),
62 DateTime.getMinute(), DateTime.getSecond());
64 return (
const char *)&theDateTimeString;
71 unsigned int traceFileNo;
73 char *file_name= NdbConfig_NextTraceFileName(globalData.ownId);
79 stream = fopen(file_name,
"r+");
84 fgets(buf, 255, stream);
85 const int scan = sscanf(buf,
"%u", &traceFileNo);
96 Uint32 tmp = globalEmulatorData.theConfiguration->maxNoOfErrorLogs();
97 if (traceFileNo > tmp ) {
104 stream = fopen(file_name,
"w");
106 fprintf(stream,
"%u", traceFileNo);
114 extern "C" const char* my_progname;
117 ErrorReporter::formatMessage(
int thr_no,
118 Uint32 num_threads,
int faultID,
119 const char* problemData,
121 const char* theNameOfTheTraceFile,
124 ndbd_exit_classification cl;
126 const char *exit_msg = ndbd_exit_message(faultID, &cl);
127 const char *exit_cl_msg = ndbd_exit_classification_message(cl, &st);
128 const char *exit_st_msg = ndbd_exit_status_message(st);
131 processId = NdbHost_GetProcessId();
132 char thrbuf[100] =
"";
149 formatTimeStampString() ,
151 exit_msg, exit_cl_msg,
153 (problemData == NULL) ?
"" : problemData,
159 theNameOfTheTraceFile ?
160 theNameOfTheTraceFile :
"<no tracefile>");
162 if (theNameOfTheTraceFile)
164 for (Uint32
i = 1 ;
i < num_threads;
i++)
166 sofar = strlen(messptr);
167 if(sofar < MESSAGE_LENGTH)
170 " %s_t%u", theNameOfTheTraceFile,
i);
175 sofar = strlen(messptr);
176 if(sofar < MESSAGE_LENGTH)
184 while (strlen(messptr) <= MESSAGE_LENGTH-3){
185 strcat(messptr,
" ");
188 messptr[MESSAGE_LENGTH -2]=
'\n';
189 messptr[MESSAGE_LENGTH -1]=0;
194 NdbShutdownType ErrorReporter::s_errorHandlerShutdownType = NST_ErrorHandler;
197 ErrorReporter::handleAssert(
const char*
message,
const char*
file,
int line,
int ec)
199 char refMessage[100];
200 Uint32 jamBlockNumber;
202 #ifdef NO_EMULATED_JAM
211 jamBlockNumber = jamBuffer->theEmulatedJamBlockNumber;
212 const char *blockName = getBlockName(jamBlockNumber);
215 file, line, blockName);
217 NdbShutdownType nst = s_errorHandlerShutdownType;
218 WriteMessage(ec, message, refMessage, nst);
220 NdbShutdown(ec, nst);
225 ErrorReporter::handleError(
int messageID,
226 const char* problemData,
230 if(messageID == NDBD_EXIT_ERROR_INSERT)
232 nst = NST_ErrorInsert;
236 if (nst == NST_ErrorHandler)
237 nst = s_errorHandlerShutdownType;
240 WriteMessage(messageID, problemData, objRef, nst);
242 g_eventLogger->
info(
"%s", problemData);
243 g_eventLogger->
info(
"%s", objRef);
245 NdbShutdown(messageID, nst);
250 WriteMessage(
int thrdMessageID,
251 const char* thrdProblemData,
252 const char* thrdObjRef,
253 NdbShutdownType & nst){
256 unsigned long maxOffset;
257 char theMessage[MESSAGE_LENGTH];
258 Uint32 thrdTheEmulatedJamIndex;
259 const Uint32 *thrdTheEmulatedJam;
260 Uint32 jamBlockNumber;
262 Uint32 threadCount = globalScheduler.traceDumpGetNumThreads();
263 int thr_no = globalScheduler.traceDumpGetCurrentThread();
268 char *theTraceFileName= 0;
269 if (globalData.ownId > 0)
270 theTraceFileName= NdbConfig_TraceFileName(globalData.ownId,
275 Uint32 noMsg = globalEmulatorData.theConfiguration->maxNoOfErrorLogs();
277 maxOffset = (69 + (noMsg * MESSAGE_LENGTH));
279 char *theErrorFileName= (
char *)NdbConfig_ErrorFileName(globalData.ownId);
282 stream = fopen(theErrorFileName,
"r+");
283 if (stream == NULL) {
287 stream = fopen(theErrorFileName,
"w");
290 fprintf(stderr,
"Unable to open error log file: %s\n", theErrorFileName);
293 fprintf(stream,
"%s%u%s",
"Current byte-offset of file-pointer is: ", 69,
297 ErrorReporter::formatMessage(thr_no,
298 threadCount, thrdMessageID,
299 thrdProblemData, thrdObjRef,
300 theTraceFileName, theMessage);
301 fprintf(stream,
"%s", theMessage);
307 offset = ftell(stream);
309 if (offset <= (maxOffset - MESSAGE_LENGTH)){
310 fseek(stream, 40, SEEK_SET);
312 fprintf(stream,
"%d", offset);
314 fseek(stream, 40, SEEK_SET);
316 fprintf(stream,
"%u%s", 69,
" ");
320 fseek(stream, 40, SEEK_SET);
321 fscanf(stream,
"%u", &offset);
322 fseek(stream, offset, SEEK_SET);
325 ErrorReporter::formatMessage(thr_no,
326 threadCount, thrdMessageID,
327 thrdProblemData, thrdObjRef,
328 theTraceFileName, theMessage);
329 fprintf(stream,
"%s", theMessage);
335 offset = ftell(stream);
338 if (offset <= (maxOffset - MESSAGE_LENGTH)){
339 fseek(stream, 40, SEEK_SET);
341 fprintf(stream,
"%d", offset);
343 fseek(stream, 40, SEEK_SET);
345 fprintf(stream,
"%u%s", 69,
" ");
351 if (theTraceFileName) {
353 globalScheduler.traceDumpPrepare(nst);
355 char *traceFileEnd = theTraceFileName + strlen(theTraceFileName);
356 for (Uint32
i = 0;
i < threadCount;
i++)
360 sprintf(traceFileEnd,
"_t%u",
i);
361 FILE *jamStream = fopen(theTraceFileName,
"w");
364 bool ok = globalScheduler.traceDumpGetJam(
i, jamBlockNumber,
366 thrdTheEmulatedJamIndex);
367 if(ok && thrdTheEmulatedJam != 0)
369 dumpJam(jamStream, thrdTheEmulatedJamIndex,
370 thrdTheEmulatedJam, jamBlockNumber);
373 globalScheduler.dumpSignalMemory(
i, jamStream);
383 dumpJam(FILE *jamStream,
384 Uint32 thrdTheEmulatedJamIndex,
385 const Uint32 thrdTheEmulatedJam[],
386 Uint32 aBlockNumber) {
387 #ifndef NO_EMULATED_JAM
389 const int maxaddr = 8;
390 fprintf(jamStream,
"JAM CONTENTS up->down left->right ?=not block entry\n");
391 fprintf(jamStream,
"%-7s ",
"BLOCK");
392 for (
int i = 0;
i < maxaddr;
i++)
393 fprintf(jamStream,
"%-6s ",
"ADDR");
394 fprintf(jamStream,
"\n");
396 const int first = thrdTheEmulatedJamIndex;
400 for (cnt = 0, idx = first; cnt < EMULATED_JAM_SIZE; cnt++, idx++) {
401 if (idx >= EMULATED_JAM_SIZE)
403 const Uint32 aJamEntry = thrdTheEmulatedJam[idx];
404 if (aJamEntry > (1 << 20))
414 else if (cnt < EMULATED_JAM_SIZE)
415 fprintf(jamStream,
"%-7s?",
"");
417 const char *aBlockName = getBlockName(aBlockNumber);
419 fprintf(jamStream,
"%-7s?", aBlockName);
421 fprintf(jamStream,
"0x%-5X?", aBlockNumber);
426 for (cnt = 0, idx = first; cnt < EMULATED_JAM_SIZE; cnt++, idx++) {
427 globalData.incrementWatchDogCounter(4);
428 if (idx >= EMULATED_JAM_SIZE)
430 const Uint32 aJamEntry = thrdTheEmulatedJam[idx];
431 if (aJamEntry > (1 << 20)) {
432 const Uint32 aBlockNumber = aJamEntry >> 20;
433 const char *aBlockName = getBlockName(aBlockNumber);
435 fprintf(jamStream,
"\n");
437 fprintf(jamStream,
"%-7s ", aBlockName);
439 fprintf(jamStream,
"0x%-5X ", aBlockNumber);
442 if (cntaddr == maxaddr) {
443 fprintf(jamStream,
"\n%-7s ",
"");
446 fprintf(jamStream,
"%06u ", aJamEntry & 0xFFFFF);
449 fprintf(jamStream,
"\n");
451 #endif // ifndef NO_EMULATED_JAM