当前位置: 首页>>代码示例>>C++>>正文


C++ NdbOperation类代码示例

本文整理汇总了C++中NdbOperation的典型用法代码示例。如果您正苦于以下问题:C++ NdbOperation类的具体用法?C++ NdbOperation怎么用?C++ NdbOperation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NdbOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: allocTransactions

int 
HugoAsynchTransactions::executeAsynchOperation(Ndb* pNdb,		      
					 int records,
					 int batch,
					 int trans,
					 int operations,
					 NDB_OPERATION theOperation,
					 ExecType theType) {

  int             check = 0;
  //  int             retryAttempt = 0;  // Not used at the moment
  //  int             retryMax = 5;      // Not used at the moment
  int             cTrans = 0;
  int             cRecords = 0;
  int             cIndex = 0;
  int a,t,r;

  transactionsCompleted = 0;
  allocTransactions(trans);

  for (int i = 0; i < batch; i++) { // For each batch
    while (cRecords < records*batch) {
      cTrans = 0;
      cIndex = 0;
      for (t = 0; t < trans; t++) { // For each transaction
	transactions[t] = pNdb->startTransaction();
	if (transactions[t] == NULL) {
	  ERR(pNdb->getNdbError());
	  return NDBT_FAILED;
	}	
	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;
	  }
	  
	  switch (theOperation) {
	  case NO_INSERT: 
	    // Insert
	    check = pOp->insertTuple();
	    if (check == -1) { 
	      ERR(transactions[t]->getNdbError());
	      pNdb->closeTransaction(transactions[t]);
	      return NDBT_FAILED;
	    }
	    
	    // Set a calculated value for each attribute in this table	 
	    for (a = 0; a < tab.getNoOfColumns(); a++) {
	      if (setValueForAttr(pOp, a, cRecords, 0 ) != 0) {	  
		ERR(transactions[t]->getNdbError());
		pNdb->closeTransaction(transactions[t]);	  
		return NDBT_FAILED;
	      }
	    } // For each attribute
	    break;
	  case NO_UPDATE:
	    // This is a special case and is handled in the calling client...
	    break;
	  break;
	  case NO_READ:
	    // Define primary keys
	    check = pOp->readTuple();
	    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;
		}
	      }
	    }	    
	    // Define attributes to read  
	    for (a = 0; a < tab.getNoOfColumns(); a++) {
	      if ((rows[cIndex]->attributeStore(a) = 
		   pOp->getValue(tab.getColumn(a)->getName())) == 0) {
		ERR(transactions[t]->getNdbError());
		pNdb->closeTransaction(transactions[t]);
		return NDBT_FAILED;
	      }
	    }	    	  
	    break;
	  case NO_DELETE:
	    // Delete
	    check = pOp->deleteTuple();
	    if (check == -1) { 
	      ERR(transactions[t]->getNdbError());
	      pNdb->closeTransaction(transactions[t]);
	      return NDBT_FAILED;
	    }

	    // Define primary keys
	    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;
		}
//.........这里部分代码省略.........
开发者ID:isleon,项目名称:Jaxer,代码行数:101,代码来源:HugoAsynchTransactions.cpp

示例2: while

