DbtupAbort.cpp 9.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#define DBTUP_C
#include "Dbtup.hpp"
#include <RefConvert.hpp>
#include <ndb_limits.h>
#include <pc.hpp>

#define ljam() { jamLine(9000 + __LINE__); }
#define ljamEntry() { jamEntryLine(9000 + __LINE__); }

void Dbtup::freeAllAttrBuffers(Operationrec*  const regOperPtr)
{
unknown's avatar
unknown committed
28
  if (regOperPtr->storedProcedureId == RNIL) {
29 30 31
    ljam();
    freeAttrinbufrec(regOperPtr->firstAttrinbufrec);
  } else {
unknown's avatar
unknown committed
32
    ljam();
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    StoredProcPtr storedPtr;
    c_storedProcPool.getPtr(storedPtr, (Uint32)regOperPtr->storedProcedureId);
    ndbrequire(storedPtr.p->storedCode == ZSCAN_PROCEDURE);
    storedPtr.p->storedCounter--;
    regOperPtr->storedProcedureId = ZNIL;
  }//if
  regOperPtr->firstAttrinbufrec = RNIL;
  regOperPtr->lastAttrinbufrec = RNIL;
}//Dbtup::freeAllAttrBuffers()

void Dbtup::freeAttrinbufrec(Uint32 anAttrBuf) 
{
  Uint32 Ttemp;
  AttrbufrecPtr localAttrBufPtr;
  Uint32 RnoFree = cnoFreeAttrbufrec;
  localAttrBufPtr.i = anAttrBuf;
  while (localAttrBufPtr.i != RNIL) {
    ljam();
    ptrCheckGuard(localAttrBufPtr, cnoOfAttrbufrec, attrbufrec);
    Ttemp = localAttrBufPtr.p->attrbuf[ZBUF_NEXT];
    localAttrBufPtr.p->attrbuf[ZBUF_NEXT] = cfirstfreeAttrbufrec;
    cfirstfreeAttrbufrec = localAttrBufPtr.i;
    localAttrBufPtr.i = Ttemp;
    RnoFree++;
  }//if
  cnoFreeAttrbufrec = RnoFree;
}//Dbtup::freeAttrinbufrec()

unknown's avatar
unknown committed
61 62 63
/**
 * Abort abort this operation and all after (nextActiveOp's)
 */
64 65 66 67 68 69 70 71
void Dbtup::execTUP_ABORTREQ(Signal* signal) 
{
  OperationrecPtr regOperPtr;
  FragrecordPtr regFragPtr;
  TablerecPtr regTabPtr;

  ljamEntry();
  regOperPtr.i = signal->theData[0];
unknown's avatar
unknown committed
72 73 74 75 76 77 78
  c_operation_pool.getPtr(regOperPtr);
  TransState trans_state= get_trans_state(regOperPtr.p);
  ndbrequire((trans_state == TRANS_STARTED) ||
             (trans_state == TRANS_TOO_MUCH_AI) ||
             (trans_state == TRANS_ERROR_WAIT_TUPKEYREQ) ||
             (trans_state == TRANS_IDLE));
  if (regOperPtr.p->op_struct.op_type == ZREAD) {
79 80
    ljam();
    freeAllAttrBuffers(regOperPtr.p);
unknown's avatar
unknown committed
81
    initOpConnection(regOperPtr.p);
82 83 84 85 86 87
    return;
  }//if

  regFragPtr.i = regOperPtr.p->fragmentPtr;
  ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);

unknown's avatar
unknown committed
88 89 90 91 92
  regTabPtr.i = regFragPtr.p->fragTableId;
  ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);

  if (get_tuple_state(regOperPtr.p) == TUPLE_PREPARED)
  {
93
    ljam();
unknown's avatar
unknown committed
94 95 96 97 98 99
    if (!regTabPtr.p->tuxCustomTriggers.isEmpty())
      executeTuxAbortTriggers(signal,
			      regOperPtr.p,
			      regFragPtr.p,
			      regTabPtr.p);
    
100
    OperationrecPtr loopOpPtr;
unknown's avatar
unknown committed
101
    loopOpPtr.i = regOperPtr.p->nextActiveOp;
102 103
    while (loopOpPtr.i != RNIL) {
      ljam();
unknown's avatar
unknown committed
104 105 106
      c_operation_pool.getPtr(loopOpPtr);
      if (get_tuple_state(loopOpPtr.p) != TUPLE_ALREADY_ABORTED &&
	  !regTabPtr.p->tuxCustomTriggers.isEmpty()) {
107 108 109
        ljam();
        executeTuxAbortTriggers(signal,
                                loopOpPtr.p,
unknown's avatar
unknown committed
110
                                regFragPtr.p,
111 112
                                regTabPtr.p);
      }
unknown's avatar
unknown committed
113 114
      set_tuple_state(loopOpPtr.p, TUPLE_ALREADY_ABORTED);      
      loopOpPtr.i = loopOpPtr.p->nextActiveOp;
115 116 117
    }
  }

