Commit 16c58c11 authored by unknown's avatar unknown
Browse files

ndb - interface change of handling of abort option

1) move AbortOption from NdbTransaction to NdbOperation

2) let each operation have a "default" abort option dependant on
   operation type

   - read - AO_IgnoreError
   - dml - AbortOnError
   - scan take over - AbortOnError

3) Changed default value to execute() from AbortOnError to DefaultAbortOption, which does not change the operations abort-option.

   Another value to execute(AO) is equivalent to setting AO on each operation before calling execute

4) execute() does _only_ return -1 if transaction has been aborted
   otherwise, you need to check each operation for error code


sql/ha_ndbcluster.cc:
  adopt to changes in aption option handling
storage/ndb/include/ndbapi/NdbOperation.hpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/include/ndbapi/NdbTransaction.hpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/src/ndbapi/NdbBlob.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/src/ndbapi/NdbIndexStat.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
  Put default value on abortoption dependant on operation type
storage/ndb/src/ndbapi/NdbOperationExec.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/src/ndbapi/NdbTransaction.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/test/include/HugoOperations.hpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/test/ndbapi/testNdbApi.cpp:
  Move "ownership" of AbortOption to operation from transaction
storage/ndb/test/src/HugoOperations.cpp:
  Move "ownership" of AbortOption to operation from transaction
parent faac0f1d
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -260,13 +260,14 @@ static int ndb_to_mysql_error(const NdbError *ndberr)
int execute_no_commit_ignore_no_key(ha_ndbcluster *h, NdbTransaction *trans)
{
  int res= trans->execute(NdbTransaction::NoCommit,
                          NdbTransaction::AO_IgnoreError,
                          NdbOperation::AO_IgnoreError,
                          h->m_force_send);
  if (res == 0)
    return 0;
  if (res == -1)
    return -1;

  const NdbError &err= trans->getNdbError();
  if (err.classification != NdbError::ConstraintViolation &&
  if (err.classification != NdbError::NoError &&
      err.classification != NdbError::ConstraintViolation &&
      err.classification != NdbError::NoDataFound)
    return res;

@@ -286,7 +287,7 @@ int execute_no_commit(ha_ndbcluster *h, NdbTransaction *trans,
  return h->m_ignore_no_key ?
    execute_no_commit_ignore_no_key(h,trans) :
    trans->execute(NdbTransaction::NoCommit,
		   NdbTransaction::AbortOnError,
		   NdbOperation::AbortOnError,
		   h->m_force_send);
}

@@ -299,7 +300,7 @@ int execute_commit(ha_ndbcluster *h, NdbTransaction *trans)
    return 0;
#endif
  return trans->execute(NdbTransaction::Commit,
                        NdbTransaction::AbortOnError,
                        NdbOperation::AbortOnError,
                        h->m_force_send);
}

@@ -312,7 +313,7 @@ int execute_commit(THD *thd, NdbTransaction *trans)
    return 0;
#endif
  return trans->execute(NdbTransaction::Commit,
                        NdbTransaction::AbortOnError,
                        NdbOperation::AbortOnError,
                        thd->variables.ndb_force_send);
}

@@ -327,7 +328,7 @@ int execute_no_commit_ie(ha_ndbcluster *h, NdbTransaction *trans,
#endif
  h->release_completed_operations(trans, force_release);
  return trans->execute(NdbTransaction::NoCommit,
                        NdbTransaction::AO_IgnoreError,
                        NdbOperation::AO_IgnoreError,
                        h->m_force_send);
}

