Ndblist.cpp 24.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 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 */

#include <NdbOut.hpp>
unknown's avatar
unknown committed
18 19 20 21
#include <Ndb.hpp>
#include <NdbOperation.hpp>
#include <NdbIndexOperation.hpp>
#include <NdbIndexScanOperation.hpp>
22
#include "NdbApiSignal.hpp"
unknown's avatar
unknown committed
23
#include <NdbRecAttr.hpp>
24 25
#include "NdbUtil.hpp"
#include "API.hpp"
unknown's avatar
unknown committed
26
#include "NdbBlob.hpp"
27 28 29 30

void
Ndb::checkFailedNode()
{
unknown's avatar
unknown committed
31
  DBUG_ENTER("Ndb::checkFailedNode");
32 33 34 35 36 37 38 39 40
  Uint32 *the_release_ind= theImpl->the_release_ind;
  if (the_release_ind[0] == 0)
  {
    DBUG_VOID_RETURN;
  }
  Uint32 tNoOfDbNodes = theImpl->theNoOfDBnodes;
  Uint8 *theDBnodes= theImpl->theDBnodes;

  DBUG_PRINT("enter", ("theNoOfDBnodes: %d", tNoOfDbNodes));
unknown's avatar
unknown committed
41

42 43
  DBUG_ASSERT(tNoOfDbNodes < MAX_NDB_NODES);
  for (Uint32 i = 0; i < tNoOfDbNodes; i++){
44
    const NodeId node_id = theDBnodes[i];
unknown's avatar
unknown committed
45
    DBUG_PRINT("info", ("i: %d, node_id: %d", i, node_id));
46
    
unknown's avatar
unknown committed
47
    DBUG_ASSERT(node_id < MAX_NDB_NODES);    
48 49 50 51 52
    if (the_release_ind[node_id] == 1){

      /**
       * Release all connections in idle list (for node)
       */
53
      NdbTransaction * tNdbCon = theConnectionArray[node_id];
54 55
      theConnectionArray[node_id] = NULL;
      while (tNdbCon != NULL) {
56
        NdbTransaction* tempNdbCon = tNdbCon;
57 58
        tNdbCon = tNdbCon->next();
        releaseNdbCon(tempNdbCon);
unknown's avatar
unknown committed
59
      }
60
      the_release_ind[node_id] = 0;
unknown's avatar
unknown committed
61 62 63
    }
  }
  DBUG_VOID_RETURN;
64 65 66 67 68 69 70 71 72
}

/***************************************************************************
 * int createConIdleList(int aNrOfCon);
 * 
 * Return Value:   Return the number of created connection object 
 *                 if createConIdleList was succesful
 *                 Return -1: In all other case.  
 * Parameters:     aNrOfCon : Number of connections offered to the application.
73
 * Remark:         Create connection idlelist with NdbTransaction objects.
74 75 76 77 78 79
 ***************************************************************************/ 
int 
Ndb::createConIdleList(int aNrOfCon)
{
  for (int i = 0; i < aNrOfCon; i++)
  {
80
    NdbTransaction* tNdbCon = new NdbTransaction(this);
81 82 83 84 85 86 87 88 89 90 91 92 93
    if (tNdbCon == NULL)
    {
      return -1;
    }
    if (theConIdleList == NULL)
    {
      theConIdleList = tNdbCon;
      theConIdleList->next(NULL);
    } else
    {
      tNdbCon->next(theConIdleList);
      theConIdleList = tNdbCon;
    }
94
    tNdbCon->Status(NdbTransaction::NotConnected);
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  }
  theNoOfAllocatedTransactions = aNrOfCon;
  return aNrOfCon; 
}

/***************************************************************************
 * int createOpIdleList(int aNrOfOp);
 *
 * Return Value:   Return the number of created operation object if 
 *                 createOpIdleList was succesful.
 *                 Return -1: In all other case.
 * Parameters:     aNrOfOp:  Number of operations offered to the application. 
 * Remark:         Create  operation idlelist with NdbOperation objects..
 ***************************************************************************/ 
