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
;
38 struct getargs args
[] = {
39 { "loops", 'l', arg_integer
, &_loops
, "number of times to run this program(0=infinite loop)", "loops" },
40 { "records", 'r', arg_integer
, &_records
, "Number of records", "recs" },
41 { "locktime", 't', arg_integer
, &_lockTime
, "Time in ms to hold lock(default=1000)", "ms" },
42 { "percent", 'p', arg_integer
, &_percentVal
, "Percent of records to lock(default=1%)", "%" },
43 { "usage", '?', arg_flag
, &_help
, "Print help", "" }
45 int num_args
= sizeof(args
) / sizeof(args
[0]);
49 "This program will lock p% of the records in the table for x milliseconds\n"\
50 "then it will lock the next 1% and continue to do so until it has locked \n"\
51 "all records in the table\n";
53 if(getarg(args
, num_args
, argc
, argv
, &optind
) ||
54 argv
[optind
] == NULL
|| _records
== 0 || _help
) {
55 arg_printusage(args
, num_args
, argv
[0], desc
);
56 return NDBT_ProgramExit(NDBT_WRONGARGS
);
58 _tabname
= argv
[optind
];
61 Ndb_cluster_connection con
;
62 if(con
.connect(12, 5, 1) != 0)
64 return NDBT_ProgramExit(NDBT_FAILED
);
66 Ndb
MyNdb(&con
, "TEST_DB" );
68 if(MyNdb
.init() != 0){
69 ERR(MyNdb
.getNdbError());
70 return NDBT_ProgramExit(NDBT_FAILED
);
73 while(MyNdb
.waitUntilReady() != 0)
74 ndbout
<< "Waiting for ndb to become ready..." << endl
;
76 // Check if table exists in db
77 const NdbDictionary::Table
* pTab
= NDBT_Table::discoverTableFromDb(&MyNdb
, _tabname
);
79 ndbout
<< " Table " << _tabname
<< " does not exist!" << endl
;
80 return NDBT_ProgramExit(NDBT_WRONGARGS
);
83 HugoTransactions
hugoTrans(*pTab
);
85 while (i
<_loops
|| _loops
==0) {
87 if (hugoTrans
.lockRecords(&MyNdb
, _records
, _percentVal
, _lockTime
) != 0){
88 return NDBT_ProgramExit(NDBT_FAILED
);
93 return NDBT_ProgramExit(NDBT_OK
);