本文整理汇总了C++中Ndb::startTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ Ndb::startTransaction方法的具体用法?C++ Ndb::startTransaction怎么用?C++ Ndb::startTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ndb
的用法示例。
在下文中一共展示了Ndb::startTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/**
* 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;
BenchmarkTime start;
get_time(&start);
int check;
NdbRecAttr * check2;
NdbConnection * MyTransaction = pNDB->startTransaction();
if (MyTransaction == NULL)
error_handler("T1: 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;
}
示例2: 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);
}
示例3: GETNDB
static int
runFullScan(NDBT_Context* ctx, NDBT_Step* step)
{
NDBT_Table* pTab = ctx->getTab();
Ndb* pNdb = GETNDB(step);
unsigned cntIndex = getTableProperty(ctx, pTab, "numIndex");
for (unsigned numIndex = 0; numIndex < cntIndex; numIndex++) {
char buf[200];
sprintf(buf, "%s_X%03d", pTab->getName(), numIndex);
NDBT_Index* pInd = NDBT_Index::discoverIndexFromDb(pNdb, buf, pTab->getName());
assert(pInd != 0);
g_info << "Scan index:" << pInd->getName() << endl << *pInd;
NdbConnection* pCon = pNdb->startTransaction();
if (pCon == 0) {
ERR(pNdb->getNdbError());
return NDBT_FAILED;
}
NdbOperation* pOp = pCon->getNdbOperation(pInd->getName(),
pTab->getName());
if (pOp == 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
if (pOp->openScanRead() != 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
if (pCon->executeScan() != 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
unsigned rows = 0;
while (1) {
int ret = pCon->nextScanResult();
if (ret == 0) {
rows++;
} else if (ret == 1) {
break;
} else {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
}
pNdb->closeTransaction(pCon);
g_info << "Scanned " << rows << " rows" << endl;
}
return NDBT_OK;
}
示例4: runV2MultiWait_Producer
/* Producer thread */
int runV2MultiWait_Producer(NDBT_Context* ctx, NDBT_Step* step,
int thd_id, int nthreads)
{
int records = ctx->getNumRecords();
HugoOperations hugoOps(*ctx->getTab());
/* For three threads (2 producers + 1 consumer) we loop 0-7.
producer 0 is slow if (loop & 1)
producer 1 is slow if (loop & 2)
consumer is slow if (loop & 4)
*/
for (int loop = 0; loop < V2_NLOOPS; loop++)
{
ctx->getPropertyWait("LOOP", loop+1);
bool slow = loop & (thd_id+1);
for (int j=0; j < records; j++)
{
if(j % nthreads == thd_id)
{
Ndb* ndb = global_ndb_pool->getNdb();
NdbTransaction* trans = ndb->startTransaction();
check(trans != NULL, (*ndb));
ndb->setCustomData(trans);
NdbOperation* readOp = trans->getNdbOperation(ctx->getTab());
check(readOp != NULL, (*trans));
check(readOp->readTuple() == 0, (*readOp));
check(hugoOps.equalForRow(readOp, j) == 0, hugoOps);
/* Read all other cols */
for (int k=0; k < ctx->getTab()->getNoOfColumns(); k++)
{
check(readOp->getValue(ctx->getTab()->getColumn(k)) != NULL,
(*readOp));
}
trans->executeAsynchPrepare(NdbTransaction::Commit,
NULL,
NULL,
NdbOperation::AbortOnError);
ndb->sendPreparedTransactions();
global_poll_group->push(ndb);
if(slow)
{
int tm = myRandom48(3) * myRandom48(3);
if(tm) NdbSleep_MilliSleep(tm);
}
}
}
}
return NDBT_OK;
}
示例5: calc
int
runInterpretedUKLookup(NDBT_Context* ctx, NDBT_Step* step)
{
const NdbDictionary::Table * pTab = ctx->getTab();
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary * dict = pNdb->getDictionary();
const NdbDictionary::Index* pIdx= dict->getIndex(pkIdxName, pTab->getName());
CHK_RET_FAILED(pIdx != 0);
const NdbRecord * pRowRecord = pTab->getDefaultRecord();
CHK_RET_FAILED(pRowRecord != 0);
const NdbRecord * pIdxRecord = pIdx->getDefaultRecord();
CHK_RET_FAILED(pIdxRecord != 0);
const Uint32 len = NdbDictionary::getRecordRowLength(pRowRecord);
Uint8 * pRow = new Uint8[len];
bzero(pRow, len);
HugoCalculator calc(* pTab);
calc.equalForRow(pRow, pRowRecord, 0);
NdbTransaction* pTrans = pNdb->startTransaction();
CHK_RET_FAILED(pTrans != 0);
NdbInterpretedCode code;
code.interpret_exit_ok();
code.finalise();
NdbOperation::OperationOptions opts;
bzero(&opts, sizeof(opts));
opts.optionsPresent = NdbOperation::OperationOptions::OO_INTERPRETED;
opts.interpretedCode = &code;
const NdbOperation * pOp = pTrans->readTuple(pIdxRecord, (char*)pRow,
pRowRecord, (char*)pRow,
NdbOperation::LM_Read,
0,
&opts,
sizeof(opts));
CHK_RET_FAILED(pOp);
int res = pTrans->execute(Commit, AbortOnError);
CHK_RET_FAILED(res == 0);
delete [] pRow;
return NDBT_OK;
}
示例6:
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;
}
示例7:
/**
* 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
}
示例8: do_delete
/*************************************************
* Delete one tuple (the one with primary key 3) *
*************************************************/
static void do_delete(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->deleteTuple();
myOperation->equal( "ATTR1", 3 );
if (myTransaction->execute(NdbTransaction::Commit) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
示例9: runBuddyTransTimeout
int runBuddyTransTimeout(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
int stepNo = step->getStepNo();
ndbout << "TransactionInactiveTimeout="<< TIMEOUT <<endl;
HugoOperations hugoOps(*ctx->getTab());
Ndb* pNdb = GETNDB(step);
for (int l = 1; l < loops && result == NDBT_OK; l++){
NdbTransaction* pTrans = 0;
do{
pTrans = pNdb->startTransaction();
NdbScanOperation* pOp = pTrans->getNdbScanOperation(ctx->getTab());
CHECK(pOp->readTuples(NdbOperation::LM_Read, 0, 0, 1) == 0);
CHECK(pTrans->execute(NoCommit) == 0);
int sleep = 2 * TIMEOUT;
ndbout << "Sleeping for " << sleep << " milliseconds" << endl;
NdbSleep_MilliSleep(sleep);
int res = 0;
while((res = pOp->nextResult()) == 0);
ndbout_c("res: %d", res);
CHECK(res == -1);
} while(false);
if (pTrans)
{
pTrans->close();
}
}
return result;
}
示例10: do_read
/*****************************
* Read and print all tuples *
*****************************/
static void do_read(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
std::cout << "ATTR1 ATTR2" << std::endl;
for (int i = 0; i < 10; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(NdbOperation::LM_Read);
myOperation->equal("ATTR1", i);
NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL);
if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError());
if(myTransaction->execute( NdbTransaction::Commit ) == -1)
{
if (i == 3) {
std::cout << "Detected that deleted tuple doesn't exist!" << std::endl;
} else {
APIERROR(myTransaction->getNdbError());
}
}
if (i != 3) {
printf(" %2d %2d\n", i, myRecAttr->u_32_value());
}
myNdb.closeTransaction(myTransaction);
}
}
示例11: 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();
MYSQL mysql;
/**************************************************************
* Connect to mysql server and create table *
**************************************************************/
{
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);
mysql_query(&mysql, "CREATE DATABASE ndb_examples_1");
if (mysql_query(&mysql, "USE ndb_examples") != 0) MYSQLERROR(mysql);
while (mysql_query(&mysql,
"CREATE TABLE"
" api_simple_index"
" (ATTR1 INT UNSIGNED,"
" ATTR2 INT UNSIGNED NOT NULL,"
" PRIMARY KEY USING HASH (ATTR1),"
" UNIQUE MYINDEXNAME USING HASH (ATTR2))"
" ENGINE=NDB"))
{
if (mysql_errno(&mysql) == ER_TABLE_EXISTS_ERROR)
{
std::cout << "MySQL Cluster already has example table: api_scan. "
<< "Dropping it..." << std::endl;
mysql_query(&mysql, "DROP TABLE api_simple_index");
}
else MYSQLERROR(mysql);
}
}
/**************************************************************
* Connect to ndb cluster *
**************************************************************/
Ndb_cluster_connection *cluster_connection=
new Ndb_cluster_connection(connectstring); // Object representing the cluster
if (cluster_connection->connect(5,3,1))
{
std::cout << "Connect to cluster management server failed.\n";
exit(-1);
}
if (cluster_connection->wait_until_ready(30,30))
{
std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
Ndb* myNdb = new Ndb( cluster_connection,
"ndb_examples" ); // Object representing the database
if (myNdb->init() == -1) {
APIERROR(myNdb->getNdbError());
exit(-1);
}
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("api_simple_index");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
const NdbDictionary::Index *myIndex= myDict->getIndex("MYINDEXNAME$unique","api_simple_index");
if (myIndex == NULL)
APIERROR(myDict->getNdbError());
/**************************************************************************
* Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
**************************************************************************/
for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i);
myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i+5);
myOperation->setValue("ATTR2", i+5);
//.........这里部分代码省略.........
示例12: runTestBug34107
int runTestBug34107(NDBT_Context* ctx, NDBT_Step* step){
const NdbDictionary::Table * pTab = ctx->getTab();
Ndb* pNdb = GETNDB(step);
const Uint32 okSize= 10000;
const Uint32 tooBig= 30000;
Uint32 codeBuff[tooBig];
int i;
for (i = 0; i <= 1; i++) {
g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl;
NdbConnection* pTrans = pNdb->startTransaction();
if (pTrans == NULL){
ERR(pNdb->getNdbError());
return NDBT_FAILED;
}
NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName());
if (pOp == NULL) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pOp->readTuples() == -1) {
ERR(pOp->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
/* Test kernel mechanism for dealing with too large program
* We need to provide our own program buffer as default
* NdbInterpretedCode buffer will not grow larger than
* NDB_MAX_SCANFILTER_SIZE
*/
NdbInterpretedCode code(NULL, // Table is irrelevant
codeBuff,
tooBig); // Size of codeBuff
int n = i == 0 ? okSize : tooBig;
int k;
for (k = 0; k < n; k++) {
// inserts 1 word ATTRINFO
if (code.interpret_exit_ok() == -1) {
ERR(code.getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
}
if (code.finalise() != 0)
{
ERR(code.getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pOp->setInterpretedCode(&code) != 0)
{
ERR(pOp->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pTrans->execute(NoCommit) == -1) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
int ret;
while ((ret = pOp->nextResult()) == 0)
;
g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl;
if (i == 0 && ret != 1) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (i == 1 && ret != -1) {
g_err << "unexpected big filter success" << endl;
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (i == 1 && pOp->getNdbError().code != 874) {
g_err << "unexpected big filter error code, wanted 874" << endl;
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
pNdb->closeTransaction(pTrans);
}
//.........这里部分代码省略.........
示例13: DEBUG
/**
* Transaction 5 - T5
*
* Delete session
*
* Input:
* SubscriberNumber
* ServerId
* ServerBit
* DoRollback
* Output:
* ChangedBy
* ChangedTime
* Location
* BranchExecuted
*/
int
T5(void * obj,
const SubscriberNumber inNumber,
const SubscriberSuffix inSuffix,
const ServerId inServerId,
const ServerBit inServerBit,
ChangedBy outChangedBy,
ChangedTime outChangedTime,
Location * outLocation,
DoRollback inDoRollback,
BranchExecuted * outBranchExecuted,
BenchmarkTime * outTransactionTime) {
Ndb * pNDB = (Ndb *) obj;
NdbConnection * MyTransaction = 0;
NdbOperation * MyOperation = 0;
GroupId groupId;
ActiveSessions sessions;
Permission permission;
BenchmarkTime start;
get_time(&start);
int check;
NdbRecAttr * check2;
MyTransaction = pNDB->startTransaction();
if (MyTransaction == NULL)
error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), 0);
MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
MyTransaction);
check = MyOperation->readTupleExclusive();
CHECK_MINUS_ONE(check, "T5-1: readTuple",
MyTransaction);
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
inNumber);
CHECK_MINUS_ONE(check, "T5-1: equal subscriber",
MyTransaction);
check2 = MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
(char *)outLocation);
CHECK_NULL(check2, "T5-1: getValue location",
MyTransaction);
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
outChangedBy);
CHECK_NULL(check2, "T5-1: getValue changed_by",
MyTransaction);
check2 = MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
outChangedTime);
CHECK_NULL(check2, "T5-1: getValue changed_time",
MyTransaction);
check2 = MyOperation->getValue(IND_SUBSCRIBER_GROUP,
(char *)&groupId);
CHECK_NULL(check2, "T5-1: getValue group",
MyTransaction);
check2 = MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
(char *)&sessions);
CHECK_NULL(check2, "T5-1: getValue sessions",
MyTransaction);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T5-1: NoCommit",
MyTransaction);
/* Operation 2 */
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
MyTransaction);
check = MyOperation->readTuple();
CHECK_MINUS_ONE(check, "T5-2: readTuple",
MyTransaction);
//.........这里部分代码省略.........
示例14: readTable
static void readTable(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";
NdbRecAttr* myRecAttrArr[MAX_NO_PARALLEL_OPERATIONS];
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->readTuple();
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;
}
myRecAttrArr[j-1] = myOp->getValue("PNUM2", NULL);
}
if (noOfOperations == 1)
printf("Trying to read person %s\n", name);
else
printf("Trying to read %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("Read person %s, %u msec\n", name, (Uint32) after - before);
else
printf("Read %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
for(unsigned int j = 0; j<noOfOperations; j++)
printf("PNUM2 = %u\n", myRecAttrArr[j]->u_32_value());
if (!oneTrans) myNdb.closeTransaction(myTrans);
}
if (oneTrans) {
if (myTrans->execute( Commit ) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
}
myNdb.closeTransaction(myTrans);
}
tafter = NdbTick_CurrentMillisecond();
ndbout << "Read "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
}
示例15: trans
static int
runBug14702377(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary * pDict = pNdb->getDictionary();
int records = ctx->getNumRecords();
int result = NDBT_OK;
while (ctx->getProperty("HalfStartedDone", (Uint32)0) == 0)
{
ndbout << "Wait for half started..." << endl;
NdbSleep_SecSleep(15);
}
ndbout << "Got half started" << endl;
while (1)
{
require(table_list.size() == 1);
const char* tabname = table_list[0].c_str();
const NdbDictionary::Table* tab = 0;
CHK2((tab = pDict->getTable(tabname)) != 0,
tabname << ": " << pDict->getNdbError());
const int ncol = tab->getNoOfColumns();
{
HugoTransactions trans(*tab);
CHK2(trans.loadTable(pNdb, records) == 0, trans.getNdbError());
}
for (int r = 0; r < records; r++)
{
// with 1000 records will surely hit bug case
const int lm = myRandom48(4); // 2
const int nval = myRandom48(ncol + 1); // most
const bool exist = myRandom48(2); // false
NdbTransaction* pTx = 0;
NdbOperation* pOp = 0;
CHK2((pTx = pNdb->startTransaction()) != 0,
pNdb->getNdbError());
CHK2((pOp = pTx->getNdbOperation(tab)) != 0,
pTx->getNdbError());
CHK2((pOp->readTuple((NdbOperation::LockMode)lm)) == 0,
pOp->getNdbError());
for (int id = 0; id <= 0; id++)
{
const NdbDictionary::Column* c = tab->getColumn(id);
require(c != 0 && c->getPrimaryKey() &&
c->getType() == NdbDictionary::Column::Unsigned);
Uint32 val = myRandom48(records);
if (!exist)
val = 0xaaaa0000 + myRandom48(0xffff + 1);
const char* valp = (const char*)&val;
CHK2(pOp->equal(id, valp) == 0, pOp->getNdbError());
}
CHK2(result == NDBT_OK, "failed");
for (int id = 0; id < nval; id++)
{
const NdbDictionary::Column* c = tab->getColumn(id);
require(c != 0 && (id == 0 || !c->getPrimaryKey()));
CHK2(pOp->getValue(id) != 0, pOp->getNdbError());
}
CHK2(result == NDBT_OK, "failed");
char info1[200];
sprintf(info1, "lm=%d nval=%d exist=%d",
lm, nval, exist);
g_info << "PK read T1 exec: " << info1 << endl;
Uint64 t1 = NdbTick_CurrentMillisecond();
int ret = pTx->execute(NdbTransaction::NoCommit);
Uint64 t2 = NdbTick_CurrentMillisecond();
int msec = (int)(t2-t1);
const NdbError& txerr = pTx->getNdbError();
const NdbError& operr = pOp->getNdbError();
char info2[200];
sprintf(info2, "%s msec=%d ret=%d txerr=%d operr=%d",
info1, msec, ret, txerr.code, operr.code);
g_info << "PK read T1 done: " << info2 << endl;
if (ret == 0 && txerr.code == 0 && operr.code == 0)
{
CHK2(exist, "row should not be found: " << info2);
}
else if (ret == 0 && txerr.code == 626 && operr.code == 626)
{
CHK2(!exist, "row should be found: " << info2);
}
else if (txerr.status == NdbError::TemporaryError)
{
g_err << "PK read T1 temporary error (tx): " << info2 << endl;
NdbSleep_MilliSleep(50);
}
else if (operr.status == NdbError::TemporaryError)
{
g_err << "PK read T1 temporary error (op): " << info2 << endl;
NdbSleep_MilliSleep(50);
}
else
//.........这里部分代码省略.........