int 
Ndb::createOpIdleList(int aNrOfOp)
{ 
  for (int i = 0; i < aNrOfOp; i++){
    NdbOperation* tOp = new NdbOperation(this);
    if ( tOp == NULL ){
      return -1;
    }
    if (theOpIdleList == NULL){
      theOpIdleList = tOp;
      theOpIdleList->next(NULL);
    } else{
      tOp->next(theOpIdleList);
      theOpIdleList = tOp;
    }
  }
  return aNrOfOp; 
}

/***************************************************************************
 * NdbBranch* NdbBranch();
 *
 * Return Value:   Return a NdbBranch if the  getNdbBranch was successful.
 *                Return NULL : In all other case.  
 * Remark:         Get a NdbBranch from theBranchList and return the object .
 ***************************************************************************/ 
NdbBranch*
Ndb::getNdbBranch()
{
  NdbBranch*    tNdbBranch;
  if ( theBranchList == NULL )
  {
    tNdbBranch = new NdbBranch;
    if (tNdbBranch == NULL)
    {
      return NULL;
    }
    tNdbBranch->theNext = NULL;
  } else
  {
    tNdbBranch = theBranchList;
    theBranchList = tNdbBranch->theNext;
    tNdbBranch->theNext = NULL;
  }
  return tNdbBranch;
}

/***************************************************************************
 * NdbCall* NdbCall();
 *
 * Return Value:   Return a NdbCall if the  getNdbCall was successful.
 *                Return NULL : In all other case.  
 * Remark:         Get a NdbCall from theCallList and return the object .
 ***************************************************************************/ 
NdbCall*
Ndb::getNdbCall()
{
  NdbCall*      tNdbCall;
  if ( theCallList == NULL )
  {
    tNdbCall = new NdbCall;
    if (tNdbCall == NULL)
    {
      return NULL;
    }
    tNdbCall->theNext = NULL;
  } else
  {
    tNdbCall = theCallList;
    theCallList = tNdbCall->theNext;
    tNdbCall->theNext = NULL;
  }
  return tNdbCall;
}

/***************************************************************************
185
 * NdbTransaction* getNdbCon();
186 187 188 189 190
 *
 * Return Value:   Return a connection if the  getNdbCon was successful.
 *                Return NULL : In all other case.  
 * Remark:         Get a connection from theConIdleList and return the object .
 ***************************************************************************/ 
191
NdbTransaction*
192 193
Ndb::getNdbCon()
{
194
  NdbTransaction*        tNdbCon;
195 196
  if ( theConIdleList == NULL ) {
    if (theNoOfAllocatedTransactions < theMaxNoOfTransactions) {
197
      tNdbCon = new NdbTransaction(this);
198 199 200 201 202 203 204 205 206 207 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
      if (tNdbCon == NULL) {
        return NULL;
      }//if
      theNoOfAllocatedTransactions++;
    } else {
      ndbout << "theNoOfAllocatedTransactions = " << theNoOfAllocatedTransactions << " theMaxNoOfTransactions = " << theMaxNoOfTransactions << endl;
      return NULL;
    }//if
    tNdbCon->next(NULL);
  } else
  {
    tNdbCon = theConIdleList;
    theConIdleList = tNdbCon->next();
    tNdbCon->next(NULL);
  }
  tNdbCon->theMagicNumber = 0x37412619;
  return tNdbCon;
}

/***************************************************************************
 * NdbLabel* getNdbLabel();
 *
 * Return Value:   Return a NdbLabel if the  getNdbLabel was successful.
 *                 Return NULL : In all other case.  
 * Remark:         Get a NdbLabel from theLabelList and return the object .
 ***************************************************************************/ 
