~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/ndbapi-examples/mgmapi_logevent/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#include <mysql.h>
 
17
#include <ndbapi/NdbApi.hpp>
 
18
#include <mgmapi.h>
 
19
#include <stdio.h>
 
20
 
 
21
/*
 
22
 * export LD_LIBRARY_PATH=../../../libmysql_r/.libs:../../../ndb/src/.libs
 
23
 */
 
24
 
 
25
#define MGMERROR(h) \
 
26
{ \
 
27
  fprintf(stderr, "code: %d msg: %s\n", \
 
28
          ndb_mgm_get_latest_error(h), \
 
29
          ndb_mgm_get_latest_error_msg(h)); \
 
30
  exit(-1); \
 
31
}
 
32
 
 
33
#define LOGEVENTERROR(h) \
 
34
{ \
 
35
  fprintf(stderr, "code: %d msg: %s\n", \
 
36
          ndb_logevent_get_latest_error(h), \
 
37
          ndb_logevent_get_latest_error_msg(h)); \
 
38
  exit(-1); \
 
39
}
 
40
 
 
41
int main(int argc, char** argv)
 
42
{
 
43
  NdbMgmHandle h;
 
44
  NdbLogEventHandle le;
 
45
  int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
 
46
                   15, NDB_MGM_EVENT_CATEGORY_CONNECTION,
 
47
                   15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART,
 
48
                   15, NDB_MGM_EVENT_CATEGORY_STARTUP,
 
49
                   15, NDB_MGM_EVENT_CATEGORY_ERROR,
 
50
                   0 };
 
51
  struct ndb_logevent event;
 
52
 
 
53
  if (argc < 2)
 
54
  {
 
55
    printf("Arguments are <connect_string cluster> [<iterations>].\n");
 
56
    exit(-1);
 
57
  }
 
58
  const char *connectstring = argv[1];
 
59
  int iterations = -1; 
 
60
  if (argc > 2)
 
61
    iterations = atoi(argv[2]);
 
62
  ndb_init();
 
63
  
 
64
  h= ndb_mgm_create_handle();
 
65
  if ( h == 0)
 
66
  {
 
67
    printf("Unable to create handle\n");
 
68
    exit(-1);
 
69
  }
 
70
  if (ndb_mgm_set_connectstring(h, connectstring) == -1)
 
71
  {
 
72
    printf("Unable to set connectstring\n");
 
73
    exit(-1);
 
74
  }
 
75
  if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h);
 
76
 
 
77
  le= ndb_mgm_create_logevent_handle(h, filter);
 
78
  if ( le == 0 )  MGMERROR(h);
 
79
 
 
80
  while (iterations-- != 0)
 
81
  {
 
82
    int timeout= 1000;
 
83
    int r= ndb_logevent_get_next(le,&event,timeout);
 
84
    if (r == 0)
 
85
      printf("No event within %d milliseconds\n", timeout);
 
86
    else if (r < 0)
 
87
      LOGEVENTERROR(le)
 
88
    else
 
89
    {
 
90
      switch (event.type) {
 
91
      case NDB_LE_BackupStarted:
 
92
        printf("Node %d: BackupStarted\n", event.source_nodeid);
 
93
        printf("  Starting node ID: %d\n", event.BackupStarted.starting_node);
 
94
        printf("  Backup ID: %d\n", event.BackupStarted.backup_id);
 
95
        break;
 
96
      case NDB_LE_BackupCompleted:
 
97
        printf("Node %d: BackupCompleted\n", event.source_nodeid);
 
98
        printf("  Backup ID: %d\n", event.BackupStarted.backup_id);
 
99
        break;
 
100
      case NDB_LE_BackupAborted:
 
101
        printf("Node %d: BackupAborted\n", event.source_nodeid);
 
102
        break;
 
103
      case NDB_LE_BackupFailedToStart:
 
104
        printf("Node %d: BackupFailedToStart\n", event.source_nodeid);
 
105
        break;
 
106
 
 
107
      case NDB_LE_NodeFailCompleted:
 
108
        printf("Node %d: NodeFailCompleted\n", event.source_nodeid);
 
109
        break;
 
110
      case NDB_LE_ArbitResult:
 
111
        printf("Node %d: ArbitResult\n", event.source_nodeid);
 
112
        printf("  code %d, arbit_node %d\n",
 
113
               event.ArbitResult.code & 0xffff,
 
114
               event.ArbitResult.arbit_node);
 
115
        break;
 
116
      case NDB_LE_DeadDueToHeartbeat:
 
117
        printf("Node %d: DeadDueToHeartbeat\n", event.source_nodeid);
 
118
        printf("  node %d\n", event.DeadDueToHeartbeat.node);
 
119
        break;
 
120
 
 
121
      case NDB_LE_Connected:
 
122
        printf("Node %d: Connected\n", event.source_nodeid);
 
123
        printf("  node %d\n", event.Connected.node);
 
124
        break;
 
125
      case NDB_LE_Disconnected:
 
126
        printf("Node %d: Disconnected\n", event.source_nodeid);
 
127
        printf("  node %d\n", event.Disconnected.node);
 
128
        break;
 
129
      case NDB_LE_NDBStartCompleted:
 
130
        printf("Node %d: StartCompleted\n", event.source_nodeid);
 
131
        printf("  version %d.%d.%d\n",
 
132
               event.NDBStartCompleted.version >> 16 & 0xff,
 
133
               event.NDBStartCompleted.version >> 8 & 0xff,
 
134
               event.NDBStartCompleted.version >> 0 & 0xff);
 
135
        break;
 
136
      case NDB_LE_ArbitState:
 
137
        printf("Node %d: ArbitState\n", event.source_nodeid);
 
138
        printf("  code %d, arbit_node %d\n",
 
139
               event.ArbitState.code & 0xffff,
 
140
               event.ArbitResult.arbit_node);
 
141
        break;
 
142
 
 
143
      default:
 
144
        break;
 
145
      }
 
146
    }
 
147
  }
 
148
      
 
149
  ndb_mgm_destroy_logevent_handle(&le);
 
150
  ndb_mgm_destroy_handle(&h);
 
151
  ndb_end(0);
 
152
  return 0;
 
153
}