Commit 01d6b13c authored by unknown's avatar unknown
Browse files

ndb - hugo - add new method for setting primary key(s)


storage/ndb/test/include/HugoOperations.hpp:
  Add method for setting of primary key
storage/ndb/test/src/HugoAsynchTransactions.cpp:
  Add method for setting of primary key
storage/ndb/test/src/HugoOperations.cpp:
  Add method for setting of primary key
storage/ndb/test/src/HugoTransactions.cpp:
  Add method for setting of primary key
parent 7b3751fc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ public:
		   int attrId, 
		   int rowId);

  int equalForRow(NdbOperation*, int rowid);
  
  int setValues(NdbOperation*, int rowId, int updateId);
  
  int verifyUpdatesValue(int updatesValue, int _numRows = 0);
+23 −35
Original line number Diff line number Diff line
@@ -188,15 +188,12 @@ HugoAsynchTransactions::pkUpdateRecordsAsynch(Ndb* pNdb,
	  // Read
	  // Define primary keys
	  check = pOp->readTupleExclusive();
	  for (a = 0; a < tab.getNoOfColumns(); a++) {
	    if (tab.getColumn(a)->getPrimaryKey() == true) {
	      if (equalForAttr(pOp, a, cReadRecords) != 0){
          if (equalForRow(pOp, cReadRecords) != 0)
          {
            ERR(transactions[t]->getNdbError());
            pNdb->closeTransaction(transactions[t]);
            return NDBT_FAILED;
	  }	    
	    }
	  }	    
	  // Define attributes to read  
	  for (a = 0; a < tab.getNoOfColumns(); a++) {
	    if ((rows[cReadIndex]->attributeStore(a) = 
@@ -259,15 +256,12 @@ HugoAsynchTransactions::pkUpdateRecordsAsynch(Ndb* pNdb,
	  }

	  // Set search condition for the record
	  for (a = 0; a < tab.getNoOfColumns(); a++) {
	    if (tab.getColumn(a)->getPrimaryKey() == true) {
	      if (equalForAttr(pOp, a, cRecords) != 0) {
          if (equalForRow(pOp, cReadRecords) != 0)
          {
            ERR(transactions[t]->getNdbError());
            pNdb->closeTransaction(transactions[t]);
            return NDBT_FAILED;
	  }	    
	    }
	  }

	  // Update the record
	  for (a = 0; a < tab.getNoOfColumns(); a++) {
@@ -396,15 +390,12 @@ HugoAsynchTransactions::executeAsynchOperation(Ndb* pNdb,
	  case NO_READ:
	    // Define primary keys
	    check = pOp->readTuple();
	    for (a = 0; a < tab.getNoOfColumns(); a++) {
	      if (tab.getColumn(a)->getPrimaryKey() == true) {
		if (equalForAttr(pOp, a, cRecords) != 0){
            if (equalForRow(pOp, cRecords) != 0)
            {
              ERR(transactions[t]->getNdbError());
              pNdb->closeTransaction(transactions[t]);
              return NDBT_FAILED;
            }	    
	      }
	    }	    
	    // Define attributes to read  
	    for (a = 0; a < tab.getNoOfColumns(); a++) {
	      if ((rows[cIndex]->attributeStore(a) = 
@@ -425,15 +416,12 @@ HugoAsynchTransactions::executeAsynchOperation(Ndb* pNdb,
	    }

	    // Define primary keys
	    for (a = 0; a < tab.getNoOfColumns(); a++) {
	      if (tab.getColumn(a)->getPrimaryKey() == true){
		if (equalForAttr(pOp, a, cRecords) != 0) {
            if (equalForRow(pOp, cRecords) != 0)
            {
              ERR(transactions[t]->getNdbError());
              pNdb->closeTransaction(transactions[t]);
              return NDBT_FAILED;
            }    
	      }
	    }
	    break;
	  default:
	    // Should not happen...
+33 −60
Original line number Diff line number Diff line
@@ -111,14 +111,8 @@ int HugoOperations::pkReadRecord(Ndb* pNdb,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
	}
      }
    }

    if(pIndexScanOp)
      pIndexScanOp->end_of_bound(r);
@@ -143,7 +137,6 @@ int HugoOperations::pkUpdateRecord(Ndb* pNdb,
				   int recordNo,
				   int numRecords,
				   int updatesValue){
  int a; 
  allocRows(numRecords);
  int check;
  for(int r=0; r < numRecords; r++){
@@ -172,14 +165,8 @@ HugoOperations::setValues(NdbOperation* pOp, int rowId, int updateId)
{
  // Define primary keys
  int a;
  for(a = 0; a<tab.getNoOfColumns(); a++){
    if (tab.getColumn(a)->getPrimaryKey() == true){
      if(equalForAttr(pOp, a, rowId) != 0){
	ERR(pTrans->getNdbError());
  if (equalForRow(pOp, rowId) != 0)
    return NDBT_FAILED;
      }
    }
  }
  
  for(a = 0; a<tab.getNoOfColumns(); a++){
    if (tab.getColumn(a)->getPrimaryKey() == false){
@@ -198,7 +185,7 @@ int HugoOperations::pkInsertRecord(Ndb* pNdb,
				   int numRecords,
				   int updatesValue){
  
  int a, check;
  int check;
  for(int r=0; r < numRecords; r++){
    NdbOperation* pOp = getOperation(pTrans, NdbOperation::InsertRequest);
    if (pOp == NULL) {
@@ -240,14 +227,8 @@ int HugoOperations::pkWriteRecord(Ndb* pNdb,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
	}
      }
    }
    
    // Define attributes to update
    for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -266,7 +247,7 @@ int HugoOperations::pkWritePartialRecord(Ndb* pNdb,
					 int recordNo,
					 int numRecords){
  
  int a, check;
  int check;
  for(int r=0; r < numRecords; r++){
    NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());	
    if (pOp == NULL) {
@@ -281,15 +262,9 @@ int HugoOperations::pkWritePartialRecord(Ndb* pNdb,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
  }
      }
    }
  }
  return NDBT_OK;
}

@@ -297,7 +272,7 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb,
				   int recordNo,
				   int numRecords){
  
  int a, check;
  int check;
  for(int r=0; r < numRecords; r++){
    NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest);
    if (pOp == NULL) {
@@ -312,15 +287,9 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
  }
      }
    }
  }
  return NDBT_OK;
}

@@ -518,6 +487,22 @@ HugoOperations::~HugoOperations(){
  }
}

int
HugoOperations::equalForRow(NdbOperation* pOp, int row)
{
  for(int a = 0; a<tab.getNoOfColumns(); a++)
  {
    if (tab.getColumn(a)->getPrimaryKey() == true)
    {
      if(equalForAttr(pOp, a, row) != 0)
      {
        ERR(pOp->getNdbError());
        return NDBT_FAILED;
      }
    }
  }
  return NDBT_OK;
}

int HugoOperations::equalForAttr(NdbOperation* pOp,
				   int attrId, 
@@ -676,14 +661,8 @@ int HugoOperations::indexReadRecords(Ndb*, const char * idxName, int recordNo,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
	}
      }
    }
    
    // Define attributes to read  
    for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -720,14 +699,8 @@ HugoOperations::indexUpdateRecord(Ndb*,
    }
    
    // Define primary keys
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pOp, a, r+recordNo) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;
	}
      }
    }
    
    // Define attributes to update
    for(a = 0; a<tab.getNoOfColumns(); a++){
+29 −53
Original line number Diff line number Diff line
@@ -520,10 +520,9 @@ HugoTransactions::loadTable(Ndb* pNdb,
                            bool oneTrans,
			    int value,
			    bool abort){
  int             check, a;
  int             check;
  int             retryAttempt = 0;
  int             retryMax = 5;
  NdbOperation	  *pOp;
  bool            first_batch = true;

  const int org = batch;
@@ -667,10 +666,9 @@ HugoTransactions::loadTable(Ndb* pNdb,
int
HugoTransactions::fillTable(Ndb* pNdb, 
			    int batch){
  int             check, a, b;
  int             check;
  int             retryAttempt = 0;
  int             retryMax = 5;
  NdbOperation	  *pOp;

  const int org = batch;
  const int cols = tab.getNoOfColumns();
@@ -791,7 +789,7 @@ HugoTransactions::pkReadRecords(Ndb* pNdb,
  int                  reads = 0;
  int                  r = 0;
  int                  retryAttempt = 0;
  int                  check, a;
  int                  check;

  if (batch == 0) {
    g_info << "ERROR: Argument batch == 0 in pkReadRecords(). Not allowed." << endl;
@@ -910,8 +908,7 @@ HugoTransactions::pkUpdateRecords(Ndb* pNdb,
  int updated = 0;
  int                  r = 0;
  int                  retryAttempt = 0;
  int                  check, a, b;
  NdbOperation	       *pOp;
  int                  check, b;

  allocRows(batch);

@@ -1097,15 +1094,11 @@ HugoTransactions::pkInterpretedUpdateRecords(Ndb* pNdb,
   }
   
   // Define primary keys
   for(a = 0; a<tab.getNoOfColumns(); a++){
     if (tab.getColumn(a)->getPrimaryKey() == true){
       if(equalForAttr(pOp, a, r) != 0){
	 ERR(pTrans->getNdbError());
   if (equalForRow(pOp, r) != 0)
   {
     closeTransaction(pNdb);
     return NDBT_FAILED;
   }
     }
   }
   
   // Read update value
   for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -1153,15 +1146,11 @@ HugoTransactions::pkInterpretedUpdateRecords(Ndb* pNdb,
    }

    // PKs
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if (tab.getColumn(a)->getPrimaryKey() == true){
	if(equalForAttr(pUpdOp, a, r) != 0){
	  ERR(pTrans->getNdbError());
    if (equalForRow(pOp, r) != 0)
    {
      closeTransaction(pNdb);
      return NDBT_FAILED;
    }
      }
    }

    // Update col
    for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -1236,8 +1225,7 @@ HugoTransactions::pkDelRecords(Ndb* pNdb,
  int deleted = 0;
  int                  r = 0;
  int                  retryAttempt = 0;
  int                  check, a;
  NdbOperation	       *pOp;
  int                  check;

  g_info << "|- Deleting records..." << endl;
  while (r < records){
@@ -1335,8 +1323,7 @@ HugoTransactions::lockRecords(Ndb* pNdb,
  // and lock som other records
  int                  r = 0;
  int                  retryAttempt = 0;
  int                  check, a, b;
  NdbOperation	       *pOp;
  int                  check;
  NdbOperation::LockMode lm = NdbOperation::LM_Exclusive;

  // Calculate how many records to lock in each batch
@@ -1522,15 +1509,11 @@ HugoTransactions::indexReadRecords(Ndb* pNdb,
      }
      
      // Define primary keys
      for(a = 0; a<tab.getNoOfColumns(); a++){
	if (tab.getColumn(a)->getPrimaryKey() == true){
	  if(equalForAttr(pOp, a, r+b) != 0){
	    ERR(pTrans->getNdbError());
      if (equalForRow(pOp, r+b) != 0)
      {
        closeTransaction(pNdb);
        return NDBT_FAILED;
      }
	}
      }
      
      // Define attributes to read  
      for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -1663,15 +1646,11 @@ HugoTransactions::indexUpdateRecords(Ndb* pNdb,
      }	
      
      // Define primary keys
      for(a = 0; a<tab.getNoOfColumns(); a++){
	if (tab.getColumn(a)->getPrimaryKey() == true){
	  if(equalForAttr(pOp, a, r+b) != 0){
	    ERR(pTrans->getNdbError());
      if (equalForRow(pOp, r+b) != 0)
      {
        closeTransaction(pNdb);
        return NDBT_FAILED;
      }
	}
      }
      
      // Define attributes to read  
      for(a = 0; a<tab.getNoOfColumns(); a++){
@@ -1733,17 +1712,14 @@ HugoTransactions::indexUpdateRecords(Ndb* pNdb,
	return NDBT_FAILED;
      }
      
      if(!ordered){
	for(a = 0; a<tab.getNoOfColumns(); a++){
	  if (tab.getColumn(a)->getPrimaryKey() == true){
	    if(equalForAttr(pUpdOp, a, r+b) != 0){
	      ERR(pTrans->getNdbError());
      if(!ordered)
      {
        if (equalForRow(pOp, r+b) != 0)
        {
          closeTransaction(pNdb);
          return NDBT_FAILED;
        }
      }
	}
      }
      
      for(a = 0; a<tab.getNoOfColumns(); a++){
	if (tab.getColumn(a)->getPrimaryKey() == false){