NdbLabel*
Ndb::getNdbLabel()
{
  NdbLabel*     tNdbLabel;
  if ( theLabelList == NULL )
  {
    tNdbLabel = new NdbLabel;
    if (tNdbLabel == NULL)
    {
      return NULL;
    }
    tNdbLabel->theNext = NULL;
  } else
  {
    tNdbLabel = theLabelList;
    theLabelList = tNdbLabel->theNext;
    tNdbLabel->theNext = NULL;
  }
  return tNdbLabel;
}

/***************************************************************************
 * NdbScanReceiver* getNdbScanRec()
 * 
 * Return Value:  Return a NdbScanReceiver
 *                Return NULL : In all other case.  
 * Remark:        Get a NdbScanReceiver from theScanRecList and return the 
 *                object .
 ****************************************************************************/ 
unknown's avatar
unknown committed
253
NdbReceiver*
254 255
Ndb::getNdbScanRec()
{
unknown's avatar
unknown committed
256
  NdbReceiver*      tNdbScanRec;
257 258
  if ( theScanList == NULL )
  {
unknown's avatar
unknown committed
259
    tNdbScanRec = new NdbReceiver(this);
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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    if (tNdbScanRec == NULL)
    {
      return NULL;
    }
    tNdbScanRec->next(NULL);
  } else
  {
    tNdbScanRec = theScanList;
    theScanList = tNdbScanRec->next();
    tNdbScanRec->next(NULL);
  }

  return tNdbScanRec;
}

/***************************************************************************
 * NdbSubroutine* getNdbSubroutine();
 *
 * Return Value: Return a NdbSubroutine if the  getNdbSubroutine was successful.
 *                Return NULL : In all other case.  
 * Remark:    Get a NdbSubroutine from theSubroutineList and return the object .
 ***************************************************************************/ 
NdbSubroutine*
Ndb::getNdbSubroutine()
{
  NdbSubroutine*        tNdbSubroutine;
  if ( theSubroutineList == NULL )
  {
    tNdbSubroutine = new NdbSubroutine;
    if (tNdbSubroutine == NULL)
    {
      return NULL;
    }
    tNdbSubroutine->theNext = NULL;
  } else
  {
    tNdbSubroutine = theSubroutineList;
    theSubroutineList = tNdbSubroutine->theNext;
    tNdbSubroutine->theNext = NULL;
  }
  return tNdbSubroutine;
}

/***************************************************************************
NdbOperation* getOperation();

Return Value:   Return theOpList : if the  getOperation was succesful.
                Return NULL : In all other case.  
Remark:         Get an operation from theOpIdleList and return the object .
***************************************************************************/ 
NdbOperation*
Ndb::getOperation()
{
  NdbOperation* tOp = theOpIdleList;
  if (tOp != NULL ) {
    NdbOperation* tOpNext = tOp->next();
    tOp->next(NULL);
    theOpIdleList = tOpNext;
    return tOp;
  } else {
    tOp = new NdbOperation(this);
    if (tOp != NULL)
      tOp->next(NULL);
  }
  return tOp;
}

/***************************************************************************
NdbScanOperation* getScanOperation();

Return Value:   Return theOpList : if the  getScanOperation was succesful.
                Return NULL : In all other case.  
Remark:         Get an operation from theScanOpIdleList and return the object .
***************************************************************************/ 
unknown's avatar
unknown committed
334
NdbIndexScanOperation*
335 336
Ndb::getScanOperation()
{
unknown's avatar
unknown committed
337
  NdbIndexScanOperation* tOp = theScanOpIdleList;
338
  if (tOp != NULL ) {
unknown's avatar
unknown committed
339
    NdbIndexScanOperation* tOpNext = (NdbIndexScanOperation*)tOp->next();
340 341 342 343
    tOp->next(NULL);
    theScanOpIdleList = tOpNext;
    return tOp;
  } else {
unknown's avatar
unknown committed
344
    tOp = new NdbIndexScanOperation(this);
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
    if (tOp != NULL)
      tOp->next(NULL);
  }
  return tOp;
}