void BackupRestore::tuple_a(restore_callback_t *cb)
{
  Uint32 partition_id = cb->fragId;
  while (cb->retries < 10) 
  {
    /**
     * start transactions
     */
    cb->connection = m_ndb->startTransaction();
    if (cb->connection == NULL) 
    {
      if (errorHandler(cb)) 
      {
	m_ndb->sendPollNdb(3000, 1);
	continue;
      }
      err << "Cannot start transaction" << endl;
      exitHandler();
    } // if
    
    const TupleS &tup = cb->tup;
    const NdbDictionary::Table * table = get_table(tup.getTable()->m_dictTable);

    NdbOperation * op = cb->connection->getNdbOperation(table);
    
    if (op == NULL) 
    {
      if (errorHandler(cb)) 
	continue;
      err << "Cannot get operation: " << cb->connection->getNdbError() << endl;
      exitHandler();
    } // if
    
    if (op->writeTuple() == -1) 
    {
      if (errorHandler(cb))
	continue;
      err << "Error defining op: " << cb->connection->getNdbError() << endl;
      exitHandler();
    } // if

    if (table->getFragmentType() == NdbDictionary::Object::UserDefined)
    {
      if (table->getDefaultNoPartitionsFlag())
      {
        /*
          This can only happen for HASH partitioning with
          user defined hash function where user hasn't
          specified the number of partitions and we
          have to calculate it. We use the hash value
          stored in the record to calculate the partition
          to use.
        */
        int i = tup.getNoOfAttributes() - 1;
	const AttributeData  *attr_data = tup.getData(i);
        Uint32 hash_value =  *attr_data->u_int32_value;
        op->setPartitionId(get_part_id(table, hash_value));
      }
      else
      {
        /*
          Either RANGE or LIST (with or without subparts)
          OR HASH partitioning with user defined hash
          function but with fixed set of partitions.
        */
        op->setPartitionId(partition_id);
      }
    }
    int ret = 0;
    for (int j = 0; j < 2; j++)
    {
      for (int i = 0; i < tup.getNoOfAttributes(); i++) 
      {
	const AttributeDesc * attr_desc = tup.getDesc(i);
	const AttributeData * attr_data = tup.getData(i);
	int size = attr_desc->size;
	int arraySize = attr_desc->arraySize;
	char * dataPtr = attr_data->string_value;
	Uint32 length = 0;
       
        if (!attr_data->null)
        {
          const unsigned char * src = (const unsigned char *)dataPtr;
          switch(attr_desc->m_column->getType()){
          case NdbDictionary::Column::Varchar:
          case NdbDictionary::Column::Varbinary:
            length = src[0] + 1;
            break;
          case NdbDictionary::Column::Longvarchar:
          case NdbDictionary::Column::Longvarbinary:
            length = src[0] + (src[1] << 8) + 2;
            break;
          default:
            length = attr_data->size;
            break;
          }
        }
	if (j == 0 && tup.getTable()->have_auto_inc(i))
	  tup.getTable()->update_max_auto_val(dataPtr,size*arraySize);
	
//.........这里部分代码省略.........
开发者ID:A-eolus,项目名称:mysql,代码行数:101,代码来源:consumer_restore.cpp

示例3: while

void
BackupRestore::tuple(const TupleS & tup)
{
  if (!m_restore)
    return;
  while (1) 
  {
    NdbTransaction * trans = m_ndb->startTransaction();
    if (trans == NULL) 
    {
      // TODO: handle the error
      ndbout << "Cannot start transaction" << endl;
      exit(-1);
    } // if
    
    const TableS * table = tup.getTable();
    NdbOperation * op = trans->getNdbOperation(table->getTableName());
    if (op == NULL) 
    {
      ndbout << "Cannot get operation: ";
      ndbout << trans->getNdbError() << endl;
      exit(-1);
    } // if
    
    // TODO: check return value and handle error
    if (op->writeTuple() == -1) 
    {
      ndbout << "writeTuple call failed: ";
      ndbout << trans->getNdbError() << endl;
      exit(-1);
    } // if
    
    for (int i = 0; i < tup.getNoOfAttributes(); i++) 
    {
      const AttributeS * attr = tup[i];
      int size = attr->Desc->size;
      int arraySize = attr->Desc->arraySize;
      const char * dataPtr = attr->Data.string_value;
      
      const Uint32 length = (size * arraySize) / 8;
      if (attr->Desc->m_column->getPrimaryKey()) 
	op->equal(i, dataPtr, length);
    }
    
    for (int i = 0; i < tup.getNoOfAttributes(); i++) 
    {
      const AttributeS * attr = tup[i];
      int size = attr->Desc->size;
      int arraySize = attr->Desc->arraySize;
      const char * dataPtr = attr->Data.string_value;
      
      const Uint32 length = (size * arraySize) / 8;
      if (!attr->Desc->m_column->getPrimaryKey())
	if (attr->Data.null)
	  op->setValue(i, NULL, 0);
	else
	  op->setValue(i, dataPtr, length);
    }
    int ret = trans->execute(Commit);
    if (ret != 0)
    {
      ndbout << "execute failed: ";
      ndbout << trans->getNdbError() << endl;
      exit(-1);
    }
    m_ndb->closeTransaction(trans);
    if (ret == 0)
      break;
  }
  m_dataCount++;
}
开发者ID:SunguckLee,项目名称:MariaDB,代码行数:71,代码来源:consumer_restorem.cpp

示例4: T5_Callback_2

void
T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
  CHECK_MINUS_ONE(result, "T5-2: NoCommit", pCON); 
  ThreadData * td = (ThreadData *)threadData;  

  Uint32 permission = td->transactionData.permission;
  Uint32 sessions   = td->transactionData.sessions;
  Uint32 server_bit = td->transactionData.server_bit;

  if(((permission & server_bit) == server_bit) &&
     ((sessions   & server_bit) == server_bit)){
    
    memcpy(td->transactionData.suffix,
	   &td->transactionData.number
	   [SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], 
	   SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
  
    DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)\n", 
	   SUBSCRIBER_NUMBER_LENGTH, 
	   td->transactionData.number, 
	   td->transactionData.server_id,
	   SUBSCRIBER_NUMBER_SUFFIX_LENGTH, 
	   td->transactionData.suffix);
    
    /* Operation 3 */
    NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
    CHECK_NULL(MyOp, "T5-3: getNdbOperation", 
	       pCON);
    
    MyOp->deleteTuple();
    MyOp->equal(IND_SESSION_SUBSCRIBER,
		(char*)td->transactionData.number);
    MyOp->equal(IND_SESSION_SERVER,
		(char*)&td->transactionData.server_id);
    /* Operation 4 */
    
    /* Operation 5 */
    MyOp = pCON->getNdbOperation(SERVER_TABLE);
    CHECK_NULL(MyOp, "T5-5: getNdbOperation", 
	       pCON);
    
    MyOp->interpretedUpdateTuple();
    MyOp->equal(IND_SERVER_ID,
		(char*)&td->transactionData.server_id);
    MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
		(char*)td->transactionData.suffix);
    MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
    td->transactionData.branchExecuted = 1;
  } else {
    td->transactionData.branchExecuted = 0;

    DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s\n", 
	   SUBSCRIBER_NUMBER_LENGTH, 
	   td->transactionData.number, 
	   td->transactionData.server_id,
	   ((permission & server_bit) ? 
	    "permission - " : "no permission - "),
	   ((sessions   & server_bit) ? 
	    "in session - " : "no in session - "));
  }
  
  if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
    pCON->executeAsynchPrepare(Commit, T5_Callback_3, td); 
  } else {
    pCON->executeAsynchPrepare(Rollback, T5_Callback_3, td);
  }
}
开发者ID:Cona19,项目名称:mysql5.6.24-improve,代码行数:67,代码来源:ndb_async1.cpp

