mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / tools / hugoScanRead.cpp
blobb28f035684c66647174e01a3d1dc768845f39bf2
1 /* Copyright (c) 2003-2005 MySQL AB
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include <ndb_global.h>
18 #include <NdbOut.hpp>
20 #include <NdbApi.hpp>
21 #include <NdbMain.h>
22 #include <NDBT.hpp>
23 #include <NdbSleep.h>
24 #include <getarg.h>
26 #include <HugoTransactions.hpp>
28 int main(int argc, const char** argv){
29 ndb_init();
31 int _records = 0;
32 int _loops = 1;
33 int _abort = 0;
34 int _parallelism = 1;
35 const char* _tabname = NULL, *db = 0;
36 int _help = 0;
37 int lock = NdbOperation::LM_Read;
38 int sorted = 0;
40 struct getargs args[] = {
41 { "aborts", 'a', arg_integer, &_abort, "percent of transactions that are aborted", "abort%" },
42 { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
43 { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
44 { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
45 { "usage", '?', arg_flag, &_help, "Print help", "" },
46 { "lock", 'm', arg_integer, &lock, "lock mode", "" },
47 { "sorted", 's', arg_flag, &sorted, "sorted", "" },
48 { "database", 'd', arg_string, &db, "Database", "" }
50 int num_args = sizeof(args) / sizeof(args[0]);
51 int optind = 0;
52 char desc[] =
53 " tabname\n"\
54 "This program will scan read all records in one table in Ndb.\n"\
55 "It will verify every column read by calculating the expected value.\n";
57 if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL || _help) {
58 arg_printusage(args, num_args, argv[0], desc);
59 return NDBT_ProgramExit(NDBT_WRONGARGS);
61 _tabname = argv[optind];
63 // Connect to Ndb
64 Ndb_cluster_connection con;
65 if(con.connect(12, 5, 1) != 0)
67 return NDBT_ProgramExit(NDBT_FAILED);
69 Ndb MyNdb( &con, db ? db : "TEST_DB" );
71 if(MyNdb.init() != 0){
72 ERR(MyNdb.getNdbError());
73 return NDBT_ProgramExit(NDBT_FAILED);
76 while(MyNdb.waitUntilReady() != 0)
77 ndbout << "Waiting for ndb to become ready..." << endl;
79 // Check if table exists in db
80 const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
81 if(pTab == NULL){
82 ndbout << " Table " << _tabname << " does not exist!" << endl;
83 return NDBT_ProgramExit(NDBT_WRONGARGS);
86 const NdbDictionary::Index * pIdx = 0;
87 if(optind+1 < argc)
89 pIdx = MyNdb.getDictionary()->getIndex(argv[optind+1], _tabname);
90 if(!pIdx)
91 ndbout << " Index " << argv[optind+1] << " not found" << endl;
92 else
93 if(pIdx->getType() != NdbDictionary::Index::OrderedIndex)
95 ndbout << " Index " << argv[optind+1] << " is not scannable" << endl;
96 pIdx = 0;
100 HugoTransactions hugoTrans(*pTab);
101 int i = 0;
102 while (i<_loops || _loops==0) {
103 ndbout << i << ": ";
104 if(!pIdx)
106 if(hugoTrans.scanReadRecords(&MyNdb,
108 _abort,
109 _parallelism,
110 (NdbOperation::LockMode)lock) != 0)
112 return NDBT_ProgramExit(NDBT_FAILED);
115 else
117 if(hugoTrans.scanReadRecords(&MyNdb, pIdx,
119 _abort,
120 _parallelism,
121 (NdbOperation::LockMode)lock,
122 sorted) != 0)
124 return NDBT_ProgramExit(NDBT_FAILED);
127 i++;
130 return NDBT_ProgramExit(NDBT_OK);