/***************************************************************************
NdbIndexOperation* getIndexOperation();

Return Value:   Return theOpList : if the  getIndexOperation was succesful.
                Return NULL : In all other case.  
Remark:         Get an operation from theIndexOpIdleList and return the object .
***************************************************************************/ 
NdbIndexOperation*
Ndb::getIndexOperation()
{
  NdbIndexOperation* tOp = theIndexOpIdleList;
  if (tOp != NULL ) {
    NdbIndexOperation* tOpNext = (NdbIndexOperation*) tOp->next();
    tOp->next(NULL);
    theIndexOpIdleList = tOpNext;
    return tOp;
  } else {
    tOp = new NdbIndexOperation(this);
    if (tOp != NULL)
      tOp->next(NULL);
  }
  return tOp;
}

/***************************************************************************
NdbRecAttr* getRecAttr();

Return Value:   Return a reference to a receive attribute object.
                Return NULL if it's not possible to get a receive attribute object.
***************************************************************************/
NdbRecAttr*
Ndb::getRecAttr()
{
  NdbRecAttr* tRecAttr;
  tRecAttr = theRecAttrIdleList;
  if (tRecAttr != NULL) {
    NdbRecAttr* tRecAttrNext = tRecAttr->next();
    tRecAttr->init();
    theRecAttrIdleList = tRecAttrNext;
    return tRecAttr;
  } else {
    tRecAttr = new NdbRecAttr;
    if (tRecAttr == NULL)
      return NULL;
    tRecAttr->next(NULL);
  }//if
  tRecAttr->init();
  return tRecAttr;
}

/***************************************************************************
NdbApiSignal* getSignal();

Return Value:   Return a reference to a signal object.
                Return NULL if not possible to get a signal object.
***************************************************************************/
NdbApiSignal*
Ndb::getSignal()
{
  NdbApiSignal* tSignal = theSignalIdleList;
  if (tSignal != NULL){
    NdbApiSignal* tSignalNext = tSignal->next();
    tSignal->next(NULL);
    theSignalIdleList = tSignalNext;
  } else {
    tSignal = new NdbApiSignal(theMyRef);
unknown's avatar
unknown committed
417
#ifdef POORMANSPURIFY
418
    cnewSignals++;
unknown's avatar
unknown committed
419
#endif
420 421 422
    if (tSignal != NULL)
      tSignal->next(NULL);
  }
unknown's avatar
unknown committed
423
#ifdef POORMANSPURIFY
424
  cgetSignals++;
unknown's avatar
unknown committed
425
#endif
426 427 428
  return tSignal;
}

unknown's avatar
unknown committed
429 430 431 432 433 434 435 436 437 438 439 440 441
NdbBlob*
Ndb::getNdbBlob()
{
  NdbBlob* tBlob = theNdbBlobIdleList;
  if (tBlob != NULL) {
    theNdbBlobIdleList = tBlob->theNext;
    tBlob->init();
  } else {
    tBlob = new NdbBlob;
  }
  return tBlob;
}

442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
/***************************************************************************
void releaseNdbBranch(NdbBranch* aNdbBranch);

Parameters:     NdbBranch: The NdbBranch object.
Remark:         Add a NdbBranch object into the Branch idlelist.
***************************************************************************/
void
Ndb::releaseNdbBranch(NdbBranch* aNdbBranch)
{
  aNdbBranch->theNext = theBranchList;
  theBranchList = aNdbBranch;
}

/***************************************************************************
void releaseNdbCall(NdbCall* aNdbCall);

Parameters:     NdbBranch: The NdbBranch object.
Remark:         Add a NdbBranch object into the Branch idlelist.
***************************************************************************/
void
Ndb::releaseNdbCall(NdbCall* aNdbCall)
{
  aNdbCall->theNext = theCallList;
  theCallList = aNdbCall;
}

