1
/* Copyright (C) 2003 MySQL AB
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.
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.
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 */
16
#define DBTUX_MAINT_CPP
24
Dbtux::execTUX_MAINT_REQ(Signal* signal)
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) {
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;
50
TuxMaintReq reqCopy = *sig;
51
TuxMaintReq* const req = &reqCopy;
52
const Uint32 opCode = req->opInfo & 0xFF;
53
const Uint32 opFlag = req->opInfo >> 8;
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;
63
for (unsigned i = 0; i < indexPtr.p->m_numFrags; i++) {
65
if (indexPtr.p->m_fragId[i] == fragId) {
67
c_fragPool.getPtr(fragPtr, indexPtr.p->m_fragPtrI[i]);
71
ndbrequire(fragPtr.i != RNIL);
72
Frag& frag = *fragPtr.p;
73
// set up index keys for this operation
75
// set up search entry
77
ent.m_tupLoc = TupLoc(req->pageId, req->pageIndex);
78
ent.m_tupVersion = req->tupVersion;
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;
85
for (unsigned i = 0; i < numAttrs; i++) {
86
if (c_searchKey[i] != 0) {
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;
115
case TuxMaintReq::OpAdd:
117
ok = searchToAdd(frag, c_searchKey, ent, treePos);
119
if (debugFlags & DebugMaint) {
120
debugOut << treePos << (! ok ? " - error" : "") << endl;
125
// there is no "Building" state so this will have to do
126
if (indexPtr.p->m_state == Index::Online) {
128
req->errorCode = TuxMaintReq::SearchError;
133
* At most one new node is inserted in the operation. Pre-allocate
134
* it so that the operation cannot fail.
136
if (frag.m_freeLoc == NullTupLoc) {
138
NodeHandle node(frag);
139
req->errorCode = allocNode(signal, node);
140
if (req->errorCode != 0) {
145
node.setLink(0, frag.m_freeLoc);
146
frag.m_freeLoc = node.m_loc;
147
ndbrequire(frag.m_freeLoc != NullTupLoc);
149
treeAdd(frag, treePos, ent);
151
case TuxMaintReq::OpRemove:
153
ok = searchToRemove(frag, c_searchKey, ent, treePos);
155
if (debugFlags & DebugMaint) {
156
debugOut << treePos << (! ok ? " - error" : "") << endl;
161
// there is no "Building" state so this will have to do
162
if (indexPtr.p->m_state == Index::Online) {
164
req->errorCode = TuxMaintReq::SearchError;
168
treeRemove(frag, treePos);
175
if (debugFlags & DebugTree) {
176
printTree(signal, frag, debugOut);