int select_count(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism, Uint64* count_rows, NdbOperation::LockMode lock) { int retryAttempt = 0; const int retryMax = 100; int check; NdbTransaction *pTrans; NdbScanOperation *pOp; const Uint32 codeWords= 1; Uint32 codeSpace[ codeWords ]; NdbInterpretedCode code(NULL, // Table is irrelevant &codeSpace[0], codeWords); if ((code.interpret_exit_last_row() != 0) || (code.finalise() != 0)) { ERR(code.getNdbError()); return NDBT_FAILED; } while (true) { if (retryAttempt >= retryMax) { g_info << "ERROR: has retried this operation " << retryAttempt << " times, failing!" << endl; return NDBT_FAILED; } pTrans = pNdb->startTransaction(); if (pTrans == NULL) { const NdbError err = pNdb->getNdbError(); if (err.status == NdbError::TemporaryError) { NdbSleep_MilliSleep(50); retryAttempt++; continue; } ERR(err); return NDBT_FAILED; } pOp = pTrans->getNdbScanOperation(pTab->getName()); if (pOp == NULL) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if( pOp->readTuples(NdbScanOperation::LM_Dirty) ) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } check = pOp->setInterpretedCode(&code); if( check == -1 ) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } Uint64 tmp; Uint32 row_size; pOp->getValue(NdbDictionary::Column::ROW_COUNT, (char*)&tmp); pOp->getValue(NdbDictionary::Column::ROW_SIZE, (char*)&row_size); check = pTrans->execute(NdbTransaction::NoCommit); if( check == -1 ) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } Uint64 row_count = 0; int eof; while((eof = pOp->nextResult(true)) == 0) { row_count += tmp; } if (eof == -1) { const NdbError err = pTrans->getNdbError(); if (err.status == NdbError::TemporaryError) { pNdb->closeTransaction(pTrans); NdbSleep_MilliSleep(50); retryAttempt++; continue; } ERR(err); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } pNdb->closeTransaction(pTrans); if (count_rows != NULL) { *count_rows = row_count; } return NDBT_OK; } return NDBT_FAILED; }
int runTestBug34107(NDBT_Context* ctx, NDBT_Step* step){ const NdbDictionary::Table * pTab = ctx->getTab(); Ndb* pNdb = GETNDB(step); const Uint32 okSize= 10000; const Uint32 tooBig= 30000; Uint32 codeBuff[tooBig]; int i; for (i = 0; i <= 1; i++) { g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl; NdbConnection* pTrans = pNdb->startTransaction(); if (pTrans == NULL){ ERR(pNdb->getNdbError()); return NDBT_FAILED; } NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName()); if (pOp == NULL) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if (pOp->readTuples() == -1) { ERR(pOp->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } /* Test kernel mechanism for dealing with too large program * We need to provide our own program buffer as default * NdbInterpretedCode buffer will not grow larger than * NDB_MAX_SCANFILTER_SIZE */ NdbInterpretedCode code(NULL, // Table is irrelevant codeBuff, tooBig); // Size of codeBuff int n = i == 0 ? okSize : tooBig; int k; for (k = 0; k < n; k++) { // inserts 1 word ATTRINFO if (code.interpret_exit_ok() == -1) { ERR(code.getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } } if (code.finalise() != 0) { ERR(code.getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if (pOp->setInterpretedCode(&code) != 0) { ERR(pOp->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if (pTrans->execute(NoCommit) == -1) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } int ret; while ((ret = pOp->nextResult()) == 0) ; g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl; if (i == 0 && ret != 1) { ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if (i == 1 && ret != -1) { g_err << "unexpected big filter success" << endl; pNdb->closeTransaction(pTrans); return NDBT_FAILED; } if (i == 1 && pOp->getNdbError().code != 874) { g_err << "unexpected big filter error code, wanted 874" << endl; ERR(pTrans->getNdbError()); pNdb->closeTransaction(pTrans); return NDBT_FAILED; } pNdb->closeTransaction(pTrans); } return NDBT_OK; }