/***************************************************************************
469
void releaseNdbCon(NdbTransaction* aNdbCon);
470

471
Parameters:     aNdbCon: The NdbTransaction object.
472 473 474
Remark:         Add a Connection object into the signal idlelist.
***************************************************************************/
void
475
Ndb::releaseNdbCon(NdbTransaction* aNdbCon)
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
{
  aNdbCon->next(theConIdleList);
  aNdbCon->theMagicNumber = 0xFE11DD;
  theConIdleList = aNdbCon;
}

/***************************************************************************
void releaseNdbLabel(NdbLabel* aNdbLabel);

Parameters:     NdbLabel: The NdbLabel object.
Remark:         Add a NdbLabel object into the Label idlelist.
***************************************************************************/
void
Ndb::releaseNdbLabel(NdbLabel* aNdbLabel)
{
  aNdbLabel->theNext = theLabelList;
  theLabelList = aNdbLabel;
}

/***************************************************************************
void releaseNdbScanRec(NdbScanReceiver* aNdbScanRec);

Parameters:     aNdbScanRec: The NdbScanReceiver object.
Remark:         Add a NdbScanReceiver object into the Scan idlelist.
***************************************************************************/
void
unknown's avatar
unknown committed
502
Ndb::releaseNdbScanRec(NdbReceiver* aNdbScanRec)
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
{
  aNdbScanRec->next(theScanList);
  theScanList = aNdbScanRec;
}

/***************************************************************************
void releaseNdbSubroutine(NdbSubroutine* aNdbSubroutine);

Parameters:     NdbSubroutine: The NdbSubroutine object.
Remark:         Add a NdbSubroutine object into theSubroutine idlelist.
***************************************************************************/
void
Ndb::releaseNdbSubroutine(NdbSubroutine* aNdbSubroutine)
{
  aNdbSubroutine->theNext = theSubroutineList;
  theSubroutineList = aNdbSubroutine;
}

/***************************************************************************
void releaseOperation(NdbOperation* anOperation);

Parameters:     anOperation : The released NdbOperation object.
Remark:         Add a NdbOperation object into the signal idlelist.
***************************************************************************/
void
Ndb::releaseOperation(NdbOperation* anOperation)
{
  if(anOperation->m_tcReqGSN == GSN_TCKEYREQ){
    anOperation->next(theOpIdleList);
    anOperation->theNdbCon = NULL;
    anOperation->theMagicNumber = 0xFE11D0;
    theOpIdleList = anOperation;
  } else {
    assert(anOperation->m_tcReqGSN == GSN_TCINDXREQ);
    anOperation->next(theIndexOpIdleList);
    anOperation->theNdbCon = NULL;
    anOperation->theMagicNumber = 0xFE11D1;
    theIndexOpIdleList = (NdbIndexOperation*)anOperation;
  }
}

/***************************************************************************
void releaseScanOperation(NdbScanOperation* aScanOperation);

Parameters:     aScanOperation : The released NdbScanOperation object.
Remark:         Add a NdbScanOperation object into the signal idlelist.
***************************************************************************/
void
unknown's avatar
unknown committed
551
Ndb::releaseScanOperation(NdbIndexScanOperation* aScanOperation)
552
{
553 554 555 556 557 558 559 560 561 562
  DBUG_ENTER("Ndb::releaseScanOperation");
  DBUG_PRINT("enter", ("op=%x", (UintPtr)aScanOperation));
#ifdef ndb_release_check_dup
  { NdbIndexScanOperation* tOp = theScanOpIdleList;
    while (tOp != NULL) {
      assert(tOp != aScanOperation);
    tOp = (NdbIndexScanOperation*)tOp->theNext;
    }
  }
#endif
563 564 565
  aScanOperation->next(theScanOpIdleList);
  aScanOperation->theNdbCon = NULL;
  aScanOperation->theMagicNumber = 0xFE11D2;
unknown's avatar
unknown committed
566
  theScanOpIdleList = aScanOperation;
567
  DBUG_VOID_RETURN;
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
}

