mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / tools / hugoLockRecords.cpp
blob7c52d553beb2f19ef71e46e9b7af8858f38be1c9
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 _percentVal = 1;
34 int _lockTime = 1000;
35 const char* _tabname = NULL;
36 int _help = 0;
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]);
46 int optind = 0;
47 char desc[] =
48 "tabname\n"\
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];
60 // Connect to Ndb
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);
78 if(pTab == NULL){
79 ndbout << " Table " << _tabname << " does not exist!" << endl;
80 return NDBT_ProgramExit(NDBT_WRONGARGS);
83 HugoTransactions hugoTrans(*pTab);
84 int i = 0;
85 while (i<_loops || _loops==0) {
86 ndbout << i << ": ";
87 if (hugoTrans.lockRecords(&MyNdb, _records, _percentVal, _lockTime) != 0){
88 return NDBT_ProgramExit(NDBT_FAILED);
90 i++;
93 return NDBT_ProgramExit(NDBT_OK);