本文整理汇总了C++中NdbOperation::updateTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ NdbOperation::updateTuple方法的具体用法?C++ NdbOperation::updateTuple怎么用?C++ NdbOperation::updateTuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NdbOperation
的用法示例。
在下文中一共展示了NdbOperation::updateTuple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/**
* Transaction 1 - T1
*
* Update location and changed by/time on a subscriber
*
* Input:
* SubscriberNumber,
* Location,
* ChangedBy,
* ChangedTime
*
* Output:
*/
void
start_T1(Ndb * pNDB, ThreadData * td){
DEBUG2("T1(%.*s): - Starting\n", SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number);
int check;
NdbConnection * pCON = pNDB->startTransaction();
if (pCON != NULL) {
NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
if (MyOp != NULL) {
MyOp->updateTuple();
MyOp->equal(IND_SUBSCRIBER_NUMBER,
td->transactionData.number);
MyOp->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&td->transactionData.location);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
td->transactionData.changed_by);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
td->transactionData.changed_time);
pCON->executeAsynchPrepare( Commit , T1_Callback, td);
} else {
CHECK_NULL(MyOp, "T1: getNdbOperation", pCON);
}//if
} else {
error_handler("T1-1: startTranscation",
pNDB->getNdbErrorString(),
pNDB->getNdbError());
}//if
}
示例2: pkUpdateRecord
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());
return NDBT_FAILED;
}
check = pOp->updateTuple();
if( check == -1 ) {
ERR(pTrans->getNdbError());
return NDBT_FAILED;
}
if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)
{
return NDBT_FAILED;
}
}
return NDBT_OK;
}
示例3: pkUpdateRecord
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;
}
示例4: while
void
start_T1(Ndb * pNDB, ThreadData * td, int async){
DEBUG2("T1(%.*s): - Starting", SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number);
NdbConnection * pCON = 0;
while((pCON = startTransaction(pNDB, td)) == 0){
CHECK_ALLOWED_ERROR("T1: startTransaction", td, pNDB->getNdbError());
NdbSleep_MilliSleep(10);
}
NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
if (MyOp != NULL) {
MyOp->updateTuple();
MyOp->equal(IND_SUBSCRIBER_NUMBER,
td->transactionData.number);
MyOp->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&td->transactionData.location);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
td->transactionData.changed_by);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
td->transactionData.changed_time);
if (async == 1) {
pCON->executeAsynchPrepare( Commit , T1_Callback, td);
} else {
int result = pCON->execute(Commit);
T1_Callback(result, pCON, (void*)td);
return;
}//if
} else {
CHECK_NULL(MyOp, "T1: getNdbOperation", td, pCON->getNdbError());
}//if
}
示例5: UpdateTransaction
int UpdateTransaction(Ndb* pNdb, long iContextId, NdbError& err)
{
int iRes = -1;
NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextId, 4);
if(pNdbConnection)
{
NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
if(pNdbOperation)
{
if(!pNdbOperation->updateTuple()
&& !pNdbOperation->equal(c_szContextId, (Int32)iContextId)
&& !pNdbOperation->setValue(c_szContextData, STATUS_DATA, g_nStatusDataSize))
{
if(!pNdbConnection->execute(Commit))
iRes = 0;
else
err = pNdbConnection->getNdbError();
}
else
err = pNdbOperation->getNdbError();
}
else
err = pNdbConnection->getNdbError();
pNdb->closeTransaction(pNdbConnection);
}
else
err = pNdb->getNdbError();
return iRes;
}
示例6:
/**
* Transaction 1 - T1
*
* Update location and changed by/time on a subscriber
*
* Input:
* SubscriberNumber,
* Location,
* ChangedBy,
* ChangedTime
*
* Output:
*/
int
T1(void * obj,
const SubscriberNumber number,
const Location new_location,
const ChangedBy changed_by,
const ChangedTime changed_time,
BenchmarkTime * transaction_time){
Ndb * pNDB = (Ndb *) obj;
DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
BenchmarkTime start;
get_time(&start);
int check;
NdbRecAttr * check2;
NdbConnection * MyTransaction = pNDB->startTransaction();
if (MyTransaction == NULL)
error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), 0);
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
check = MyOperation->updateTuple();
CHECK_MINUS_ONE(check, "T1: updateTuple",
MyTransaction);
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
number);
CHECK_MINUS_ONE(check, "T1: equal subscriber",
MyTransaction);
check = MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&new_location);
CHECK_MINUS_ONE(check, "T1: setValue location",
MyTransaction);
check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
changed_by);
CHECK_MINUS_ONE(check, "T1: setValue changed_by",
MyTransaction);
check = MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
changed_time);
CHECK_MINUS_ONE(check, "T1: setValue changed_time",
MyTransaction);
check = MyTransaction->execute( Commit );
CHECK_MINUS_ONE(check, "T1: Commit",
MyTransaction);
pNDB->closeTransaction(MyTransaction);
get_time(transaction_time);
time_diff(transaction_time, &start);
return 0;
}
示例7: run_master_update
static void run_master_update(struct Xxx &xxx, struct XxxR &xxxr)
{
Ndb *ndb = xxx.ndb;
const NdbDictionary::Table *myTable = xxx.table;
int retry_sleep= 10; /* 10 milliseconds */
int retries= 100;
while (1)
{
Uint32 val;
NdbTransaction *trans = ndb->startTransaction();
if (trans == NULL)
goto err;
{
NdbOperation *op = trans->getNdbOperation(myTable);
if (op == NULL)
APIERROR(trans->getNdbError());
op->readTupleExclusive();
op->equal(xxx.pk_col, xxxr.pk_val);
op->getValue(xxx.col, (char *)&val);
}
if (trans->execute(NdbTransaction::NoCommit))
goto err;
//fprintf(stderr, "read %u\n", val);
xxxr.val = val + 1;
{
NdbOperation *op = trans->getNdbOperation(myTable);
if (op == NULL)
APIERROR(trans->getNdbError());
op->updateTuple();
op->equal(xxx.pk_col, xxxr.pk_val);
op->setValue(xxx.col, xxxr.val);
}
if (trans->execute(NdbTransaction::Commit))
goto err;
ndb->closeTransaction(trans);
//fprintf(stderr, "updated to %u\n", xxxr.val);
break;
err:
const NdbError this_error= trans ?
trans->getNdbError() : ndb->getNdbError();
if (this_error.status == NdbError::TemporaryError)
{
if (retries--)
{
if (trans)
ndb->closeTransaction(trans);
NdbSleep_MilliSleep(retry_sleep);
continue; // retry
}
}
if (trans)
ndb->closeTransaction(trans);
APIERROR(this_error);
}
/* update done start timer */
gettimeofday(&xxxr.start_time, 0);
}
示例8: allocRows
int
HugoOperations::indexUpdateRecord(Ndb*,
const char * idxName,
int recordNo,
int numRecords,
int updatesValue){
int a;
allocRows(numRecords);
int check;
for(int r=0; r < numRecords; r++){
NdbOperation* pOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
if (pOp == NULL) {
NDB_ERR(pTrans->getNdbError());
setNdbError(pTrans->getNdbError());
return NDBT_FAILED;
}
check = pOp->updateTuple();
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;
}
// 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;
}
示例9:
/**
* Transaction 1 - T1
*
* Update location and changed by/time on a subscriber
*
* Input:
* SubscriberNumber,
* Location,
* ChangedBy,
* ChangedTime
*
* Output:
*/
void
userTransaction_T1(UserHandle * uh,
SubscriberNumber number,
Location new_location,
ChangedBy changed_by,
ChangedTime changed_time){
Ndb * pNDB = uh->pNDB;
DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
int check;
NdbRecAttr * check2;
NdbConnection * MyTransaction = pNDB->startTransaction();
if (MyTransaction != NULL) {
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
if (MyOperation != NULL) {
MyOperation->updateTuple();
MyOperation->equal(IND_SUBSCRIBER_NUMBER,
number);
MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&new_location);
MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
changed_by);
MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
changed_time);
check = MyTransaction->execute( Commit );
if (check != -1) {
pNDB->closeTransaction(MyTransaction);
return;
} else {
CHECK_MINUS_ONE(check, "T1: Commit",
MyTransaction);
}//if
} else {
CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
}//if
} else {
error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
}//if
}
示例10: exit
void
BackupRestore::logEntry(const LogEntry & tup)
{
if (!m_restore)
return;
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exit(-1);
} // if
const TableS * table = tup.m_table;
NdbOperation * op = trans->getNdbOperation(table->getTableName());
if (op == NULL)
{
ndbout << "Cannot get operation: ";
ndbout << trans->getNdbError() << endl;
exit(-1);
} // if
int check = 0;
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
check = op->insertTuple();
break;
case LogEntry::LE_UPDATE:
check = op->updateTuple();
break;
case LogEntry::LE_DELETE:
check = op->deleteTuple();
break;
default:
ndbout << "Log entry has wrong operation type."
<< " Exiting...";
exit(-1);
}
for (int i = 0; i < tup.m_values.size(); i++)
{
const AttributeS * attr = tup.m_values[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size / 8) * arraySize;
if (attr->Desc->m_column->getPrimaryKey())
op->equal(attr->Desc->attrId, dataPtr, length);
else
op->setValue(attr->Desc->attrId, dataPtr, length);
}
#if 1
trans->execute(Commit);
#else
const int ret = trans->execute(Commit);
// Both insert update and delete can fail during log running
// and it's ok
if (ret != 0)
{
ndbout << "execute failed: ";
ndbout << trans->getNdbError() << endl;
exit(-1);
}
#endif
m_ndb->closeTransaction(trans);
m_logCount++;
}
示例11: allocRows
//.........这里部分代码省略.........
return NDBT_FAILED;
}
}
}
check = pTrans->execute(NoCommit, AbortOnError);
check = (check == -1 ? -1 : !ordered ? check : sOp->nextResult(true));
if( check == -1 ) {
const NdbError err = pTrans->getNdbError();
ERR(err);
closeTransaction(pNdb);
if (err.status == NdbError::TemporaryError){
NdbSleep_MilliSleep(50);
retryAttempt++;
continue;
}
return NDBT_FAILED;
}
if(ordered && check != 0){
g_err << check << " - Row: " << r << " not found!!" << endl;
closeTransaction(pNdb);
return NDBT_FAILED;
}
for(b = 0; b<batch && (b+r)<records; b++){
if (calc.verifyRowValues(rows[b]) != 0){
closeTransaction(pNdb);
return NDBT_FAILED;
}
int updates = calc.getUpdatesValue(rows[b]) + 1;
NdbOperation* pUpdOp;
if(!ordered){
pUpdOp = pTrans->getNdbIndexOperation(idxName, tab.getName());
check = (pUpdOp == 0 ? -1 : pUpdOp->updateTuple());
} else {
pUpdOp = sOp->updateCurrentTuple();
}
if (pUpdOp == NULL) {
ERR(pTrans->getNdbError());
closeTransaction(pNdb);
return NDBT_FAILED;
}
if( check == -1 ) {
ERR(pTrans->getNdbError());
closeTransaction(pNdb);
return NDBT_FAILED;
}
if(!ordered)
{
if (equalForRow(pUpdOp, r+b) != 0)
{
closeTransaction(pNdb);
return NDBT_FAILED;
}
}
for(a = 0; a<tab.getNoOfColumns(); a++){
if (tab.getColumn(a)->getPrimaryKey() == false){
if(setValueForAttr(pUpdOp, a, r+b, updates ) != 0){
ERR(pTrans->getNdbError());
closeTransaction(pNdb);
return NDBT_FAILED;
}
}
}
}
check = pTrans->execute(Commit, AbortOnError);
if( check == -1 ) {
const NdbError err = pTrans->getNdbError();
ERR(err);
closeTransaction(pNdb);
if (err.status == NdbError::TemporaryError){
NdbSleep_MilliSleep(50);
retryAttempt++;
continue;
}
ndbout << "r = " << r << endl;
return NDBT_FAILED;
} else {
updated += batch;
m_latest_gci = pTrans->getGCI();
}
closeTransaction(pNdb);
r+= batch; // Read next record
}
g_info << "|- " << updated << " records updated" << endl;
return NDBT_OK;
}
示例12: while
void
start_T1(Ndb * pNDB, ThreadData * td, int async) {
DEBUG2("T1(%.*s): - Starting", SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number);
NdbConnection * pCON = 0;
while((pCON = startTransaction(pNDB, td)) == 0) {
CHECK_ALLOWED_ERROR("T1: startTransaction", td, pNDB->getNdbError());
NdbSleep_MilliSleep(10);
}
const NdbOperation* op= NULL;
if (td->ndbRecordSharedData)
{
char* rowPtr= (char*) &td->transactionData;
const NdbRecord* record= td->ndbRecordSharedData->
subscriberTableNdbRecord;
Uint32 m=0;
unsigned char* mask= (unsigned char*) &m;
//SET_MASK(mask, IND_SUBSCRIBER_NUMBER);
SET_MASK(mask, IND_SUBSCRIBER_LOCATION);
SET_MASK(mask, IND_SUBSCRIBER_CHANGED_BY);
SET_MASK(mask, IND_SUBSCRIBER_CHANGED_TIME);
op= pCON->updateTuple(record,
rowPtr,
record,
rowPtr,
mask);
}
else
{
NdbOperation *MyOp = pCON->getNdbOperation(SUBSCRIBER_TABLE);
op= MyOp;
if (MyOp != NULL) {
MyOp->updateTuple();
MyOp->equal(IND_SUBSCRIBER_NUMBER,
td->transactionData.number);
MyOp->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&td->transactionData.location);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_BY,
td->transactionData.changed_by);
MyOp->setValue(IND_SUBSCRIBER_CHANGED_TIME,
td->transactionData.changed_time);
}
}
if (op != NULL)
{
if (async == 1) {
pCON->executeAsynchPrepare( Commit , T1_Callback, td);
} else {
int result = pCON->execute(Commit);
T1_Callback(result, pCON, (void*)td);
return;
}//if
} else {
CHECK_NULL(NULL, "T1: getNdbOperation", td, pCON->getNdbError());
}//if
}
示例13: allocRows
//.........这里部分代码省略.........
cTrans++;
if (cReadRecords >= records) {
// No more transactions needed
break;
}
} // For each transaction
// Wait for all outstanding transactions
pNdb->sendPollNdb(3000, 0, 0);
// Verify the data!
for (r = 0; r < trans*operations; r++) {
if (calc.verifyRowValues(rows[r]) != 0) {
g_info << "|- Verify failed..." << endl;
// Close all transactions
for (int t = 0; t < cTrans; t++) {
pNdb->closeTransaction(transactions[t]);
}
return NDBT_FAILED;
}
}
// Update
cTrans = 0;
cIndex = 0;
for (t = 0; t < trans; t++) { // For each transaction
for (int k = 0; k < operations; k++) { // For each operation
NdbOperation* pOp = transactions[t]->getNdbOperation(tab.getName());
if (pOp == NULL) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
int updates = calc.getUpdatesValue(rows[cIndex]) + 1;
check = pOp->updateTuple();
if (check == -1) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
// 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) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
}
}
// Update the record
for (a = 0; a < tab.getNoOfColumns(); a++) {
if (tab.getColumn(a)->getPrimaryKey() == false) {
if (setValueForAttr(pOp, a, cRecords, updates) != 0) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
}
}
cIndex++;
cRecords++;
} // For each operation
// Let's prepare...
transactions[t]->executeAsynchPrepare(Commit, &asynchCallback,
this);
cTrans++;
if (cRecords >= records) {
// No more transactions needed
break;
}
} // For each transaction
// Wait for all outstanding transactions
pNdb->sendPollNdb(3000, 0, 0);
// Close all transactions
for (t = 0; t < cTrans; t++) {
pNdb->closeTransaction(transactions[t]);
}
} // while (cRecords < records*batch)
} // For each batch
deallocTransactions();
deallocRows();
g_info << "|- " << ((unsigned int)transactionsCompleted * operations)/2
<< " updated..." << endl;
return NDBT_OK;
}
示例14: updateTable
static void updateTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
{
Uint64 tbefore, tafter, before, after;
NdbConnection *myTrans;
NdbOperation *myOp;
char name[] = "Kalle0000000";
tbefore = NdbTick_CurrentMillisecond();
if (oneTrans) myTrans = myNdb.startTransaction();
for (unsigned int i = 0; i<noOfTuples; i++) {
if (!oneTrans) myTrans = myNdb.startTransaction();
for(unsigned int j = 1;
((j<=noOfOperations)&&(i<noOfTuples));
(++j<=noOfOperations)?i++:i) {
if (myTrans == NULL)
error_handler4(__LINE__, myNdb.getNdbError());
myOp = myTrans->getNdbOperation("PERSON");
if (myOp == NULL)
error_handler4(__LINE__, myTrans->getNdbError());
myOp->updateTuple();
sprintf(name, "Kalle%.7i", i);
if (longKey)
memcpy(longName, name, strlen(name));
if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (twoKey)
if (myOp->equal("KEY2", i) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM1", 77) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM2", 88)) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM4", 99)) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("AGE", 100) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("STRING_AGE", hundred) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
}
if (noOfOperations == 1)
printf("Trying to update person %s\n", name);
else
printf("Trying to update %u persons\n", noOfOperations);
before = NdbTick_CurrentMillisecond();
if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
{
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
after = NdbTick_CurrentMillisecond();
if (noOfOperations == 1)
printf("Updated person %s, %u msec\n", name, (Uint32) after - before);
else
printf("Update %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
if (!oneTrans) myNdb.closeTransaction(myTrans);
}
if (oneTrans) {
if (myTrans->execute( Commit ) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
}
myNdb.closeTransaction(myTrans);
}
tafter = NdbTick_CurrentMillisecond();
ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
}
示例15: exitHandler
void
BackupRestore::logEntry(const LogEntry & tup)
{
if (!m_restore)
return;
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
err << "Cannot start transaction" << endl;
exitHandler();
} // if
const NdbDictionary::Table * table = get_table(tup.m_table->m_dictTable);
NdbOperation * op = trans->getNdbOperation(table);
if (op == NULL)
{
err << "Cannot get operation: " << trans->getNdbError() << endl;
exitHandler();
} // if
int check = 0;
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
check = op->insertTuple();
break;
case LogEntry::LE_UPDATE:
check = op->updateTuple();
break;
case LogEntry::LE_DELETE:
check = op->deleteTuple();
break;
default:
err << "Log entry has wrong operation type."
<< " Exiting...";
exitHandler();
}
if (check != 0)
{
err << "Error defining op: " << trans->getNdbError() << endl;
exitHandler();
} // if
Bitmask<4096> keys;
for (Uint32 i= 0; i < tup.size(); i++)
{
const AttributeS * attr = tup[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
if (tup.m_table->have_auto_inc(attr->Desc->attrId))
tup.m_table->update_max_auto_val(dataPtr,size*arraySize);
const Uint32 length = (size / 8) * arraySize;
if (attr->Desc->m_column->getPrimaryKey())
{
if(!keys.get(attr->Desc->attrId))
{
keys.set(attr->Desc->attrId);
check= op->equal(attr->Desc->attrId, dataPtr, length);
}
}
else
check= op->setValue(attr->Desc->attrId, dataPtr, length);
if (check != 0)
{
err << "Error defining op: " << trans->getNdbError() << endl;
exitHandler();
} // if
}
const int ret = trans->execute(NdbTransaction::Commit);
if (ret != 0)
{
// Both insert update and delete can fail during log running
// and it's ok
// TODO: check that the error is either tuple exists or tuple does not exist?
bool ok= false;
NdbError errobj= trans->getNdbError();
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
if(errobj.status == NdbError::PermanentError &&
errobj.classification == NdbError::ConstraintViolation)
ok= true;
break;
case LogEntry::LE_UPDATE:
case LogEntry::LE_DELETE:
if(errobj.status == NdbError::PermanentError &&
errobj.classification == NdbError::NoDataFound)
ok= true;
break;
}
if (!ok)
{
//.........这里部分代码省略.........