19 #include <ndb_global.h>
21 #include <NDBT_Test.hpp>
22 #include <NDBT_ReturnCodes.h>
23 #include <HugoTransactions.hpp>
24 #include <UtilTransactions.hpp>
25 #include <TestNdbEventOperation.hpp>
26 #include <NdbRestarter.hpp>
27 #include <NdbRestarts.hpp>
31 ndb_std_print_version();
36 if (ops[0]->startTransaction(ndb) != NDBT_OK)
39 for (
int i= ops.size()-1;
i > 0;
i--)
41 ops[
i]->setTransaction(t);
48 if (ops[0]->closeTransaction(ndb) != NDBT_OK)
50 for (
int i= ops.size()-1;
i > 0;
i--)
52 ops[
i]->setTransaction(NULL);
59 if (ops[0]->execute_Commit(ndb) != NDBT_OK)
64 static int copy_events(
Ndb *ndb)
66 DBUG_ENTER(
"copy_events");
72 DBUG_PRINT(
"info", (
"pollEvents res=%d", res));
87 g_err <<
"unable to find table " << buf << endl;
93 g_err <<
"buffer overrun\n";
101 g_err <<
"A node failure has occured and events might be missing\n";
111 g_err <<
"startTransaction failed "
120 g_err <<
"getNdbOperation failed "
130 g_err <<
"insertTuple "
139 g_err <<
"deleteTuple "
148 g_err <<
"updateTuple "
159 for (
const NdbRecAttr *pk= pOp->getFirstPkAttr(); pk; pk= pk->next())
163 g_err <<
"internal error: primary key isNull()="
164 << pk->isNULL() << endl;
165 DBUG_RETURN(NDBT_FAILED);
167 if (op->
equal(pk->getColumn()->getColumnNo(),pk->aRef()))
169 g_err <<
"equal " << pk->getColumn()->getColumnNo() <<
" "
172 DBUG_RETURN(NDBT_FAILED);
180 for (
const NdbRecAttr *data= pOp->getFirstDataAttr(); data; data= data->next())
182 if (data->isNULL() < 0 ||
183 op->
setValue(data->getColumn()->getColumnNo(),
184 data->isNULL() ? 0:data->aRef()))
186 g_err <<
"setValue(insert) " << data->getColumn()->getColumnNo() <<
" "
198 for (
const NdbRecAttr *data= pOp->getFirstDataAttr(); data; data= data->next())
200 if (data->isNULL() >= 0 &&
201 op->
setValue(data->getColumn()->getColumnNo(),
202 data->isNULL() ? 0:data->aRef()))
204 g_err <<
"setValue(update) " << data->getColumn()->getColumnNo() <<
" "
207 DBUG_RETURN(NDBT_FAILED);
215 if (trans->
execute(Commit) == 0)
221 if (noRetries++ == 10 ||
224 g_err <<
"execute " << r <<
" failed "
231 NdbSleep_MilliSleep(100);
236 g_err <<
"nextEvent()\n";
243 static int verify_copy(
Ndb *ndb,
247 for (
unsigned i= 0;
i < tabs1.size();
i++)
251 if (hugoTrans.compare(ndb, tabs2[i]->getName(), 0))
257 static const char* _dbname =
"TEST_DB";
261 {
"database",
'd',
"Name of database table is in",
262 (uchar**) &_dbname, (uchar**) &_dbname, 0,
263 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
264 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
268 main(
int argc,
char** argv)
271 const char *load_default_groups[]= {
"mysql_cluster",0 };
272 load_defaults(
"my",load_default_groups,&argc,&argv);
276 opt_debug=
"d:t:F:L";
278 if ((ho_error=handle_options(&argc, &argv, my_long_options,
279 ndb_std_get_one_option)))
280 return NDBT_ProgramExit(NDBT_WRONGARGS);
286 DBUG_RETURN(NDBT_ProgramExit(NDBT_FAILED));
290 Ndb ndb(&con,_dbname);
302 NDBT_Tables::dropAllTables(&ndb);
303 NDBT_Tables::createAllTables(&ndb);
304 for (i= 0; no_error && i < NDBT_Tables::getNumTables(); i++)
309 ndbout <<
"Failed to create table" << endl;
314 pTabs.push_back(pTab);
319 for (i= 0; no_error && argc; argc--, i++)
322 NDBT_Tables::createTable(&ndb, argv[i]);
326 ndbout <<
"Failed to create table" << endl;
331 pTabs.push_back(pTab);
334 pTabs.push_back(NULL);
337 for (i= 0; no_error && pTabs[
i]; i++)
340 if (ht.createEvent(&ndb)){
348 for (i= 0; no_error && pTabs[
i]; i++)
351 sprintf(buf,
"%s_EVENT", pTabs[i]->getName());
362 for (i= 0; no_error && pTabs[
i]; i++)
364 int n_columns= pTabs[
i]->getNoOfColumns();
365 for (
int j = 0; j < n_columns; j++) {
366 pOps[
i]->getValue(pTabs[i]->getColumn(j)->getName());
367 pOps[
i]->getPreValue(pTabs[i]->getColumn(j)->getName());
372 for (i= 0; no_error && pTabs[
i]; i++)
374 if ( pOps[i]->execute() )
383 for (i= 0; no_error && pTabs[
i]; i++)
386 sprintf(buf,
"%s_SHADOW", pTabs[i]->getName());
396 table_shadow.setName(buf);
398 pShadowTabs.push_back(dict->
getTable(buf));
408 for (i= 0; no_error && pTabs[
i]; i++)
416 if (start_transaction(&ndb, hugo_ops))
421 for (i= 0; no_error && pTabs[
i]; i++)
423 hugo_ops[
i]->pkInsertRecord(&ndb, 0, n_records);
425 if (execute_commit(&ndb, hugo_ops))
430 if(close_transaction(&ndb, hugo_ops))
439 if (copy_events(&ndb) < 0)
444 if (verify_copy(&ndb, pTabs, pShadowTabs))
453 if (start_transaction(&ndb, hugo_ops))
459 hugo_ops[0]->pkUpdateRecord(&ndb, n_records-1);
461 if (execute_commit(&ndb, hugo_ops))
466 if(close_transaction(&ndb, hugo_ops))
475 if (copy_events(&ndb) < 0)
480 if (verify_copy(&ndb, pTabs, pShadowTabs))
490 for (
int j= 0; j < 10; j++)
496 if (restarts.executeRestart(
"RestartRandomNodeAbort", timeout))
504 if (start_transaction(&ndb, hugo_ops))
510 for (
int r= 0; r < n_records; r++)
512 for (i= 0; pTabs[
i]; i++)
514 hugo_ops[
i]->pkUpdateRecord(&ndb, r);
517 if (execute_commit(&ndb, hugo_ops))
522 if(close_transaction(&ndb, hugo_ops))
529 if (copy_events(&ndb) < 0)
534 if (verify_copy(&ndb, pTabs, pShadowTabs))
543 for (i= 0; i < (int)pOps.size(); i++)
552 DBUG_RETURN(NDBT_ProgramExit(NDBT_OK));
553 DBUG_RETURN(NDBT_ProgramExit(NDBT_FAILED));