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

« back to all changes in this revision

Viewing changes to storage/ndb/test/tools/log_listner.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
#include <mgmapi.h>
 
2
#include <ndb_global.h>
 
3
#include <ndb_opts.h>
 
4
#include <NDBT.hpp>
 
5
 
 
6
NDB_STD_OPTS_VARS;
 
7
 
 
8
static struct my_option my_long_options[] =
 
9
{
 
10
  NDB_STD_OPTS("ndb_logevent_listen"),
 
11
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
12
};
 
13
static void usage()
 
14
{
 
15
  char desc[] = 
 
16
    "tabname\n"\
 
17
    "This program list all properties of table(s) in NDB Cluster.\n"\
 
18
    "  ex: desc T1 T2 T4\n";
 
19
  ndb_std_print_version();
 
20
  my_print_help(my_long_options);
 
21
  my_print_variables(my_long_options);
 
22
}
 
23
 
 
24
int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP,
 
25
                 15, NDB_MGM_EVENT_CATEGORY_CONNECTION,
 
26
                 15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART,
 
27
                 15, NDB_MGM_EVENT_CATEGORY_STARTUP,
 
28
                 15, NDB_MGM_EVENT_CATEGORY_SHUTDOWN,
 
29
                 15, NDB_MGM_EVENT_CATEGORY_STATISTIC,
 
30
                 15, NDB_MGM_EVENT_CATEGORY_ERROR,
 
31
                 15, NDB_MGM_EVENT_CATEGORY_CHECKPOINT,
 
32
                 15, NDB_MGM_EVENT_CATEGORY_CONGESTION,
 
33
                 0 };
 
34
 
 
35
int 
 
36
main(int argc, char** argv)
 
37
{
 
38
  NDB_INIT(argv[0]);
 
39
  const char *load_default_groups[]= { "mysql_cluster",0 };
 
40
  load_defaults("my",load_default_groups,&argc,&argv);
 
41
  int ho_error;
 
42
#ifndef DBUG_OFF
 
43
  opt_debug= "d:t:O,/tmp/ndb_desc.trace";
 
44
#endif
 
45
  if ((ho_error=handle_options(&argc, &argv, my_long_options, 
 
46
                               ndb_std_get_one_option)))
 
47
    return NDBT_ProgramExit(NDBT_WRONGARGS);
 
48
 
 
49
  NdbMgmHandle handle= ndb_mgm_create_handle();
 
50
  ndb_mgm_set_connectstring(handle, opt_connect_str);
 
51
  
 
52
  while (true)
 
53
  {
 
54
    if (ndb_mgm_connect(handle,0,0,0) == -1)
 
55
    {
 
56
      ndbout_c("Failed to connect");
 
57
      exit(0);
 
58
    }
 
59
    
 
60
    NdbLogEventHandle le = ndb_mgm_create_logevent_handle(handle, filter);
 
61
    if (le == 0)
 
62
    {
 
63
      ndbout_c("Failed to create logevent handle");
 
64
      exit(0);
 
65
    }
 
66
    
 
67
    struct ndb_logevent event;
 
68
    while (true)
 
69
    {
 
70
      int r= ndb_logevent_get_next(le, &event,5000);
 
71
      if (r < 0)
 
72
      {
 
73
        ndbout_c("Error while getting next event");
 
74
        break;
 
75
      }
 
76
      if (r == 0)
 
77
      {
 
78
        continue;
 
79
      }
 
80
      ndbout_c("Got event: %d", event.type);
 
81
    }
 
82
    
 
83
    ndb_mgm_destroy_logevent_handle(&le);
 
84
    ndb_mgm_disconnect(handle);
 
85
  }
 
86
 
 
87
  return 0;
 
88
}