本文整理汇总了C++中Ndb类的典型用法代码示例。如果您正苦于以下问题:C++ Ndb类的具体用法?C++ Ndb怎么用?C++ Ndb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ndb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_update
/*****************************************************************
* Update the second attribute in half of the tuples (adding 10) *
*****************************************************************/
static void do_update(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 10; i+=2) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->updateTuple();
myOperation->equal( "ATTR1", i );
myOperation->setValue( "ATTR2", i+10);
if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
示例2: createDropEvent
static
int
createDropEvent(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
if (ctx->getProperty("NoDDL", Uint32(0)) == 0)
{
for (unsigned i = 0; i<table_list.size(); i++)
{
int res = NDBT_OK;
const NdbDictionary::Table* tab = myDict->getTable(table_list[i].c_str());
if (tab == 0)
{
continue;
}
if ((res = createEvent(pNdb, *tab) != NDBT_OK))
{
return res;
}
if ((res = dropEvent(pNdb, *tab)) != NDBT_OK)
{
return res;
}
}
}
return NDBT_OK;
}
示例3: dropTable
int dropTable(NDBT_Context* ctx, NDBT_Step* step, Uint32 num)
{
Ndb* pNdb = GETNDB(step);
const NdbDictionary::Table* pTab= ctx->getTab();
/* Run as a 'T1' testcase - do nothing for other tables */
if (strcmp(pTab->getName(), "T1") != 0)
return NDBT_OK;
char tabnameBuff[10];
snprintf(tabnameBuff, sizeof(tabnameBuff), "TAB%u", num);
if (pNdb->getDictionary()->dropTable(tabnameBuff) != 0)
{
ndbout << "Drop table failed with error : "
<< pNdb->getDictionary()->getNdbError().code
<< " "
<< pNdb->getDictionary()->getNdbError().message
<< endl;
}
else
{
ndbout << "Dropped table " << tabnameBuff << endl;
}
return NDBT_OK;
}
示例4: runRestartGciControl
int runRestartGciControl(NDBT_Context* ctx, NDBT_Step* step){
int records = ctx->getNumRecords();
Ndb* pNdb = GETNDB(step);
UtilTransactions utilTrans(*ctx->getTab());
NdbRestarter restarter;
// Wait until we have enough records in db
int count = 0;
while (count < records){
if (utilTrans.selectCount(pNdb, 64, &count) != 0){
ctx->stopTest();
return NDBT_FAILED;
}
}
// Restart cluster with abort
if (restarter.restartAll(false, false, true) != 0){
ctx->stopTest();
return NDBT_FAILED;
}
// Stop the other thread
ctx->stopTest();
if (restarter.waitClusterStarted(300) != 0){
return NDBT_FAILED;
}
if (pNdb->waitUntilReady() != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
示例5: runBug24717
int runBug24717(NDBT_Context* ctx, NDBT_Step* step){
int result = NDBT_OK;
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
NdbRestarter restarter;
Ndb* pNdb = GETNDB(step);
HugoTransactions hugoTrans(*ctx->getTab());
int dump[] = { 9002, 0 } ;
Uint32 ownNode = refToNode(pNdb->getReference());
dump[1] = ownNode;
for (; loops; loops --)
{
int nodeId = restarter.getRandomNotMasterNodeId(rand());
restarter.restartOneDbNode(nodeId, false, true, true);
restarter.waitNodesNoStart(&nodeId, 1);
if (restarter.dumpStateOneNode(nodeId, dump, 2))
return NDBT_FAILED;
restarter.startNodes(&nodeId, 1);
do {
for (Uint32 i = 0; i < 100; i++)
{
hugoTrans.pkReadRecords(pNdb, 100, 1, NdbOperation::LM_CommittedRead);
}
} while (restarter.waitClusterStarted(5) != 0);
}
return NDBT_OK;
}
示例6: runCreateIndexT1
int
runCreateIndexT1(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
const NdbDictionary::Table* pTab = pDict->getTable("T1");
if (pTab == 0)
{
g_err << "getTable(T1) error: " << pDict->getNdbError() << endl;
return NDBT_FAILED;
}
NdbDictionary::Index ind;
ind.setName("T1X1");
ind.setTable("T1");
ind.setType(NdbDictionary::Index::OrderedIndex);
ind.setLogging(false);
ind.addColumn("KOL2");
ind.addColumn("KOL3");
ind.addColumn("KOL4");
if (pDict->createIndex(ind, *pTab) != 0)
{
g_err << "createIndex(T1X1) error: " << pDict->getNdbError() << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}
示例7: runSetup
int runSetup(NDBT_Context* ctx, NDBT_Step* step, int waitGroupSize){
int records = ctx->getNumRecords();
int batchSize = ctx->getProperty("BatchSize", 1);
int transactions = (records / 100) + 1;
int operations = (records / transactions) + 1;
Ndb* pNdb = GETNDB(step);
HugoAsynchTransactions hugoTrans(*ctx->getTab());
if (hugoTrans.loadTableAsynch(pNdb, records, batchSize,
transactions, operations) != 0){
return NDBT_FAILED;
}
Ndb_cluster_connection* conn = &pNdb->get_ndb_cluster_connection();
/* The first call to create_multi_ndb_wait_group() should succeed ... */
global_poll_group = conn->create_ndb_wait_group(waitGroupSize);
if(global_poll_group == 0) {
return NDBT_FAILED;
}
/* and subsequent calls should fail */
if(conn->create_ndb_wait_group(waitGroupSize) != 0) {
return NDBT_FAILED;
}
return NDBT_OK;
}
示例8: do_insert
/**************************************************************************
* Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
**************************************************************************/
static void do_insert(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
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);
if (myTransaction->execute( NdbTransaction::Commit ) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
示例9: T1
/**
* 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;
}
示例10: Ndb
Ndb* JniNdbEventStreamingImp::create_ndb_connection(const char* database) {
Ndb* ndb = new Ndb(mClusterConnection, database);
if (ndb->init() == -1) {
LOG_NDB_API_ERROR(ndb->getNdbError());
}
return ndb;
}
示例11: runVerifyUndoData
int runVerifyUndoData(NDBT_Context* ctx, NDBT_Step* step){
int records = ctx->getNumRecords();
Ndb* pNdb = GETNDB(step);
int count = 0;
int num = 5;
if (records - 5 < 0)
num = 1;
const NdbDictionary::Table* tab =
GETNDB(step)->getDictionary()->getTable(ctx->getTab()->getName());
if(tab == 0) {
g_err << " Can't find table" << endl;
return NDBT_FAILED;
}
UtilTransactions utilTrans(* tab);
HugoTransactions hugoTrans(* tab);
// Check that there are as many records as we expected
if(utilTrans.selectCount(pNdb, 64, &count) != 0) {
g_err << "Can't get records count" << endl;
return NDBT_FAILED;
}
g_err << "count = " << count;
g_err << " records = " << records;
g_err << endl;
if (count != records) {
g_err << "The records count is not correct" << endl;
return NDBT_FAILED;
}
// make sure all the update data is there
NdbTransaction *pTransaction= pNdb->startTransaction();
if (pTransaction == NULL) {
g_err << "Can't get transaction pointer" << endl;
return NDBT_FAILED;
}
if(hugoTrans.setTransaction(pTransaction) != 0) {
g_err << "Set transaction error" << endl;
pNdb->closeTransaction(pTransaction);
return NDBT_FAILED;
}
if(hugoTrans.pkReadRecord(pNdb, 0, records, NdbOperation::LM_Read) != 0) {
g_err << "Can't read record" << endl;
return NDBT_FAILED;
}
if(hugoTrans.verifyUpdatesValue(0, records) != 0) {
g_err << "The records restored with undo log is not correct" << endl;
return NDBT_FAILED;
}
hugoTrans.closeTransaction(pNdb);
return NDBT_OK;
}
示例12: lock
void NdbPool::closeAll() {
lock();
while(list) {
Ndb *n = list;
list = (Ndb *) n->getCustomData();
delete n;
}
size = 0;
unlock();
}
示例13: getStatistics
Handle<Value> getStatistics(const Arguments &args) {
HandleScope scope;
Ndb *ndb = unwrapPointer<Ndb *>(args.Holder());
Local<Object> stats = Object::New();
for(int i = 0 ; i < Ndb::NumClientStatistics ; i ++) {
stats->Set(String::NewSymbol(ndb->getClientStatName(i)),
Number::New(ndb->getClientStat(i)),
ReadOnly);
}
return scope.Close(stats);
}
示例14: getStatistics
void getStatistics(const Arguments &args) {
EscapableHandleScope scope(args.GetIsolate());
Ndb *ndb = unwrapPointer<Ndb *>(args.Holder());
Local<Object> stats = Object::New(args.GetIsolate());
for(int i = 0 ; i < Ndb::NumClientStatistics ; i ++) {
stats->Set(String::NewFromUtf8(args.GetIsolate(), ndb->getClientStatName(i)),
Number::New(args.GetIsolate(), ndb->getClientStat(i)));
}
args.GetReturnValue().Set(scope.Escape(stats));
}
示例15: 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;
}