18 #include <ndb_global.h>
20 #include <mgmapi_internal.h>
23 #include <Properties.hpp>
24 #include <InputStream.hpp>
27 #include <debugger/EventLogger.hpp>
28 #include <kernel/NodeBitmask.hpp>
30 #include "ndb_logevent.hpp"
33 int ndb_mgm_listen_event_internal(
NdbMgmHandle,
const int filter[],
34 int, NDB_SOCKET_TYPE*);
37 enum ndb_logevent_handle_error
code;
42 { NDB_LEH_READ_ERROR,
"Read error" },
43 { NDB_LEH_MISSING_EVENT_SPECIFIER,
"Missing event specifier" },
44 { NDB_LEH_UNKNOWN_EVENT_VARIABLE,
"Unknown event variable" },
45 { NDB_LEH_UNKNOWN_EVENT_TYPE,
"Unknown event type" },
46 { NDB_LEH_INTERNAL_ERROR,
"Unknown internal error" },
51 NDB_SOCKET_TYPE socket;
52 enum ndb_logevent_handle_error m_error;
61 ndb_mgm_create_logevent_handle_same_socket(
NdbMgmHandle mh)
68 h->socket= _ndb_mgm_get_socket(mh);
84 if(ndb_mgm_listen_event_internal(mh, filter, 1, &sock) < 0)
117 my_socket_close((*h)->socket);
123 #define ROW(a,b,c,d) \
124 { NDB_LE_ ## a, b, c, 0, offsetof(struct ndb_logevent, a.d), \
125 sizeof(((struct ndb_logevent *)0)->a.d) }
127 #define ROW_FN(a,b,c,d,e) \
128 { NDB_LE_ ## a, b, c, e, offsetof(struct ndb_logevent, a.d), \
129 sizeof(((struct ndb_logevent *)0)->a.d) }
131 static int ref_to_node(
int ref){
138 ROW( Connected,
"node", 1, node),
140 ROW( Disconnected,
"node", 1, node),
142 ROW( CommunicationClosed,
"node", 1, node),
144 ROW( CommunicationOpened,
"node", 1, node),
146 ROW( ConnectedApiVersion,
"node", 1, node),
147 ROW( ConnectedApiVersion,
"version", 2, version),
151 ROW( GlobalCheckpointStarted,
"gci", 1, gci),
153 ROW( GlobalCheckpointCompleted,
"gci", 1, gci),
155 ROW( LocalCheckpointStarted,
"lci", 1, lci),
156 ROW( LocalCheckpointStarted,
"keep_gci", 2, keep_gci),
157 ROW( LocalCheckpointStarted,
"restore_gci", 3, restore_gci),
159 ROW( LocalCheckpointCompleted,
"lci", 1, lci),
161 ROW( LCPStoppedInCalcKeepGci,
"data", 1, data),
163 ROW( LCPFragmentCompleted,
"node", 1, node),
164 ROW( LCPFragmentCompleted,
"table_id", 2, table_id),
165 ROW( LCPFragmentCompleted,
"fragment_id", 3, fragment_id),
167 ROW( UndoLogBlocked,
"acc_count", 1, acc_count),
168 ROW( UndoLogBlocked,
"tup_count", 2, tup_count),
171 ROW( NDBStartStarted,
"version", 1, version),
173 ROW( NDBStartCompleted,
"version", 1, version),
177 ROW( StartPhaseCompleted,
"phase", 1, phase),
178 ROW( StartPhaseCompleted,
"starttype", 2, starttype),
180 ROW( CM_REGCONF,
"own_id", 1, own_id),
181 ROW( CM_REGCONF,
"president_id", 2, president_id),
182 ROW( CM_REGCONF,
"dynamic_id", 3, dynamic_id),
184 ROW( CM_REGREF,
"own_id", 1, own_id),
185 ROW( CM_REGREF,
"other_id", 2, other_id),
186 ROW( CM_REGREF,
"cause", 3, cause),
188 ROW( FIND_NEIGHBOURS,
"own_id", 1, own_id),
189 ROW( FIND_NEIGHBOURS,
"left_id", 3, left_id),
190 ROW( FIND_NEIGHBOURS,
"right_id", 3, right_id),
191 ROW( FIND_NEIGHBOURS,
"dynamic_id", 4, dynamic_id),
193 ROW( NDBStopStarted,
"stoptype", 1, stoptype),
195 ROW( NDBStopCompleted,
"action", 1, action),
196 ROW( NDBStopCompleted,
"signum", 2, signum),
198 ROW( NDBStopForced,
"action", 1, action),
199 ROW( NDBStopForced,
"signum", 2, signum),
200 ROW( NDBStopForced,
"error", 3, error),
201 ROW( NDBStopForced,
"sphase", 4, sphase),
202 ROW( NDBStopForced,
"extra", 5,
extra),
206 ROW( StartREDOLog,
"node", 1, node),
207 ROW( StartREDOLog,
"keep_gci", 2, keep_gci),
208 ROW( StartREDOLog,
"completed_gci", 3, completed_gci),
209 ROW( StartREDOLog,
"restorable_gci", 4, restorable_gci),
211 ROW( StartLog,
"log_part", 1, log_part),
212 ROW( StartLog,
"start_mb", 2, start_mb),
213 ROW( StartLog,
"stop_mb", 3, stop_mb),
214 ROW( StartLog,
"gci", 4, gci),
216 ROW( UNDORecordsExecuted,
"block", 1,
block),
217 ROW( UNDORecordsExecuted,
"data1", 2, data1),
218 ROW( UNDORecordsExecuted,
"data2", 3, data2),
219 ROW( UNDORecordsExecuted,
"data3", 4, data3),
220 ROW( UNDORecordsExecuted,
"data4", 5, data4),
221 ROW( UNDORecordsExecuted,
"data5", 6, data5),
222 ROW( UNDORecordsExecuted,
"data6", 7, data6),
223 ROW( UNDORecordsExecuted,
"data7", 8, data7),
224 ROW( UNDORecordsExecuted,
"data8", 9, data8),
225 ROW( UNDORecordsExecuted,
"data9", 10, data9),
226 ROW( UNDORecordsExecuted,
"data10", 11, data10),
233 ROW( NR_CopyFragsStarted,
"dest_node", 1, dest_node),
235 ROW( NR_CopyFragDone,
"dest_node", 1, dest_node),
236 ROW( NR_CopyFragDone,
"table_id", 2, table_id),
237 ROW( NR_CopyFragDone,
"fragment_id", 3, fragment_id),
239 ROW( NR_CopyFragsCompleted,
"dest_node", 1, dest_node),
241 ROW( NodeFailCompleted,
"block", 1,
block),
242 ROW( NodeFailCompleted,
"failed_node", 2, failed_node),
243 ROW( NodeFailCompleted,
"completing_node", 3, completing_node),
245 ROW( NODE_FAILREP,
"failed_node", 1, failed_node),
246 ROW( NODE_FAILREP,
"failure_state", 2, failure_state),
249 ROW( ArbitState,
"code", 1,
code),
250 ROW( ArbitState,
"arbit_node", 2, arbit_node),
251 ROW( ArbitState,
"ticket_0", 3, ticket_0),
252 ROW( ArbitState,
"ticket_1", 4, ticket_1),
255 ROW( ArbitResult,
"code", 1,
code),
256 ROW( ArbitResult,
"arbit_node", 2, arbit_node),
257 ROW( ArbitResult,
"ticket_0", 3, ticket_0),
258 ROW( ArbitResult,
"ticket_1", 4, ticket_1),
266 ROW( LCP_TakeoverCompleted,
"state", 1, state),
269 ROW( TransReportCounters,
"trans_count", 1, trans_count),
270 ROW( TransReportCounters,
"commit_count", 2, commit_count),
271 ROW( TransReportCounters,
"read_count", 3, read_count),
272 ROW( TransReportCounters,
"simple_read_count", 4, simple_read_count),
273 ROW( TransReportCounters,
"write_count", 5, write_count),
274 ROW( TransReportCounters,
"attrinfo_count", 6, attrinfo_count),
275 ROW( TransReportCounters,
"conc_op_count", 7, conc_op_count),
276 ROW( TransReportCounters,
"abort_count", 8, abort_count),
277 ROW( TransReportCounters,
"scan_count", 9, scan_count),
278 ROW( TransReportCounters,
"range_scan_count", 10, range_scan_count),
280 ROW( OperationReportCounters,
"ops", 1, ops),
282 ROW( TableCreated,
"table_id", 1, table_id),
284 ROW( JobStatistic,
"mean_loop_count", 1, mean_loop_count),
286 ROW( SendBytesStatistic,
"to_node", 1, to_node),
287 ROW( SendBytesStatistic,
"mean_sent_bytes", 2, mean_sent_bytes),
289 ROW( ReceiveBytesStatistic,
"from_node", 1, from_node),
290 ROW( ReceiveBytesStatistic,
"mean_received_bytes", 2, mean_received_bytes),
292 ROW( MemoryUsage,
"gth", 1, gth),
293 ROW( MemoryUsage,
"page_size_bytes", 2, page_size_bytes),
294 ROW( MemoryUsage,
"pages_used", 3, pages_used),
295 ROW( MemoryUsage,
"pages_total", 4, pages_total),
296 ROW( MemoryUsage,
"block", 5,
block),
298 ROW( MTSignalStatistics,
"mt_deliver_thread", 1, thr_no),
299 ROW( MTSignalStatistics,
"mt_prioa_count", 2, prioa_count),
300 ROW( MTSignalStatistics,
"mt_prioa_size", 3, prioa_size),
301 ROW( MTSignalStatistics,
"mt_priob_count", 4, priob_count),
302 ROW( MTSignalStatistics,
"mt_priob_size", 5, priob_size),
305 ROW( TransporterError,
"to_node", 1, to_node),
306 ROW( TransporterError,
"code", 2,
code),
308 ROW( TransporterWarning,
"to_node", 1, to_node),
309 ROW( TransporterWarning,
"code", 2,
code),
311 ROW( MissedHeartbeat,
"node", 1, node),
312 ROW( MissedHeartbeat,
"count", 2, count),
314 ROW( DeadDueToHeartbeat,
"node", 1, node),
320 ROW( SentHeartbeat,
"node", 1, node),
322 ROW( CreateLogBytes,
"node", 1, node),
327 ROW( EventBufferStatus,
"usage", 1, usage),
328 ROW( EventBufferStatus,
"alloc", 2, alloc),
329 ROW( EventBufferStatus,
"max", 3, max),
330 ROW( EventBufferStatus,
"apply_gci_l", 4, apply_gci_l),
331 ROW( EventBufferStatus,
"apply_gci_h", 5, apply_gci_h),
332 ROW( EventBufferStatus,
"latest_gci_l", 6, latest_gci_l),
333 ROW( EventBufferStatus,
"latest_gci_h", 7, latest_gci_h),
336 ROW_FN( BackupStarted,
"starting_node", 1, starting_node, ref_to_node),
337 ROW( BackupStarted,
"backup_id", 2, backup_id),
339 ROW_FN(BackupFailedToStart,
"starting_node",1, starting_node, ref_to_node),
340 ROW( BackupFailedToStart,
"error", 2, error),
342 ROW_FN( BackupCompleted,
"starting_node", 1, starting_node, ref_to_node),
343 ROW( BackupCompleted,
"backup_id", 2, backup_id),
344 ROW( BackupCompleted,
"start_gci", 3, start_gci),
345 ROW( BackupCompleted,
"stop_gci", 4, stop_gci),
346 ROW( BackupCompleted,
"n_bytes", 5, n_bytes),
347 ROW( BackupCompleted,
"n_records", 6, n_records),
348 ROW( BackupCompleted,
"n_log_bytes", 7, n_log_bytes),
349 ROW( BackupCompleted,
"n_log_records", 8, n_log_records),
350 ROW( BackupCompleted,
"n_bytes_hi", 9+NdbNodeBitmask::Size, n_bytes_hi),
351 ROW( BackupCompleted,
"n_records_hi", 10+NdbNodeBitmask::Size, n_records_hi),
352 ROW( BackupCompleted,
"n_log_bytes_hi", 11+NdbNodeBitmask::Size, n_log_bytes_hi),
353 ROW( BackupCompleted,
"n_log_records_hi", 12+NdbNodeBitmask::Size, n_log_records_hi),
355 ROW_FN( BackupStatus,
"starting_node", 1, starting_node, ref_to_node),
356 ROW( BackupStatus,
"backup_id", 2, backup_id),
357 ROW( BackupStatus,
"n_bytes_lo", 3, n_bytes_lo),
358 ROW( BackupStatus,
"n_bytes_hi", 4, n_bytes_hi),
359 ROW( BackupStatus,
"n_records_lo", 5, n_records_lo),
360 ROW( BackupStatus,
"n_records_hi", 6, n_records_hi),
361 ROW( BackupStatus,
"n_log_bytes_lo", 7, n_log_bytes_lo),
362 ROW( BackupStatus,
"n_log_bytes_hi", 8, n_log_bytes_hi),
363 ROW( BackupStatus,
"n_log_records_lo", 9, n_log_records_lo),
364 ROW( BackupStatus,
"n_log_records_hi",10, n_log_records_hi),
366 ROW_FN( BackupAborted,
"starting_node", 1, starting_node, ref_to_node),
367 ROW( BackupAborted,
"backup_id", 2, backup_id),
368 ROW( BackupAborted,
"error", 3, error),
370 ROW( RestoreStarted,
"backup_id", 1, backup_id),
371 ROW( RestoreStarted,
"node_id", 2, node_id),
381 ROW( RestoreData,
"backup_id", 1, backup_id),
382 ROW( RestoreData,
"node_id", 2, node_id),
383 ROW( RestoreData,
"n_records_lo", 3, n_records_lo),
384 ROW( RestoreData,
"n_records_hi", 4, n_records_hi),
385 ROW( RestoreData,
"n_bytes_lo", 5, n_bytes_lo),
386 ROW( RestoreData,
"n_bytes_hi", 6, n_bytes_hi),
388 ROW( RestoreLog,
"backup_id", 1, backup_id),
389 ROW( RestoreLog,
"node_id", 2, node_id),
390 ROW( RestoreLog,
"n_records_lo", 3, n_records_lo),
391 ROW( RestoreLog,
"n_records_hi", 4, n_records_hi),
392 ROW( RestoreLog,
"n_bytes_lo", 5, n_bytes_lo),
393 ROW( RestoreLog,
"n_bytes_hi", 6, n_bytes_hi),
395 ROW( RestoreCompleted,
"backup_id", 1, backup_id),
396 ROW( RestoreCompleted,
"node_id", 2, node_id),
398 ROW( SingleUser,
"type", 1,
type),
399 ROW( SingleUser,
"node_id", 2, node_id),
401 ROW( LogFileInitStatus,
"node_id", 1, node_id ),
402 ROW( LogFileInitStatus,
"total_files", 2, total_files),
403 ROW( LogFileInitStatus,
"file_done", 3, file_done),
404 ROW( LogFileInitStatus,
"total_mbytes", 4, total_mbytes),
405 ROW( LogFileInitStatus,
"mbytes_done", 5, mbytes_done),
407 { NDB_LE_ILLEGAL_TYPE, 0, 0, 0, 0, 0}
417 { a, offsetof(struct ndb_logevent, b), \
418 sizeof(((struct ndb_logevent *)0)->b) }
423 ROW2(
"source_nodeid", source_nodeid),
428 insert_row(
const char * pair,
Properties & p){
433 tmp.split(split,
":=", 2);
434 if(split.size() != 2)
436 p.
put(split[0].trim().c_str(), split[1].trim().c_str());
442 int memcpy_atoi(
void *dst,
const char *str,
int sz)
454 Int16 val= atoi(str);
460 Int32 val= atoi(str);
466 Int64 val= atoi(str);
480 unsigned timeout_in_milliseconds)
482 if (timeout_in_milliseconds == 0)
497 NDB_TICKS start = NdbTick_CurrentMillisecond();
500 if (in.gets(buf,
sizeof(buf)) == 0)
502 h->m_error= NDB_LEH_READ_ERROR;
511 if ( strcmp(
"log event reply\n", buf) == 0 )
514 if ( strcmp(
"<PING>\n", buf) )
515 ndbout_c(
"skipped: %s", buf);
520 if ((NdbTick_CurrentMillisecond() - start) > timeout_in_milliseconds)
529 if (in.gets(buf,
sizeof(buf)) == 0)
531 h->m_error= NDB_LEH_READ_ERROR;
537 if ( buf[0] ==
'\n' )
541 if (insert_row(buf,p))
543 h->m_error= NDB_LEH_READ_ERROR;
553 for (i= 0; ndb_logevent_header[
i].token; i++)
555 if ( p.get(ndb_logevent_header[i].token, &val) == 0 )
557 ndbout_c(
"missing: %s\n", ndb_logevent_header[i].token);
558 h->m_error= NDB_LEH_MISSING_EVENT_SPECIFIER;
561 if ( memcpy_atoi((
char *)dst+ndb_logevent_header[i].
offset, val,
562 ndb_logevent_header[i].
size) )
564 h->m_error= NDB_LEH_INTERNAL_ERROR;
570 LogLevel::EventCategory category;
575 if (EventLoggerBase::event_lookup(dst->
type,category,level,severity,text_fn))
577 ndbout_c(
"unknown type: %d\n", dst->
type);
578 h->m_error= NDB_LEH_UNKNOWN_EVENT_TYPE;
586 for (i= 0; ndb_logevent_body[
i].token; i++)
588 if ( ndb_logevent_body[i].
type == dst->
type )
592 if (ndb_logevent_body[i].token)
596 if ( p.get(ndb_logevent_body[i].token, &val) == 0 )
598 h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE;
601 if ( memcpy_atoi((
char *)dst+ndb_logevent_body[i].
offset, val,
602 ndb_logevent_body[i].
size) )
604 h->m_error= NDB_LEH_INTERNAL_ERROR;
607 }
while (ndb_logevent_body[++i].
type == dst->
type);
611 if (!p.get(
"data", &val))
613 h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE;
619 for (
size_t j = 0; j<list.size(); j++)
621 dst->
Data[j] = atoi(list[j].c_str());
636 for (
int i= 0; ndb_logevent_error_messages[
i].msg;
i++)
637 if (ndb_logevent_error_messages[
i].
code == h->m_error)
638 return ndb_logevent_error_messages[
i].msg;
639 return "<unknown error msg>";