@@ -1731,7 +1732,8 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf,
      ERR_RETURN(trans->getNdbError());
  }

  if (execute_no_commit_ie(this,trans,false) != 0) 
  if ((res = execute_no_commit_ie(this,trans,false)) != 0 ||
      op->getNdbError().code) 
  {
    table->status= STATUS_NOT_FOUND;
    DBUG_RETURN(ndb_err(trans));
@@ -2003,7 +2005,8 @@ int ha_ndbcluster::unique_index_read(const byte *key,
  if ((res= define_read_attrs(buf, op)))
    DBUG_RETURN(res);

  if (execute_no_commit_ie(this,trans,false) != 0) 
  if (execute_no_commit_ie(this,trans,false) != 0 ||
      op->getNdbError().code) 
  {
    table->status= STATUS_NOT_FOUND;
    DBUG_RETURN(ndb_err(trans));
@@ -7742,7 +7745,7 @@ ndb_get_table_statistics(ha_ndbcluster* file, bool report_error, Ndb* ndb, const
		  (char*)&var_mem);
    
    if (pTrans->execute(NdbTransaction::NoCommit,
                        NdbTransaction::AbortOnError,
                        NdbOperation::AbortOnError,
                        TRUE) == -1)
    {
      error= pTrans->getNdbError();
@@ -8000,7 +8003,6 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
          !op->readTuple(lm) && 
          !set_primary_key(op, multi_range_curr->start_key.key) &&
          !define_read_attrs(curr, op) &&
          (op->setAbortOption(AO_IgnoreError), TRUE) &&
          (!m_use_partition_function ||
           (op->setPartitionId(part_spec.start_part), true)))
        curr += reclength;
@@ -8022,8 +8024,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
      if ((op= m_active_trans->getNdbIndexOperation(unique_idx, tab)) && 
          !op->readTuple(lm) && 
          !set_index_key(op, key_info, multi_range_curr->start_key.key) &&
          !define_read_attrs(curr, op) &&
          (op->setAbortOption(AO_IgnoreError), TRUE))
          !define_read_attrs(curr, op))
        curr += reclength;
      else
        ERR_RETURN(op ? op->getNdbError() : m_active_trans->getNdbError());
+21 −2
Original line number Diff line number Diff line
@@ -98,6 +98,19 @@ public:
#endif
  };

  /**
   * How should transaction be handled if operation fails
   *
   * For READ, default is AO_IgnoreError
   *     DML,  default is AbortOnError
   * CommittedRead does _only_ support AO_IgnoreError
   */
  enum AbortOption {
    DefaultAbortOption = -1,///< Use default as specified by op-type
    AbortOnError = 0,       ///< Abort transaction on failed operation
    AO_IgnoreError = 2      ///< Transaction continues on failed operation
  };

  /**
   * Define the NdbOperation to be a standard operation of type insertTuple.
   * When calling NdbTransaction::execute, this operation 
@@ -777,8 +790,13 @@ public:
   */
  LockMode getLockMode() const { return theLockMode; }

  /**
   * Get/set abort option
   */
  AbortOption getAbortOption() const;
  int setAbortOption(AbortOption);
  
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
  void setAbortOption(Int8 ao) { m_abortOption = ao; }
  
  /**
   * Set/get partition key
@@ -857,7 +875,8 @@ protected:

  int    doSend(int ProcessorId, Uint32 lastFlag);
  virtual int	 prepareSend(Uint32  TC_ConnectPtr,
                             Uint64  TransactionId);
                             Uint64  TransactionId,
			     AbortOption);
  virtual void   setLastFlag(NdbApiSignal* signal, Uint32 lastFlag);
    
  int	 prepareSendInterpreted();            // Help routine to prepare*
+22 −34
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "NdbError.hpp"
#include "NdbDictionary.hpp"
#include "Ndb.hpp"
#include "NdbOperation.hpp"

class NdbTransaction;
class NdbOperation;
@@ -45,11 +46,12 @@ typedef void (* NdbAsynchCallback)(int, NdbTransaction*, void*);

#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
enum AbortOption {
  CommitIfFailFree= 0,         
  TryCommit= 0,
  AbortOnError= 0,
  CommitAsMuchAsPossible= 2,
  AO_IgnoreError= 2
  DefaultAbortOption = NdbOperation::DefaultAbortOption,
  CommitIfFailFree = NdbOperation::AbortOnError,         
  TryCommit = NdbOperation::AbortOnError,
  AbortOnError= NdbOperation::AbortOnError,
  CommitAsMuchAsPossible = NdbOperation::AO_IgnoreError,
  AO_IgnoreError= NdbOperation::AO_IgnoreError
};
enum ExecType { 
  NoExecTypeDef = -1,
@@ -145,20 +147,6 @@ class NdbTransaction

public:

  /**
   * Commit type of transaction
   */
  enum AbortOption {
    AbortOnError=               ///< Abort transaction on failed operation
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
    ::AbortOnError
#endif
    ,AO_IgnoreError=            ///< Transaction continues on failed operation
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
    ::AO_IgnoreError
#endif
  };

  /**
   * Execution type of transaction
   */
@@ -317,13 +305,15 @@ public:
   * @return 0 if successful otherwise -1.
   */
  int execute(ExecType execType,
	      AbortOption abortOption = AbortOnError,
	      NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
	      int force = 0 );
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
  int execute(::ExecType execType,
	      ::AbortOption abortOption = ::AbortOnError,
	      int force = 0 )
  { return execute ((ExecType)execType,(AbortOption)abortOption,force); }
	      ::AbortOption abortOption = ::DefaultAbortOption,
	      int force = 0 ) {
    return execute ((ExecType)execType,
		    (NdbOperation::AbortOption)abortOption,
		    force); }
