本文整理汇总了C++中Ndb::sendPreparedTransactions方法的典型用法代码示例。如果您正苦于以下问题:C++ Ndb::sendPreparedTransactions方法的具体用法?C++ Ndb::sendPreparedTransactions怎么用?C++ Ndb::sendPreparedTransactions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ndb
的用法示例。
在下文中一共展示了Ndb::sendPreparedTransactions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
//.........这里部分代码省略.........
示例3: runPkReadMultiBasic
int runPkReadMultiBasic(NDBT_Context* ctx, NDBT_Step* step){
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
const int MAX_NDBS = 200;
Ndb* pNdb = GETNDB(step);
Ndb_cluster_connection* conn = &pNdb->get_ndb_cluster_connection();
int i = 0;
HugoOperations hugoOps(*ctx->getTab());
Ndb* ndbObjs[ MAX_NDBS ];
NdbTransaction* transArray[ MAX_NDBS ];
Ndb ** ready_ndbs;
for (int j=0; j < MAX_NDBS; j++)
{
Ndb* ndb = new Ndb(conn);
check(ndb->init() == 0, (*ndb));
ndbObjs[ j ] = ndb;
}
while (i<loops) {
ndbout << "Loop : " << i << ": ";
int recordsLeft = records;
do
{
/* Define and execute Pk read requests on
* different Ndb objects
*/
int ndbcnt = 0;
int pollcnt = 0;
int lumpsize = 1 + myRandom48(MIN(recordsLeft, MAX_NDBS));
while(lumpsize &&
recordsLeft &&
ndbcnt < MAX_NDBS)
{
Ndb* ndb = ndbObjs[ ndbcnt ];
NdbTransaction* trans = ndb->startTransaction();
check(trans != NULL, (*ndb));
NdbOperation* readOp = trans->getNdbOperation(ctx->getTab());
check(readOp != NULL, (*trans));
check(readOp->readTuple() == 0, (*readOp));
check(hugoOps.equalForRow(readOp, recordsLeft) == 0, hugoOps);
/* Read all other cols */
for (int k=0; k < ctx->getTab()->getNoOfColumns(); k++)
{
check(readOp->getValue(ctx->getTab()->getColumn(k)) != NULL,
(*readOp));
}
/* Now send em off */
trans->executeAsynchPrepare(NdbTransaction::Commit,
NULL,
NULL,
NdbOperation::AbortOnError);
ndb->sendPreparedTransactions();
transArray[ndbcnt] = trans;
global_poll_group->addNdb(ndb);
ndbcnt++;
pollcnt++;
recordsLeft--;
lumpsize--;
};
/* Ok, now wait for the Ndbs to complete */
while (pollcnt)
{
/* Occasionally check with no timeout */
Uint32 timeout_millis = myRandom48(2)?10000:0;
int count = global_poll_group->wait(ready_ndbs, timeout_millis);
if (count > 0)
{
for (int y=0; y < count; y++)
{
Ndb *ndb = ready_ndbs[y];
check(ndb->pollNdb(0, 1) != 0, (*ndb));
}
pollcnt -= count;
}
}
/* Ok, now close the transactions */
for (int t=0; t < ndbcnt; t++)
{
transArray[t]->close();
}
} while (recordsLeft);
i++;
}
for (int j=0; j < MAX_NDBS; j++)
{
delete ndbObjs[ j ];
}
//.........这里部分代码省略.........
示例4: main
int main()
{
ndb_init();
Ndb_cluster_connection *cluster_connection=
new Ndb_cluster_connection(); // Object representing the cluster
if (cluster_connection->wait_until_ready(30,30))
{
std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
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,30))
{
std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
Ndb* myNdb = new Ndb( cluster_connection,
"TEST_DB_2" ); // 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;
ndb_end(0);
return 0;
}