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 */
19
Dbtux::Dbtux(Block_context& ctx) :
20
SimulatedBlock(DBTUX, ctx),
25
debugOut(*new NullOutputStream()),
28
c_internalStartPhase(0),
29
c_typeOfStart(NodeState::ST_ILLEGAL_TYPE),
32
BLOCK_CONSTRUCTOR(Dbtux);
33
// verify size assumptions (also when release-compiled)
35
(sizeof(TreeEnt) & 0x3) == 0 &&
36
(sizeof(TreeNode) & 0x3) == 0 &&
37
(sizeof(DescHead) & 0x3) == 0 &&
38
(sizeof(DescAttr) & 0x3) == 0
43
addRecSignal(GSN_CONTINUEB, &Dbtux::execCONTINUEB);
44
addRecSignal(GSN_STTOR, &Dbtux::execSTTOR);
45
addRecSignal(GSN_READ_CONFIG_REQ, &Dbtux::execREAD_CONFIG_REQ, true);
49
addRecSignal(GSN_TUXFRAGREQ, &Dbtux::execTUXFRAGREQ);
50
addRecSignal(GSN_TUX_ADD_ATTRREQ, &Dbtux::execTUX_ADD_ATTRREQ);
51
addRecSignal(GSN_ALTER_INDX_REQ, &Dbtux::execALTER_INDX_REQ);
52
addRecSignal(GSN_DROP_TAB_REQ, &Dbtux::execDROP_TAB_REQ);
56
addRecSignal(GSN_TUX_MAINT_REQ, &Dbtux::execTUX_MAINT_REQ);
60
addRecSignal(GSN_ACC_SCANREQ, &Dbtux::execACC_SCANREQ);
61
addRecSignal(GSN_TUX_BOUND_INFO, &Dbtux::execTUX_BOUND_INFO);
62
addRecSignal(GSN_NEXT_SCANREQ, &Dbtux::execNEXT_SCANREQ);
63
addRecSignal(GSN_ACC_CHECK_SCAN, &Dbtux::execACC_CHECK_SCAN);
64
addRecSignal(GSN_ACCKEYCONF, &Dbtux::execACCKEYCONF);
65
addRecSignal(GSN_ACCKEYREF, &Dbtux::execACCKEYREF);
66
addRecSignal(GSN_ACC_ABORTCONF, &Dbtux::execACC_ABORTCONF);
70
addRecSignal(GSN_READ_PSEUDO_REQ, &Dbtux::execREAD_PSEUDO_REQ);
74
addRecSignal(GSN_DUMP_STATE_ORD, &Dbtux::execDUMP_STATE_ORD);
82
Dbtux::execCONTINUEB(Signal* signal)
85
const Uint32* data = signal->getDataPtr();
87
case TuxContinueB::DropIndex: // currently unused
90
c_indexPool.getPtr(indexPtr, data[1]);
91
dropIndex(signal, indexPtr, data[2], data[3]);
101
* STTOR is sent to one block at a time. In NDBCNTR it triggers
102
* NDB_STTOR to the "old" blocks. STTOR carries start phase (SP) and
103
* NDB_STTOR carries internal start phase (ISP).
108
* 3 2 recover metadata, activate indexes
113
* 8 7 build non-logged indexes on SR
115
* DBTUX catches type of start (IS, SR, NR, INR) at SP 3 and updates
116
* internal start phase at SP 7. These are used to prevent index
117
* maintenance operations caused by redo log at SR.
120
Dbtux::execSTTOR(Signal* signal)
123
Uint32 startPhase = signal->theData[1];
124
switch (startPhase) {
127
CLEAR_ERROR_INSERT_VALUE;
128
c_tup = (Dbtup*)globalData.getBlock(DBTUP);
129
ndbrequire(c_tup != 0);
133
c_typeOfStart = signal->theData[7];
136
c_internalStartPhase = 6;
141
signal->theData[0] = 0; // garbage
142
signal->theData[1] = 0; // garbage
143
signal->theData[2] = 0; // garbage
144
signal->theData[3] = 1;
145
signal->theData[4] = 3; // for c_typeOfStart
146
signal->theData[5] = 7; // for c_internalStartPhase
147
signal->theData[6] = 255;
148
sendSignal(NDBCNTR_REF, GSN_STTORRY, signal, 7, JBB);
152
Dbtux::execREAD_CONFIG_REQ(Signal* signal)
156
const ReadConfigReq * req = (ReadConfigReq*)signal->getDataPtr();
157
Uint32 ref = req->senderRef;
158
Uint32 senderData = req->senderData;
159
ndbrequire(req->noOfParameters == 0);
167
const ndb_mgm_configuration_iterator * p =
168
m_ctx.m_config.getOwnConfigIterator();
171
ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_INDEX, &nIndex));
172
ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_FRAGMENT, &nFragment));
173
ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_ATTRIBUTE, &nAttribute));
174
ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_SCAN_OP, &nScanOp));
175
ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_BATCH_SIZE, &nScanBatch));
177
const Uint32 nDescPage = (nIndex * DescHeadSize + nAttribute * DescAttrSize + DescPageSize - 1) / DescPageSize;
178
const Uint32 nScanBoundWords = nScanOp * ScanBoundSegmentSize * 4;
179
const Uint32 nScanLock = nScanOp * nScanBatch;
181
c_indexPool.setSize(nIndex);
182
c_fragPool.setSize(nFragment);
183
c_descPagePool.setSize(nDescPage);
184
c_fragOpPool.setSize(MaxIndexFragments);
185
c_scanOpPool.setSize(nScanOp);
186
c_scanBoundPool.setSize(nScanBoundWords);
187
c_scanLockPool.setSize(nScanLock);
189
* Index id is physical array index. We seize and initialize all
196
c_indexPool.seize(indexPtr);
197
if (indexPtr.i == RNIL) {
201
new (indexPtr.p) Index();
204
c_keyAttrs = (Uint32*)allocRecord("c_keyAttrs", sizeof(Uint32), MaxIndexAttributes);
205
c_sqlCmp = (NdbSqlUtil::Cmp**)allocRecord("c_sqlCmp", sizeof(NdbSqlUtil::Cmp*), MaxIndexAttributes);
206
c_searchKey = (Uint32*)allocRecord("c_searchKey", sizeof(Uint32), MaxAttrDataSize);
207
c_entryKey = (Uint32*)allocRecord("c_entryKey", sizeof(Uint32), MaxAttrDataSize);
208
c_dataBuffer = (Uint32*)allocRecord("c_dataBuffer", sizeof(Uint64), (MaxAttrDataSize + 1) >> 1);
210
ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend();
211
conf->senderRef = reference();
212
conf->senderData = senderData;
213
sendSignal(ref, GSN_READ_CONFIG_CONF, signal,
214
ReadConfigConf::SignalLength, JBB);
220
Dbtux::setKeyAttrs(const Frag& frag)
222
Data keyAttrs = c_keyAttrs; // global
223
NdbSqlUtil::Cmp** sqlCmp = c_sqlCmp; // global
224
const unsigned numAttrs = frag.m_numAttrs;
225
const DescEnt& descEnt = getDescEnt(frag.m_descPage, frag.m_descOff);
226
for (unsigned i = 0; i < numAttrs; i++) {
228
const DescAttr& descAttr = descEnt.m_descAttr[i];
229
Uint32 size = AttributeDescriptor::getSizeInWords(descAttr.m_attrDesc);
230
// set attr id and fixed size
231
ah(keyAttrs) = AttributeHeader(descAttr.m_primaryAttrId, size);
233
// set comparison method pointer
234
const NdbSqlUtil::Type& sqlType = NdbSqlUtil::getTypeBinary(descAttr.m_typeId);
235
ndbrequire(sqlType.m_cmp != 0);
236
*(sqlCmp++) = sqlType.m_cmp;
241
Dbtux::readKeyAttrs(const Frag& frag, TreeEnt ent, unsigned start, Data keyData)
243
ConstData keyAttrs = c_keyAttrs; // global
244
const Uint32 tableFragPtrI = frag.m_tupTableFragPtrI;
245
const TupLoc tupLoc = ent.m_tupLoc;
246
const Uint32 tupVersion = ent.m_tupVersion;
247
ndbrequire(start < frag.m_numAttrs);
248
const Uint32 numAttrs = frag.m_numAttrs - start;
249
// skip to start position in keyAttrs only
251
int ret = c_tup->tuxReadAttrs(tableFragPtrI, tupLoc.getPageId(), tupLoc.getPageOffset(), tupVersion, keyAttrs, numAttrs, keyData);
256
if (debugFlags & (DebugMaint | DebugScan)) {
257
debugOut << "readKeyAttrs:" << endl;
258
ConstData data = keyData;
259
Uint32 totalSize = 0;
260
for (Uint32 i = start; i < frag.m_numAttrs; i++) {
261
Uint32 attrId = ah(data).getAttributeId();
262
Uint32 dataSize = ah(data).getDataSize();
263
debugOut << i << " attrId=" << attrId << " size=" << dataSize;
265
for (Uint32 j = 0; j < dataSize; j++) {
266
debugOut << " " << hex << data[0];
270
totalSize += 1 + dataSize;
272
ndbassert((int)totalSize == ret);
278
Dbtux::readTablePk(const Frag& frag, TreeEnt ent, Data pkData, unsigned& pkSize)
280
const Uint32 tableFragPtrI = frag.m_tupTableFragPtrI;
281
const TupLoc tupLoc = ent.m_tupLoc;
282
int ret = c_tup->tuxReadPk(tableFragPtrI, tupLoc.getPageId(), tupLoc.getPageOffset(), pkData, true);
290
* Copy attribute data with headers. Input is all index key data.
291
* Copies whatever fits.
294
Dbtux::copyAttrs(const Frag& frag, ConstData data1, Data data2, unsigned maxlen2)
296
unsigned n = frag.m_numAttrs;
297
unsigned len2 = maxlen2;
300
const unsigned dataSize = ah(data1).getDataSize();
309
for (unsigned i = 0; i < dataSize; i++) {
320
memset(data2, DataFillByte, len2 << 2);
325
Dbtux::unpackBound(const ScanBound& bound, Data dest)
327
ScanBoundIterator iter;
329
const unsigned n = bound.getSize();
331
for (j = 0; j < n; j++) {
332
dest[j] = *iter.data;
337
BLOCK_FUNCTIONS(Dbtux)