unknown's avatar
unknown committed
118 119 120
  PagePtr page;
  Tuple_header *tuple_ptr= (Tuple_header*)
    get_ptr(&page, &regOperPtr.p->m_tuple_location, regTabPtr.p);
unknown's avatar
unknown committed
121 122

  Uint32 bits= tuple_ptr->m_header_bits;  
unknown's avatar
unknown committed
123 124 125 126 127 128
  if(regOperPtr.p->op_struct.op_type != ZDELETE)
  {
    Tuple_header *copy= (Tuple_header*)
      c_undo_buffer.get_ptr(&regOperPtr.p->m_copy_tuple_location);
    
    if(regOperPtr.p->op_struct.m_disk_preallocated)
129
    {
unknown's avatar
unknown committed
130 131 132 133
      jam();
      Local_key key;
      memcpy(&key, copy->get_disk_ref_ptr(regTabPtr.p), sizeof(key));
      disk_page_abort_prealloc(signal, regFragPtr.p, &key, key.m_page_idx);
134
    }
unknown's avatar
unknown committed
135
    
unknown's avatar
unknown committed
136

unknown's avatar
unknown committed
137
    Uint32 copy_bits= copy->m_header_bits;
unknown's avatar
unknown committed
138 139
    if(! (bits & Tuple_header::ALLOC))
    {
unknown's avatar
unknown committed
140
      if(copy_bits & Tuple_header::MM_GROWN)
unknown's avatar
unknown committed
141 142
      {
	ndbout_c("abort grow");
unknown's avatar
unknown committed
143 144
	Ptr<Page> vpage;
	Uint32 idx= regOperPtr.p->m_tuple_location.m_page_idx;
unknown's avatar
unknown committed
145 146
	Uint32 mm_vars= regTabPtr.p->m_attributes[MM].m_no_of_varsize;
	Uint32 *var_part;
unknown's avatar
unknown committed
147 148 149 150 151 152 153

	ndbassert(tuple_ptr->m_header_bits & Tuple_header::CHAINED_ROW);
	
	Uint32 ref= * tuple_ptr->get_var_part_ptr(regTabPtr.p);
	Local_key tmp; 
	tmp.assref(ref); 
	
unknown's avatar
unknown committed
154 155
	idx= tmp.m_page_idx;
	var_part= get_ptr(&vpage, *(Var_part_ref*)&ref);
unknown's avatar
unknown committed
156
	Var_page* pageP = (Var_page*)vpage.p;
unknown's avatar
unknown committed
157
	Uint32 len= pageP->get_entry_len(idx) & ~Var_page::CHAIN;
unknown's avatar
unknown committed
158
	Uint32 sz = ((((mm_vars + 1) << 1) + (((Uint16*)var_part)[mm_vars]) + 3)>> 2);
unknown's avatar
unknown committed
159 160
	ndbassert(sz <= len);
	pageP->shrink_entry(idx, sz);
unknown's avatar
unknown committed
161
	update_free_page_list(regFragPtr.p, vpage);
unknown's avatar
unknown committed
162 163 164 165 166 167
      } 
      else if(bits & Tuple_header::MM_SHRINK)
      {
	ndbout_c("abort shrink");
      }
    }
unknown's avatar
unknown committed
168 169 170 171 172 173 174
    else if (regOperPtr.p->is_first_operation() && 
	     regOperPtr.p->is_last_operation())
    {
      /**
       * Aborting last operation that performed ALLOC
       */
      tuple_ptr->m_header_bits &= ~(Uint32)Tuple_header::ALLOC;
unknown's avatar
unknown committed
175 176 177 178 179 180 181 182 183
      tuple_ptr->m_header_bits |= Tuple_header::FREED;
    }
  }
  else if (regOperPtr.p->is_first_operation() && 
	   regOperPtr.p->is_last_operation())
  {
    if (bits & Tuple_header::ALLOC)
    {
      tuple_ptr->m_header_bits &= ~(Uint32)Tuple_header::ALLOC;
184
      tuple_ptr->m_header_bits |= Tuple_header::FREED;
unknown's avatar
unknown committed
185
    }
unknown's avatar
unknown committed
186 187 188 189 190 191 192 193 194 195 196 197
  }
  
  if(regOperPtr.p->is_first_operation() && regOperPtr.p->is_last_operation())
  {
    if (regOperPtr.p->m_undo_buffer_space)
      c_lgman->free_log_space(regFragPtr.p->m_logfile_group_id, 
			      regOperPtr.p->m_undo_buffer_space);
  }

  removeActiveOpList(regOperPtr.p, tuple_ptr);
  initOpConnection(regOperPtr.p);
}
198 199 200 201 202 203 204 205 206