示例5: allocRows

int HugoOperations::pkReadRecord(Ndb* pNdb,
				 int recordNo,
				 int numRecords,
				 NdbOperation::LockMode lm){
  int a;  
  allocRows(numRecords);
  int check;

  NdbOperation* pOp = 0;
  pIndexScanOp = 0;

  for(int r=0; r < numRecords; r++){
    
    if(pOp == 0)
    {
      pOp = getOperation(pTrans, NdbOperation::ReadRequest);
    }
    if (pOp == NULL) {
      ERR(pTrans->getNdbError());
      return NDBT_FAILED;
    }
    
rand_lock_mode:
    switch(lm){
    case NdbOperation::LM_Read:
    case NdbOperation::LM_Exclusive:
    case NdbOperation::LM_CommittedRead:
    case NdbOperation::LM_SimpleRead:
      if(idx && idx->getType() == NdbDictionary::Index::OrderedIndex && 
	 pIndexScanOp == 0)
      {
	pIndexScanOp = ((NdbIndexScanOperation*)pOp);
	check = pIndexScanOp->readTuples(lm);
      }
      else
	check = pOp->readTuple(lm);
      break;
    default:
      lm = (NdbOperation::LockMode)((rand() >> 16) & 3);
      goto rand_lock_mode;
    }
    
    if( check == -1 ) {
      ERR(pTrans->getNdbError());
      return NDBT_FAILED;
    }
    
    // Define primary keys
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;

    if(pIndexScanOp)
      pIndexScanOp->end_of_bound(r);
    
    if(r == 0 || pIndexScanOp == 0)
    {
      // Define attributes to read  
      for(a = 0; a<tab.getNoOfColumns(); a++){
	if((rows[r]->attributeStore(a) = 
	    pOp->getValue(tab.getColumn(a)->getName())) == 0) {
	  ERR(pTrans->getNdbError());
	  return NDBT_FAILED;
	}
      } 
    }
    pOp = pIndexScanOp;
  }
  return NDBT_OK;
}
开发者ID:0x00xw,项目名称:mysql-2,代码行数:69,代码来源:HugoOperations.cpp

示例6: ndb_oc_attrs

/* set all the unique attrs of this objectclass into the table
 */
