~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#define DBTUX_MAINT_CPP
 
17
#include "Dbtux.hpp"
 
18
 
 
19
/*
 
20
 * Maintain index.
 
21
 */
 
22
 
 
23
void
 
24
Dbtux::execTUX_MAINT_REQ(Signal* signal)
 
25
{
 
26
  jamEntry();
 
27
  TuxMaintReq* const sig = (TuxMaintReq*)signal->getDataPtrSend();
 
28
  // ignore requests from redo log
 
29
  if (c_internalStartPhase < 6 &&
 
30
      c_typeOfStart != NodeState::ST_NODE_RESTART &&
 
31
      c_typeOfStart != NodeState::ST_INITIAL_NODE_RESTART) {
 
32
    jam();
 
33
#ifdef VM_TRACE
 
34
    if (debugFlags & DebugMaint) {
 
35
      TupLoc tupLoc(sig->pageId, sig->pageIndex);
 
36
      debugOut << "opInfo=" << hex << sig->opInfo;
 
37
      debugOut << " tableId=" << dec << sig->tableId;
 
38
      debugOut << " indexId=" << dec << sig->indexId;
 
39
      debugOut << " fragId=" << dec << sig->fragId;
 
40
      debugOut << " tupLoc=" << tupLoc;
 
41
      debugOut << " tupVersion=" << dec << sig->tupVersion;
 
42
      debugOut << " -- ignored at ISP=" << dec << c_internalStartPhase;
 
43
      debugOut << " TOS=" << dec << c_typeOfStart;
 
44
      debugOut << endl;
 
45
    }
 
46
#endif
 
47
    sig->errorCode = 0;
 
48
    return;
 
49
  }
 
50
  TuxMaintReq reqCopy = *sig;
 
51
  TuxMaintReq* const req = &reqCopy;
 
52
  const Uint32 opCode = req->opInfo & 0xFF;
 
53
  const Uint32 opFlag = req->opInfo >> 8;
 
54
  // get the index
 
55
  IndexPtr indexPtr;
 
56
  c_indexPool.getPtr(indexPtr, req->indexId);
 
57
  ndbrequire(indexPtr.p->m_tableId == req->tableId);
 
58
  // get base fragment id and extra bits
 
59
  const Uint32 fragId = req->fragId;
 
60
  // get the fragment
 
61
  FragPtr fragPtr;
 
62
  fragPtr.i = RNIL;
 
63
  for (unsigned i = 0; i < indexPtr.p->m_numFrags; i++) {
 
64
    jam();
 
65
    if (indexPtr.p->m_fragId[i] == fragId) {
 
66
      jam();
 
67
      c_fragPool.getPtr(fragPtr, indexPtr.p->m_fragPtrI[i]);
 
68
      break;
 
69
    }
 
70
  }
 
71
  ndbrequire(fragPtr.i != RNIL);
 
72
  Frag& frag = *fragPtr.p;
 
73
  // set up index keys for this operation
 
74
  setKeyAttrs(frag);
 
75
  // set up search entry
 
76
  TreeEnt ent;
 
77
  ent.m_tupLoc = TupLoc(req->pageId, req->pageIndex);
 
78
  ent.m_tupVersion = req->tupVersion;
 
79
  // read search key
 
80
  readKeyAttrs(frag, ent, 0, c_searchKey);
 
81
  if (! frag.m_storeNullKey) {
 
82
    // check if all keys are null
 
83
    const unsigned numAttrs = frag.m_numAttrs;
 
84
    bool allNull = true;
 
85
    for (unsigned i = 0; i < numAttrs; i++) {
 
86
      if (c_searchKey[i] != 0) {
 
87
        jam();
 
88
        allNull = false;
 
89
        break;
 
90
      }
 
91
    }
 
92
    if (allNull) {
 
93
      jam();
 
94
      req->errorCode = 0;
 
95
      *sig = *req;
 
96
      return;
 
97
    }
 
98
  }
 
99
#ifdef VM_TRACE
 
100
  if (debugFlags & DebugMaint) {
 
101
    debugOut << "opCode=" << dec << opCode;
 
102
    debugOut << " opFlag=" << dec << opFlag;
 
103
    debugOut << " tableId=" << dec << req->tableId;
 
104
    debugOut << " indexId=" << dec << req->indexId;
 
105
    debugOut << " fragId=" << dec << req->fragId;
 
106
    debugOut << " entry=" << ent;
 
107
    debugOut << endl;
 
108
  }
 
109
#endif
 
110
  // do the operation
 
111
  req->errorCode = 0;
 
112
  TreePos treePos;
 
113
  bool ok;
 
114
  switch (opCode) {
 
115
  case TuxMaintReq::OpAdd:
 
116
    jam();
 
117
    ok = searchToAdd(frag, c_searchKey, ent, treePos);
 
118
#ifdef VM_TRACE
 
119
    if (debugFlags & DebugMaint) {
 
120
      debugOut << treePos << (! ok ? " - error" : "") << endl;
 
121
    }
 
122
#endif
 
123
    if (! ok) {
 
124
      jam();
 
125
      // there is no "Building" state so this will have to do
 
126
      if (indexPtr.p->m_state == Index::Online) {
 
127
        jam();
 
128
        req->errorCode = TuxMaintReq::SearchError;
 
129
      }
 
130
      break;
 
131
    }
 
132
    /*
 
133
     * At most one new node is inserted in the operation.  Pre-allocate
 
134
     * it so that the operation cannot fail.
 
135
     */
 
136
    if (frag.m_freeLoc == NullTupLoc) {
 
137
      jam();
 
138
      NodeHandle node(frag);
 
139
      req->errorCode = allocNode(signal, node);
 
140
      if (req->errorCode != 0) {
 
141
        jam();
 
142
        break;
 
143
      }
 
144
      // link to freelist
 
145
      node.setLink(0, frag.m_freeLoc);
 
146
      frag.m_freeLoc = node.m_loc;
 
147
      ndbrequire(frag.m_freeLoc != NullTupLoc);
 
148
    }
 
149
    treeAdd(frag, treePos, ent);
 
150
    break;
 
151
  case TuxMaintReq::OpRemove:
 
152
    jam();
 
153
    ok = searchToRemove(frag, c_searchKey, ent, treePos);
 
154
#ifdef VM_TRACE
 
155
    if (debugFlags & DebugMaint) {
 
156
      debugOut << treePos << (! ok ? " - error" : "") << endl;
 
157
    }
 
158
#endif
 
159
    if (! ok) {
 
160
      jam();
 
161
      // there is no "Building" state so this will have to do
 
162
      if (indexPtr.p->m_state == Index::Online) {
 
163
        jam();
 
164
        req->errorCode = TuxMaintReq::SearchError;
 
165
      }
 
166
      break;
 
167
    }
 
168
    treeRemove(frag, treePos);
 
169
    break;
 
170
  default:
 
171
    ndbrequire(false);
 
172
    break;
 
173
  }
 
174
#ifdef VM_TRACE
 
175
  if (debugFlags & DebugTree) {
 
176
    printTree(signal, frag, debugOut);
 
177
  }
 
178
#endif
 
179
  // copy back
 
180
  *sig = *req;
 
181
}