19 #include <NDBT_Test.hpp>
20 #include <NDBT_ReturnCodes.h>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
37 uint r = (uint)random();
61 unsigned long long masterEpoch = 0;
62 unsigned long long slaveEpoch = 0;
63 unsigned long long slaveEpochOld = 0;
71 if (!master.connect())
73 g_err <<
"sync connect to master failed" << endl;
78 if(!master.doQuery(
"SELECT MAX(epoch) FROM mysql.ndb_binlog_index", result))
80 g_err <<
"Select max(epoch) SQL failed" << endl;
83 masterEpoch = result.columnAsLong(
"epoch");
93 DbUtil slave(
"mysql",
".1.slave");
98 g_err <<
"sync connect to slave failed" << endl;
102 while(slaveEpoch != masterEpoch && loopCnt < maxLoops)
104 if(!slave.doQuery(
"SELECT epoch FROM mysql.ndb_apply_status",result))
106 g_err <<
"Select epoch SQL on slave failed" << endl;
110 if (result.numRows() > 0)
111 slaveEpoch = result.columnAsLong(
"epoch");
113 if(slaveEpoch != slaveEpochOld)
115 slaveEpochOld = slaveEpoch;
127 if(slaveEpoch != masterEpoch)
129 g_err <<
"Slave not in sync with master!" << endl;
140 unsigned int masterCount = 0;
141 unsigned int slaveCount = 0;
147 printf(
"Calling syncSlave\n");
148 if(!syncSlaveWithMaster())
150 g_err <<
"Verify Load -> Syncing with slave failed" << endl;
158 if (!master.connect())
160 g_err <<
"Verify Load -> connect to master failed" << endl;
164 if((masterCount = master.selectCountTable(table.
c_str())) == 0 )
166 g_err <<
"Verify Load -> masterCount == ZERO!" << endl;
174 if (!slave.connect())
176 g_err <<
"Verify Load -> connect to master failed" << endl;
180 if((slaveCount = slave.selectCountTable(table.
c_str())) == 0 )
182 g_err <<
"Verify Load -> slaveCount == ZERO" << endl;
186 if(slaveCount != masterCount)
188 g_err <<
"Verify Load -> Slave Count != Master Count "
204 if (!master.connect())
206 g_err <<
"Create DB -> Connect to master failed"
211 if (!master.createDb(cdb))
225 if (!master.connect())
227 g_err <<
"Drop DB -> Connect to master failed"
232 if(!master.doQuery(
"DROP DATABASE TEST_DB"))
234 g_err <<
"Drop DB -> SQL failed"
239 if(!syncSlaveWithMaster())
241 g_err <<
"Drop DB -> Syncing with slave failed"
259 if(!syncSlaveWithMaster())
261 g_err <<
"Verify Slave -> Syncing with slave failed"
267 if (!master.connect())
269 g_err <<
"Verify Slave -> connect master failed"
274 if(!master.doQuery(sqlStm.
c_str(),result))
278 masterSum = result.columnAsInt(column.
c_str());
281 if (!slave.connect())
286 if(!slave.doQuery(sqlStm.
c_str(),result))
290 slaveSum = result.columnAsInt(column.
c_str());
292 if(masterSum != slaveSum)
294 g_err <<
"VerifySlave -> masterSum != slaveSum..." << endl;
313 if(!syncSlaveWithMaster())
315 g_err <<
"Create Table -> Syncing with slave failed"
324 if (!master.connect())
326 g_err <<
"Create Table -> Connect to Master failed"
331 if (!master.doQuery(
"CREATE TABLE rep1 (c1 MEDIUMINT NOT NULL AUTO_INCREMENT,"
332 " c2 FLOAT, c3 CHAR(5), c4 TEXT(8), c5 FLOAT, c6 INT,"
333 " c7 INT, PRIMARY KEY (c1))ENGINE=NDB"))
335 g_err <<
"Create Table -> Create table SQL failed"
356 for(
int i = 0;
i < ctx->getNumRecords();
i++)
358 if (!master.doQuery(
"INSERT INTO rep1 VALUES(NULL, 0, 'TEXAS', 'works', 0, 2, 1)"))
360 g_err <<
"Create Table -> Insert SQL failed"
366 if(!verifySlaveLoad(table))
368 g_err <<
"Create Table -> Failed on verify slave load!"
379 Ndb* ndb=GETNDB(step);
383 while(!ctx->isTestStopped())
385 if (hugoTrans.pkUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30)
388 g_err <<
"pkUpdate Failed!" << endl;
391 if (hugoTrans.scanUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30)
394 g_err <<
"scanUpdate Failed!" << endl;
407 int loops = ctx->getNumLoops();
411 if (!master.connect())
417 for (
int j= 0; loops == 0 || j < loops; j++)
419 record = urandom(ctx->getNumRecords());
420 sqlStm.
assfmt(
"UPDATE TEST_DB.rep1 SET c2 = 33.3221 where c1 = %u", record);
421 if(!master.doQuery(sqlStm.
c_str()))
437 sql.
assign(
"SELECT SUM(c3) FROM rep1");
441 if (!verifySlave(sql,db,column))
466 NDBT_TESTSUITE(NdbRepStress);
467 TESTCASE(
"PHASE_I_Stress",
"Basic Replication Stressing")
469 INITIALIZER(createTEST_DB);
470 INITIALIZER(createTable_rep1);
472 STEP(stressSQL_rep1);
473 FINALIZER(verifySlave_rep1);
474 FINALIZER(dropTEST_DB);
476 NDBT_TESTSUITE_END(NdbRepStress);
478 int main(
int argc,
const char** argv){
480 NDBT_TESTSUITE_INSTANCE(NdbRepStress);
481 NdbRepStress.setCreateAllTables(
true);
482 return NdbRepStress.execute(argc, argv);