/***************************************************************************
void releaseRecAttr(NdbRecAttr* aRecAttr);

Parameters:     aRecAttr : The released NdbRecAttr object.
Remark:         Add a NdbRecAttr object into the RecAtt idlelist.
***************************************************************************/
void
Ndb::releaseRecAttr(NdbRecAttr* aRecAttr)
{
  aRecAttr->release();
  aRecAttr->next(theRecAttrIdleList);
  theRecAttrIdleList = aRecAttr;
}

/***************************************************************************
void releaseSignal(NdbApiSignal* aSignal);

Parameters:     aSignal : The released NdbApiSignal object.
Remark:         Add a NdbApiSignal object into the signal idlelist.
***************************************************************************/
void
Ndb::releaseSignal(NdbApiSignal* aSignal)
{
#if defined VM_TRACE
  // Check that signal is not null
  assert(aSignal != NULL);
596
#if 0
597 598 599 600 601 602
  // Check that signal is not already in list
  NdbApiSignal* tmp = theSignalIdleList;
  while (tmp != NULL){
    assert(tmp != aSignal);
    tmp = tmp->next();
  }
603
#endif
604
#endif
unknown's avatar
unknown committed
605
#ifdef POORMANSPURIFY
606
  creleaseSignals++;
unknown's avatar
unknown committed
607
#endif
608 609 610 611 612 613 614 615 616 617 618 619 620 621
  aSignal->next(theSignalIdleList);
  theSignalIdleList = aSignal;
}

void
Ndb::releaseSignalsInList(NdbApiSignal** pList){
  NdbApiSignal* tmp;
  while (*pList != NULL){
    tmp = *pList;
    *pList = (*pList)->next();
    releaseSignal(tmp);
  }
}

unknown's avatar
unknown committed
622 623 624 625 626 627 628 629
void
Ndb::releaseNdbBlob(NdbBlob* aBlob)
{
  aBlob->release();
  aBlob->theNext = theNdbBlobIdleList;
  theNdbBlobIdleList = aBlob;
}

630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
/***************************************************************************
void freeOperation();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeOperation()
{
  NdbOperation* tOp = theOpIdleList;
  theOpIdleList = theOpIdleList->next();
  delete tOp;
}

/***************************************************************************
void freeScanOperation();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeScanOperation()
{
unknown's avatar
unknown committed
651 652
  NdbIndexScanOperation* tOp = theScanOpIdleList;
  theScanOpIdleList = (NdbIndexScanOperation *)tOp->next();
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
  delete tOp;
}

/***************************************************************************
void freeIndexOperation();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeIndexOperation()
{
  NdbIndexOperation* tOp = theIndexOpIdleList;
  theIndexOpIdleList = (NdbIndexOperation *) theIndexOpIdleList->next();
  delete tOp;
}

/***************************************************************************
void freeNdbBranch();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbBranch()
{
  NdbBranch* tNdbBranch = theBranchList;
  theBranchList = theBranchList->theNext;
  delete tNdbBranch;
}

/***************************************************************************
void freeNdbCall();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbCall()
{
  NdbCall* tNdbCall = theCallList;
  theCallList = theCallList->theNext;
  delete tNdbCall;
}

/***************************************************************************
void freeNdbScanRec();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbScanRec()
{
unknown's avatar
unknown committed
703
  NdbReceiver* tNdbScanRec = theScanList;
704 705 706 707 708 709 710 711 712 713 714 715
  theScanList = theScanList->next();
  delete tNdbScanRec;
}

/***************************************************************************
void freeNdbCon();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbCon()
{
716
  NdbTransaction* tNdbCon = theConIdleList;
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
  theConIdleList = theConIdleList->next();
  delete tNdbCon;
}

/***************************************************************************
void freeNdbLabel();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbLabel()
{
  NdbLabel* tNdbLabel = theLabelList;
  theLabelList = theLabelList->theNext;
  delete tNdbLabel;
}

/***************************************************************************
void freeNdbSubroutine();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeNdbSubroutine()
{
  NdbSubroutine* tNdbSubroutine = theSubroutineList;
  theSubroutineList = theSubroutineList->theNext;
  delete tNdbSubroutine;
}

/***************************************************************************
void freeRecAttr();

Remark:         Always release the first item in the free list
***************************************************************************/
void
Ndb::freeRecAttr()
{
  NdbRecAttr* tRecAttr = theRecAttrIdleList;
  theRecAttrIdleList = theRecAttrIdleList->next();
  delete tRecAttr;
}

