updated logevent example

added handling of Arbit log events
parent 51def113
...@@ -42,8 +42,13 @@ ...@@ -42,8 +42,13 @@
int main() int main()
{ {
NdbMgmHandle h; NdbMgmHandle h;
NdbLogEventHandle l; NdbLogEventHandle le;
int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
15, NDB_MGM_EVENT_CATEGORY_CONNECTION,
15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART,
15, NDB_MGM_EVENT_CATEGORY_STARTUP,
15, NDB_MGM_EVENT_CATEGORY_ERROR,
0 };
struct ndb_logevent event; struct ndb_logevent event;
ndb_init(); ndb_init();
...@@ -56,48 +61,79 @@ int main() ...@@ -56,48 +61,79 @@ int main()
} }
if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h); if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h);
l= ndb_mgm_create_logevent_handle(h, filter); le= ndb_mgm_create_logevent_handle(h, filter);
if ( l == 0 ) MGMERROR(h); if ( le == 0 ) MGMERROR(h);
while (1) while (1)
{ {
int timeout= 5000; int timeout= 5000;
int r= ndb_logevent_get_next(l,&event,timeout); int r= ndb_logevent_get_next(le,&event,timeout);
if (r == 0) if (r == 0)
printf("No event within %d milliseconds\n", timeout); printf("No event within %d milliseconds\n", timeout);
else if (r < 0) else if (r < 0)
LOGEVENTERROR(l) LOGEVENTERROR(le)
else else
{ {
printf("Event %d from node ID %d\n",
event.type,
event.source_nodeid);
printf("Category %d, severity %d, level %d\n",
event.category,
event.severity,
event.level);
switch (event.type) { switch (event.type) {
case NDB_LE_BackupStarted: case NDB_LE_BackupStarted:
printf("BackupStartded\n"); printf("Node %d: BackupStarted\n", event.source_nodeid);
printf("Starting node ID: %d\n", event.BackupStarted.starting_node); printf(" Starting node ID: %d\n", event.BackupStarted.starting_node);
printf("Backup ID: %d\n", event.BackupStarted.backup_id); printf(" Backup ID: %d\n", event.BackupStarted.backup_id);
break; break;
case NDB_LE_BackupCompleted: case NDB_LE_BackupCompleted:
printf("BackupCompleted\n"); printf("Node %d: BackupCompleted\n", event.source_nodeid);
printf("Backup ID: %d\n", event.BackupStarted.backup_id); printf(" Backup ID: %d\n", event.BackupStarted.backup_id);
break; break;
case NDB_LE_BackupAborted: case NDB_LE_BackupAborted:
printf("Node %d: BackupAborted\n", event.source_nodeid);
break; break;
case NDB_LE_BackupFailedToStart: case NDB_LE_BackupFailedToStart:
printf("Node %d: BackupFailedToStart\n", event.source_nodeid);
break; break;
case NDB_LE_NodeFailCompleted:
printf("Node %d: NodeFailCompleted\n", event.source_nodeid);
break;
case NDB_LE_ArbitResult:
printf("Node %d: ArbitResult\n", event.source_nodeid);
printf(" code %d, arbit_node %d\n",
event.ArbitResult.code & 0xffff,
event.ArbitResult.arbit_node);
break;
case NDB_LE_DeadDueToHeartbeat:
printf("Node %d: DeadDueToHeartbeat\n", event.source_nodeid);
printf(" node %d\n", event.DeadDueToHeartbeat.node);
break;
case NDB_LE_Connected:
printf("Node %d: Connected\n", event.source_nodeid);
printf(" node %d\n", event.Connected.node);
break;
case NDB_LE_Disconnected:
printf("Node %d: Disconnected\n", event.source_nodeid);
printf(" node %d\n", event.Disconnected.node);
break;
case NDB_LE_NDBStartCompleted:
printf("Node %d: StartCompleted\n", event.source_nodeid);
printf(" version %d.%d.%d\n",
event.NDBStartCompleted.version >> 16 & 0xff,
event.NDBStartCompleted.version >> 8 & 0xff,
event.NDBStartCompleted.version >> 0 & 0xff);
break;
case NDB_LE_ArbitState:
printf("Node %d: ArbitState\n", event.source_nodeid);
printf(" code %d, arbit_node %d\n",
event.ArbitState.code & 0xffff,
event.ArbitResult.arbit_node);
break;
default: default:
printf("Unexpected event\n");
break; break;
} }
} }
} }
ndb_mgm_destroy_logevent_handle(&l); ndb_mgm_destroy_logevent_handle(&le);
ndb_mgm_destroy_handle(&h); ndb_mgm_destroy_handle(&h);
ndb_end(0); ndb_end(0);
return 0; return 0;
......
...@@ -286,101 +286,125 @@ extern "C" { ...@@ -286,101 +286,125 @@ extern "C" {
*/ */
union { union {
/* CONNECT */ /* CONNECT */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} Connected; } Connected;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} Disconnected; } Disconnected;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} CommunicationClosed; } CommunicationClosed;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} CommunicationOpened; } CommunicationOpened;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
unsigned version; unsigned version;
} ConnectedApiVersion; } ConnectedApiVersion;
/* CHECKPOINT */ /* CHECKPOINT */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned gci; unsigned gci;
} GlobalCheckpointStarted; } GlobalCheckpointStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned gci; unsigned gci;
} GlobalCheckpointCompleted; } GlobalCheckpointCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned lci; unsigned lci;
unsigned keep_gci; unsigned keep_gci;
unsigned restore_gci; unsigned restore_gci;
} LocalCheckpointStarted; } LocalCheckpointStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned lci; unsigned lci;
} LocalCheckpointCompleted; } LocalCheckpointCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned data; unsigned data;
} LCPStoppedInCalcKeepGci; } LCPStoppedInCalcKeepGci;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
unsigned table_id; unsigned table_id;
unsigned fragment_id; unsigned fragment_id;
} LCPFragmentCompleted; } LCPFragmentCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned acc_count; unsigned acc_count;
unsigned tup_count; unsigned tup_count;
} UndoLogBlocked; } UndoLogBlocked;
/* STARTUP */ /* STARTUP */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned version; unsigned version;
} NDBStartStarted; } NDBStartStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned version; unsigned version;
} NDBStartCompleted; } NDBStartCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} STTORRYRecieved; } STTORRYRecieved;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned phase; unsigned phase;
unsigned starttype; unsigned starttype;
} StartPhaseCompleted; } StartPhaseCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned own_id; unsigned own_id;
unsigned president_id; unsigned president_id;
unsigned dynamic_id; unsigned dynamic_id;
} CM_REGCONF; } CM_REGCONF;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned own_id; unsigned own_id;
unsigned other_id; unsigned other_id;
unsigned cause; unsigned cause;
} CM_REGREF; } CM_REGREF;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned own_id; unsigned own_id;
unsigned left_id; unsigned left_id;
unsigned right_id; unsigned right_id;
unsigned dynamic_id; unsigned dynamic_id;
} FIND_NEIGHBOURS; } FIND_NEIGHBOURS;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned stoptype; unsigned stoptype;
} NDBStopStarted; } NDBStopStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} NDBStopAborted; } NDBStopAborted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
unsigned keep_gci; unsigned keep_gci;
unsigned completed_gci; unsigned completed_gci;
unsigned restorable_gci; unsigned restorable_gci;
} StartREDOLog; } StartREDOLog;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned log_part; unsigned log_part;
unsigned start_mb; unsigned start_mb;
unsigned stop_mb; unsigned stop_mb;
unsigned gci; unsigned gci;
} StartLog; } StartLog;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned block; unsigned block;
unsigned data1; unsigned data1;
...@@ -396,48 +420,70 @@ extern "C" { ...@@ -396,48 +420,70 @@ extern "C" {
} UNDORecordsExecuted; } UNDORecordsExecuted;
/* NODERESTART */ /* NODERESTART */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} NR_CopyDict; } NR_CopyDict;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} NR_CopyDistr; } NR_CopyDistr;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned dest_node; unsigned dest_node;
} NR_CopyFragsStarted; } NR_CopyFragsStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned dest_node; unsigned dest_node;
unsigned table_id; unsigned table_id;
unsigned fragment_id; unsigned fragment_id;
} NR_CopyFragDone; } NR_CopyFragDone;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned dest_node; unsigned dest_node;
} NR_CopyFragsCompleted; } NR_CopyFragsCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned block; /* 0 = all */ unsigned block; /* 0 = all */
unsigned failed_node; unsigned failed_node;
unsigned completing_node; /* 0 = all */ unsigned completing_node; /* 0 = all */
} NodeFailCompleted; } NodeFailCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned failed_node; unsigned failed_node;
unsigned failure_state; unsigned failure_state;
} NODE_FAILREP; } NODE_FAILREP;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned code; /* code & state << 16 */
unsigned arbit_node;
unsigned ticket_0;
unsigned ticket_1;
/* TODO */ /* TODO */
} ArbitState; } ArbitState;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned code; /* code & state << 16 */
unsigned arbit_node;
unsigned ticket_0;
unsigned ticket_1;
/* TODO */ /* TODO */
} ArbitResult; } ArbitResult;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} GCP_TakeoverStarted; } GCP_TakeoverStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} GCP_TakeoverCompleted; } GCP_TakeoverCompleted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
} LCP_TakeoverStarted; } LCP_TakeoverStarted;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned state; unsigned state;
} LCP_TakeoverCompleted; } LCP_TakeoverCompleted;
/* STATISTIC */ /* STATISTIC */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned trans_count; unsigned trans_count;
unsigned commit_count; unsigned commit_count;
...@@ -450,23 +496,29 @@ extern "C" { ...@@ -450,23 +496,29 @@ extern "C" {
unsigned scan_count; unsigned scan_count;
unsigned range_scan_count; unsigned range_scan_count;
} TransReportCounters; } TransReportCounters;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned ops; unsigned ops;
} OperationReportCounters; } OperationReportCounters;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned table_id; unsigned table_id;
} TableCreated; } TableCreated;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned mean_loop_count; unsigned mean_loop_count;
} JobStatistic; } JobStatistic;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned to_node; unsigned to_node;
unsigned mean_sent_bytes; unsigned mean_sent_bytes;
} SendBytesStatistic; } SendBytesStatistic;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned from_node; unsigned from_node;
unsigned mean_received_bytes; unsigned mean_received_bytes;
} ReceiveBytesStatistic; } ReceiveBytesStatistic;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
int gth; int gth;
unsigned page_size_kb; unsigned page_size_kb;
...@@ -476,32 +528,40 @@ extern "C" { ...@@ -476,32 +528,40 @@ extern "C" {
} MemoryUsage; } MemoryUsage;
/* ERROR */ /* ERROR */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned to_node; unsigned to_node;
unsigned code; unsigned code;
} TransporterError; } TransporterError;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned to_node; unsigned to_node;
unsigned code; unsigned code;
} TransporterWarning; } TransporterWarning;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
unsigned count; unsigned count;
} MissedHeartbeat; } MissedHeartbeat;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} DeadDueToHeartbeat; } DeadDueToHeartbeat;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
/* TODO */ /* TODO */
} WarningEvent; } WarningEvent;
/* INFO */ /* INFO */
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} SentHeartbeat; } SentHeartbeat;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
unsigned node; unsigned node;
} CreateLogBytes; } CreateLogBytes;
/** Log event specific data for for corresponding NDB_LE_ log event */
struct { struct {
/* TODO */ /* TODO */
} InfoEvent; } InfoEvent;
......
...@@ -197,10 +197,16 @@ struct Ndb_logevent_body_row ndb_logevent_body[]= { ...@@ -197,10 +197,16 @@ struct Ndb_logevent_body_row ndb_logevent_body[]= {
ROW( NODE_FAILREP, "failure_state", 2, failure_state), ROW( NODE_FAILREP, "failure_state", 2, failure_state),
/* TODO */ /* TODO */
// ROW( ArbitState), ROW( ArbitState, "code", 1, code),
ROW( ArbitState, "arbit_node", 2, arbit_node),
ROW( ArbitState, "ticket_0", 3, ticket_0),
ROW( ArbitState, "ticket_1", 4, ticket_1),
/* TODO */ /* TODO */
// ROW( ArbitResult), ROW( ArbitResult, "code", 1, code),
ROW( ArbitResult, "arbit_node", 2, arbit_node),
ROW( ArbitResult, "ticket_0", 3, ticket_0),
ROW( ArbitResult, "ticket_1", 4, ticket_1),
// ROW( GCP_TakeoverStarted), // ROW( GCP_TakeoverStarted),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment