19 #include <NDBT_Test.hpp>
20 #include "../../src/ndbapi/NdbInfo.hpp"
22 #include <NdbRestarter.hpp>
27 NdbInfo ndbinfo(&ctx->m_cluster_connection,
"ndbinfo/");
30 g_err <<
"ndbinfo.init failed" << endl;
35 if (ndbinfo.openTable(
"ndbinfo/tables", &table) != 0)
37 g_err <<
"Failed to openTable(tables)" << endl;
41 for (
int l = 0; l < ctx->getNumLoops(); l++)
45 if (ndbinfo.createScanOperation(table, &scanOp))
47 g_err <<
"No NdbInfoScanOperation" << endl;
51 if (scanOp->readTuples() != 0)
53 g_err <<
"scanOp->readTuples failed" << endl;
60 if(scanOp->execute() != 0)
62 g_err <<
"scanOp->execute failed" << endl;
66 while(scanOp->nextResult() == 1)
68 g_info <<
"NAME: " << tableName->c_str() << endl;
69 g_info <<
"COMMENT: " << comment->c_str() << endl;
71 ndbinfo.releaseScanOperation(scanOp);
74 ndbinfo.closeTable(table);
82 if (ndbinfo.createScanOperation(table, &scanOp))
84 g_err <<
"No NdbInfoScanOperation" << endl;
88 if (scanOp->readTuples() != 0)
90 g_err <<
"scanOp->readTuples failed" << endl;
91 ndbinfo.releaseScanOperation(scanOp);
96 while (scanOp->getValue(columnId))
99 assert(columnId >= 1);
101 if((ret = scanOp->execute()) != 0)
103 g_err <<
"scanOp->execute failed, ret: " << ret << endl;
104 ndbinfo.releaseScanOperation(scanOp);
108 while((ret = scanOp->nextResult()) == 1)
111 ndbinfo.releaseScanOperation(scanOp);
115 g_err <<
"scanOp->nextResult failed, ret: " << ret << endl;
125 NdbInfo ndbinfo(&ctx->m_cluster_connection,
"ndbinfo/");
128 g_err <<
"ndbinfo.init failed" << endl;
136 int err = ndbinfo.openTable(tableId, &table);
137 if (err == NdbInfo::ERR_NoSuchTable)
145 g_err <<
"Failed to openTable(" << tableId <<
"), err: " << err << endl;
148 ndbout <<
"table("<<tableId<<
"): " << table->getName() << endl;
151 for (
int l = 0; l < ctx->getNumLoops(); l++)
153 if (ctx->isTestStopped())
157 if (!scan_table(ndbinfo, table, rows))
166 g_err <<
"Got different number of rows this round, expected: "
167 << last_rows <<
", got: " << rows << endl;
168 ndbinfo.closeTable(table);
174 ndbinfo.closeTable(table);
186 while (ctx->isTestStopped() ==
false) {
188 if (runScanAll(ctx, step) != NDBT_OK){
199 NdbInfo ndbinfo(&ctx->m_cluster_connection,
"ndbinfo/");
202 g_err <<
"ndbinfo.init failed" << endl;
210 int err = ndbinfo.openTable(tableId, &table);
211 if (err == NdbInfo::ERR_NoSuchTable)
219 g_err <<
"Failed to openTable(" << tableId <<
"), err: " << err << endl;
222 ndbout <<
"table: " << table->getName() << endl;
224 for (
int l = 0; l < ctx->getNumLoops()*10; l++)
227 if (ndbinfo.createScanOperation(table, &scanOp))
229 g_err <<
"No NdbInfoScanOperation" << endl;
233 if (scanOp->readTuples() != 0)
235 g_err <<
"scanOp->readTuples failed" << endl;
240 while (scanOp->getValue(columnId))
243 assert(columnId >= 1);
245 if(scanOp->execute() != 0)
247 g_err <<
"scanOp->execute failed" << endl;
251 int stopRow = rand() % 100;
253 while(scanOp->nextResult() == 1)
258 ndbout_c(
"Aborting scan at row %d", stopRow);
262 ndbinfo.releaseScanOperation(scanOp);
264 ndbinfo.closeTable(table);
276 NdbInfo ndbinfo(&ctx->m_cluster_connection,
"ndbinfo/");
279 g_err <<
"ndbinfo.init failed" << endl;
288 int err = ndbinfo.openTable(tableId, &table);
289 if (err == NdbInfo::ERR_NoSuchTable)
297 g_err <<
"Failed to openTable(" << tableId <<
"), err: " << err << endl;
300 ndbout <<
"table: " << table->getName() << endl;
303 struct { Uint32 rows; Uint32 bytes; } limits[] = {
305 { 1, 0 }, { 2, 0 }, { 10, 0 }, { 37, 0 }, { 1000, 0 },
306 { 0, 1 }, { 0, 2 }, { 0, 10 }, { 0, 37 }, { 0, 1000 },
307 { 1, 1 }, { 2, 2 }, { 10, 10 }, { 37, 37 }, { 1000, 1000 }
311 for (
int l = 0; l < (int)(
sizeof(limits)/
sizeof(limits[0])); l++)
314 Uint32 maxRows = limits[l].rows;
315 Uint32 maxBytes = limits[l].bytes;
318 if (ndbinfo.createScanOperation(table, &scanOp, maxRows, maxBytes))
320 g_err <<
"No NdbInfoScanOperation" << endl;
324 if (scanOp->readTuples() != 0)
326 g_err <<
"scanOp->readTuples failed" << endl;
331 while (scanOp->getValue(columnId))
334 assert(columnId >= 1);
336 if(scanOp->execute() != 0)
338 g_err <<
"scanOp->execute failed" << endl;
343 while(scanOp->nextResult() == 1)
345 ndbinfo.releaseScanOperation(scanOp);
347 ndbout_c(
"[%u,%u] rows: %d", maxRows, maxBytes, row);
353 g_err <<
"Got different number of rows this round, expected: "
354 << lastRows <<
", got: " << row << endl;
355 ndbinfo.closeTable(table);
361 ndbinfo.closeTable(table);
372 NdbInfo ndbinfo(&ctx->m_cluster_connection,
"ndbinfo/");
375 g_err <<
"ndbinfo.init failed" << endl;
380 if (ndbinfo.openTable(
"ndbinfo/test", &table) != 0)
382 g_err <<
"Failed to openTable(test)" << endl;
386 for (
int l = 0; l < ctx->getNumLoops(); l++)
390 if (ndbinfo.createScanOperation(table, &scanOp))
392 ndbinfo.closeTable(table);
393 g_err <<
"No NdbInfoScanOperation" << endl;
397 if (scanOp->readTuples() != 0)
399 ndbinfo.releaseScanOperation(scanOp);
400 ndbinfo.closeTable(table);
401 g_err <<
"scanOp->readTuples failed" << endl;
406 const NdbInfoRecAttr* blockNumber= scanOp->getValue(
"block_number");
407 const NdbInfoRecAttr* blockInstance= scanOp->getValue(
"block_instance");
411 if(scanOp->execute() != 0)
413 ndbinfo.releaseScanOperation(scanOp);
414 ndbinfo.closeTable(table);
415 g_err <<
"scanOp->execute failed" << endl;
421 while((ret = scanOp->nextResult()) == 1)
424 (void)nodeId->u_32_value();
425 (void)blockNumber->u_32_value();
426 (void)blockInstance->u_32_value();
427 (void)counter->u_32_value();
428 (void)counter2->u_64_value();
430 ndbinfo.releaseScanOperation(scanOp);
433 ndbinfo.closeTable(table);
434 g_err <<
"scan failed, ret: " << ret << endl;
437 ndbout <<
"rows: " << rows << endl;
441 ndbinfo.closeTable(table);
448 while (ctx->isTestStopped() ==
false) {
450 (void)runTestTable(ctx, step);
458 int result = NDBT_OK;
459 int loops = ctx->getNumLoops();
460 int sync_threads = ctx->getProperty(
"SyncThreads", (
unsigned)0);
461 int sleep0 = ctx->getProperty(
"Sleep0", (
unsigned)0);
462 int sleep1 = ctx->getProperty(
"Sleep1", (
unsigned)0);
463 int randnode = ctx->getProperty(
"RandNode", (
unsigned)0);
468 if (restarter.getNumDbNodes() < 2){
473 if(restarter.waitClusterStarted() != 0){
474 g_err <<
"Cluster failed to start" << endl;
478 if (loops > restarter.getNumDbNodes())
479 loops = restarter.getNumDbNodes();
481 while(i<loops && result != NDBT_FAILED && !ctx->isTestStopped()){
483 int id = lastId % restarter.getNumDbNodes();
486 id = rand() % restarter.getNumDbNodes();
488 int nodeId = restarter.getDbNodeId(
id);
489 ndbout <<
"Restart node " << nodeId << endl;
490 if(restarter.restartOneDbNode(nodeId,
false,
true,
true) != 0){
491 g_err <<
"Failed to restartNextDbNode" << endl;
492 result = NDBT_FAILED;
496 if (restarter.waitNodesNoStart(&nodeId, 1))
498 g_err <<
"Failed to waitNodesNoStart" << endl;
499 result = NDBT_FAILED;
504 NdbSleep_MilliSleep(sleep1);
506 if (restarter.startNodes(&nodeId, 1))
508 g_err <<
"Failed to start node" << endl;
509 result = NDBT_FAILED;
513 if(restarter.waitClusterStarted() != 0){
514 g_err <<
"Cluster failed to start" << endl;
515 result = NDBT_FAILED;
520 NdbSleep_MilliSleep(sleep0);
522 ctx->sync_up_and_wait(
"PauseThreads", sync_threads);
535 NDBT_TESTSUITE(testNdbinfo);
540 TESTCASE(
"NodeRestart",
"Scan NdbInfo tables while restarting nodes"){
542 STEPS(runTestTableUntilStopped, 1);
546 "Test ndbapi interface to NDB$INFO"){
547 INITIALIZER(runTestNdbInfo);
549 TESTCASE(
"Ndbinfo10",
550 "Test ndbapi interface to NDB$INFO"){
551 STEPS(runTestNdbInfo, 10);
554 "Scan all colums of all table known to NdbInfo"
555 "check that number of rows returned are constant"){
556 STEPS(runScanAll, 1);
558 TESTCASE(
"ScanAll10",
559 "Scan all columns of all table known to NdbInfo from "
560 "10 parallel threads, check that number of rows returned "
562 STEPS(runScanAll, 10);
565 "Randomly stop the scan"){
566 STEPS(runScanStop, 1);
568 TESTCASE(
"Ratelimit",
569 "Scan wit different combinations of ratelimit"){
570 STEPS(runRatelimit, 1);
572 TESTCASE(
"TestTable",
573 "Scan the test table and make sure it returns correct number "
574 "of rows which will depend on how many TUP blocks are configured"){
577 NDBT_TESTSUITE_END(testNdbinfo);
580 int main(
int argc,
const char** argv){
582 NDBT_TESTSUITE_INSTANCE(testNdbinfo);
583 testNdbinfo.setCreateTable(
false);
584 testNdbinfo.setRunAllTables(
true);
585 return testNdbinfo.execute(argc, argv);