/***************************************************************************
void freeSignal();

Remark:         Delete  a signal object from the signal idlelist.
***************************************************************************/
void
Ndb::freeSignal()
{
  NdbApiSignal* tSignal = theSignalIdleList;
  theSignalIdleList = tSignal->next();
  delete tSignal;
unknown's avatar
unknown committed
771
#ifdef POORMANSPURIFY
772
  cfreeSignals++;
unknown's avatar
unknown committed
773
#endif
774 775
}

unknown's avatar
unknown committed
776 777 778 779 780 781 782 783
void
Ndb::freeNdbBlob()
{
  NdbBlob* tBlob = theNdbBlobIdleList;
  theNdbBlobIdleList = tBlob->theNext;
  delete tBlob;
}

784
/****************************************************************************
785
int releaseConnectToNdb(NdbTransaction* aConnectConnection);
786 787 788 789 790 791

Return Value:   -1 if error 
Parameters:     aConnectConnection : Seized schema connection to DBTC
Remark:         Release and disconnect from DBTC a connection and seize it to theConIdleList.
*****************************************************************************/
void
792
Ndb::releaseConnectToNdb(NdbTransaction* a_con)     
793
{
794
  DBUG_ENTER("Ndb::releaseConnectToNdb");
795 796 797 798 799 800 801
  NdbApiSignal          tSignal(theMyRef);
  int                   tConPtr;

// I need to close the connection irrespective of whether I
// manage to reach NDB or not.

  if (a_con == NULL)
802
    DBUG_VOID_RETURN;
803 804 805 806 807 808 809

  Uint32 node_id = a_con->getConnectedNodeId();
  Uint32 conn_seq = a_con->theNodeSequence;
  tSignal.setSignal(GSN_TCRELEASEREQ);
  tSignal.setData((tConPtr = a_con->getTC_ConnectPtr()), 1);
  tSignal.setData(theMyRef, 2);
  tSignal.setData(a_con->ptr2int(), 3); 
810
  a_con->Status(NdbTransaction::DisConnecting);
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
  a_con->theMagicNumber = 0x37412619;
  int ret_code = sendRecSignal(node_id,
                               WAIT_TC_RELEASE,
                               &tSignal,
                               conn_seq);
  if (ret_code == 0) {
    ;
  } else if (ret_code == -1) {
    TRACE_DEBUG("Time-out when TCRELEASE sent");
  } else if (ret_code == -2) {
    TRACE_DEBUG("Node failed when TCRELEASE sent");
  } else if (ret_code == -3) {
    TRACE_DEBUG("Send failed when TCRELEASE sent");
  } else if (ret_code == -4) {
    TRACE_DEBUG("Send buffer full when TCRELEASE sent");
  } else if (ret_code == -5) {
    TRACE_DEBUG("Node stopping when TCRELEASE sent");
  } else {
    ndbout << "Impossible return from sendRecSignal when TCRELEASE" << endl;
    abort();
  }//if
  releaseNdbCon(a_con);
833
  DBUG_VOID_RETURN;
834 835
}