extern "C" int
ndb_oc_attrs(
	NdbTransaction *txn,
	const NdbDictionary::Table *myTable,
	Entry *e,
	NdbOcInfo *no,
	NdbAttrInfo **attrs,
	int nattrs,
	Attribute *old
)
{
	char buf[65538], *ptr;
	Attribute **an, **ao, *a;
	NdbOperation *myop;
	int i, j, max = 0;
	int changed, rc;
	Uint64 eid = e->e_id;

	if ( !nattrs )
		return 0;

	an = (Attribute **)ch_malloc( 2 * nattrs * sizeof(Attribute *));
	ao = an + nattrs;

	/* Turn lists of attrs into arrays for easier access */
	for ( i=0; i<nattrs; i++ ) {
		if ( attrs[i]->na_oi != no ) {
			an[i] = NULL;
			ao[i] = NULL;
			continue;
		}
		for ( a=e->e_attrs; a; a=a->a_next ) {
			if ( a->a_desc == slap_schema.si_ad_objectClass )
				continue;
			if ( a->a_desc->ad_type == attrs[i]->na_attr ) {
				/* Don't process same attr twice */
				if ( a->a_flags & SLAP_ATTR_IXADD )
					a = NULL;
				else
					a->a_flags |= SLAP_ATTR_IXADD;
				break;
			}
		}
		an[i] = a;
		if ( a && a->a_numvals > max )
			max = a->a_numvals;
		for ( a=old; a; a=a->a_next ) {
			if ( a->a_desc == slap_schema.si_ad_objectClass )
				continue;
			if ( a->a_desc->ad_type == attrs[i]->na_attr )
				break;
		}
		ao[i] = a;
		if ( a && a->a_numvals > max )
			max = a->a_numvals;
	}

	for ( i=0; i<max; i++ ) {
		myop = NULL;
		for ( j=0; j<nattrs; j++ ) {
			if ( !an[j] && !ao[j] )
				continue;
			changed = 0;
			if ( an[j] && an[j]->a_numvals > i ) {
				/* both old and new are present, compare for changes */
				if ( ao[j] && ao[j]->a_numvals > i ) {
					if ( ber_bvcmp( &ao[j]->a_nvals[i], &an[j]->a_nvals[i] ))
						changed = V_REP;
				} else {
					changed = V_INS;
				}
			} else {
				if ( ao[j] && ao[j]->a_numvals > i )
					changed = V_DEL;
			}
			if ( changed ) {
				if ( !myop ) {
					rc = LDAP_OTHER;
					myop = txn->getNdbOperation( myTable );
					if ( !myop ) {
						goto done;
					}
					if ( old ) {
						if ( myop->writeTuple()) {
							goto done;
						}
					} else {
						if ( myop->insertTuple()) {
							goto done;
						}
					}
					if ( myop->equal( EID_COLUMN, eid )) {
						goto done;
					}
					if ( myop->equal( VID_COLUMN, i )) {
						goto done;
					}
				}
//.........这里部分代码省略.........
开发者ID:1ack,项目名称:Impala,代码行数:101,代码来源:ndbio.cpp

示例7: tabRow

int 
UtilTransactions::readRowFromTableAndIndex(Ndb* pNdb,
					   NdbConnection* scanTrans,
					   const NdbDictionary::Index* pIndex,
					   NDBT_ResultRow& row ){


  NdbDictionary::Index::Type indexType= pIndex->getType();
  int                  retryAttempt = 0;
  const int            retryMax = 100;
  int                  check, a;
  NdbConnection	       *pTrans1=NULL;
  NdbOperation	       *pOp;

  int return_code= NDBT_FAILED;

  // Allocate place to store the result
  NDBT_ResultRow       tabRow(tab);
  NDBT_ResultRow       indexRow(tab);
  const char * indexName = pIndex->getName();

  while (true){
    if(retryAttempt)
      ndbout_c("retryAttempt %d", retryAttempt);
    if (retryAttempt >= retryMax){
      g_info << "ERROR: has retried this operation " << retryAttempt 
	     << " times, failing!" << endl;
	goto close_all;
    }

    pTrans1 = pNdb->hupp(scanTrans); //startTransaction();
    if (pTrans1 == NULL) {
      const NdbError err = pNdb->getNdbError();
      
      if (err.status == NdbError::TemporaryError){
	ERR(err);
	NdbSleep_MilliSleep(50);
	retryAttempt++;
	continue;
      }

      if(err.code == 0){
	return_code = NDBT_OK;
	goto close_all;
      }
      ERR(err);
      goto close_all;
    }

    /**
     * Read the record from TABLE
     */
    pOp = pTrans1->getNdbOperation(tab.getName());	
    if (pOp == NULL) {
      ERR(pTrans1->getNdbError());
      goto close_all;
    }
    
    check = pOp->readTuple();
    if( check == -1 ) {
      ERR(pTrans1->getNdbError());
      goto close_all;
    }
    
    // Define primary keys
#if VERBOSE
    printf("PK: ");
#endif
    for(a = 0; a<tab.getNoOfColumns(); a++){
      const NdbDictionary::Column* attr = tab.getColumn(a);
      if (attr->getPrimaryKey() == true){
	if (pOp->equal(attr->getName(), row.attributeStore(a)->aRef()) != 0){
	  ERR(pTrans1->getNdbError());
	  goto close_all;
	}
#if VERBOSE
	printf("%s = %d: ", attr->getName(), row.attributeStore(a)->aRef());
#endif
      }
    }
#if VERBOSE
    printf("\n");
#endif
    // Read all attributes
#if VERBOSE
    printf("Reading %u attributes: ", tab.getNoOfColumns());
#endif
    for(a = 0; a<tab.getNoOfColumns(); a++){
      if((tabRow.attributeStore(a) = 
	  pOp->getValue(tab.getColumn(a)->getName())) == 0) {
	ERR(pTrans1->getNdbError());
	goto close_all;
      }
#if VERBOSE
      printf("%s ", tab.getColumn(a)->getName());
#endif
    }
#if VERBOSE
    printf("\n");
#endif
//.........这里部分代码省略.........
开发者ID:4T-Shirt,项目名称:mysql,代码行数:101,代码来源:UtilTransactions.cpp

示例8: userTransaction_T5

/**
 * Transaction 5 - T5
 * 
 * Delete session
 *
 * Input:
 *   SubscriberNumber
 *   ServerId
 *   ServerBit
 *   DoRollback
 * Output:
 *   ChangedBy
 *   ChangedTime
 *   Location
 *   BranchExecuted
 */
void
userTransaction_T5(UserHandle * uh,
		   SubscriberNumber   inNumber,
		   ServerId           inServerId,
		   ServerBit          inServerBit,
		   DoRollback         inDoRollback,
		   BranchExecuted   * outBranchExecuted){
  Ndb * pNDB = uh->pNDB;

  DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);

  NdbConnection * MyTransaction = 0;
  NdbOperation  * MyOperation = 0;

  char             outChangedBy   [sizeof(ChangedBy)  +(4-(sizeof(ChangedBy)   & 3))];
  char             outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
  Location         outLocation;
  GroupId          groupId;
  ActiveSessions   sessions;
  Permission       permission;
  SubscriberSuffix inSuffix;

  int check;
  NdbRecAttr * check2;

  MyTransaction = pNDB->startTransaction();
  if (MyTransaction == NULL)	  
    error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
  
  MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
  CHECK_NULL(MyOperation, "T5-1: getNdbOperation", 
	     MyTransaction);
  
  MyOperation->interpretedUpdateTuple();
  MyOperation->equal(IND_SUBSCRIBER_NUMBER, 
		     inNumber);
  MyOperation->getValue(IND_SUBSCRIBER_LOCATION, 
		        (char *)&outLocation);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY, 
			&outChangedBy[0]);
  MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME, 
                        &outChangedTime[0]);
  MyOperation->getValue(IND_SUBSCRIBER_GROUP,
		        (char *)&groupId);
  MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
		        (char *)&sessions);
  MyOperation->subValue(IND_SUBSCRIBER_SESSIONS, 
		        (uint32)inServerBit);
  MyTransaction->execute( NoCommit ); 
    /* Operation 2 */

  MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
  CHECK_NULL(MyOperation, "T5-2: getNdbOperation", 
	     MyTransaction);
    
  MyOperation->readTuple();
  MyOperation->equal(IND_GROUP_ID,
		     (char*)&groupId);
  MyOperation->getValue(IND_GROUP_ALLOW_DELETE, 
			(char *)&permission);
  check = MyTransaction->execute( NoCommit ); 
  CHECK_MINUS_ONE(check, "T5-2: NoCommit", 
		  MyTransaction);
  
  if(((permission & inServerBit) == inServerBit) &&
     ((sessions   & inServerBit) == inServerBit)){
  
    memcpy(inSuffix,
	   &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
    
    DEBUG2("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);

    /* Operation 3 */
    MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
    CHECK_NULL(MyOperation, "T5-3: getNdbOperation", 
	       MyTransaction);
    
    MyOperation->deleteTuple();
    MyOperation->equal(IND_SESSION_SUBSCRIBER,
		       (char*)inNumber);
    MyOperation->equal(IND_SESSION_SERVER,
		       (char*)&inServerId);
    /* Operation 4 */
        
//.........这里部分代码省略.........
开发者ID:0x00xw,项目名称:mysql-2,代码行数:101,代码来源:ndb_user_transaction6.cpp

示例9: allocRows

int HugoOperations::pkReadRecord(Ndb* pNdb,
				 int recordNo,
				 int numRecords,
				 NdbOperation::LockMode lm,
                                 NdbOperation::LockMode *lmused){
  int a;  
  allocRows(numRecords);
  indexScans.clear();  
  int check;

  NdbOperation* pOp = 0;
  pIndexScanOp = 0;

  for(int r=0; r < numRecords; r++){
    
    if(pOp == 0)
    {
      pOp = getOperation(pTrans, NdbOperation::ReadRequest);
    }
    if (pOp == NULL) {
      ERR(pTrans->getNdbError());
      setNdbError(pTrans->getNdbError());
      return NDBT_FAILED;
    }
    
rand_lock_mode:
    switch(lm){
    case NdbOperation::LM_Read:
    case NdbOperation::LM_Exclusive:
    case NdbOperation::LM_CommittedRead:
    case NdbOperation::LM_SimpleRead:
      if (lmused)
        * lmused = lm;
      if(idx && idx->getType() == NdbDictionary::Index::OrderedIndex)
      {
        if (pIndexScanOp == 0)
        {
          pIndexScanOp = ((NdbIndexScanOperation*)pOp);
          bool mrrScan= (numRecords > 1);
          Uint32 flags= mrrScan? NdbScanOperation::SF_MultiRange : 0; 
          check = pIndexScanOp->readTuples(lm, flags);
          /* Record NdbIndexScanOperation ptr for later... */
          indexScans.push_back(pIndexScanOp);
        }
      }
      else
	check = pOp->readTuple(lm);
      break;
    default:
      lm = (NdbOperation::LockMode)((rand() >> 16) & 3);
      goto rand_lock_mode;
    }
    
    if( check == -1 ) {
      ERR(pTrans->getNdbError());
      setNdbError(pTrans->getNdbError());
      return NDBT_FAILED;
    }
    
    // Define primary keys
    if (equalForRow(pOp, r+recordNo) != 0)
      return NDBT_FAILED;

    Uint32 partId;
    /* Do we need to set the partitionId for this operation? */
    if (getPartIdForRow(pOp, r+recordNo, partId))
    {
      g_info << "Setting operation partition Id" << endl;
      pOp->setPartitionId(partId);
    }

    if(pIndexScanOp)
      pIndexScanOp->end_of_bound(r);
    
    if(r == 0 || pIndexScanOp == 0)
    {
      // Define attributes to read  
      for(a = 0; a<tab.getNoOfColumns(); a++){
	if((rows[r]->attributeStore(a) = 
	    pOp->getValue(tab.getColumn(a)->getName())) == 0) {
	  ERR(pTrans->getNdbError());
          setNdbError(pTrans->getNdbError());
	  return NDBT_FAILED;
	}
      } 
    }
    /* Note pIndexScanOp will point to the 'last' index scan op
     * we used.  The full list is in the indexScans vector
     */
    pOp = pIndexScanOp;
  }
  return NDBT_OK;
}
开发者ID:,项目名称:,代码行数:93,代码来源:

示例10: T4_Callback_2

void
T4_Callback_2(int result, NdbConnection * pCON, void * threadData) {
    ThreadData * td = (ThreadData *)threadData;
    if (result == -1) {
        CHECK_ALLOWED_ERROR("T4-2: execute", td, pCON->getNdbError());
        td->pNDB->closeTransaction(pCON);
        start_T4(td->pNDB, td, stat_async);
        return;
    }//if

    Uint32 permission = td->transactionData.permission;
    Uint32 sessions   = td->transactionData.sessions;
    Uint32 server_bit = td->transactionData.server_bit;

    if(((permission & server_bit) == server_bit) &&
            ((sessions   & server_bit) == 0)) {

        memcpy(td->transactionData.suffix,
               &td->transactionData.number[SFX_START],
               SUBSCRIBER_NUMBER_SUFFIX_LENGTH);

        DEBUG5("T4(%.*s, %.2d): - Callback 2 - inserting(%.*s)",
               SUBSCRIBER_NUMBER_LENGTH,
               td->transactionData.number,
               td->transactionData.server_id,
               SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
               td->transactionData.suffix);

        /* Operations 3 + 4 */

        if (td->ndbRecordSharedData)
        {
            char* rowPtr= (char*) &td->transactionData;
            const NdbRecord* record= td->ndbRecordSharedData->
                                     sessionTableNdbRecord;
            Uint32 m=0;
            unsigned char* mask= (unsigned char*) &m;

            SET_MASK(mask, IND_SESSION_SUBSCRIBER);
            SET_MASK(mask, IND_SESSION_SERVER);
            SET_MASK(mask, IND_SESSION_DATA);

            const NdbOperation* MyOp= pCON->insertTuple(record, rowPtr, mask);

            CHECK_NULL((void*)MyOp, "T4-3: insertTuple", td,
                       pCON->getNdbError());

            record= td->ndbRecordSharedData->
                    serverTableNdbRecord;
            m= 0;

            NdbOperation::OperationOptions opts;
            opts.optionsPresent= NdbOperation::OperationOptions::OO_INTERPRETED;
            opts.interpretedCode= td->ndbRecordSharedData->incrServerInsertsProg;

            MyOp= pCON->updateTuple(record, rowPtr, record, rowPtr, mask,
                                    &opts, sizeof(opts));

            CHECK_NULL((void*)MyOp, "T4-3: updateTuple", td,
                       pCON->getNdbError());
        }
        else
        {
            NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
            CHECK_NULL(MyOp, "T4-3: getNdbOperation", td,
                       pCON->getNdbError());

            MyOp->insertTuple();
            MyOp->equal(IND_SESSION_SUBSCRIBER,
                        (char*)td->transactionData.number);
            MyOp->equal(IND_SESSION_SERVER,
                        (char*)&td->transactionData.server_id);
            MyOp->setValue(IND_SESSION_DATA,
                           (char *)td->transactionData.session_details);
            /* Operation 4 */

            /* Operation 5 */
            MyOp = pCON->getNdbOperation(SERVER_TABLE);
            CHECK_NULL(MyOp, "T4-5: getNdbOperation", td,
                       pCON->getNdbError());

            MyOp->interpretedUpdateTuple();
            MyOp->equal(IND_SERVER_ID,
                        (char*)&td->transactionData.server_id);
            MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
                        (char*)td->transactionData.suffix);
            MyOp->incValue(IND_SERVER_INSERTS, (uint32)1);
        }
        td->transactionData.branchExecuted = 1;
    } else {
        td->transactionData.branchExecuted = 0;
        DEBUG5("T4(%.*s, %.2d): - Callback 2 - %s %s",
               SUBSCRIBER_NUMBER_LENGTH,
               td->transactionData.number,
               td->transactionData.server_id,
               ((permission & server_bit) ?
                "permission - " : "no permission - "),
               ((sessions   & server_bit) ?
                "in session - " : "no in session - "));
    }
//.........这里部分代码省略.........
开发者ID:jimodb,项目名称:codes,代码行数:101,代码来源:ndb_async2.cpp

示例11: start_T1

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
}
开发者ID:jimodb,项目名称:codes,代码行数:63,代码来源:ndb_async2.cpp

示例12: T3_Callback_2

void
T3_Callback_2(int result, NdbConnection * pCON, void * threadData) {
    ThreadData * td = (ThreadData *)threadData;

    if (result == -1) {
        CHECK_ALLOWED_ERROR("T3-2: execute", td, pCON->getNdbError());
        td->pNDB->closeTransaction(pCON);
        start_T3(td->pNDB, td, stat_async);
        return;
    }//if

    Uint32 permission = td->transactionData.permission;
    Uint32 sessions   = td->transactionData.sessions;
    Uint32 server_bit = td->transactionData.server_bit;

    if(((permission & server_bit) == server_bit) &&
            ((sessions   & server_bit) == server_bit)) {

        memcpy(td->transactionData.suffix,
               &td->transactionData.number[SFX_START],
               SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
        DEBUG5("T3(%.*s, %.2d): - Callback 2 - reading(%.*s)",
               SUBSCRIBER_NUMBER_LENGTH,
               td->transactionData.number,
               td->transactionData.server_id,
               SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
               td->transactionData.suffix);

        /* Operations 3 + 4 */
        if (td->ndbRecordSharedData)
        {
            /* Op 3 */
            char* rowPtr= (char*) &td->transactionData;
            const NdbRecord* record= td->ndbRecordSharedData->
                                     sessionTableNdbRecord;
            Uint32 m=0;
            unsigned char* mask= (unsigned char*) &m;

            SET_MASK(mask, IND_SESSION_DATA);

            const NdbOperation* MyOp = pCON->readTuple(record, rowPtr, record, rowPtr,
                                       NdbOperation::LM_SimpleRead,
                                       mask);
            CHECK_NULL((void*) MyOp, "T3-3: readTuple", td,
                       pCON->getNdbError());

            /* Op 4 */
            record= td->ndbRecordSharedData->
                    serverTableNdbRecord;
            m= 0;

            /* Attach interpreted program */
            NdbOperation::OperationOptions opts;
            opts.optionsPresent= NdbOperation::OperationOptions::OO_INTERPRETED;
            opts.interpretedCode= td->ndbRecordSharedData->incrServerReadsProg;

            MyOp= pCON->updateTuple(record, rowPtr, record, rowPtr, mask,
                                    &opts,
                                    sizeof(opts));
            CHECK_NULL((void*) MyOp, "T3-3: updateTuple", td,
                       pCON->getNdbError());
        }
        else
        {
            NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
            CHECK_NULL(MyOp, "T3-3: getNdbOperation", td,
                       pCON->getNdbError());

            MyOp->simpleRead();
            MyOp->equal(IND_SESSION_SUBSCRIBER,
                        (char*)td->transactionData.number);
            MyOp->equal(IND_SESSION_SERVER,
                        (char*)&td->transactionData.server_id);
            MyOp->getValue(IND_SESSION_DATA,
                           (char *)td->transactionData.session_details);

            MyOp = pCON->getNdbOperation(SERVER_TABLE);
            CHECK_NULL(MyOp, "T3-4: getNdbOperation", td,
                       pCON->getNdbError());

            MyOp->interpretedUpdateTuple();
            MyOp->equal(IND_SERVER_ID,
                        (char*)&td->transactionData.server_id);
            MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
                        (char*)td->transactionData.suffix);
            MyOp->incValue(IND_SERVER_READS, (uint32)1);
        }

        td->transactionData.branchExecuted = 1;
    } else {
        DEBUG3("T3(%.*s, %.2d): - Callback 2 - no read",
               SUBSCRIBER_NUMBER_LENGTH,
               td->transactionData.number,
               td->transactionData.server_id);
        td->transactionData.branchExecuted = 0;
    }
    if (stat_async == 1) {
        pCON->executeAsynchPrepare( Commit , T3_Callback_3, td);
    } else {
        int result = pCON->execute( Commit );
//.........这里部分代码省略.........
开发者ID:jimodb,项目名称:codes,代码行数:101,代码来源:ndb_async2.cpp

示例13: 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;

//.........这里部分代码省略.........
开发者ID:Abner-Sun,项目名称:mysql5.1-vx-pre1,代码行数:101,代码来源:ndbapi_async1.cpp

示例14: main

int main(int argc, const char** argv)
{
  ndb_init();
  int _row = 0;
  int _hex = 0;
  int _primaryKey = 0;
  const char* _tableName = NULL;

  struct getargs args[] = {
    { "row", 'r', 
      arg_integer, &_row, "The row number", "row" },
    { "primarykey", 'p', 
      arg_integer, &_primaryKey, "The primary key", "primarykey" },
    { "hex", 'h', 
      arg_flag, &_hex, "Print hex", "hex" }
  };

  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0, i;

  if(getarg(args, num_args, argc, argv, &optind) || argv[optind] == NULL) {
    arg_printusage(args, num_args, argv[0], "table name\n");
    return NDBT_WRONGARGS;
  }
  // Check if table name is supplied
  if (argv[optind] != NULL) 
    _tableName = argv[optind];


  const NdbDictionary::Table* table = NDBT_Tables::getTable(_tableName);
  //  const NDBT_Attribute* attribute = table->getAttribute(_column);

  g_info << "Table " << _tableName << endl
	 << "Row: " << _row << ", PrimaryKey: " << _primaryKey
	 << endl;

  Ndb_cluster_connection con;
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb* ndb = new Ndb(&con, "TEST_DB");
  if (ndb->init() == 0 && ndb->waitUntilReady(30) == 0)
  {
    NdbConnection* conn = ndb->startTransaction();
    if (conn == NULL)
    {
      g_info << "ERROR: " << ndb->getNdbError() << endl;
      delete ndb;
      return -1;
    }
    NdbOperation* op = conn->getNdbOperation(_tableName);
    if (op == NULL)
    {
      g_info << "ERROR: " << conn->getNdbError() << endl;
      delete ndb;
      return -1;
    }
    op->readTuple();
    NdbRecAttr** data = new NdbRecAttr*[table->getNoOfColumns()];
    for (i = 0; i < table->getNoOfColumns(); i++)
    {
      const NdbDictionary::Column* c = table->getColumn(i);
      if (c->getPrimaryKey())
      {
	op->equal(c->getName(), _primaryKey);
	data[i] = op->getValue(c->getName(), NULL);
      }
      else
      {
	data[i] = op->getValue(c->getName(), NULL);
      }      
    }
    if (conn->execute(Commit) == 0)
    {
      // Print column names
      for (i = 0; i < table->getNoOfColumns(); i++)
      {
	const NdbDictionary::Column* c = table->getColumn(i);
	
	g_info 
	  << c->getName()
	  << "[" << c->getType() << "]   ";	  
      }
      g_info << endl;

      if (_hex)
      {
	g_info << hex;
      }
      for (i = 0; i < table->getNoOfColumns(); i++)
      {
	NdbRecAttr* a = data[i];
	ndbout << (* a) << " ";
      } // for   
      g_info << endl;   
    } // if (conn
    else
    {
      g_info << "Failed to commit read transaction... " 
//.........这里部分代码省略.........
开发者ID:Cona19,项目名称:mysql5.6.24-improve,代码行数:101,代码来源:hugoPkReadRecord.cpp

示例15: ERR

inline
int 
ScanInterpretTest::addRowToInsert(Ndb* pNdb, 
				  NdbConnection* pInsTrans){

  NdbOperation* pOp = 
    pInsTrans->getNdbOperation(restab.getName());	
  if (pOp == NULL) {
    ERR(pInsTrans->getNdbError());
    pNdb->closeTransaction(pInsTrans);
    return NDBT_FAILED;
  }
  
  if( pOp->insertTuple() == -1 ) {
    ERR(pInsTrans->getNdbError());
    pNdb->closeTransaction(pInsTrans);
    return NDBT_FAILED;
  }
  
  // Copy all attribute to the new operation
  for (int a = 0; a<restab.getNoOfColumns(); a++){
    const NdbDictionary::Column* attr = tab.getColumn(a); 
    NdbRecAttr* reca = row.attributeStore(a);
    int check = -1;
    switch (attr->getType()){
    case NdbDictionary::Column::Char:
    case NdbDictionary::Column::Varchar:
    case NdbDictionary::Column::Binary:
    case NdbDictionary::Column::Varbinary:{
      check = pOp->setValue( attr->getName(), 
			     reca->aRef());
      break;
    }
    case NdbDictionary::Column::Int:{
      check = pOp->setValue( attr->getName(), 
			     reca->int32_value());      
    }
      break;
    case NdbDictionary::Column::Bigint:{
      check = pOp->setValue( attr->getName(), 
			     reca->int64_value());
    }
      break;
    case NdbDictionary::Column::Unsigned:{
      check = pOp->setValue( attr->getName(), 
			     reca->u_32_value());
    }
      break;
    case NdbDictionary::Column::Bigunsigned:{
      check = pOp->setValue( attr->getName(), 
			     reca->u_64_value());
    }
      break;
    case NdbDictionary::Column::Float:
      check = pOp->setValue( attr->getName(), 
			     reca->float_value());

      break;
    default:
      check = -1;
      break;
    }
    if(check != 0){
      ERR(pInsTrans->getNdbError());
      pNdb->closeTransaction(pInsTrans);
      return NDBT_FAILED;
    }
  }
  
  return NDBT_OK;
}
开发者ID:4T-Shirt,项目名称:mysql,代码行数:71,代码来源:ScanInterpretTest.hpp


注:本文中的NdbOperation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。