本文整理汇总了C++中NdbOperation::insertTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ NdbOperation::insertTuple方法的具体用法?C++ NdbOperation::insertTuple怎么用?C++ NdbOperation::insertTuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NdbOperation
的用法示例。
在下文中一共展示了NdbOperation::insertTuple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ERR
int
UtilTransactions::addRowToInsert(Ndb* pNdb,
NdbConnection* pInsTrans,
NDBT_ResultRow & row,
const char *insertTabName){
int check;
NdbOperation* pInsOp;
pInsOp = pInsTrans->getNdbOperation(insertTabName);
if (pInsOp == NULL) {
ERR(pInsTrans->getNdbError());
return NDBT_FAILED;
}
check = pInsOp->insertTuple();
if( check == -1 ) {
ERR(pInsTrans->getNdbError());
return NDBT_FAILED;
}
// Set all attributes
for (int a = 0; a < tab.getNoOfColumns(); a++){
NdbRecAttr* r = row.attributeStore(a);
int sz = r->get_size_in_bytes();
if (pInsOp->setValue(tab.getColumn(a)->getName(),
r->aRef(),
sz) != 0) {
ERR(pInsTrans->getNdbError());
return NDBT_FAILED;
}
}
return NDBT_OK;
}
示例2: pkInsertRecord
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;
}
示例3: pkInsertRecord
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());
return NDBT_FAILED;
}
check = pOp->insertTuple();
if( check == -1 ) {
ERR(pTrans->getNdbError());
return NDBT_FAILED;
}
if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK)
{
return NDBT_FAILED;
}
}
return NDBT_OK;
}
示例4: userDbInsertSubscriber
int userDbInsertSubscriber(UserHandle *uh,
SubscriberNumber number,
uint32 groupId,
SubscriberName name)
{
int check;
uint32 activeSessions = 0;
Location l = 0;
ChangedBy changedBy;
ChangedTime changedTime;
BaseString::snprintf(changedBy, sizeof(changedBy), "ChangedBy");
BaseString::snprintf(changedTime, sizeof(changedTime), "ChangedTime");
NdbConnection * MyTransaction = 0;
if(uh->pCurrTrans != 0){
MyTransaction = uh->pCurrTrans;
} else {
uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
}
if (MyTransaction == NULL)
error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
check = MyOperation->insertTuple();
CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
CHECK_MINUS_ONE(check, "equal", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_NAME, name);
CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
return 0;
}
示例5:
int
insert_subscriber(void * obj,
SubscriberNumber number,
SubscriberName name,
GroupId groupId,
Location l,
ActiveSessions activeSessions,
ChangedBy changedBy,
ChangedTime changedTime){
Ndb * pNDB = (Ndb *)obj;
int check;
NdbConnection * MyTransaction = pNDB->startTransaction();
if (MyTransaction == NULL)
error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
check = MyOperation->insertTuple();
CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
CHECK_MINUS_ONE(check, "equal", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_NAME, name);
CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
check = MyTransaction->execute( Commit );
CHECK_MINUS_ONE(check, "commit", MyTransaction);
pNDB->closeTransaction(MyTransaction);
return 0;
}
示例6: insert
//
// Example insert
// @param myNdb Ndb object representing NDB Cluster
// @param myTransaction NdbTransaction used for transaction
// @param myTable Table to insert into
// @param error NdbError object returned in case of errors
// @return -1 in case of failures, 0 otherwise
//
int insert(int transactionId, NdbTransaction* myTransaction,
const NdbDictionary::Table *myTable) {
NdbOperation *myOperation; // For other operations
myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) return -1;
if (myOperation->insertTuple() ||
myOperation->equal("ATTR1", transactionId) ||
myOperation->setValue("ATTR2", transactionId)) {
APIERROR(myOperation->getNdbError());
exit(-1);
}
return myTransaction->execute(NdbTransaction::NoCommit);
}
示例7: userDbInsertServer
int userDbInsertServer(UserHandle *uh,
ServerId serverId,
SubscriberSuffix suffix,
ServerName name)
{
int check;
uint32 noOfRead = 0;
uint32 noOfInsert = 0;
uint32 noOfDelete = 0;
NdbConnection * MyTransaction = 0;
if(uh->pCurrTrans != 0){
MyTransaction = uh->pCurrTrans;
} else {
uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
}
if (MyTransaction == NULL)
error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
check = MyOperation->insertTuple();
CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);
check = MyOperation->equal(SERVER_ID, (char*)&serverId);
CHECK_MINUS_ONE(check, "setValue id", MyTransaction);
check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);
check = MyOperation->setValue(SERVER_NAME, name);
CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);
check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);
check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);
return 0;
}
示例8: InsertTransaction
int InsertTransaction(Ndb* pNdb,
long iContextID,
long iVersion,
long iLockFlag,
long iLockTime,
long iLockTimeUSec,
const char* pchContextData,
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(!(g_bWriteTuple ? pNdbOperation->writeTuple() : pNdbOperation->insertTuple())
&& !pNdbOperation->equal(c_szContextId, (Int32)iContextID)
&& !pNdbOperation->setValue(c_szVersion, (Int32)iVersion)
&& !pNdbOperation->setValue(c_szLockFlag, (Int32)iLockFlag)
&& !pNdbOperation->setValue(c_szLockTime, (Int32)iLockTime)
&& !pNdbOperation->setValue(c_szLockTimeUSec, (Int32)iLockTimeUSec)
&& !pNdbOperation->setValue(c_szContextData, pchContextData, 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;
}
示例9: userDbInsertGroup
int userDbInsertGroup(UserHandle *uh,
GroupId groupId,
GroupName name,
Permission allowRead,
Permission allowInsert,
Permission allowDelete)
{
int check;
NdbConnection * MyTransaction = 0;
if(uh->pCurrTrans != 0){
MyTransaction = uh->pCurrTrans;
} else {
uh->pCurrTrans = MyTransaction = uh->pNDB->startTransaction();
}
if (MyTransaction == NULL)
error_handler("startTranscation", uh->pNDB->getNdbError(), 0);
NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
check = MyOperation->insertTuple();
CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
check = MyOperation->equal(GROUP_ID, (char*)&groupId);
CHECK_MINUS_ONE(check, "equal", MyTransaction);
check = MyOperation->setValue(NDB_GROUP_NAME, name);
CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);
check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);
check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);
return 0;
}
示例10: insertLine
int insertLine(Ndb* pNdb,
const NdbDictionary::Table* pTab,
char* line){
int check;
int retryAttempt = 0;
int retryMax = 5;
NdbConnection *pTrans;
NdbOperation *pOp;
while (retryAttempt < retryMax){
pTrans = pNdb->startTransaction();
if (pTrans == NULL) {
ERR(pNdb->getNdbError());
NdbSleep_MilliSleep(50);
retryAttempt++;
continue;
}
pOp = pTrans->getNdbOperation(pTab->getName());
if (pOp == NULL) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return -1;
}
check = pOp->insertTuple();
if( check == -1 ) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return -1;
}
check = setValuesFromLine(pOp,
pTab,
line);
if (check == -2){
pNdb->closeTransaction(pTrans);
return -2;
}
if( check == -1 ) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return -1;
}
// Execute the transaction and insert the record
check = pTrans->execute( Commit );
if(check == -1 ) {
const NdbError err = pTrans->getNdbError();
pNdb->closeTransaction(pTrans);
switch(err.status){
case NdbError::Success:
ERR(err);
ndbout << "ERROR: NdbError reports success when transcaction failed" << endl;
return -1;
break;
case NdbError::TemporaryError:
ERR(err);
NdbSleep_MilliSleep(50);
retryAttempt++;
continue;
break;
case NdbError::UnknownResult:
ERR(err);
return -1;
break;
case NdbError::PermanentError:
switch (err.classification){
case NdbError::ConstraintViolation:
// Tuple already existed, OK in this application, but should be reported
ndbout << err.code << " " << err.message << endl;
break;
default:
ERR(err);
return -1;
break;
}
break;
}
}
else{
pNdb->closeTransaction(pTrans);
}
return 0;
}
return check;
}
示例11: 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++;
}
示例12: populate
/************************************************************************
* populate()
* 1. Prepare 'parallelism' number of insert transactions.
* 2. Send transactions to NDB and wait for callbacks to execute
*/
int populate(Ndb * myNdb, int data, async_callback_t * cbData)
{
NdbOperation* myNdbOperation; // For operations
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("api_async");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
async_callback_t * cb;
int retries = 0;
int current = 0;
for(int i=0; i<1024; i++)
{
if(transaction[i].used == 0)
{
current = i;
if (cbData == 0)
{
/**
* We already have a callback
* This is an absolutely new transaction
*/
cb = new async_callback_t;
cb->retries = 0;
}
else
{
/**
* We already have a callback
*/
cb =cbData;
retries = cbData->retries;
}
/**
* Set data used by the callback
*/
cb->ndb = myNdb; //handle to Ndb object so that we can close transaction
// in the callback (alt. make myNdb global).
cb->data = data; //this is the data we want to insert
cb->transaction = current; //This is the number (id) of this transaction
transaction[current].used = 1 ; //Mark the transaction as used
break;
}
}
if(!current)
return -1;
while(retries < MAX_RETRIES)
{
transaction[current].conn = myNdb->startTransaction();
if (transaction[current].conn == NULL) {
/**
* no transaction to close since conn == null
*/
milliSleep(10);
retries++;
continue;
}
myNdbOperation = transaction[current].conn->getNdbOperation(myTable);
if (myNdbOperation == NULL)
{
if (asynchErrorHandler(transaction[current].conn, myNdb))
{
myNdb->closeTransaction(transaction[current].conn);
transaction[current].conn = 0;
milliSleep(10);
retries++;
continue;
}
asynchExitHandler(myNdb);
} // if
if(myNdbOperation->insertTuple() < 0 ||
myNdbOperation->equal("REG_NO", data) < 0 ||
myNdbOperation->setValue("BRAND", "Mercedes") <0 ||
myNdbOperation->setValue("COLOR", "Blue") < 0)
{
if (asynchErrorHandler(transaction[current].conn, myNdb))
{
myNdb->closeTransaction(transaction[current].conn);
transaction[current].conn = 0;
retries++;
milliSleep(10);
continue;
}
asynchExitHandler(myNdb);
}
/*Prepare transaction (the transaction is NOT yet sent to NDB)*/
transaction[current].conn->executeAsynchPrepare(NdbTransaction::Commit,
&callback,
cb);
/**
* When we have prepared parallelism number of transactions ->
//.........这里部分代码省略.........
示例13: DEBUG
//.........这里部分代码省略.........
/* Operation 2 */
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
CHECK_NULL(MyOperation, "T4-2: getNdbOperation",
MyTransaction);
check = MyOperation->readTuple();
CHECK_MINUS_ONE(check, "T4-2: readTuple",
MyTransaction);
check = MyOperation->equal(IND_GROUP_ID,
(char*)&groupId);
CHECK_MINUS_ONE(check, "T4-2: equal group",
MyTransaction);
check2 = MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
(char *)&permission);
CHECK_NULL(check2, "T4-2: getValue allow_insert",
MyTransaction);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T4-2: NoCommit",
MyTransaction);
if(((permission & inServerBit) == inServerBit) &&
((sessions & inServerBit) == 0)) {
DEBUG("inserting - ");
/* Operation 3 */
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOperation, "T4-3: getNdbOperation",
MyTransaction);
check = MyOperation->insertTuple();
CHECK_MINUS_ONE(check, "T4-3: insertTuple",
MyTransaction);
check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
(char*)inNumber);
CHECK_MINUS_ONE(check, "T4-3: equal number",
MyTransaction);
check = MyOperation->equal(IND_SESSION_SERVER,
(char*)&inServerId);
CHECK_MINUS_ONE(check, "T4-3: equal server id",
MyTransaction);
check = MyOperation->setValue(SESSION_DATA,
(char *)inSessionDetails);
CHECK_MINUS_ONE(check, "T4-3: setValue session details",
MyTransaction);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T4-3: NoCommit",
MyTransaction);
/* Operation 4 */
MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T4-4: getNdbOperation",
MyTransaction);
check = MyOperation->interpretedUpdateTuple();
CHECK_MINUS_ONE(check, "T4-4: interpretedUpdateTuple",
MyTransaction);
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
示例14: main
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
exit(-1);
}
char * mysqld_sock = argv[1];
const char *connectstring = argv[2];
ndb_init();
Ndb_cluster_connection *cluster_connection=
new Ndb_cluster_connection(connectstring); // Object representing the cluster
int r= cluster_connection->connect(5 /* retries */,
3 /* delay between retries */,
1 /* verbose */);
if (r > 0)
{
std::cout
<< "Cluster connect failed, possibly resolved with more retries.\n";
exit(-1);
}
else if (r < 0)
{
std::cout
<< "Cluster connect failed.\n";
exit(-1);
}
if (cluster_connection->wait_until_ready(30,0) < 0)
{
std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
// connect to mysql server
MYSQL mysql;
if ( !mysql_init(&mysql) ) {
std::cout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
0, mysqld_sock, 0) )
MYSQLERROR(mysql);
/********************************************
* Connect to database via mysql-c *
********************************************/
mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
create_table(mysql);
Ndb* myNdb = new Ndb( cluster_connection,
"TEST_DB_1" ); // Object representing the database
NdbTransaction* myNdbTransaction[2]; // For transactions
NdbOperation* myNdbOperation; // For operations
if (myNdb->init(2) == -1) { // Want two parallel insert transactions
APIERROR(myNdb->getNdbError());
exit(-1);
}
/******************************************************
* Insert (we do two insert transactions in parallel) *
******************************************************/
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 2; i++) {
myNdbTransaction[i] = myNdb->startTransaction();
if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError());
myNdbOperation = myNdbTransaction[i]->getNdbOperation(myTable);
if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError());
myNdbOperation->insertTuple();
myNdbOperation->equal("ATTR1", 20 + i);
myNdbOperation->setValue("ATTR2", 20 + i);
// Prepare transaction (the transaction is NOT yet sent to NDB)
myNdbTransaction[i]->executeAsynchPrepare(NdbTransaction::Commit,
&callback, NULL);
}
// Send all transactions to NDB
myNdb->sendPreparedTransactions(0);
// Poll all transactions
myNdb->pollNdb(3000, 2);
// Close all transactions
for (int i = 0; i < 2; i++)
myNdb->closeTransaction(myNdbTransaction[i]);
delete myNdb;
delete cluster_connection;
//.........这里部分代码省略.........
示例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)
{
//.........这里部分代码省略.........