⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utiltransactions.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      while (true){    if (retryAttempt >= retryMax){      g_info << "ERROR: has retried this operation " << retryAttempt 	     << " times, failing!" << endl;      return NDBT_FAILED;    }    pOp = getScanOperation(pTrans);    if (pOp == NULL) {      ERR(pTrans->getNdbError());      closeTransaction(pNdb);      return NDBT_FAILED;    }    if( pOp->readTuples(lm) ) {      ERR(pTrans->getNdbError());      closeTransaction(pNdb);      return NDBT_FAILED;    }    if(0){      NdbScanFilter sf(pOp);      sf.begin(NdbScanFilter::OR);      sf.eq(2, (Uint32)30);      sf.end();    } else {      check = pOp->interpret_exit_ok();      if( check == -1 ) {	ERR(pTrans->getNdbError());	closeTransaction(pNdb);	return NDBT_FAILED;      }    }            check = pTrans->execute(NoCommit);    if( check == -1 ) {      ERR(pTrans->getNdbError());      closeTransaction(pNdb);      return NDBT_FAILED;    }    int eof;    int rows = 0;        while((eof = pOp->nextResult()) == 0){      rows++;    }    if (eof == -1) {      const NdbError err = pTrans->getNdbError();            if (err.status == NdbError::TemporaryError){	closeTransaction(pNdb);	NdbSleep_MilliSleep(50);	retryAttempt++;	continue;      }      ERR(err);      closeTransaction(pNdb);      return NDBT_FAILED;    }        closeTransaction(pNdb);        if (count_rows != NULL){      *count_rows = rows;    }        return NDBT_OK;  }  return NDBT_FAILED;}  int UtilTransactions::verifyIndex(Ndb* pNdb,			      const char* indexName,			      int parallelism,			      bool transactional){    const NdbDictionary::Index* pIndex    = pNdb->getDictionary()->getIndex(indexName, tab.getName());  if (pIndex == 0){    ndbout << " Index " << indexName << " does not exist!" << endl;    return NDBT_FAILED;  }    switch (pIndex->getType()){  case NdbDictionary::Index::UniqueHashIndex:    return verifyUniqueIndex(pNdb, pIndex, parallelism, transactional);  case NdbDictionary::Index::OrderedIndex:    return verifyOrderedIndex(pNdb, pIndex, parallelism, transactional);    break;  default:    ndbout << "Unknown index type" << endl;    break;  }    return NDBT_FAILED;}int UtilTransactions::verifyUniqueIndex(Ndb* pNdb,				    const NdbDictionary::Index * pIndex,				    int parallelism,				    bool transactional){    /**   * Scan all rows in TABLE and for each found row make one read in   * TABLE and one using INDEX_TABLE. Then compare the two returned    * rows. They should be equal!   *   */  if (scanAndCompareUniqueIndex(pNdb, 				pIndex,				parallelism,				transactional) != NDBT_OK){    return NDBT_FAILED;  }  return NDBT_OK;  }int UtilTransactions::scanAndCompareUniqueIndex(Ndb* pNdb,					    const NdbDictionary::Index* pIndex,					    int parallelism,					    bool transactional){    int                  retryAttempt = 0;  const int            retryMax = 100;  int                  check;  NdbScanOperation       *pOp;  NDBT_ResultRow       row(tab);  parallelism = 1;  while (true){restart:    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) {      const NdbError err = pNdb->getNdbError();      closeTransaction(pNdb);      ERR(err);            if (err.status == NdbError::TemporaryError){	NdbSleep_MilliSleep(50);	retryAttempt++;	continue;      }      return NDBT_FAILED;    }    int rs;    if(transactional){      rs = pOp->readTuples(NdbScanOperation::LM_Read, 0, parallelism);    } else {      rs = pOp->readTuples(NdbScanOperation::LM_CommittedRead, 0, parallelism);    }        if( rs != 0 ) {      ERR(pTrans->getNdbError());      closeTransaction(pNdb);      return NDBT_FAILED;    }    check = pOp->interpret_exit_ok();    if( check == -1 ) {      ERR(pTrans->getNdbError());      closeTransaction(pNdb);      return NDBT_FAILED;    }    // Read all attributes    for (int a = 0; a < tab.getNoOfColumns(); a++){      if ((row.attributeStore(a) =  	   pOp->getValue(tab.getColumn(a)->getName())) == 0) {	ERR(pTrans->getNdbError());	closeTransaction(pNdb);	return NDBT_FAILED;      }    }    check = pTrans->execute(NoCommit);    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((eof = pOp->nextResult()) == 0){      rows++;            // ndbout << row.c_str().c_str() << endl;            if (readRowFromTableAndIndex(pNdb,				   pTrans,				   pIndex,				   row) != NDBT_OK){			while((eof= pOp->nextResult(false)) == 0);	if(eof == 2)	  eof = pOp->nextResult(true); // this should give -1	if(eof == -1)	{	  const NdbError err = pTrans->getNdbError();	  	  if (err.status == NdbError::TemporaryError){	    ERR(err);	    closeTransaction(pNdb);	    NdbSleep_MilliSleep(50);	    retryAttempt++;	    goto restart;	  }	}	closeTransaction(pNdb);	return NDBT_FAILED;      }    }    if (eof == -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;    }        closeTransaction(pNdb);        return NDBT_OK;  }  return NDBT_FAILED;}int UtilTransactions::readRowFromTableAndIndex(Ndb* pNdb,					   NdbConnection* scanTrans,					   const NdbDictionary::Index* pIndex,					   NDBT_ResultRow& row ){  NdbDictionary::Index::Type indexType= pIndex->getType();  int                  retryAttempt = 0;  const int            retryMax = 100;  int                  check, a;  NdbConnection	       *pTrans1=NULL;  NdbOperation	       *pOp;  int return_code= NDBT_FAILED;  // Allocate place to store the result  NDBT_ResultRow       tabRow(tab);  NDBT_ResultRow       indexRow(tab);  const char * indexName = pIndex->getName();  while (true){    if(retryAttempt)      ndbout_c("retryAttempt %d", retryAttempt);    if (retryAttempt >= retryMax){      g_info << "ERROR: has retried this operation " << retryAttempt 	     << " times, failing!" << endl;	goto close_all;    }    pTrans1 = pNdb->hupp(scanTrans); //startTransaction();    if (pTrans1 == NULL) {      const NdbError err = pNdb->getNdbError();            if (err.status == NdbError::TemporaryError){	ERR(err);	NdbSleep_MilliSleep(50);	retryAttempt++;	continue;      }      if(err.code == 0){	return_code = NDBT_OK;	goto close_all;      }      ERR(err);      goto close_all;    }    /**     * Read the record from TABLE     */    pOp = pTrans1->getNdbOperation(tab.getName());	    if (pOp == NULL) {      ERR(pTrans1->getNdbError());      goto close_all;    }        check = pOp->readTuple();    if( check == -1 ) {      ERR(pTrans1->getNdbError());      goto close_all;    }        // Define primary keys#if VERBOSE    printf("PK: ");#endif    for(a = 0; a<tab.getNoOfColumns(); a++){      const NdbDictionary::Column* attr = tab.getColumn(a);      if (attr->getPrimaryKey() == true){	if (pOp->equal(attr->getName(), row.attributeStore(a)->aRef()) != 0){	  ERR(pTrans1->getNdbError());	  goto close_all;	}#if VERBOSE	printf("%s = %d: ", attr->getName(), row.attributeStore(a)->aRef());#endif      }    }#if VERBOSE    printf("\n");#endif    // Read all attributes#if VERBOSE    printf("Reading %u attributes: ", tab.getNoOfColumns());#endif    for(a = 0; a<tab.getNoOfColumns(); a++){      if((tabRow.attributeStore(a) = 	  pOp->getValue(tab.getColumn(a)->getName())) == 0) {	ERR(pTrans1->getNdbError());	goto close_all;      }#if VERBOSE      printf("%s ", tab.getColumn(a)->getName());#endif    }#if VERBOSE    printf("\n");#endif    /**     * Read the record from INDEX_TABLE     */        NdbIndexOperation* pIndexOp= NULL;    NdbIndexScanOperation *pScanOp= NULL;    NdbOperation *pIOp= 0;    bool null_found= false;    for(a = 0; a<(int)pIndex->getNoOfColumns(); a++){      const NdbDictionary::Column *  col = pIndex->getColumn(a);            if (row.attributeStore(col->getName())->isNULL())      {	null_found= true;	break;      }    }        const char * tabName= tab.getName();    if(!null_found)    {      if (indexType == NdbDictionary::Index::UniqueHashIndex) {	pIOp= pIndexOp= pTrans1->getNdbIndexOperation(indexName, tabName);      } else {	pIOp= pScanOp= pTrans1->getNdbIndexScanOperation(indexName, tabName);      }            if (pIOp == NULL) {	ERR(pTrans1->getNdbError());	goto close_all;      }          {	bool not_ok;	if (pIndexOp) {	  not_ok = pIndexOp->readTuple() == -1;	} else {	  not_ok = pScanOp->readTuples();	}		if( not_ok ) {	  ERR(pTrans1->getNdbError());	  goto close_all;	}      }        // Define primary keys for index#if VERBOSE      printf("SI: ");#endif      for(a = 0; a<(int)pIndex->getNoOfColumns(); a++){	const NdbDictionary::Column *  col = pIndex->getColumn(a);		int r;	if ( !row.attributeStore(col->getName())->isNULL() ) {	  if(pIOp->equal(col->getName(), 			 row.attributeStore(col->getName())->aRef()) != 0){	    ERR(pTrans1->getNdbError());	    goto close_all;	  }	}#if VERBOSE	printf("%s = %d: ", col->getName(), row.attributeStore(a)->aRef());#endif      }#if VERBOSE      printf("\n");#endif            // Read all attributes#if VERBOSE      printf("Reading %u attributes: ", tab.getNoOfColumns());#endif      for(a = 0; a<tab.getNoOfColumns(); a++){	void* pCheck;		pCheck= indexRow.attributeStore(a)= 	  pIOp->getValue(tab.getColumn(a)->getName());		if(pCheck == NULL) {	  ERR(pTrans1->getNdbError());	  goto close_all;	}#if VERBOSE	printf("%s ", tab.getColumn(a)->getName());#endif      }    }#if VERBOSE    printf("\n");#endif    scanTrans->refresh();    check = pTrans1->execute(Commit);    if( check == -1 ) {      const NdbError err = pTrans1->getNdbError();            if (err.status == NdbError::TemporaryError){	ERR(err);	pNdb->closeTransaction(pTrans1);	NdbSleep_MilliSleep(50);	retryAttempt++;	continue;      }      ndbout << "Error when comparing records - normal op" << endl;      ERR(err);      ndbout << "row: " << row.c_str().c_str() << endl;      goto close_all;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -