MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
keso.c
1 /*
2  Copyright (C) 2003-2006 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 
20 #include <ndb_global.h>
21 
22 #include <mgmapi.h>
23 
24 #ifdef VM_TRACE
25 #include <mgmapi_debug.h>
26 #endif
27 
28 #include <NdbOut.hpp>
29 
30 static int testConnect(NdbMgmHandle h, struct ndb_mgm_reply* reply);
31 static int testDisconnect(NdbMgmHandle h, struct ndb_mgm_reply* reply);
32 
33 static int testStatus(NdbMgmHandle h, struct ndb_mgm_reply* reply);
34 static int testGetConfig(NdbMgmHandle h, struct ndb_mgm_reply* reply);
35 #ifdef VM_TRACE
36 static int testLogSignals(NdbMgmHandle h, struct ndb_mgm_reply* reply);
37 static int testStartSignalLog(NdbMgmHandle h, struct ndb_mgm_reply* reply);
38 static int testStopSignalLog(NdbMgmHandle h, struct ndb_mgm_reply* reply);
39 static int testSetTrace(NdbMgmHandle h, struct ndb_mgm_reply* reply);
40 static int testInsertError(NdbMgmHandle h, struct ndb_mgm_reply* reply);
41 static int testDumpState(NdbMgmHandle h, struct ndb_mgm_reply* reply);
42 #endif
43 static int testFilterClusterLog(NdbMgmHandle h, struct ndb_mgm_reply* reply);
44 static int testSetLogLevelClusterLog(NdbMgmHandle h,
45  struct ndb_mgm_reply* reply);
46 static int testSetLogLevelNode(NdbMgmHandle h, struct ndb_mgm_reply* reply);
47 static int testRestartNode(NdbMgmHandle h, struct ndb_mgm_reply* reply);
48 static int testGetStatPort(NdbMgmHandle h, struct ndb_mgm_reply* reply);
49 
50 typedef int (*FUNC)(NdbMgmHandle h, struct ndb_mgm_reply* reply);
51 
52 struct test_case {
53  char name[255];
54  FUNC func;
55 };
56 
57 struct test_case test_connect_disconnect[] = {
58  {"testConnect", &testConnect},
59  {"testDisconnect", &testDisconnect}
60 };
61 
62 struct test_case tests[] = {
63  { "testStatus", &testStatus },
64  { "testFilterClusterLog", &testFilterClusterLog },
65  /*{ "testSetLogLevelClusterLog", &testSetLogLevelClusterLog },*/
66  /*{ "testSetLogLevelNode", &testSetLogLevelNode },*/
67  { "testRestartNode", &testRestartNode },
68  { "testGetStatPort", &testGetStatPort },
69 #ifdef VM_TRACE
70  { "testLogSignals", &testLogSignals },
71  { "testStartSignalLog", &testStartSignalLog },
72  { "testStopSignalLog", &testStopSignalLog },
73  { "testSetTrace", &testSetTrace },
74  { "testDumpState", &testDumpState },
75  { "testInsertError", &testInsertError }
76 #endif
77 };
78 
79 static int no_of_tests = sizeof(tests) / sizeof(struct test_case);
80 static int testFailed = 0;
81 
82 static const char * g_connect_string = "localhost:2200";
83 
84 int
85 main(int argc, const char** argv){
86 
87  struct ndb_mgm_reply reply;
88  int i = 0;
89  NdbMgmHandle h = NULL;
90 
91  if(argc > 1)
92  g_connect_string = argv[1];
93 
94  ndbout_c("Using connectstring: %s", g_connect_string);
95 
96  for (i = 0; i < 2; i++) {
97  ndbout_c("-- %s --", test_connect_disconnect[i].name);
98  if (test_connect_disconnect[i].func(h, &reply) == 0) {
99  ndbout_c("-- Passed --");
100  } else {
101  testFailed++;
102  ndbout_c("-- Failed --");
103  }
104  }
105  ndbout_c("-- %d passed, %d failed --", (2 - testFailed), testFailed);
106 
107 
108  h = ndb_mgm_create_handle();
109  ndb_mgm_connect(h, g_connect_string);
110 
111  for (i = 0; i < no_of_tests; i ++) {
112  ndbout_c("-- %s --", tests[i].name);
113  if (tests[i].func(h, &reply) == 0) {
114  ndbout_c("-- Passed --");
115  } else {
116  testFailed++;
117  ndbout_c("-- Failed --");
119  ndb_mgm_connect(h, g_connect_string);
120  }
121  }
122  ndbout_c("-- %d passed, %d failed --", (no_of_tests - testFailed),
123  testFailed);
124 
126 
127  return 0;
128 }
129 
130 static
131 int testConnect(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
132  h = ndb_mgm_create_handle();
133  if (h != NULL) {
134  if (ndb_mgm_connect(h, g_connect_string) == -1) {
135  ndbout_c(g_connect_string);
136  /*ndbout_c("last_error: %d", h->last_error); */
137  return -1;
138  } else {
139  ndbout_c("Connected to localhost:37123");
140  }
141 
142  } else {
143  ndbout_c("Unable to create a NdbMgmHandle...");
144  return -1;
145  }
146 
147  return 0;
148 }
149 
150 static
151 int testDisconnect(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
152  ndb_mgm_disconnect(h);
153 
154  return 0;
155 }
156 
157 static
158 int testGetConfig(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
159  int i = 0;
161  if (config != NULL) {
162  free(config);
163  } else {
164  ndbout_c("Unable to get config");
165  return -1;
166  }
167  return 0;
168 }
169 
170 static
171 int testStatus(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
172  int i = 0;
173  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
174  if (cluster != NULL) {
175  ndbout_c("Number of nodes: %d", cluster->no_of_nodes);
176  for (i = 0; i < cluster->no_of_nodes; i++) {
177  struct ndb_mgm_node_state state = cluster->node_states[i];
178  ndbout_c("NodeId: %d (%s)-- %s", state.node_id,
181 
182  }
183  free(cluster);
184  } else {
185  ndbout_c("Unable to get node status.");
186  return -1;
187  }
188  return 0;
189 }
190 
191 
192 #ifdef VM_TRACE
193 
194 static
195 int testLogSignals(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
196  int rc = 0;
197  int nodeId = 0;
198  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
199  if (cluster != NULL) {
200  if (cluster->no_of_nodes != 0) {
201  nodeId = cluster->node_states[0].node_id;
202  }
203  free(cluster);
204  } else {
205  ndbout_c("Unable to get node status.");
206  return -1;
207  }
208 
209  rc = ndb_mgm_log_signals(h, nodeId, NDB_MGM_SIGNAL_LOG_MODE_INOUT,
210  "CMVMI QMGR",
211  reply);
212  if (rc != 0) {
213  ndbout_c("rc = %d", reply->return_code);
214  }
215 
216  ndbout_c("%s", reply->message);
217 
218  return rc;
219 }
220 
221 static
222 int testStartSignalLog(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
223  int rc = 0;
224  int nodeId = 0;
225  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
226  if (cluster != NULL) {
227  if (cluster->no_of_nodes != 0) {
228  nodeId = cluster->node_states[0].node_id;
229  }
230  free(cluster);
231  } else {
232  ndbout_c("Unable to get node status.");
233  return -1;
234  }
235 
236  rc = ndb_mgm_start_signallog(h, nodeId, reply);
237  if (rc != 0) {
238  ndbout_c("rc = %d", reply->return_code);
239  }
240 
241  ndbout_c("%s", reply->message);
242 
243  return rc;
244 }
245 
246 static
247 int testStopSignalLog(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
248 
249  int rc = 0;
250  int nodeId = 0;
251  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
252  if (cluster != NULL) {
253  if (cluster->no_of_nodes != 0) {
254  nodeId = cluster->node_states[0].node_id;
255  }
256  free(cluster);
257  } else {
258  ndbout_c("Unable to get node status.");
259  return -1;
260  }
261 
262  rc = ndb_mgm_stop_signallog(h, nodeId, reply);
263  if (rc != 0) {
264  ndbout_c("rc = %d", reply->return_code);
265  }
266 
267  ndbout_c("%s", reply->message);
268 
269  return rc;
270 
271 }
272 
273 static
274 int testSetTrace(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
275  int rc = 0;
276  int nodeId = 0;
277  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
278  if (cluster != NULL) {
279  if (cluster->no_of_nodes != 0) {
280  nodeId = cluster->node_states[0].node_id;
281  }
282  free(cluster);
283  } else {
284  ndbout_c("Unable to get node status.");
285  return -1;
286  }
287 
288  rc = ndb_mgm_set_trace(h, nodeId, 2, reply);
289  if (rc != 0) {
290  ndbout_c("rc = %d", reply->return_code);
291  }
292 
293  ndbout_c("%s", reply->message);
294 
295  return rc;
296 
297 }
298 
299 static
300 int testInsertError(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
301  int rc = 0;
302  int nodeId = 0;
303  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
304  if (cluster != NULL) {
305  if (cluster->no_of_nodes != 0) {
306  nodeId = cluster->node_states[0].node_id;
307  }
308  free(cluster);
309  } else {
310  ndbout_c("Unable to get node status.");
311  return -1;
312  }
313 
314  rc = ndb_mgm_insert_error(h, nodeId, 9999, reply);
315  if (rc != 0) {
316  ndbout_c("rc = %d", reply->return_code);
317  }
318 
319  ndbout_c("%s", reply->message);
320 
321  return rc;
322 
323 }
324 
325 static
326 int testDumpState(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
327 
328  int rc = 0;
329  int nodeId = 0;
330  int dump[3];
331 
332  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
333  if (cluster != NULL) {
334  if (cluster->no_of_nodes != 0) {
335  nodeId = cluster->node_states[0].node_id;
336  }
337  free(cluster);
338  } else {
339  ndbout_c("Unable to get node status.");
340  return -1;
341  }
342 
343  dump[0] = 1;
344  dump[1] = 2;
345  dump[2] = 3;
346  rc = ndb_mgm_dump_state(h, nodeId, dump, 3, reply);
347 
348  if (rc != 0) {
349  ndbout_c("rc = %d", reply->return_code);
350  }
351 
352  ndbout_c("%s", reply->message);
353 
354  return rc;
355 }
356 
357 #endif
358 
359 static
360 int testFilterClusterLog(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
361  int rc = 0;
362 
363  rc = ndb_mgm_filter_clusterlog(h, NDB_MGM_CLUSTERLOG_INFO, reply);
364  if (rc == -1) {
365  ndbout_c("rc = %d", reply->return_code);
366  ndbout_c("%s", reply->message);
367  return -1;
368  }
369 
370  ndbout_c("%s", reply->message);
371 
372  rc = ndb_mgm_filter_clusterlog(h, NDB_MGM_CLUSTERLOG_DEBUG, reply);
373  if (rc == -1) {
374  ndbout_c("rc = %d", reply->return_code);
375  ndbout_c("%s", reply->message);
376  return -1;
377  }
378 
379  ndbout_c("%s", reply->message);
380 
381  return rc;
382 
383 }
384 
385 static
386 int testSetLogLevelClusterLog(NdbMgmHandle h,
387  struct ndb_mgm_reply* reply) {
388  int rc = 0;
389  int nodeId = 0;
390  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
391  if (cluster != NULL) {
392  if (cluster->no_of_nodes != 0) {
393  nodeId = cluster->node_states[0].node_id;
394  }
395  free(cluster);
396  } else {
397  ndbout_c("Unable to get node status.");
398  return -1;
399  }
400 
401  rc = ndb_mgm_set_loglevel_clusterlog(h, nodeId,
403  5,
404  reply);
405  if (rc != 0) {
406  ndbout_c("rc = %d", reply->return_code);
407  }
408 
409  ndbout_c("%s", reply->message);
410 
411  return rc;
412 
413 }
414 
415 static
416 int testSetLogLevelNode(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
417 
418  int rc = 0;
419  int nodeId = 0;
420  struct ndb_mgm_cluster_state* cluster = ndb_mgm_get_status(h);
421  if (cluster != NULL) {
422  if (cluster->no_of_nodes != 0) {
423  nodeId = cluster->node_states[0].node_id;
424  }
425  free(cluster);
426  } else {
427  ndbout_c("Unable to get node status.");
428  return -1;
429  }
430 
431  rc = ndb_mgm_set_loglevel_node(h, nodeId,
433  15,
434  reply);
435  if (rc != 0) {
436  ndbout_c("rc = %d", reply->return_code);
437  }
438 
439  ndbout_c("%s", reply->message);
440 
441  return rc;
442 
443 }
444 
445 static int
446 testRestartNode(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
447  int restarts = 0;
448 
449  restarts = ndb_mgm_restart(h, 0, 0); /* Restart all */
450  if (restarts == 0) {
451  ndbout_c("No nodes restarted...");
452  return -1;
453  } else {
454  ndbout_c("%d nodes restarted...", restarts);
455  }
456 
457  return 0;
458 }
459 
460 static
461 int testGetStatPort(NdbMgmHandle h, struct ndb_mgm_reply* reply) {
462 
463  int rc = 0;
464  rc = ndb_mgm_get_stat_port(h, reply);
465  if (rc == 0) {
466  ndbout_c("stat port %s", reply->message);
467  } else {
468  ndbout_c("failed");
469  }
470 
471  return rc;
472 }