1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <ndb_global.h>
21
#include <Properties.hpp>
22
#include <socket_io.h>
23
#include <InputStream.hpp>
25
#include <debugger/EventLogger.hpp>
27
#include "ndb_logevent.hpp"
30
int ndb_mgm_listen_event_internal(NdbMgmHandle, const int filter[], int);
32
struct ndb_logevent_error_msg {
33
enum ndb_logevent_handle_error code;
37
struct ndb_logevent_error_msg ndb_logevent_error_messages[]= {
38
{ NDB_LEH_READ_ERROR, "Read error" },
39
{ NDB_LEH_MISSING_EVENT_SPECIFIER, "Missing event specifier" },
40
{ NDB_LEH_UNKNOWN_EVENT_VARIABLE, "Unknown event variable" },
41
{ NDB_LEH_UNKNOWN_EVENT_TYPE, "Unknown event type" },
42
{ NDB_LEH_INTERNAL_ERROR, "Unknown internal error" },
46
struct ndb_logevent_handle {
47
NDB_SOCKET_TYPE socket;
48
enum ndb_logevent_handle_error m_error;
53
ndb_mgm_create_logevent_handle(NdbMgmHandle mh,
56
int fd= ndb_mgm_listen_event_internal(mh, filter, 1);
62
(NdbLogEventHandle)my_malloc(sizeof(ndb_logevent_handle),MYF(MY_WME));
71
ndb_logevent_get_fd(const NdbLogEventHandle h)
77
void ndb_mgm_destroy_logevent_handle(NdbLogEventHandle * h)
85
my_free((char*)* h,MYF(MY_ALLOW_ZERO_PTR));
89
#define ROW(a,b,c,d) \
90
{ NDB_LE_ ## a, b, c, 0, offsetof(struct ndb_logevent, a.d), \
91
sizeof(((struct ndb_logevent *)0)->a.d) }
93
#define ROW_FN(a,b,c,d,e) \
94
{ NDB_LE_ ## a, b, c, e, offsetof(struct ndb_logevent, a.d), \
95
sizeof(((struct ndb_logevent *)0)->a.d) }
97
static int ref_to_node(int ref){
101
struct Ndb_logevent_body_row ndb_logevent_body[]= {
104
ROW( Connected, "node", 1, node),
106
ROW( Disconnected, "node", 1, node),
108
ROW( CommunicationClosed, "node", 1, node),
110
ROW( CommunicationOpened, "node", 1, node),
112
ROW( ConnectedApiVersion, "node", 1, node),
113
ROW( ConnectedApiVersion, "version", 2, version),
117
ROW( GlobalCheckpointStarted, "gci", 1, gci),
119
ROW( GlobalCheckpointCompleted, "gci", 1, gci),
121
ROW( LocalCheckpointStarted, "lci", 1, lci),
122
ROW( LocalCheckpointStarted, "keep_gci", 2, keep_gci),
123
ROW( LocalCheckpointStarted, "restore_gci", 3, restore_gci),
125
ROW( LocalCheckpointCompleted, "lci", 1, lci),
127
ROW( LCPStoppedInCalcKeepGci, "data", 1, data),
129
ROW( LCPFragmentCompleted, "node", 1, node),
130
ROW( LCPFragmentCompleted, "table_id", 2, table_id),
131
ROW( LCPFragmentCompleted, "fragment_id", 3, fragment_id),
133
ROW( UndoLogBlocked, "acc_count", 1, acc_count),
134
ROW( UndoLogBlocked, "tup_count", 2, tup_count),
137
ROW( NDBStartStarted, "version", 1, version),
139
ROW( NDBStartCompleted, "version", 1, version),
141
// ROW( STTORRYRecieved),
143
ROW( StartPhaseCompleted, "phase", 1, phase),
144
ROW( StartPhaseCompleted, "starttype", 2, starttype),
146
ROW( CM_REGCONF, "own_id", 1, own_id),
147
ROW( CM_REGCONF, "president_id", 2, president_id),
148
ROW( CM_REGCONF, "dynamic_id", 3, dynamic_id),
150
ROW( CM_REGREF, "own_id", 1, own_id),
151
ROW( CM_REGREF, "other_id", 2, other_id),
152
ROW( CM_REGREF, "cause", 3, cause),
154
ROW( FIND_NEIGHBOURS, "own_id", 1, own_id),
155
ROW( FIND_NEIGHBOURS, "left_id", 3, left_id),
156
ROW( FIND_NEIGHBOURS, "right_id", 3, right_id),
157
ROW( FIND_NEIGHBOURS, "dynamic_id", 4, dynamic_id),
159
ROW( NDBStopStarted, "stoptype", 1, stoptype),
161
ROW( NDBStopCompleted, "action", 1, action),
162
ROW( NDBStopCompleted, "signum", 2, signum),
164
ROW( NDBStopForced, "action", 1, action),
165
ROW( NDBStopForced, "signum", 2, signum),
166
ROW( NDBStopForced, "error", 3, error),
167
ROW( NDBStopForced, "sphase", 4, sphase),
168
ROW( NDBStopForced, "extra", 5, extra),
170
// ROW( NDBStopAborted),
172
ROW( StartREDOLog, "node", 1, node),
173
ROW( StartREDOLog, "keep_gci", 2, keep_gci),
174
ROW( StartREDOLog, "completed_gci", 3, completed_gci),
175
ROW( StartREDOLog, "restorable_gci", 4, restorable_gci),
177
ROW( StartLog, "log_part", 1, log_part),
178
ROW( StartLog, "start_mb", 2, start_mb),
179
ROW( StartLog, "stop_mb", 3, stop_mb),
180
ROW( StartLog, "gci", 4, gci),
182
ROW( UNDORecordsExecuted, "block", 1, block),
183
ROW( UNDORecordsExecuted, "data1", 2, data1),
184
ROW( UNDORecordsExecuted, "data2", 3, data2),
185
ROW( UNDORecordsExecuted, "data3", 4, data3),
186
ROW( UNDORecordsExecuted, "data4", 5, data4),
187
ROW( UNDORecordsExecuted, "data5", 6, data5),
188
ROW( UNDORecordsExecuted, "data6", 7, data6),
189
ROW( UNDORecordsExecuted, "data7", 8, data7),
190
ROW( UNDORecordsExecuted, "data8", 9, data8),
191
ROW( UNDORecordsExecuted, "data9", 10, data9),
192
ROW( UNDORecordsExecuted, "data10", 11, data10),
195
// ROW( NR_CopyDict),
197
// ROW( NR_CopyDistr),
199
ROW( NR_CopyFragsStarted, "dest_node", 1, dest_node),
201
ROW( NR_CopyFragDone, "dest_node", 1, dest_node),
202
ROW( NR_CopyFragDone, "table_id", 2, table_id),
203
ROW( NR_CopyFragDone, "fragment_id", 3, fragment_id),
205
ROW( NR_CopyFragsCompleted, "dest_node", 1, dest_node),
207
ROW( NodeFailCompleted, "block", 1, block), /* 0 = all */
208
ROW( NodeFailCompleted, "failed_node", 2, failed_node),
209
ROW( NodeFailCompleted, "completing_node", 3, completing_node), /* 0 = all */
211
ROW( NODE_FAILREP, "failed_node", 1, failed_node),
212
ROW( NODE_FAILREP, "failure_state", 2, failure_state),
215
ROW( ArbitState, "code", 1, code),
216
ROW( ArbitState, "arbit_node", 2, arbit_node),
217
ROW( ArbitState, "ticket_0", 3, ticket_0),
218
ROW( ArbitState, "ticket_1", 4, ticket_1),
221
ROW( ArbitResult, "code", 1, code),
222
ROW( ArbitResult, "arbit_node", 2, arbit_node),
223
ROW( ArbitResult, "ticket_0", 3, ticket_0),
224
ROW( ArbitResult, "ticket_1", 4, ticket_1),
226
// ROW( GCP_TakeoverStarted),
228
// ROW( GCP_TakeoverCompleted),
230
// ROW( LCP_TakeoverStarted),
232
ROW( LCP_TakeoverCompleted, "state", 1, state),
235
ROW( TransReportCounters, "trans_count", 1, trans_count),
236
ROW( TransReportCounters, "commit_count", 2, commit_count),
237
ROW( TransReportCounters, "read_count", 3, read_count),
238
ROW( TransReportCounters, "simple_read_count", 4, simple_read_count),
239
ROW( TransReportCounters, "write_count", 5, write_count),
240
ROW( TransReportCounters, "attrinfo_count", 6, attrinfo_count),
241
ROW( TransReportCounters, "conc_op_count", 7, conc_op_count),
242
ROW( TransReportCounters, "abort_count", 8, abort_count),
243
ROW( TransReportCounters, "scan_count", 9, scan_count),
244
ROW( TransReportCounters, "range_scan_count", 10, range_scan_count),
246
ROW( OperationReportCounters, "ops", 1, ops),
248
ROW( TableCreated, "table_id", 1, table_id),
250
ROW( JobStatistic, "mean_loop_count", 1, mean_loop_count),
252
ROW( SendBytesStatistic, "to_node", 1, to_node),
253
ROW( SendBytesStatistic, "mean_sent_bytes", 2, mean_sent_bytes),
255
ROW( ReceiveBytesStatistic, "from_node", 1, from_node),
256
ROW( ReceiveBytesStatistic, "mean_received_bytes", 2, mean_received_bytes),
258
ROW( MemoryUsage, "gth", 1, gth),
259
ROW( MemoryUsage, "page_size_bytes", 2, page_size_bytes),
260
ROW( MemoryUsage, "pages_used", 3, pages_used),
261
ROW( MemoryUsage, "pages_total", 4, pages_total),
262
ROW( MemoryUsage, "block", 5, block),
265
ROW( TransporterError, "to_node", 1, to_node),
266
ROW( TransporterError, "code", 2, code),
268
ROW( TransporterWarning, "to_node", 1, to_node),
269
ROW( TransporterWarning, "code", 2, code),
271
ROW( MissedHeartbeat, "node", 1, node),
272
ROW( MissedHeartbeat, "count", 2, count),
274
ROW( DeadDueToHeartbeat, "node", 1, node),
277
// ROW( WarningEvent),
280
ROW( SentHeartbeat, "node", 1, node),
282
ROW( CreateLogBytes, "node", 1, node),
287
ROW( EventBufferStatus, "usage", 1, usage),
288
ROW( EventBufferStatus, "alloc", 2, alloc),
289
ROW( EventBufferStatus, "max", 3, max),
290
ROW( EventBufferStatus, "apply_gci_l", 4, apply_gci_l),
291
ROW( EventBufferStatus, "apply_gci_h", 5, apply_gci_h),
292
ROW( EventBufferStatus, "latest_gci_l", 6, latest_gci_l),
293
ROW( EventBufferStatus, "latest_gci_h", 7, latest_gci_h),
296
ROW_FN( BackupStarted, "starting_node", 1, starting_node, ref_to_node),
297
ROW( BackupStarted, "backup_id", 2, backup_id),
299
ROW_FN(BackupFailedToStart,"starting_node",1, starting_node, ref_to_node),
300
ROW( BackupFailedToStart, "error", 2, error),
302
ROW_FN( BackupCompleted, "starting_node", 1, starting_node, ref_to_node),
303
ROW( BackupCompleted, "backup_id", 2, backup_id),
304
ROW( BackupCompleted, "start_gci", 3, start_gci),
305
ROW( BackupCompleted, "stop_gci", 4, stop_gci),
306
ROW( BackupCompleted, "n_bytes", 5, n_bytes),
307
ROW( BackupCompleted, "n_records", 6, n_records),
308
ROW( BackupCompleted, "n_log_bytes", 7, n_log_bytes),
309
ROW( BackupCompleted, "n_log_records", 8, n_log_records),
311
ROW_FN( BackupAborted, "starting_node", 1, starting_node, ref_to_node),
312
ROW( BackupAborted, "backup_id", 2, backup_id),
313
ROW( BackupAborted, "error", 3, error),
315
ROW( SingleUser, "type", 1, type),
316
ROW( SingleUser, "node_id", 2, node_id),
317
{ NDB_LE_ILLEGAL_TYPE, 0, 0, 0, 0, 0}
320
struct Ndb_logevent_header_row {
321
const char *token; // token to use for text transfer
322
int offset; // offset into struct ndb_logevent
327
{ a, offsetof(struct ndb_logevent, b), \
328
sizeof(((struct ndb_logevent *)0)->b) }
330
struct Ndb_logevent_header_row ndb_logevent_header[]= {
333
ROW2( "source_nodeid", source_nodeid),
338
insert_row(const char * pair, Properties & p){
339
BaseString tmp(pair);
342
Vector<BaseString> split;
343
tmp.split(split, ":=", 2);
344
if(split.size() != 2)
346
p.put(split[0].trim().c_str(), split[1].trim().c_str());
352
int memcpy_atoi(void *dst, const char *str, int sz)
364
Int16 val= atoi(str);
370
Int32 val= atoi(str);
376
Int64 val= atoi(str);
388
int ndb_logevent_get_next(const NdbLogEventHandle h,
389
struct ndb_logevent *dst,
390
unsigned timeout_in_milliseconds)
392
if (timeout_in_milliseconds == 0)
395
while ((res = ndb_logevent_get_next(h, dst, 60000))==0);
399
SocketInputStream in(h->socket, timeout_in_milliseconds);
406
if (in.gets(buf,sizeof(buf)) == 0)
408
h->m_error= NDB_LEH_READ_ERROR;
417
if ( strcmp("log event reply\n", buf) == 0 )
420
if ( strcmp("<PING>\n", buf) )
421
ndbout_c("skipped: %s", buf);
427
/* read name-value pairs into properties object */
430
if (in.gets(buf,sizeof(buf)) == 0)
432
h->m_error= NDB_LEH_READ_ERROR;
438
if ( buf[0] == '\n' )
442
if (insert_row(buf,p))
444
h->m_error= NDB_LEH_READ_ERROR;
452
dst->type= (enum Ndb_logevent_type)-1;
453
/* fill in header info from p*/
454
for (i= 0; ndb_logevent_header[i].token; i++)
456
if ( p.get(ndb_logevent_header[i].token, &val) == 0 )
458
ndbout_c("missing: %s\n", ndb_logevent_header[i].token);
459
h->m_error= NDB_LEH_MISSING_EVENT_SPECIFIER;
462
if ( memcpy_atoi((char *)dst+ndb_logevent_header[i].offset, val,
463
ndb_logevent_header[i].size) )
465
h->m_error= NDB_LEH_INTERNAL_ERROR;
471
LogLevel::EventCategory category;
472
Logger::LoggerLevel severity;
473
EventLoggerBase::EventTextFunction text_fn;
475
/* fill in rest of header info event_lookup */
476
if (EventLoggerBase::event_lookup(dst->type,category,level,severity,text_fn))
478
ndbout_c("unknown type: %d\n", dst->type);
479
h->m_error= NDB_LEH_UNKNOWN_EVENT_TYPE;
482
dst->category= (enum ndb_mgm_event_category)category;
483
dst->severity= (enum ndb_mgm_event_severity)severity;
486
/* fill in header info from p */
487
for (i= 0; ndb_logevent_body[i].token; i++)
489
if ( ndb_logevent_body[i].type != dst->type )
491
if ( p.get(ndb_logevent_body[i].token, &val) == 0 )
493
h->m_error= NDB_LEH_UNKNOWN_EVENT_VARIABLE;
496
if ( memcpy_atoi((char *)dst+ndb_logevent_body[i].offset, val,
497
ndb_logevent_body[i].size) )
499
h->m_error= NDB_LEH_INTERNAL_ERROR;
507
int ndb_logevent_get_latest_error(const NdbLogEventHandle h)
513
const char *ndb_logevent_get_latest_error_msg(const NdbLogEventHandle h)
515
for (int i= 0; ndb_logevent_error_messages[i].msg; i++)
516
if (ndb_logevent_error_messages[i].code == h->m_error)
517
return ndb_logevent_error_messages[i].msg;
518
return "<unknown error msg>";