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

« back to all changes in this revision

Viewing changes to storage/ndb/test/tools/connect.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 <ndb_global.h>
 
17
#include <ndb_opts.h>
 
18
#include <NDBT.hpp>
 
19
#include <NdbApi.hpp>
 
20
#include <NdbSleep.h>
 
21
 
 
22
NDB_STD_OPTS_VARS;
 
23
 
 
24
static int _loop = 25;
 
25
static int _sleep = 25;
 
26
static int _drop = 1;
 
27
 
 
28
typedef uchar* gptr;
 
29
 
 
30
static struct my_option my_long_options[] =
 
31
{
 
32
  NDB_STD_OPTS("ndb_desc"),
 
33
  { "loop", 'l', "loops",
 
34
    (gptr*) &_loop, (gptr*) &_loop, 0,
 
35
    GET_INT, REQUIRED_ARG, _loop, 0, 0, 0, 0, 0 }, 
 
36
  { "sleep", 's', "Sleep (ms) between connection attempt",
 
37
    (gptr*) &_sleep, (gptr*) &_sleep, 0,
 
38
    GET_INT, REQUIRED_ARG, _sleep, 0, 0, 0, 0, 0 }, 
 
39
  { "drop", 'd', 
 
40
    "Drop event operations before disconnect (0 = no, 1 = yes, else rand",
 
41
    (gptr*) &_drop, (gptr*) &_drop, 0,
 
42
    GET_INT, REQUIRED_ARG, _drop, 0, 0, 0, 0, 0 }, 
 
43
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
44
};
 
45
 
 
46
static void usage()
 
47
{
 
48
  char desc[] =  "This program connects to ndbd, and then disconnects\n";
 
49
  ndb_std_print_version();
 
50
  my_print_help(my_long_options);
 
51
  my_print_variables(my_long_options);
 
52
}
 
53
 
 
54
int main(int argc, char** argv){
 
55
  NDB_INIT(argv[0]);
 
56
 
 
57
  const char *load_default_groups[]= { "mysql_cluster",0 };
 
58
  load_defaults("my",load_default_groups,&argc,&argv);
 
59
  int ho_error;
 
60
#ifndef DBUG_OFF
 
61
  opt_debug= "d:t:O,/tmp/ndb_desc.trace";
 
62
#endif
 
63
  if ((ho_error=handle_options(&argc, &argv, my_long_options, 
 
64
                               ndb_std_get_one_option)))
 
65
    return NDBT_ProgramExit(NDBT_WRONGARGS);
 
66
 
 
67
  for (int i = 0; i<_loop; i++)
 
68
  {
 
69
    Ndb_cluster_connection con(opt_connect_str);
 
70
    if(con.connect(12, 5, 1) != 0)
 
71
    {
 
72
      ndbout << "Unable to connect to management server." << endl;
 
73
      return NDBT_ProgramExit(NDBT_FAILED);
 
74
    }
 
75
    if (con.wait_until_ready(30,30) != 0)
 
76
    {
 
77
      ndbout << "Cluster nodes not ready in 30 seconds." << endl;
 
78
      return NDBT_ProgramExit(NDBT_FAILED);
 
79
    }
 
80
    
 
81
    Ndb MyNdb(&con, "TEST_DB");
 
82
    if(MyNdb.init() != 0){
 
83
      ERR(MyNdb.getNdbError());
 
84
      return NDBT_ProgramExit(NDBT_FAILED);
 
85
    }
 
86
 
 
87
    Vector<NdbEventOperation*> ops;
 
88
    const NdbDictionary::Dictionary * dict= MyNdb.getDictionary();
 
89
    for (int j = 0; j < argc; j++) 
 
90
    {
 
91
      const NdbDictionary::Table * pTab = dict->getTable(argv[j]);
 
92
      if (pTab == 0)
 
93
      {
 
94
        ndbout_c("Failed to retreive table: \"%s\"", argv[j]);
 
95
      }
 
96
 
 
97
      BaseString tmp;
 
98
      tmp.appfmt("EV-%s", argv[j]);
 
99
      NdbEventOperation* pOp = MyNdb.createEventOperation(tmp.c_str());
 
100
      if ( pOp == NULL ) 
 
101
      {
 
102
        ndbout << "Event operation creation failed: " << 
 
103
          MyNdb.getNdbError() << endl;
 
104
        return NDBT_ProgramExit(NDBT_FAILED);
 
105
      }
 
106
 
 
107
      for (int a = 0; a < pTab->getNoOfColumns(); a++) 
 
108
      {
 
109
        pOp->getValue(pTab->getColumn(a)->getName());
 
110
        pOp->getPreValue(pTab->getColumn(a)->getName());
 
111
      }
 
112
      
 
113
      if (pOp->execute())
 
114
      { 
 
115
        ndbout << "operation execution failed: " << pOp->getNdbError()
 
116
               << endl;
 
117
        return NDBT_ProgramExit(NDBT_FAILED);
 
118
      }
 
119
      ops.push_back(pOp);
 
120
    }
 
121
    
 
122
    if (_sleep)
 
123
    {
 
124
      NdbSleep_MilliSleep(10 + rand() % _sleep);
 
125
    }
 
126
    
 
127
    for (Uint32 i = 0; i<ops.size(); i++)
 
128
    {
 
129
      switch(_drop){
 
130
      case 0:
 
131
        break;
 
132
      do_drop:
 
133
      case 1:
 
134
        if (MyNdb.dropEventOperation(ops[i]))
 
135
        {
 
136
          ndbout << "drop event operation failed " 
 
137
                 << MyNdb.getNdbError() << endl;
 
138
          return NDBT_ProgramExit(NDBT_FAILED);
 
139
        }
 
140
        break;
 
141
      default:
 
142
        if ((rand() % 100) > 50)
 
143
          goto do_drop;
 
144
      }
 
145
    }
 
146
  }
 
147
  
 
148
  return NDBT_ProgramExit(NDBT_OK);
 
149
}
 
150
 
 
151
template class Vector<NdbEventOperation*>;