int UtilTransactions::verifyOrderedIndex(Ndb* pNdb, const NdbDictionary::Index* pIndex, int parallelism, bool transactional){ int retryAttempt = 0; const int retryMax = 100; int check; NdbScanOperation *pOp; NdbIndexScanOperation * iop = 0; NDBT_ResultRow scanRow(tab); NDBT_ResultRow pkRow(tab); NDBT_ResultRow indexRow(tab); const char * indexName = pIndex->getName(); int res; parallelism = 1; 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){ ERR(err); NdbSleep_MilliSleep(50); retryAttempt++; continue; } ERR(err); return NDBT_FAILED; } pOp = pTrans->getNdbScanOperation(tab.getName()); if (pOp == NULL) { ERR(pTrans->getNdbError()); closeTransaction(pNdb); return NDBT_FAILED; } if( pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism) ) { ERR(pTrans->getNdbError()); closeTransaction(pNdb); return NDBT_FAILED; } check = pOp->interpret_exit_ok(); if( check == -1 ) { ERR(pTrans->getNdbError()); closeTransaction(pNdb); return NDBT_FAILED; } if(get_values(pOp, scanRow)) { abort(); } check = pTrans->execute(NoCommit, AbortOnError); if( check == -1 ) { const NdbError err = pTrans->getNdbError(); if (err.status == NdbError::TemporaryError){ ERR(err); closeTransaction(pNdb); NdbSleep_MilliSleep(50); retryAttempt++; continue; } ERR(err); closeTransaction(pNdb); return NDBT_FAILED; } int eof; int rows = 0; while(check == 0 && (eof = pOp->nextResult()) == 0){ rows++; bool null_found= false; for(int a = 0; a<(int)pIndex->getNoOfColumns(); a++){ const NdbDictionary::Column * col = pIndex->getColumn(a); if (scanRow.attributeStore(col->getName())->isNULL()) { null_found= true; break; } } // Do pk lookup NdbOperation * pk = pTrans->getNdbOperation(tab.getName()); if(!pk || pk->readTuple()) goto error; if(equal(&tab, pk, scanRow) || get_values(pk, pkRow)) goto error; if(!null_found) { if(!iop && (iop= pTrans->getNdbIndexScanOperation(indexName, tab.getName()))) { if(iop->readTuples(NdbScanOperation::LM_CommittedRead, parallelism)) goto error; iop->interpret_exit_ok(); if(get_values(iop, indexRow)) goto error; } else if(!iop || iop->reset_bounds()) { goto error; } if(equal(pIndex, iop, scanRow)) goto error; } check = pTrans->execute(NoCommit, AbortOnError); if(check) goto error; if(scanRow.c_str() != pkRow.c_str()){ g_err << "Error when comapring records" << endl; g_err << " scanRow: \n" << scanRow.c_str().c_str() << endl; g_err << " pkRow: \n" << pkRow.c_str().c_str() << endl; closeTransaction(pNdb); return NDBT_FAILED; } if(!null_found) { if((res= iop->nextResult()) != 0){ g_err << "Failed to find row using index: " << res << endl; ERR(pTrans->getNdbError()); closeTransaction(pNdb); return NDBT_FAILED; } if(scanRow.c_str() != indexRow.c_str()){ g_err << "Error when comapring records" << endl; g_err << " scanRow: \n" << scanRow.c_str().c_str() << endl; g_err << " indexRow: \n" << indexRow.c_str().c_str() << endl; closeTransaction(pNdb); return NDBT_FAILED; } if(iop->nextResult() == 0){ g_err << "Found extra row!!" << endl; g_err << " indexRow: \n" << indexRow.c_str().c_str() << endl; closeTransaction(pNdb); return NDBT_FAILED; } } } if (eof == -1 || check == -1) { error: const NdbError err = pTrans->getNdbError(); if (err.status == NdbError::TemporaryError){ ERR(err); iop = 0; closeTransaction(pNdb); NdbSleep_MilliSleep(50); retryAttempt++; rows--; continue; } ERR(err); closeTransaction(pNdb); return NDBT_FAILED; } closeTransaction(pNdb); return NDBT_OK; } return NDBT_FAILED; }
int run_scan(){ int iter = g_paramters[P_LOOPS].value; NDB_TICKS start1, stop; int sum_time= 0; int sample_rows = 0; int tot_rows = 0; NDB_TICKS sample_start = NdbTick_CurrentMillisecond(); Uint32 tot = g_paramters[P_ROWS].value; if(g_paramters[P_BOUND].value >= 2 || g_paramters[P_FILT].value == 2) iter *= g_paramters[P_ROWS].value; NdbScanOperation * pOp = 0; NdbIndexScanOperation * pIOp = 0; NdbConnection * pTrans = 0; int check = 0; for(int i = 0; i<iter; i++){ start1 = NdbTick_CurrentMillisecond(); pTrans = pTrans ? pTrans : g_ndb->startTransaction(); if(!pTrans){ g_err << "Failed to start transaction" << endl; err(g_ndb->getNdbError()); return -1; } int par = g_paramters[P_PARRA].value; int bat = 0; // g_paramters[P_BATCH].value; NdbScanOperation::LockMode lm; switch(g_paramters[P_LOCK].value){ case 0: lm = NdbScanOperation::LM_CommittedRead; break; case 1: lm = NdbScanOperation::LM_Read; break; case 2: lm = NdbScanOperation::LM_Exclusive; break; default: abort(); } if(g_paramters[P_ACCESS].value == 0){ pOp = pTrans->getNdbScanOperation(g_tablename); assert(pOp); pOp->readTuples(lm, bat, par); } else { if(g_paramters[P_RESET].value == 0 || pIOp == 0) { pOp= pIOp= pTrans->getNdbIndexScanOperation(g_indexname, g_tablename); bool ord = g_paramters[P_ACCESS].value == 2; pIOp->readTuples(lm, bat, par, ord); } else { pIOp->reset_bounds(); } switch(g_paramters[P_BOUND].value){ case 0: // All break; case 1: // None pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, 0); break; case 2: { // 1 row default: assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far int tot = g_paramters[P_ROWS].value; int row = rand() % tot; #if 0 fix_eq_bound(pIOp, row); #else pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, &row); #endif if(g_paramters[P_RESET].value == 2) goto execute; break; } case 3: { // read multi int multi = g_paramters[P_MULTI].value; int tot = g_paramters[P_ROWS].value; for(; multi > 0 && i < iter; --multi, i++) { int row = rand() % tot; pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, &row); pIOp->end_of_bound(i); } if(g_paramters[P_RESET].value == 2) goto execute; break; } } } assert(pOp); switch(g_paramters[P_FILT].value){ case 0: // All check = pOp->interpret_exit_ok(); break; case 1: // None check = pOp->interpret_exit_nok(); break; case 2: { // 1 row default: assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far abort(); #if 0 int tot = g_paramters[P_ROWS].value; int row = rand() % tot; NdbScanFilter filter(pOp) ; filter.begin(NdbScanFilter::AND); fix_eq(filter, pOp, row); filter.end(); break; #endif } } if(check != 0){ err(pOp->getNdbError()); return -1; } assert(check == 0); if(g_paramters[P_RESET].value == 1) g_paramters[P_RESET].value = 2; for(int i = 0; i<g_table->getNoOfColumns(); i++){ pOp->getValue(i); } if(g_paramters[P_RESET].value == 1) g_paramters[P_RESET].value = 2; execute: int rows = 0; check = pTrans->execute(NoCommit); assert(check == 0); int fetch = g_paramters[P_FETCH].value; while((check = pOp->nextResult(true)) == 0){ do { rows++; } while(!fetch && ((check = pOp->nextResult(false)) == 0)); if(check == -1){ err(pTrans->getNdbError()); return -1; } assert(check == 2); } if(check == -1){ err(pTrans->getNdbError()); return -1; } assert(check == 1); if(g_paramters[P_RESET].value == 0) { pTrans->close(); pTrans = 0; } stop = NdbTick_CurrentMillisecond(); int time_passed= (int)(stop - start1); sample_rows += rows; sum_time+= time_passed; tot_rows+= rows; if(sample_rows >= tot) { int sample_time = (int)(stop - sample_start); g_info << "Found " << sample_rows << " rows" << endl; g_err.println("Time: %d ms = %u rows/sec", sample_time, (1000*sample_rows)/sample_time); sample_rows = 0; sample_start = stop; } } g_err.println("Avg time: %d ms = %u rows/sec", sum_time/tot_rows, (1000*tot_rows)/sum_time); return 0; }