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>
26 #include <HugoTransactions.hpp>
28 int main(int argc
, const char** argv
){
35 const char* _tabname
= NULL
, *db
= 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]);
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
];
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
);
85 ndbout
<< " Table " << _tabname
<< " does not exist!" << endl
;
86 return NDBT_ProgramExit(NDBT_WRONGARGS
);
89 HugoTransactions
hugoTrans(*pTab
);
91 int res
= NDBT_FAILED
;
92 while (i
<_loops
|| _loops
==0) {
95 res
= hugoTrans
.scanUpdateRecords(&MyNdb
,
100 res
= hugoTrans
.scanUpdateRecords2(&MyNdb
,
105 if (res
!= NDBT_OK
){
106 return NDBT_ProgramExit(NDBT_FAILED
);
109 //NdbSleep_MilliSleep(300);
112 return NDBT_ProgramExit(NDBT_OK
);