/* **************************************************************** */
/* ********************** TRANSACTION ERROR MODULE **************** */
/* **************************************************************** */
int Dbtup::TUPKEY_abort(Signal* signal, int error_type)
{
  switch(error_type) {
  case 1:
//tmupdate_alloc_error:
unknown's avatar
unknown committed
207
    terrorCode= ZMEM_NOMEM_ERROR;
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
    ljam();
    break;

  case 15:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 16:
    ljam();
    terrorCode = ZTRY_TO_UPDATE_ERROR;
    break;

  case 17:
    ljam();
    terrorCode = ZNO_ILLEGAL_NULL_ATTR;
    break;

  case 19:
    ljam();
    terrorCode = ZTRY_TO_UPDATE_ERROR;
    break;

  case 20:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 22:
    ljam();
    terrorCode = ZTOTAL_LEN_ERROR;
    break;

  case 23:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 24:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 26:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 27:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 28:
    ljam();
    terrorCode = ZREGISTER_INIT_ERROR;
    break;

  case 29:
    ljam();
    break;

  case 30:
    ljam();
    terrorCode = ZCALL_ERROR;
    break;

  case 31:
    ljam();
    terrorCode = ZSTACK_OVERFLOW_ERROR;
    break;

  case 32:
    ljam();
    terrorCode = ZSTACK_UNDERFLOW_ERROR;
    break;

  case 33:
    ljam();
    terrorCode = ZNO_INSTRUCTION_ERROR;
    break;

  case 34:
    ljam();
    terrorCode = ZOUTSIDE_OF_PROGRAM_ERROR;
    break;

  case 35:
    ljam();
    terrorCode = ZTOO_MANY_INSTRUCTIONS_ERROR;
    break;

  case 38:
    ljam();
    terrorCode = ZTEMPORARY_RESOURCE_FAILURE;
    break;

  case 39:
unknown's avatar
unknown committed
306
    if (get_trans_state(operPtr.p) == TRANS_TOO_MUCH_AI) {
307 308
      ljam();
      terrorCode = ZTOO_MUCH_ATTRINFO_ERROR;
unknown's avatar
unknown committed
309
    } else if (get_trans_state(operPtr.p) == TRANS_ERROR_WAIT_TUPKEYREQ) {
310 311 312 313 314 315 316 317 318 319 320 321
      ljam();
      terrorCode = ZSEIZE_ATTRINBUFREC_ERROR;
    } else {
      ndbrequire(false);
    }//if
    break;
  default:
    ndbrequire(false);
    break;
  }//switch
  tupkeyErrorLab(signal);
  return -1;
unknown's avatar
unknown committed
322 323 324 325 326 327 328 329 330 331 332
}

void Dbtup::early_tupkey_error(Signal* signal)
{
  Operationrec * const regOperPtr = operPtr.p;
  ndbrequire(!regOperPtr->op_struct.in_active_list);
  set_trans_state(regOperPtr, TRANS_IDLE);
  set_tuple_state(regOperPtr, TUPLE_PREPARED);
  initOpConnection(regOperPtr);
  send_TUPKEYREF(signal, regOperPtr);
}
333 334 335 336

void Dbtup::tupkeyErrorLab(Signal* signal) 
{
  Operationrec * const regOperPtr = operPtr.p;
unknown's avatar
unknown committed
337 338
  set_trans_state(regOperPtr, TRANS_IDLE);
  set_tuple_state(regOperPtr, TUPLE_PREPARED);
339

unknown's avatar
unknown committed
340 341 342 343 344 345 346
  FragrecordPtr fragPtr;
  fragPtr.i= regOperPtr->fragmentPtr;
  ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);

  TablerecPtr tabPtr;
  tabPtr.i= fragPtr.p->fragTableId;
  ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
347

unknown's avatar
unknown committed
348 349 350 351 352
  if (regOperPtr->m_undo_buffer_space)
  {
    c_lgman->free_log_space(fragPtr.p->m_logfile_group_id, 
			    regOperPtr->m_undo_buffer_space);
  }
unknown's avatar
unknown committed
353 354 355 356 357 358 359 360 361

  Uint32 *ptr = 0;
  if (!regOperPtr->m_tuple_location.isNull())
  {
    PagePtr tmp;
    ptr= get_ptr(&tmp, &regOperPtr->m_tuple_location, tabPtr.p);
  }


unknown's avatar
unknown committed
362 363 364 365 366 367 368 369 370
  removeActiveOpList(regOperPtr, (Tuple_header*)ptr);
  initOpConnection(regOperPtr);
  send_TUPKEYREF(signal, regOperPtr);
}

void Dbtup::send_TUPKEYREF(Signal* signal,
                           Operationrec* const regOperPtr)
{
  TupKeyRef * const tupKeyRef = (TupKeyRef *)signal->getDataPtrSend();  
371 372
  tupKeyRef->userRef = regOperPtr->userpointer;
  tupKeyRef->errorCode = terrorCode;
unknown's avatar
unknown committed
373
  sendSignal(DBLQH_REF, GSN_TUPKEYREF, signal, 
374
             TupKeyRef::SignalLength, JBB);
unknown's avatar
unknown committed
375
}
376