MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hugoScanUpdate.cpp
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 #include <ndb_global.h>
20 
21 #include <NdbOut.hpp>
22 
23 #include <NdbApi.hpp>
24 #include <NdbMain.h>
25 #include <NDBT.hpp>
26 #include <NdbSleep.h>
27 #include <getarg.h>
28 
29 #include <HugoTransactions.hpp>
30 
31 int main(int argc, const char** argv){
32  ndb_init();
33 
34  int _records = 0;
35  int _loops = 1;
36  int _parallelism = 1;
37  int _ver2 = 0;
38  const char* _tabname = NULL, *db = 0;
39  int _help = 0;
40  int abort= 0;
41 
42  struct getargs args[] = {
43  { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
44  { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
45  { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
46  { "ver2", '2', arg_flag, &_ver2, "Use version 2 of scanUpdateRecords", "" },
47  { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of scanUpdateRecords (default)", "" },
48  { "abort", 'a', arg_integer, &abort, "Abort probability", "" },
49  { "usage", '?', arg_flag, &_help, "Print help", "" },
50  { "database", 'd', arg_string, &db, "Database", "" }
51  };
52  int num_args = sizeof(args) / sizeof(args[0]);
53  int optind = 0;
54  char desc[] =
55  "tabname\n"\
56  "This program will scan update all records in one table in Ndb\n";
57 
58  if(getarg(args, num_args, argc, argv, &optind) ||
59  argv[optind] == NULL || _help) {
60  arg_printusage(args, num_args, argv[0], desc);
61  return NDBT_ProgramExit(NDBT_WRONGARGS);
62  }
63  _tabname = argv[optind];
64 
65  // Connect to Ndb
67  if(con.connect(12, 5, 1) != 0)
68  {
69  return NDBT_ProgramExit(NDBT_FAILED);
70  }
71 
72  if (con.wait_until_ready(30,0) < 0)
73  {
74  ndbout << "Cluster nodes not ready in 30 seconds." << endl;
75  return NDBT_ProgramExit(NDBT_FAILED);
76  }
77 
78  Ndb MyNdb( &con, db ? db : "TEST_DB" );
79 
80  if(MyNdb.init() != 0){
81  ERR(MyNdb.getNdbError());
82  return NDBT_ProgramExit(NDBT_FAILED);
83  }
84 
85  // Check if table exists in db
86  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
87  if(pTab == NULL){
88  ndbout << " Table " << _tabname << " does not exist!" << endl;
89  return NDBT_ProgramExit(NDBT_WRONGARGS);
90  }
91 
92  HugoTransactions hugoTrans(*pTab);
93  int i = 0;
94  int res = NDBT_FAILED;
95  while (i<_loops || _loops==0) {
96  ndbout << i << ": ";
97  if (_ver2 == 0){
98  res = hugoTrans.scanUpdateRecords(&MyNdb,
99  _records,
100  abort % 101,
101  _parallelism);
102  } else{
103  res = hugoTrans.scanUpdateRecords2(&MyNdb,
104  _records,
105  abort % 101,
106  _parallelism);
107  }
108  if (res != NDBT_OK ){
109  return NDBT_ProgramExit(NDBT_FAILED);
110  }
111  i++;
112  //NdbSleep_MilliSleep(300);
113  }
114 
115  return NDBT_ProgramExit(NDBT_OK);
116 }