Bug #40923 NdbOperation not returning error code when using wrong API NdbInterpretedCode
Submitted: 21 Nov 2008 13:13 Modified: 18 Jan 2009 15:18
Reporter: Jonathan Miller Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:telco-6.2+ OS:Any
Assigned to: Jon Stephens CPU Architecture:Any

[21 Nov 2008 13:13] Jonathan Miller
Description:
While trying to get NDBAtomics running on ACRT I ran in to an issue where interpret_exit_last_row() was returning -1, but when calling APIERROR(m_pMyTrans->getNdbError()); no error code or message was returned

Note from Frazer:

The problem is that you need to use the NdbInterpretedCode class to write interpreted code for scans in all clones from telco-6.2 up.
  The replacement code would look something like shown below (There's similar code in storage/ndb/tools/select_count.cpp) :

 NdbInterpretedCode code;

 if ((code.interpret_exit_last_row() != 0) ||
     (code.finalise() != 0))
 {
   ERR(code.getNdbError());
   return NDBT_FAILED;
 }

 m_pMyScanOp->setInterpretedCode(&code);

 I would have expected that you'd get error 4537 - "Wrong API.  Use NdbInterpretedCode for NdbRecord operations" on the NdbOperation object after the old call failed.  If you don't get this error then I think it's a bug. 

How to repeat:
   // Start an NDB transaction
   NdbTransaction  *m_pMyTrans = pMyNdb->startTransaction();
   if (m_pMyTrans == NULL) {
     const NdbError err = pMyNdb->getNdbError();
     if (err.status == NdbError::TemporaryError){
       NdbSleep_MilliSleep(50);
       m_retryAttempt++;
       continue;
     }
     APIERROR(pMyNdb->getNdbError());
     exit(-1);
   }
   //Start an NDB Operation
   NdbScanOperation  * m_pMyScanOp = m_pMyTrans->getNdbScanOperation(m_pMyTable);
   if (m_pMyScanOp == NULL) {
     APIERROR(m_pMyTrans->getNdbError());
     pMyNdb->closeTransaction(m_pMyTrans);
     exit(-1);
   }
   //Tell the NDB operation that this will be a read op
   if( m_pMyScanOp->readTuples(NdbScanOperation::LM_Dirty) ) {
     APIERROR(m_pMyTrans->getNdbError());
     pMyNdb->closeTransaction(m_pMyTrans);
     exit(-1);
   }
   m_check = m_pMyScanOp->interpret_exit_last_row();
   if( m_check == -1 ) {
     APIERROR(m_pMyTrans->getNdbError());  <---- Error -1
     pMyNdb->closeTransaction(m_pMyTrans);
     exit(-1);
   } 

Suggested fix:
get error 4537 - "Wrong API.  Use NdbInterpretedCode for NdbRecord operations"
[21 Nov 2008 14:58] Frazer Clement
Can you check whether the NdbOperation object has an Error (rather than the NdbTransaction object)?

e.g.
   m_check = m_pMyScanOp->interpret_exit_last_row();
   if( m_check == -1 ) {
     APIERROR(m_pMyTrans->getNdbError());  <---- Error -1
     pMyNdb->closeTransaction(m_pMyTrans);
     exit(-1);
   } 

becomes

   m_check = m_pMyScanOp->interpret_exit_last_row();
   if( m_check == -1 ) {
     APIERROR(m_pMyScanOp->getNdbError());  <---- Error -1
     pMyNdb->closeTransaction(m_pMyTrans);
     exit(-1);
   }
[21 Nov 2008 18:20] Jonathan Miller
Was a bug in app code and not in API.
[22 Nov 2008 12:20] Jon Stephens
Changing to Docs bug, assigning to myself as a reminder to review and possibly update relevant documentation. (Jeb sent me an email asking me to look this one over, seems like I should.)
[18 Jan 2009 15:18] Jon Stephens
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.