1 /*
2    Copyright (C) 2003-2006 MySQL AB
3     All rights reserved. Use is subject to license terms.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 
26 #include <ndb_global.h>
27 
28 #include <NdbOut.hpp>
29 
30 #include <NdbApi.hpp>
31 #include <NdbMain.h>
32 #include <NDBT.hpp>
33 #include <NdbSleep.h>
34 #include <getarg.h>
35 
36 #include <HugoTransactions.hpp>
37 
main(int argc,const char ** argv)38 int main(int argc, const char** argv){
39   ndb_init();
40 
41   int _records = 0;
42   int _loops = 1;
43   int _parallelism = 1;
44   int _ver2 = 0;
45   const char* _tabname = NULL, *db = 0;
46   int _help = 0;
47   int abort= 0;
48 
49   struct getargs args[] = {
50     { "loops", 'l', arg_integer, &_loops, "number of times to run this program(0=infinite loop)", "loops" },
51     { "parallelism", 'p', arg_integer, &_parallelism, "parallelism(1-240)", "para" },
52     { "records", 'r', arg_integer, &_records, "Number of records", "recs" },
53     { "ver2", '2', arg_flag, &_ver2, "Use version 2 of scanUpdateRecords", "" },
54     { "ver2", '1', arg_negative_flag, &_ver2, "Use version 1 of scanUpdateRecords (default)", "" },
55     { "abort", 'a', arg_integer, &abort, "Abort probability", "" },
56     { "usage", '?', arg_flag, &_help, "Print help", "" },
57     { "database", 'd', arg_string, &db, "Database", "" }
58   };
59   int num_args = sizeof(args) / sizeof(args[0]);
60   int optind = 0;
61   char desc[] =
62     "tabname\n"\
63     "This program will scan update all records in one table in Ndb\n";
64 
65   if(getarg(args, num_args, argc, argv, &optind) ||
66      argv[optind] == NULL || _help) {
67     arg_printusage(args, num_args, argv[0], desc);
68     return NDBT_ProgramExit(NDBT_WRONGARGS);
69   }
70   _tabname = argv[optind];
71 
72   // Connect to Ndb
73   Ndb_cluster_connection con;
74   if(con.connect(12, 5, 1) != 0)
75   {
76     return NDBT_ProgramExit(NDBT_FAILED);
77   }
78 
79   if (con.wait_until_ready(30,0) < 0)
80   {
81     ndbout << "Cluster nodes not ready in 30 seconds." << endl;
82     return NDBT_ProgramExit(NDBT_FAILED);
83   }
84 
85   Ndb MyNdb( &con, db ? db : "TEST_DB" );
86 
87   if(MyNdb.init() != 0){
88     ERR(MyNdb.getNdbError());
89     return NDBT_ProgramExit(NDBT_FAILED);
90   }
91 
92   // Check if table exists in db
93   const NdbDictionary::Table * pTab = NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
94   if(pTab == NULL){
95     ndbout << " Table " << _tabname << " does not exist!" << endl;
96     return NDBT_ProgramExit(NDBT_WRONGARGS);
97   }
98 
99   HugoTransactions hugoTrans(*pTab);
100   int i = 0;
101   int res = NDBT_FAILED;
102   while (i<_loops || _loops==0) {
103     ndbout << i << ": ";
104     if (_ver2 == 0){
105       res = hugoTrans.scanUpdateRecords(&MyNdb,
106 					_records,
107 					abort % 101,
108 					_parallelism);
109     } else{
110       res = hugoTrans.scanUpdateRecords2(&MyNdb,
111 					 _records,
112 					 abort % 101,
113 					 _parallelism);
114     }
115     if (res != NDBT_OK ){
116       return NDBT_ProgramExit(NDBT_FAILED);
117     }
118     i++;
119     //NdbSleep_MilliSleep(300);
120   }
121 
122   return NDBT_ProgramExit(NDBT_OK);
123 }
124