int HugoOperations::pkDeleteRecord(Ndb* pNdb, int recordNo, int numRecords){ int check; for(int r=0; r < numRecords; r++){ NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest); if (pOp == NULL) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } check = pOp->deleteTuple(); if( check == -1 ) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } // Define primary keys if (equalForRow(pOp, r+recordNo) != 0) return NDBT_FAILED; Uint32 partId; if(getPartIdForRow(pOp, r+recordNo, partId)) pOp->setPartitionId(partId); } return NDBT_OK; }
int HugoOperations::pkInsertRecord(Ndb* pNdb, int recordNo, int numRecords, int updatesValue){ int check; for(int r=0; r < numRecords; r++){ NdbOperation* pOp = getOperation(pTrans, NdbOperation::InsertRequest); if (pOp == NULL) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } check = pOp->insertTuple(); if( check == -1 ) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK) { m_error.code = pTrans->getNdbError().code; return NDBT_FAILED; } Uint32 partId; if(getPartIdForRow(pOp, r+recordNo, partId)) pOp->setPartitionId(partId); } return NDBT_OK; }
int HugoOperations::pkUpdateRecord(Ndb* pNdb, int recordNo, int numRecords, int updatesValue){ allocRows(numRecords); int check; for(int r=0; r < numRecords; r++){ NdbOperation* pOp = getOperation(pTrans, NdbOperation::UpdateRequest); if (pOp == NULL) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } check = pOp->updateTuple(); if( check == -1 ) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK) { return NDBT_FAILED; } Uint32 partId; if(getPartIdForRow(pOp, r+recordNo, partId)) pOp->setPartitionId(partId); pOp->setAnyValue(getAnyValueForRowUpd(r+recordNo, updatesValue)); } return NDBT_OK; }
int HugoOperations::pkWritePartialRecord(Ndb* pNdb, int recordNo, int numRecords){ int check; for(int r=0; r < numRecords; r++){ NdbOperation* pOp = pTrans->getNdbOperation(tab.getName()); if (pOp == NULL) { NDB_ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } check = pOp->writeTuple(); if( check == -1 ) { NDB_ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } // Define primary keys if (equalForRow(pOp, r+recordNo) != 0) { g_err << __LINE__ << " equal for row failed" << endl; return NDBT_FAILED; } Uint32 partId; if(getPartIdForRow(pOp, r+recordNo, partId)) pOp->setPartitionId(partId); } return NDBT_OK; }
int HugoOperations::pkWriteRecord(Ndb* pNdb, int recordNo, int numRecords, int updatesValue){ int a, check; for(int r=0; r < numRecords; r++){ NdbOperation* pOp = pTrans->getNdbOperation(tab.getName()); if (pOp == NULL) { NDB_ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } check = pOp->writeTuple(); if( check == -1 ) { NDB_ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } // Define primary keys if (equalForRow(pOp, r+recordNo) != 0) { g_err << __LINE__ << " equal for row failed" << endl; return NDBT_FAILED; } Uint32 partId; if(getPartIdForRow(pOp, r+recordNo, partId)) pOp->setPartitionId(partId); // Define attributes to update for(a = 0; a<tab.getNoOfColumns(); a++){ if (tab.getColumn(a)->getPrimaryKey() == false){ if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){ NDB_ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } } } } return NDBT_OK; }
void BackupRestore::tuple_a(restore_callback_t *cb) { Uint32 partition_id = cb->fragId; while (cb->retries < 10) { /** * start transactions */ cb->connection = m_ndb->startTransaction(); if (cb->connection == NULL) { if (errorHandler(cb)) { m_ndb->sendPollNdb(3000, 1); continue; } err << "Cannot start transaction" << endl; exitHandler(); } // if const TupleS &tup = cb->tup; const NdbDictionary::Table * table = get_table(tup.getTable()->m_dictTable); NdbOperation * op = cb->connection->getNdbOperation(table); if (op == NULL) { if (errorHandler(cb)) continue; err << "Cannot get operation: " << cb->connection->getNdbError() << endl; exitHandler(); } // if if (op->writeTuple() == -1) { if (errorHandler(cb)) continue; err << "Error defining op: " << cb->connection->getNdbError() << endl; exitHandler(); } // if if (table->getFragmentType() == NdbDictionary::Object::UserDefined) { if (table->getDefaultNoPartitionsFlag()) { /* This can only happen for HASH partitioning with user defined hash function where user hasn't specified the number of partitions and we have to calculate it. We use the hash value stored in the record to calculate the partition to use. */ int i = tup.getNoOfAttributes() - 1; const AttributeData *attr_data = tup.getData(i); Uint32 hash_value = *attr_data->u_int32_value; op->setPartitionId(get_part_id(table, hash_value)); } else { /* Either RANGE or LIST (with or without subparts) OR HASH partitioning with user defined hash function but with fixed set of partitions. */ op->setPartitionId(partition_id); } } int ret = 0; for (int j = 0; j < 2; j++) { for (int i = 0; i < tup.getNoOfAttributes(); i++) { const AttributeDesc * attr_desc = tup.getDesc(i); const AttributeData * attr_data = tup.getData(i); int size = attr_desc->size; int arraySize = attr_desc->arraySize; char * dataPtr = attr_data->string_value; Uint32 length = 0; if (!attr_data->null) { const unsigned char * src = (const unsigned char *)dataPtr; switch(attr_desc->m_column->getType()){ case NdbDictionary::Column::Varchar: case NdbDictionary::Column::Varbinary: length = src[0] + 1; break; case NdbDictionary::Column::Longvarchar: case NdbDictionary::Column::Longvarbinary: length = src[0] + (src[1] << 8) + 2; break; default: length = attr_data->size; break; } } if (j == 0 && tup.getTable()->have_auto_inc(i)) tup.getTable()->update_max_auto_val(dataPtr,size*arraySize); if (attr_desc->m_column->getPrimaryKey()) { if (j == 1) continue; ret = op->equal(i, dataPtr, length); } else { if (j == 0) continue; if (attr_data->null) ret = op->setValue(i, NULL, 0); else ret = op->setValue(i, dataPtr, length); } if (ret < 0) { ndbout_c("Column: %d type %d %d %d %d",i, attr_desc->m_column->getType(), size, arraySize, length); break; } } if (ret < 0) break; } if (ret < 0) { if (errorHandler(cb)) continue; err << "Error defining op: " << cb->connection->getNdbError() << endl; exitHandler(); } // Prepare transaction (the transaction is NOT yet sent to NDB) cb->connection->executeAsynchPrepare(NdbTransaction::Commit, &callback, cb); m_transactions++; return; } err << "Retried transaction " << cb->retries << " times.\nLast error" << m_ndb->getNdbError(cb->error_code) << endl << "...Unable to recover from errors. Exiting..." << endl; exitHandler(); }
int HugoOperations::pkReadRecord(Ndb* pNdb, int recordNo, int numRecords, NdbOperation::LockMode lm, NdbOperation::LockMode *lmused){ int a; allocRows(numRecords); indexScans.clear(); int check; NdbOperation* pOp = 0; pIndexScanOp = 0; for(int r=0; r < numRecords; r++){ if(pOp == 0) { pOp = getOperation(pTrans, NdbOperation::ReadRequest); } if (pOp == NULL) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } rand_lock_mode: switch(lm){ case NdbOperation::LM_Read: case NdbOperation::LM_Exclusive: case NdbOperation::LM_CommittedRead: case NdbOperation::LM_SimpleRead: if (lmused) * lmused = lm; if(idx && idx->getType() == NdbDictionary::Index::OrderedIndex) { if (pIndexScanOp == 0) { pIndexScanOp = ((NdbIndexScanOperation*)pOp); bool mrrScan= (numRecords > 1); Uint32 flags= mrrScan? NdbScanOperation::SF_MultiRange : 0; check = pIndexScanOp->readTuples(lm, flags); /* Record NdbIndexScanOperation ptr for later... */ indexScans.push_back(pIndexScanOp); } } else check = pOp->readTuple(lm); break; default: lm = (NdbOperation::LockMode)((rand() >> 16) & 3); goto rand_lock_mode; } if( check == -1 ) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } // Define primary keys if (equalForRow(pOp, r+recordNo) != 0) return NDBT_FAILED; Uint32 partId; /* Do we need to set the partitionId for this operation? */ if (getPartIdForRow(pOp, r+recordNo, partId)) { g_info << "Setting operation partition Id" << endl; pOp->setPartitionId(partId); } if(pIndexScanOp) pIndexScanOp->end_of_bound(r); if(r == 0 || pIndexScanOp == 0) { // Define attributes to read for(a = 0; a<tab.getNoOfColumns(); a++){ if((rows[r]->attributeStore(a) = pOp->getValue(tab.getColumn(a)->getName())) == 0) { ERR(pTrans->getNdbError()); setNdbError(pTrans->getNdbError()); return NDBT_FAILED; } } } /* Note pIndexScanOp will point to the 'last' index scan op * we used. The full list is in the indexScans vector */ pOp = pIndexScanOp; } return NDBT_OK; }