#endif

#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
@@ -354,14 +344,14 @@ public:
  void executeAsynchPrepare(ExecType          execType,
			    NdbAsynchCallback callback,
			    void*             anyObject,
			    AbortOption abortOption = AbortOnError);
			    NdbOperation::AbortOption = NdbOperation::DefaultAbortOption);
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
  void executeAsynchPrepare(::ExecType       execType,
			    NdbAsynchCallback callback,
			    void*             anyObject,
			    ::AbortOption abortOption = ::AbortOnError)
  { executeAsynchPrepare((ExecType)execType, callback, anyObject,
			 (AbortOption)abortOption); }
			    ::AbortOption ao = ::DefaultAbortOption) {
    executeAsynchPrepare((ExecType)execType, callback, anyObject,
			 (NdbOperation::AbortOption)ao); }
#endif

  /**
@@ -380,14 +370,14 @@ public:
  void executeAsynch(ExecType            aTypeOfExec,
		     NdbAsynchCallback   aCallback,
		     void*               anyObject,
		     AbortOption abortOption = AbortOnError);
		     NdbOperation::AbortOption = NdbOperation::DefaultAbortOption);
#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
  void executeAsynch(::ExecType         aTypeOfExec,
		     NdbAsynchCallback   aCallback,
		     void*               anyObject,
		     ::AbortOption abortOption= ::AbortOnError)
		     ::AbortOption abortOption= ::DefaultAbortOption)
  { executeAsynch((ExecType)aTypeOfExec, aCallback, anyObject,
		  (AbortOption)abortOption); }
		  (NdbOperation::AbortOption)abortOption); }
#endif
#endif
  /**
@@ -589,7 +579,7 @@ private:
  void init();           // Initialize connection object for new transaction

  int executeNoBlobs(ExecType execType, 
	             AbortOption abortOption = AbortOnError,
	             NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
	             int force = 0 );
  
  /**
@@ -643,7 +633,7 @@ private:
  int 	sendCOMMIT();                   // Send a TC_COMMITREQ signal;
  void	setGCI(int GCI);		// Set the global checkpoint identity
 
  int	OpCompleteFailure(Uint8 abortoption, bool setFailure = true);
  int	OpCompleteFailure(NdbOperation*);
  int	OpCompleteSuccess();
  void	CompletedOperations();	        // Move active ops to list of completed
 
@@ -733,7 +723,6 @@ private:

  Uint32	theNoOfOpSent;				// How many operations have been sent	    
  Uint32	theNoOfOpCompleted;			// How many operations have completed
  Uint32        theNoOfOpFetched;           	        // How many operations was actually fetched
  Uint32	theMyRef;				// Our block reference		
  Uint32	theTCConPtr;				// Transaction Co-ordinator connection pointer.
  Uint64	theTransactionId;			// theTransactionId of the transaction
@@ -757,7 +746,6 @@ private:
  bool theTransactionIsStarted; 
  bool theInUseState;
  bool theSimpleState;
  Uint8 m_abortOption;           // Type of commi

  enum ListState {  
    NotInList, 
+9 −9
Original line number Diff line number Diff line
@@ -1134,7 +1134,7 @@ NdbBlob::readTableParts(char* buf, Uint32 part, Uint32 count)
      setErrorCode(tOp);
      DBUG_RETURN(-1);
    }
    tOp->m_abortOption = NdbTransaction::AbortOnError;
    tOp->m_abortOption = NdbOperation::AbortOnError;
    buf += thePartSize;
    n++;
    thePendingBlobOps |= (1 << NdbOperation::ReadRequest);
@@ -1170,7 +1170,7 @@ NdbBlob::insertParts(const char* buf, Uint32 part, Uint32 count)
      setErrorCode(tOp);
      DBUG_RETURN(-1);
    }
    tOp->m_abortOption = NdbTransaction::AbortOnError;
    tOp->m_abortOption = NdbOperation::AbortOnError;
    buf += thePartSize;
    n++;
    thePendingBlobOps |= (1 << NdbOperation::InsertRequest);
@@ -1194,7 +1194,7 @@ NdbBlob::updateParts(const char* buf, Uint32 part, Uint32 count)
      setErrorCode(tOp);
      DBUG_RETURN(-1);
    }
    tOp->m_abortOption = NdbTransaction::AbortOnError;
    tOp->m_abortOption = NdbOperation::AbortOnError;
    buf += thePartSize;
    n++;
    thePendingBlobOps |= (1 << NdbOperation::UpdateRequest);
@@ -1217,7 +1217,7 @@ NdbBlob::deleteParts(Uint32 part, Uint32 count)
      setErrorCode(tOp);
      DBUG_RETURN(-1);
    }
    tOp->m_abortOption = NdbTransaction::AbortOnError;
    tOp->m_abortOption = NdbOperation::AbortOnError;
    n++;
    thePendingBlobOps |= (1 << NdbOperation::DeleteRequest);
    theNdbCon->thePendingBlobOps |= (1 << NdbOperation::DeleteRequest);
@@ -1253,7 +1253,7 @@ NdbBlob::deletePartsUnknown(Uint32 part)
        setErrorCode(tOp);
        DBUG_RETURN(-1);
      }
      tOp->m_abortOption= NdbTransaction::AO_IgnoreError;
      tOp->m_abortOption= NdbOperation::AO_IgnoreError;
      n++;
    }
    DBUG_PRINT("info", ("bat=%u", bat));
@@ -1589,7 +1589,7 @@ NdbBlob::preExecute(NdbTransaction::ExecType anExecType, bool& batch)
        DBUG_RETURN(-1);
      }
      if (isWriteOp()) {
        tOp->m_abortOption = NdbTransaction::AO_IgnoreError;
        tOp->m_abortOption = NdbOperation::AO_IgnoreError;
      }
      theHeadInlineReadOp = tOp;
      // execute immediately
@@ -1635,7 +1635,7 @@ NdbBlob::preExecute(NdbTransaction::ExecType anExecType, bool& batch)
        DBUG_RETURN(-1);
      }
      if (isWriteOp()) {
        tOp->m_abortOption = NdbTransaction::AO_IgnoreError;
        tOp->m_abortOption = NdbOperation::AO_IgnoreError;
      }
      theHeadInlineReadOp = tOp;
      // execute immediately
@@ -1808,7 +1808,7 @@ NdbBlob::postExecute(NdbTransaction::ExecType anExecType)
      setErrorCode(NdbBlobImpl::ErrAbort);
      DBUG_RETURN(-1);
    }
    tOp->m_abortOption = NdbTransaction::AbortOnError;
    tOp->m_abortOption = NdbOperation::AbortOnError;
    DBUG_PRINT("info", ("added op to update head+inline"));
  }
  DBUG_RETURN(0);
@@ -1838,7 +1838,7 @@ NdbBlob::preCommit()
          setErrorCode(NdbBlobImpl::ErrAbort);
          DBUG_RETURN(-1);
        }
        tOp->m_abortOption = NdbTransaction::AbortOnError;
        tOp->m_abortOption = NdbOperation::AbortOnError;
        DBUG_PRINT("info", ("added op to update head+inline"));
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -428,7 +428,7 @@ NdbIndexStat::records_in_range(const NdbDictionary::Index* index, NdbIndexScanOp
      DBUG_RETURN(-1);
    }
    if (trans->execute(NdbTransaction::NoCommit,
                       NdbTransaction::AbortOnError, forceSend) == -1) {
                       NdbOperation::AbortOnError, forceSend) == -1) {
      m_error = trans->getNdbError();
      DBUG_PRINT("error", ("trans:%d op:%d", trans->getNdbError().code,
                           op->getNdbError().code));
Loading