benchronja.cpp

来自「MySQL数据库开发源码 值得一看哦」· C++ 代码 · 共 1,202 行 · 第 1/3 页

CPP
1,202
字号
  theTransaction = aNdb->startTransaction();  theOperation = theTransaction->getNdbOperation("SHORT_REC");  theOperation->committedRead();  theOperation->equal((Uint32)0, key);  theOperation->getValue((Uint32)1, (char*)&readFlip);  int ret = theTransaction->execute(Commit);  assert (ret == expected_ret);  if (ret == 0)     assert (*flip == readFlip);  aNdb->closeTransaction(theTransaction);}int multiRecordTest(Ndb* aNdb, unsigned int key){  NdbConnection* theTransaction;  Uint32 flip = 0;  Uint32 save_flip;  ndbout << "0" << endl;  theTransaction = aNdb->startTransaction();  updateNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  updateNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  commitTrans(aNdb, theTransaction);  ndbout << "1 " << endl;  readVerify(aNdb, &flip, key, 0);  readDirty(aNdb, &flip, key, 0);  save_flip = flip;  ndbout << "1.1 " << endl;  theTransaction = aNdb->startTransaction();  deleteNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, -1);  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, -1);  ndbout << "1.2 " << endl;  insertNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!  ndbout << "1.3 " << endl;  updateNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  readDirty(aNdb, &save_flip, key, 0);           // COMMITTED READ!!!  ndbout << "1.4 " << endl;  commitTrans(aNdb, theTransaction);  ndbout << "2 " << endl;  readDirty(aNdb, &flip, key, 0);           // COMMITTED READ!!!  readVerify(aNdb, &flip, key, 0);  save_flip = flip;  theTransaction = aNdb->startTransaction();  deleteNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, -1);       // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, -1);  insertNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  updateNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, 0);        // COMMITTED READ!!!  deleteNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, -1);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, -1);  rollbackTrans(aNdb, theTransaction);  ndbout << "3 " << endl;  flip = save_flip;  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readVerify(aNdb, &flip, key, 0);  theTransaction = aNdb->startTransaction();  updateNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, 0);  readNoCommit(theTransaction, &flip, key, 0);  deleteNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, -1);  readDirtyNoCommit(theTransaction, &flip, key, -1);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  insertNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  updateNoCommit(theTransaction, &flip, key);  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  deleteNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, 0);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, -1);  readDirtyNoCommit(theTransaction, &flip, key, -1);  commitTrans(aNdb, theTransaction);  ndbout << "4 " << endl;  readVerify(aNdb, &flip, key, -1);  theTransaction = aNdb->startTransaction();  insertNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  deleteNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, -1);  readDirtyNoCommit(theTransaction, &flip, key, -1);  insertNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  updateNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, 0);  readDirtyNoCommit(theTransaction, &flip, key, 0);  deleteNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &save_flip, key, -1);                     // COMMITTED READ!!!  readNoCommit(theTransaction, &flip, key, -1);  readDirtyNoCommit(theTransaction, &flip, key, -1);  commitTrans(aNdb, theTransaction);  ndbout << "5 " << endl;  readDirty(aNdb, &flip, key, -1);                         // COMMITTED READ!!!  readVerify(aNdb, &flip, key, -1);  theTransaction = aNdb->startTransaction();  insertNoCommit(theTransaction, &flip, key);  readDirty(aNdb, &flip, key, -1);                         // COMMITTED READ!!!  readDirtyNoCommit(theTransaction, &flip, key, 0);        // COMMITTED READ!!!  commitTrans(aNdb, theTransaction);  readDirty(aNdb, &flip, key, 0);                          // COMMITTED READ!!!  ndbout << "6 " << endl;  theTransaction = aNdb->startTransaction();  deleteNoCommit(theTransaction, &flip, key);  updateNoCommitFail(theTransaction, key);  rollbackTrans(aNdb, theTransaction);  return 0;}int lookup(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){  int placeholder[500];  unsigned int flip, count;  int ret_value, i;  NdbConnection* theTransaction;  NdbOperation* theOperation;  if ( !aNdb ) return -1 ;	  if (guess != 0)    theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);  else    theTransaction = aNdb->startTransaction();  for (i = 0; i < tNoOfOpsPerExecute; i++) {    if (long_short == 0)      theOperation = theTransaction->getNdbOperation("SHORT_REC");    else      theOperation = theTransaction->getNdbOperation("LONG_REC");    if (theOperation == NULL) {      ndbout << "Table missing" << endl;	  aNdb->closeTransaction(theTransaction) ;	  return -1;    }//if    theOperation->simpleRead();    theOperation->equal((Uint32)0, key);    theOperation->getValue((Uint32)1, (char*)&flip);    theOperation->getValue((Uint32)2, (char*)&count);    if (theOperation->getValue((Uint32)3, (char*)&placeholder[0]) == NULL) {      ndbout << "Error in definition phase = " << theTransaction->getNdbError() << endl;        aNdb->closeTransaction(theTransaction);      return -1;    }//if  }//for  ret_value = theTransaction->execute(Commit);  if (ret_value == -1)    ndbout << "Error in lookup:" << theTransaction->getNdbError() << endl;    aNdb->closeTransaction(theTransaction);	return ret_value;}//lookup()int update(Ndb* aNdb, unsigned int key, unsigned int long_short, int guess){  int placeholder[500];  int ret_value, i;  unsigned int flip, count;  NdbConnection* theTransaction;  NdbOperation* theOperation;  if ( !aNdb ) return -1 ;  if (guess != 0)    theTransaction = aNdb->startTransaction((Uint32)0, (const char*)&key, (Uint32)4);  else    theTransaction = aNdb->startTransaction();  for (i = 0; i < tNoOfOpsPerExecute; i++) {    if (long_short == 0)      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC    else      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC    if (theOperation == NULL) {      ndbout << "Table missing" << endl;	  aNdb->closeTransaction(theTransaction) ;	  delete aNdb ;      return -1;    }//if    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel    theOperation->equal((Uint32)0, key);                          // Search key    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder    theOperation->load_const_u32((Uint32)1, (Uint32)0);           // Load register 1 with 0    theOperation->read_attr((Uint32)1, (Uint32)2);                // Read Flip value into register 2    theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0);     // If Flip (register 2) == 0 (register 1) goto label 0    theOperation->branch_label((Uint32)1);                        // Goto label 1    theOperation->def_label((Uint32)0);                           // Define label 0    theOperation->load_const_u32((Uint32)1, (Uint32)1);           // Load register 1 with 1    theOperation->def_label((Uint32)1);                           // Define label 0    theOperation->write_attr((Uint32)1, (Uint32)1);               // Write 1 (register 1) into Flip    ret_value = theOperation->incValue((Uint32)2, (Uint32)1);     // Increment Count by 1    if (ret_value == -1) {      ndbout << "Error in definition phase " << endl;        aNdb->closeTransaction(theTransaction);      return ret_value;    }//if  }//for  ret_value = theTransaction->execute(Commit);                  // Perform the actual read and update  if (ret_value == -1) {    ndbout << "Error in update:" << theTransaction->getNdbError() << endl;    aNdb->closeTransaction(theTransaction); // < epaulsa	return ret_value ;  }//if  aNdb->closeTransaction(theTransaction);  return ret_value;}//update()int update_bug(Ndb* aNdb, unsigned int key, unsigned int long_short){  int placeholder[500];  int ret_value, i;  unsigned int flip, count;  NdbConnection* theTransaction;  NdbOperation* theOperation;  if ( !aNdb ) return -1 ;  theTransaction = aNdb->startTransaction();  for (i = 0; i < tNoOfOpsPerExecute; i++) {    if (long_short == 0)      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC    else      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC    if (theOperation == NULL) {      ndbout << "Table missing" << endl;  	  aNdb->closeTransaction(theTransaction) ;      return -1;    }//if    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel    theOperation->equal((Uint32)0, key);                          // Search key    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder    theOperation->load_const_u32((Uint32)1, (Uint32)0);           // Load register 1 with 0    theOperation->read_attr((Uint32)1, (Uint32)2);                // Read Flip value into register 2    theOperation->branch_eq((Uint32)1, (Uint32)2, (Uint32)0);     // If Flip (register 2) == 0 (register 1) goto label 0    theOperation->branch_label((Uint32)1);                        // Goto label 1    theOperation->def_label((Uint32)0);                           // Define label 0    theOperation->load_const_u32((Uint32)1, (Uint32)1);           // Load register 1 with 1    theOperation->def_label((Uint32)1);                           // Define label 0    theOperation->write_attr((Uint32)1, (Uint32)1);               // Write 1 (register 1) into Flip    ret_value = theOperation->incValue((Uint32)2, (Uint32)1);     // Increment Count by 1    if (ret_value == -1) {      ndbout << "Error in definition phase " << endl;        aNdb->closeTransaction(theTransaction);      return ret_value;    }//if  }//for  ret_value = theTransaction->execute(NoCommit);                  // Perform the actual read and update  if (ret_value == -1) {    ndbout << "Error in update:" << theTransaction->getNdbError() << endl;    aNdb->closeTransaction(theTransaction);	return ret_value ;  }//if  aNdb->closeTransaction(theTransaction);  return ret_value;}//update_bug()int update_interpreter_test(Ndb* aNdb, unsigned int key, unsigned int long_short){  int placeholder[500];  int ret_value, i;  unsigned int flip, count;  NdbConnection* theTransaction;  NdbOperation* theOperation;  Uint32 Tlabel = 0;  if ( !aNdb ) return -1 ; //------------------------------------------------------------------------------// Start the transaction and get a unique transaction id//------------------------------------------------------------------------------  theTransaction = aNdb->startTransaction();  for (i = 0; i < tNoOfOpsPerExecute; i++) {//------------------------------------------------------------------------------// Get the proper table object and load schema information if not already// present.//------------------------------------------------------------------------------    if (long_short == 0)      theOperation = theTransaction->getNdbOperation("SHORT_REC"); // Use table SHORT_REC    else      theOperation = theTransaction->getNdbOperation("LONG_REC"); // Use table LONG_REC    if (theOperation == NULL) {      ndbout << "Table missing" << endl;  	  aNdb->closeTransaction(theTransaction) ;      return -1;    }//if//------------------------------------------------------------------------------// Define the operation type and the tuple key (primary key in this case).//------------------------------------------------------------------------------    theOperation->interpretedUpdateTuple();                       // Send interpreted program to NDB kernel    theOperation->equal((Uint32)0, key);                          // Search key//------------------------------------------------------------------------------// Perform initial read of attributes before updating them//------------------------------------------------------------------------------    theOperation->getValue((Uint32)1, (char*)&flip);              // Read value of flip    theOperation->getValue((Uint32)2, (char*)&count);             // Read value of count    theOperation->getValue((Uint32)3, (char*)&placeholder[0]);    // Read value of placeholder//------------------------------------------------------------------------------// Test that the various branch operations can handle things correctly.// Test first 2 + 3 = 5 with 32 bit registers// Next test the same with 32 bit + 64 bit = 64 //------------------------------------------------------------------------------    theOperation->load_const_u32((Uint32)4, (Uint32)0);           // Load register 4 with 0    theOperation->load_const_u32((Uint32)0, (Uint32)0);    theOperation->load_const_u32((Uint32)1, (Uint32)3);    theOperation->load_const_u32((Uint32)2, (Uint32)5);    theOperation->load_const_u32((Uint32)3, (Uint32)1);    theOperation->def_label(Tlabel++);    theOperation->def_label(Tlabel++);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?