mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / tools / hugoScanUpdate.cpp
blobe47ecb74628847a76db56fc892587c41ee6bbef7
1 /* Copyright (c) 2003-2006 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 _parallelism = 1;
34 int _ver2 = 0;
35 const char* _tabname = NULL, *db = 0;
36 int _help = 0;
37 int abort= 0;
39 struct getargs args[] = {
40 { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
41 { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
42 { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
43 { "ver2", '2', arg_flag, &_ver2, "Use version 2 of scanUpdateRecords", "" },
44 { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of scanUpdateRecords (default)", "" },
45 { "abort", 'a', arg_integer, &abort, "Abort probability", "" },
46 { "usage", '?', arg_flag, &_help, "Print help", "" },
47 { "database", 'd', arg_string, &db, "Database", "" }
49 int num_args = sizeof(args) / sizeof(args[0]);
50 int optind = 0;
51 char desc[] =
52 "tabname\n"\
53 "This program will scan update all records in one table in Ndb\n";
55 if(getarg(args, num_args, argc, argv, &optind) ||
56 argv[optind] == NULL || _help) {
57 arg_printusage(args, num_args, argv[0], desc);
58 return NDBT_ProgramExit(NDBT_WRONGARGS);
60 _tabname = argv[optind];
62 // Connect to Ndb
63 Ndb_cluster_connection con;
64 if(con.connect(12, 5, 1) != 0)
66 return NDBT_ProgramExit(NDBT_FAILED);
69 if (con.wait_until_ready(30,0) < 0)
71 ndbout << "Cluster nodes not ready in 30 seconds." << endl;
72 return NDBT_ProgramExit(NDBT_FAILED);
75 Ndb MyNdb( &con, db ? db : "TEST_DB" );
77 if(MyNdb.init() != 0){
78 ERR(MyNdb.getNdbError());
79 return NDBT_ProgramExit(NDBT_FAILED);
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);
89 HugoTransactions hugoTrans(*pTab);
90 int i = 0;
91 int res = NDBT_FAILED;
92 while (i<_loops || _loops==0) {
93 ndbout << i << ": ";
94 if (_ver2 == 0){
95 res = hugoTrans.scanUpdateRecords(&MyNdb,
96 _records,
97 abort % 101,
98 _parallelism);
99 } else{
100 res = hugoTrans.scanUpdateRecords2(&MyNdb,
101 _records,
102 abort % 101,
103 _parallelism);
105 if (res != NDBT_OK ){
106 return NDBT_ProgramExit(NDBT_FAILED);
108 i++;
109 //NdbSleep_MilliSleep(300);
112 return NDBT_ProgramExit(NDBT_OK);