MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hugoScanRead.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 _abort = 0;
37  int _parallelism = 1;
38  const char* _tabname = NULL, *db = 0;
39  int _help = 0;
40  int lock = NdbOperation::LM_Read;
41  int sorted = 0;
42 
43  struct getargs args[] = {
44  { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
45  { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
46  { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
47  { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
48  { "usage", '?', arg_flag, &_help, "Print help", "" },
49  { "lock", 'm', arg_integer, &lock, "lock mode", "" },
50  { "sorted", 's', arg_flag, &sorted, "sorted", "" },
51  { "database", 'd', arg_string, &db, "Database", "" }
52  };
53  int num_args = sizeof(args) / sizeof(args[0]);
54  int optind = 0;
55  char desc[] =
56  " tabname\n"\
57  "This program will scan read all records in one table in Ndb.\n"\
58  "It will verify every column read by calculating the expected value.\n";
59 
60  if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL || _help) {
61  arg_printusage(args, num_args, argv[0], desc);
62  return NDBT_ProgramExit(NDBT_WRONGARGS);
63  }
64  _tabname = argv[optind];
65 
66  // Connect to Ndb
68  if(con.connect(12, 5, 1) != 0)
69  {
70  return NDBT_ProgramExit(NDBT_FAILED);
71  }
72  Ndb MyNdb( &con, db ? db : "TEST_DB" );
73 
74  if(MyNdb.init() != 0){
75  ERR(MyNdb.getNdbError());
76  return NDBT_ProgramExit(NDBT_FAILED);
77  }
78 
79  while(MyNdb.waitUntilReady() != 0)
80  ndbout << "Waiting for ndb to become ready..." << endl;
81 
82  // Check if table exists in db
83  const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
84  if(pTab == NULL){
85  ndbout << " Table " << _tabname << " does not exist!" << endl;
86  return NDBT_ProgramExit(NDBT_WRONGARGS);
87  }
88 
89  const NdbDictionary::Index * pIdx = 0;
90  if(optind+1 < argc)
91  {
92  pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname);
93  if(!pIdx)
94  ndbout << " Index " << argv[optind+1] << " not found" << endl;
95  else
97  {
98  ndbout << " Index " << argv[optind+1] << " is not scannable" << endl;
99  pIdx = 0;
100  }
101  }
102 
103  HugoTransactions hugoTrans(*pTab);
104  int i = 0;
105  while (i<_loops || _loops==0) {
106  ndbout << i << ": ";
107  if(!pIdx)
108  {
109  if(hugoTrans.scanReadRecords(&MyNdb,
110  0,
111  _abort,
112  _parallelism,
113  (NdbOperation::LockMode)lock) != 0)
114  {
115  return NDBT_ProgramExit(NDBT_FAILED);
116  }
117  }
118  else
119  {
120  if(hugoTrans.scanReadRecords(&MyNdb, pIdx,
121  0,
122  _abort,
123  _parallelism,
125  sorted) != 0)
126  {
127  return NDBT_ProgramExit(NDBT_FAILED);
128  }
129  }
130  i++;
131  }
132 
133  return NDBT_ProgramExit(NDBT_OK);
134 }