1 /* Copyright (c) 2003-2008 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>
23 #include <NDBT_Thread.hpp>
24 #include <NDBT_Stats.hpp>
28 #include <HugoTransactions.hpp>
30 static NDBT_ThreadFunc hugoPkUpdate
;
33 const NdbDictionary::Table
* pTab
;
43 int main(int argc
, const char** argv
){
52 const char* _tabname
= NULL
, *db
= 0;
55 struct getargs args
[] = {
56 { "aborts", 'a', arg_integer
, &_abort
, "percent of transactions that are aborted", "abort%" },
57 { "loops", 'l', arg_integer
, &_loops
, "number of times to run this program(0=infinite loop)", "loops" },
58 { "threads", 't', arg_integer
, &_threads
, "number of threads (default 1)", "threads" },
59 { "stats", 's', arg_flag
, &_stats
, "report latency per batch", "stats" },
60 // { "batch", 'b', arg_integer, &_batch, "batch value", "batch" },
61 { "records", 'r', arg_integer
, &_records
, "Number of records", "records" },
62 { "usage", '?', arg_flag
, &_help
, "Print help", "" },
63 { "database", 'd', arg_string
, &db
, "Database", "" }
65 int num_args
= sizeof(args
) / sizeof(args
[0]);
69 "This program will update all records in a table using PK\n";
71 if(getarg(args
, num_args
, argc
, argv
, &optind
) ||
72 argv
[optind
] == NULL
|| _records
== 0 || _help
) {
73 arg_printusage(args
, num_args
, argv
[0], desc
);
74 return NDBT_ProgramExit(NDBT_WRONGARGS
);
76 _tabname
= argv
[optind
];
79 Ndb_cluster_connection con
;
80 if(con
.connect(12, 5, 1) != 0)
82 return NDBT_ProgramExit(NDBT_FAILED
);
85 if (con
.wait_until_ready(30,0) < 0)
87 ndbout
<< "Cluster nodes not ready in 30 seconds." << endl
;
88 return NDBT_ProgramExit(NDBT_FAILED
);
91 Ndb
MyNdb( &con
, db
? db
: "TEST_DB" );
93 if(MyNdb
.init() != 0){
94 ERR(MyNdb
.getNdbError());
95 return NDBT_ProgramExit(NDBT_FAILED
);
98 // Check if table exists in db
99 const NdbDictionary::Table
* pTab
= NDBT_Table::discoverTableFromDb(&MyNdb
, _tabname
);
101 ndbout
<< " Table " << _tabname
<< " does not exist!" << endl
;
102 return NDBT_ProgramExit(NDBT_WRONGARGS
);
106 NDBT_ThreadSet
ths(_threads
);
108 // create Ndb object for each thread
109 if (ths
.connect(&con
, db
? db
: "TEST_DB") == -1) {
110 ndbout
<< "connect failed: err=" << ths
.get_err() << endl
;
111 return NDBT_ProgramExit(NDBT_FAILED
);
116 ths
.set_input(&input
);
118 input
.records
= _records
;
119 input
.batch
= _batch
;
120 input
.stats
= _stats
;
124 ths
.set_output
<ThrOutput
>();
127 while (i
< _loops
|| _loops
== 0) {
130 ths
.set_func(hugoPkUpdate
);
135 NDBT_ProgramExit(NDBT_FAILED
);
140 // add stats from each thread
142 for (n
= 0; n
< ths
.get_count(); n
++) {
143 NDBT_Thread
& thr
= ths
.get_thread(n
);
144 ThrOutput
* output
= (ThrOutput
*)thr
.get_output();
145 latency
+= output
->latency
;
149 << "latency per batch (us): "
150 << " samples=" << latency
.getCount()
151 << " min=" << (int)latency
.getMin()
152 << " max=" << (int)latency
.getMax()
153 << " mean=" << (int)latency
.getMean()
154 << " stddev=" << (int)latency
.getStddev()
160 return NDBT_ProgramExit(NDBT_OK
);
163 static void hugoPkUpdate(NDBT_Thread
& thr
)
165 const ThrInput
* input
= (const ThrInput
*)thr
.get_input();
166 ThrOutput
* output
= (ThrOutput
*)thr
.get_output();
168 HugoTransactions
hugoTrans(*input
->pTab
);
169 output
->latency
.reset();
171 hugoTrans
.setStatsLatency(&output
->latency
);
173 NDBT_ThreadSet
& ths
= thr
.get_thread_set();
174 hugoTrans
.setThrInfo(ths
.get_count(), thr
.get_thread_no());
177 ret
= hugoTrans
.pkUpdateRecords(thr
.get_ndb(),