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>
26 #include <HugoTransactions.hpp>
28 int main(int argc
, const char** argv
){
35 const char* _tabname
= NULL
, *db
= 0;
37 int lock
= NdbOperation::LM_Read
;
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]);
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
];
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
);
82 ndbout
<< " Table " << _tabname
<< " does not exist!" << endl
;
83 return NDBT_ProgramExit(NDBT_WRONGARGS
);
86 const NdbDictionary::Index
* pIdx
= 0;
89 pIdx
= MyNdb
.getDictionary()->getIndex(argv
[optind
+1], _tabname
);
91 ndbout
<< " Index " << argv
[optind
+1] << " not found" << endl
;
93 if(pIdx
->getType() != NdbDictionary::Index::OrderedIndex
)
95 ndbout
<< " Index " << argv
[optind
+1] << " is not scannable" << endl
;
100 HugoTransactions
hugoTrans(*pTab
);
102 while (i
<_loops
|| _loops
==0) {
106 if(hugoTrans
.scanReadRecords(&MyNdb
,
110 (NdbOperation::LockMode
)lock
) != 0)
112 return NDBT_ProgramExit(NDBT_FAILED
);
117 if(hugoTrans
.scanReadRecords(&MyNdb
, pIdx
,
121 (NdbOperation::LockMode
)lock
,
124 return NDBT_ProgramExit(NDBT_FAILED
);
130 return NDBT_ProgramExit(NDBT_OK
);