Commit 25c8705d authored by joreland@mysql.com's avatar joreland@mysql.com

ndb - major update HugoOperations/Transactions

     +more code reuse
     +easier testing of indexes
parent b439d7f1
...@@ -754,8 +754,6 @@ public: ...@@ -754,8 +754,6 @@ public:
Undefined = 0, ///< Undefined object type (initial value) Undefined = 0, ///< Undefined object type (initial value)
UniqueHashIndex = 3, ///< Unique un-ordered hash index UniqueHashIndex = 3, ///< Unique un-ordered hash index
///< (only one currently supported) ///< (only one currently supported)
HashIndex = 4, ///< Non-unique un-ordered hash index
UniqueOrderedIndex = 5, ///< Unique ordered index
OrderedIndex = 6 ///< Non-unique ordered index OrderedIndex = 6 ///< Non-unique ordered index
}; };
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
class HugoOperations : public UtilTransactions { class HugoOperations : public UtilTransactions {
public: public:
HugoOperations(const NdbDictionary::Table&); HugoOperations(const NdbDictionary::Table&,
const NdbDictionary::Index* idx = 0);
~HugoOperations(); ~HugoOperations();
int startTransaction(Ndb*); int startTransaction(Ndb*);
int closeTransaction(Ndb*); int closeTransaction(Ndb*);
...@@ -98,8 +100,6 @@ protected: ...@@ -98,8 +100,6 @@ protected:
struct RsPair { NdbResultSet* m_result_set; int records; }; struct RsPair { NdbResultSet* m_result_set; int records; };
Vector<RsPair> m_result_sets; Vector<RsPair> m_result_sets;
Vector<RsPair> m_executed_result_sets; Vector<RsPair> m_executed_result_sets;
private:
NdbConnection* pTrans;
}; };
#endif #endif
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
class HugoTransactions : public HugoOperations { class HugoTransactions : public HugoOperations {
public: public:
HugoTransactions(const NdbDictionary::Table&); HugoTransactions(const NdbDictionary::Table&,
const NdbDictionary::Index* idx = 0);
~HugoTransactions(); ~HugoTransactions();
int createEvent(Ndb*); int createEvent(Ndb*);
int eventOperation(Ndb*, void* stats, int eventOperation(Ndb*, void* stats,
......
...@@ -23,14 +23,10 @@ typedef int (ReadCallBackFn)(NDBT_ResultRow*); ...@@ -23,14 +23,10 @@ typedef int (ReadCallBackFn)(NDBT_ResultRow*);
class UtilTransactions { class UtilTransactions {
public: public:
enum ScanLock { UtilTransactions(const NdbDictionary::Table&,
SL_Read = 0, const NdbDictionary::Index* idx = 0);
SL_ReadHold = 1, UtilTransactions(Ndb* ndb,
SL_Exclusive = 2 const char * tableName, const char * indexName = 0);
};
UtilTransactions(const NdbDictionary::Table&);
UtilTransactions(Ndb* ndb, const char * tableName);
int clearTable(Ndb*, int clearTable(Ndb*,
int records = 0, int records = 0,
...@@ -114,6 +110,12 @@ private: ...@@ -114,6 +110,12 @@ private:
protected: protected:
int m_defaultClearMethod; int m_defaultClearMethod;
const NdbDictionary::Table& tab; const NdbDictionary::Table& tab;
const NdbDictionary::Index* idx;
NdbConnection* pTrans;
NdbOperation* getOperation(NdbConnection*,
NdbOperation::OperationType);
NdbScanOperation* getScanOperation(NdbConnection*);
}; };
#endif #endif
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
#include <NdbSleep.h> #include <NdbSleep.h>
#include <HugoAsynchTransactions.hpp> #include <HugoAsynchTransactions.hpp>
HugoAsynchTransactions::HugoAsynchTransactions(const NdbDictionary::Table& _tab): HugoAsynchTransactions::HugoAsynchTransactions(const NdbDictionary::Table& _t)
HugoTransactions(_tab), : HugoTransactions(_t),
transactionsCompleted(0), transactionsCompleted(0),
numTransactions(0), numTransactions(0),
transactions(NULL){ transactions(NULL)
{
} }
HugoAsynchTransactions::~HugoAsynchTransactions(){ HugoAsynchTransactions::~HugoAsynchTransactions(){
......
...@@ -57,8 +57,10 @@ int HugoOperations::pkReadRecord(Ndb* pNdb, ...@@ -57,8 +57,10 @@ int HugoOperations::pkReadRecord(Ndb* pNdb,
int a; int a;
allocRows(numRecords); allocRows(numRecords);
int check; int check;
for(int r=0; r < numRecords; r++){ for(int r=0; r < numRecords; r++){
NdbOperation* pOp = pTrans->getNdbOperation(tab.getName());
NdbOperation* pOp = getOperation(pTrans, NdbOperation::ReadRequest);
if (pOp == NULL) { if (pOp == NULL) {
ERR(pTrans->getNdbError()); ERR(pTrans->getNdbError());
return NDBT_FAILED; return NDBT_FAILED;
...@@ -115,7 +117,7 @@ int HugoOperations::pkUpdateRecord(Ndb* pNdb, ...@@ -115,7 +117,7 @@ int HugoOperations::pkUpdateRecord(Ndb* pNdb,
allocRows(numRecords); allocRows(numRecords);
int check; int check;
for(int r=0; r < numRecords; r++){ for(int r=0; r < numRecords; r++){
NdbOperation* pOp = pTrans->getNdbOperation(tab.getName()); NdbOperation* pOp = getOperation(pTrans, NdbOperation::UpdateRequest);
if (pOp == NULL) { if (pOp == NULL) {
ERR(pTrans->getNdbError()); ERR(pTrans->getNdbError());
return NDBT_FAILED; return NDBT_FAILED;
...@@ -157,7 +159,7 @@ int HugoOperations::pkInsertRecord(Ndb* pNdb, ...@@ -157,7 +159,7 @@ int HugoOperations::pkInsertRecord(Ndb* pNdb,
int a, check; int a, check;
for(int r=0; r < numRecords; r++){ for(int r=0; r < numRecords; r++){
NdbOperation* pOp = pTrans->getNdbOperation(tab.getName()); NdbOperation* pOp = getOperation(pTrans, NdbOperation::InsertRequest);
if (pOp == NULL) { if (pOp == NULL) {
ERR(pTrans->getNdbError()); ERR(pTrans->getNdbError());
return NDBT_FAILED; return NDBT_FAILED;
...@@ -198,7 +200,7 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb, ...@@ -198,7 +200,7 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb,
int a, check; int a, check;
for(int r=0; r < numRecords; r++){ for(int r=0; r < numRecords; r++){
NdbOperation* pOp = pTrans->getNdbOperation(tab.getName()); NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest);
if (pOp == NULL) { if (pOp == NULL) {
ERR(pTrans->getNdbError()); ERR(pTrans->getNdbError());
return NDBT_FAILED; return NDBT_FAILED;
...@@ -222,65 +224,6 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb, ...@@ -222,65 +224,6 @@ int HugoOperations::pkDeleteRecord(Ndb* pNdb,
} }
return NDBT_OK; return NDBT_OK;
} }
#if 0
NdbResultSet*
HugoOperations::scanReadRecords(Ndb* pNdb, ScanLock lock){
NDBT_ResultRow * m_tmpRow = new NDBT_ResultRow(tab);
NdbScanOperation* pOp = pTrans->getNdbScanOperation(tab.getName());
if (pOp == NULL) {
ERR(pTrans->getNdbError());
return 0;
}
int check = 0;
NdbResultSet * rs = 0;
switch(lock){
case SL_ReadHold:
rs = pOp->readTuples(NdbScanOperation::LM_Read, 1, 1);
break;
case SL_Exclusive:
rs = pOp->readTuples(NdbScanOperation::LM_Exclusive, 1, 1);
break;
case SL_Read:
default:
rs = pOp->readTuples(NdbScanOperation::LM_Dirty, 1, 1);
}
if( rs == 0) {
ERR(pTrans->getNdbError());
return 0;
}
check = pOp->interpret_exit_ok();
if( check == -1 ) {
ERR(pTrans->getNdbError());
return 0;
}
// Define attributes to read
for(int a = 0; a<tab.getNoOfColumns(); a++){
if((m_tmpRow->attributeStore(a) =
pOp->getValue(tab.getColumn(a)->getName())) == 0) {
ERR(pTrans->getNdbError());
return 0;
}
}
return rs;
}
int
HugoOperations::readTuples(NdbResultSet* rs){
int res = 0;
while((res = rs->nextResult()) == 0){
}
if(res != 1)
return NDBT_FAILED;
return NDBT_OK;
}
#endif
int HugoOperations::execute_Commit(Ndb* pNdb, int HugoOperations::execute_Commit(Ndb* pNdb,
AbortOption eao){ AbortOption eao){
...@@ -392,11 +335,11 @@ int HugoOperations::execute_Rollback(Ndb* pNdb){ ...@@ -392,11 +335,11 @@ int HugoOperations::execute_Rollback(Ndb* pNdb){
return NDBT_OK; return NDBT_OK;
} }
HugoOperations::HugoOperations(const NdbDictionary::Table& _tab): HugoOperations::HugoOperations(const NdbDictionary::Table& _tab,
UtilTransactions(_tab), const NdbDictionary::Index* idx):
calc(_tab), UtilTransactions(_tab, idx),
pTrans(NULL){ calc(_tab)
{
} }
HugoOperations::~HugoOperations(){ HugoOperations::~HugoOperations(){
...@@ -531,14 +474,12 @@ HugoOperations::verifyUpdatesValue(int updatesValue, int _numRows){ ...@@ -531,14 +474,12 @@ HugoOperations::verifyUpdatesValue(int updatesValue, int _numRows){
} }
void HugoOperations::allocRows(int _numRows){ void HugoOperations::allocRows(int _numRows){
deallocRows();
if(_numRows <= 0){ if(_numRows <= 0){
g_info << "Illegal value for num rows : " << _numRows << endl; g_info << "Illegal value for num rows : " << _numRows << endl;
abort(); abort();
} }
for(int b=0; b<_numRows; b++){ for(int b=rows.size(); b<_numRows; b++){
rows.push_back(new NDBT_ResultRow(tab)); rows.push_back(new NDBT_ResultRow(tab));
} }
} }
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment