MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp
1 /*
2  Copyright (C) 2005-2007 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <mysql.h>
20 #include <ndbapi/NdbApi.hpp>
21 #include <mgmapi.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 
25 /*
26  * export LD_LIBRARY_PATH=../../../../libmysql_r/.libs:../../src/.libs
27  */
28 
29 #define MGMERROR(h) \
30 { \
31  fprintf(stderr, "code: %d msg: %s\n", \
32  ndb_mgm_get_latest_error(h), \
33  ndb_mgm_get_latest_error_msg(h)); \
34  exit(-1); \
35 }
36 
37 #define LOGEVENTERROR(h) \
38 { \
39  fprintf(stderr, "code: %d msg: %s\n", \
40  ndb_logevent_get_latest_error(h), \
41  ndb_logevent_get_latest_error_msg(h)); \
42  exit(-1); \
43 }
44 
45 #define make_uint64(a,b) (((Uint64)(a)) + (((Uint64)(b)) << 32))
46 
47 int main(int argc, char** argv)
48 {
49  NdbMgmHandle h;
51  int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
56  0 };
57  struct ndb_logevent event;
58 
59  if (argc < 2)
60  {
61  printf("Arguments are <connect_string cluster> [<iterations>].\n");
62  exit(-1);
63  }
64  const char *connectstring = argv[1];
65  int iterations = -1;
66  if (argc > 2)
67  iterations = atoi(argv[2]);
68  ndb_init();
69 
71  if ( h == 0)
72  {
73  printf("Unable to create handle\n");
74  exit(-1);
75  }
76  if (ndb_mgm_set_connectstring(h, connectstring) == -1)
77  {
78  printf("Unable to set connectstring\n");
79  exit(-1);
80  }
81  if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h);
82 
83  le= ndb_mgm_create_logevent_handle(h, filter);
84  if ( le == 0 ) MGMERROR(h);
85 
86  while (iterations-- != 0)
87  {
88  int timeout= 1000;
89  int r= ndb_logevent_get_next(le,&event,timeout);
90  if (r == 0)
91  printf("No event within %d milliseconds\n", timeout);
92  else if (r < 0)
93  LOGEVENTERROR(le)
94  else
95  {
96  switch (event.type) {
98  printf("Node %d: BackupStarted\n", event.source_nodeid);
99  printf(" Starting node ID: %d\n", event.BackupStarted.starting_node);
100  printf(" Backup ID: %d\n", event.BackupStarted.backup_id);
101  break;
102  case NDB_LE_BackupStatus:
103  printf("Node %d: BackupStatus\n", event.source_nodeid);
104  printf(" Starting node ID: %d\n", event.BackupStarted.starting_node);
105  printf(" Backup ID: %d\n", event.BackupStarted.backup_id);
106  printf(" Data written: %llu bytes (%llu records)\n",
107  make_uint64(event.BackupStatus.n_bytes_lo,
108  event.BackupStatus.n_bytes_hi),
109  make_uint64(event.BackupStatus.n_records_lo,
110  event.BackupStatus.n_records_hi));
111  printf(" Log written: %llu bytes (%llu records)\n",
112  make_uint64(event.BackupStatus.n_log_bytes_lo,
113  event.BackupStatus.n_log_bytes_hi),
114  make_uint64(event.BackupStatus.n_log_records_lo,
115  event.BackupStatus.n_log_records_hi));
116  break;
118  printf("Node %d: BackupCompleted\n", event.source_nodeid);
119  printf(" Backup ID: %d\n", event.BackupStarted.backup_id);
120  printf(" Data written: %llu bytes (%llu records)\n",
121  make_uint64(event.BackupCompleted.n_bytes,
122  event.BackupCompleted.n_bytes_hi),
123  make_uint64(event.BackupCompleted.n_records,
124  event.BackupCompleted.n_records_hi));
125  printf(" Log written: %llu bytes (%llu records)\n",
126  make_uint64(event.BackupCompleted.n_log_bytes,
127  event.BackupCompleted.n_log_bytes_hi),
128  make_uint64(event.BackupCompleted.n_log_records,
129  event.BackupCompleted.n_log_records_hi));
130  break;
132  printf("Node %d: BackupAborted\n", event.source_nodeid);
133  break;
135  printf("Node %d: BackupFailedToStart\n", event.source_nodeid);
136  break;
137 
139  printf("Node %d: NodeFailCompleted\n", event.source_nodeid);
140  break;
141  case NDB_LE_ArbitResult:
142  printf("Node %d: ArbitResult\n", event.source_nodeid);
143  printf(" code %d, arbit_node %d\n",
144  event.ArbitResult.code & 0xffff,
145  event.ArbitResult.arbit_node);
146  break;
148  printf("Node %d: DeadDueToHeartbeat\n", event.source_nodeid);
149  printf(" node %d\n", event.DeadDueToHeartbeat.node);
150  break;
151 
152  case NDB_LE_Connected:
153  printf("Node %d: Connected\n", event.source_nodeid);
154  printf(" node %d\n", event.Connected.node);
155  break;
156  case NDB_LE_Disconnected:
157  printf("Node %d: Disconnected\n", event.source_nodeid);
158  printf(" node %d\n", event.Disconnected.node);
159  break;
161  printf("Node %d: StartCompleted\n", event.source_nodeid);
162  printf(" version %d.%d.%d\n",
163  event.NDBStartCompleted.version >> 16 & 0xff,
164  event.NDBStartCompleted.version >> 8 & 0xff,
165  event.NDBStartCompleted.version >> 0 & 0xff);
166  break;
167  case NDB_LE_ArbitState:
168  printf("Node %d: ArbitState\n", event.source_nodeid);
169  printf(" code %d, arbit_node %d\n",
170  event.ArbitState.code & 0xffff,
171  event.ArbitResult.arbit_node);
172  break;
173 
174  default:
175  break;
176  }
177  }
178  }
179 
180  ndb_mgm_destroy_logevent_handle(&le);
182  ndb_end(0);
183  return 0;
184 }