18 #define DBTUX_META_CPP
38 #include <signaldata/CreateTab.hpp>
39 #include <signaldata/LqhFrag.hpp>
42 Dbtux::execCREATE_TAB_REQ(
Signal* signal)
56 if (req->tableId >= c_indexPool.getSize()) {
58 errorCode = TuxFragRef::InvalidRequest;
61 c_indexPool.
getPtr(indexPtr, req->tableId);
62 if (indexPtr.p->m_state != Index::NotDefined)
65 errorCode = TuxFragRef::InvalidRequest;
71 c_fragOpPool.
seize(fragOpPtr);
72 ndbrequire(fragOpPtr.i != RNIL);
73 new (fragOpPtr.p) FragOp();
74 fragOpPtr.p->m_userPtr = req->senderData;
75 fragOpPtr.p->m_userRef = req->senderRef;
76 fragOpPtr.p->m_indexId = req->tableId;
77 fragOpPtr.p->m_fragId = RNIL;
78 fragOpPtr.p->m_fragNo = RNIL;
79 fragOpPtr.p->m_numAttrsRecvd = 0;
81 if (debugFlags & DebugMeta) {
82 debugOut <<
"Seize frag op " << fragOpPtr.i <<
" " << *fragOpPtr.p << endl;
86 ndbrequire(indexPtr.p->m_state == Index::NotDefined &&
87 DictTabInfo::isOrderedIndex(req->tableType) &&
88 req->noOfAttributes > 0 &&
89 req->noOfAttributes <= MaxIndexAttributes &&
90 indexPtr.p->m_descPage == RNIL);
92 indexPtr.p->m_state = Index::Defining;
94 indexPtr.p->m_tableId = req->primaryTableId;
95 indexPtr.p->m_numAttrs = req->noOfAttributes;
96 indexPtr.p->m_storeNullKey =
true;
98 if (! allocDescEnt(indexPtr)) {
100 errorCode = TuxFragRef::NoFreeAttributes;
105 if ((ERROR_INSERTED(12001) && fragOpPtr.p->m_fragNo == 0) ||
106 (ERROR_INSERTED(12002) && fragOpPtr.p->m_fragNo == 1)) {
108 errorCode = (TuxFragRef::ErrorCode)1;
109 CLEAR_ERROR_INSERT_VALUE;
114 conf->senderRef = reference();
115 conf->senderData = req->senderData;
116 conf->tuxConnectPtr = fragOpPtr.i;
117 sendSignal(req->senderRef, GSN_CREATE_TAB_CONF,
118 signal, CreateTabConf::SignalLength, JBB);
124 ref->senderData = req->senderData;
125 ref->errorCode = errorCode;
126 sendSignal(req->senderRef, GSN_CREATE_TAB_REF,
127 signal, CreateTabRef::SignalLength, JBB);
129 if (indexPtr.i != RNIL) {
134 if (fragOpPtr.i != RNIL)
137 c_fragOpPool.
release(fragOpPtr);
142 Dbtux::execTUX_ADD_ATTRREQ(
Signal* signal)
150 c_fragOpPool.
getPtr(fragOpPtr, req->tuxConnectPtr);
151 c_indexPool.
getPtr(indexPtr, fragOpPtr.p->m_indexId);
152 TuxAddAttrRef::ErrorCode errorCode = TuxAddAttrRef::NoError;
155 const unsigned attrId = fragOpPtr.p->m_numAttrsRecvd++;
157 indexPtr.p->m_state == Index::Defining &&
158 attrId < indexPtr.p->m_numAttrs &&
159 attrId == req->attrId);
160 const Uint32 ad = req->attrDescriptor;
162 const Uint32 sizeInBytes = AttributeDescriptor::getSizeInBytes(ad);
163 const Uint32 nullable = AttributeDescriptor::getNullable(ad);
164 const Uint32 csNumber = req->extTypeInfo >> 16;
165 const Uint32 primaryAttrId = req->primaryAttrId;
167 DescHead& descHead = getDescHead(*indexPtr.p);
169 KeySpec& keySpec = indexPtr.p->m_keySpec;
170 KeyType keyType(typeId, sizeInBytes, nullable, csNumber);
171 if (keySpec.add(keyType) == -1) {
173 errorCode = TuxAddAttrRef::InvalidAttributeType;
181 if (debugFlags & DebugMeta) {
182 debugOut <<
"attr " << attrId <<
" " << keyType << endl;
189 if ((err = NdbSqlUtil::check_column_for_ordered_index(typeId, cs))) {
191 errorCode = (TuxAddAttrRef::ErrorCode) err;
195 const bool lastAttr = (indexPtr.p->m_numAttrs == fragOpPtr.p->m_numAttrsRecvd);
196 if ((ERROR_INSERTED(12003) && attrId == 0) ||
197 (ERROR_INSERTED(12004) && lastAttr))
199 errorCode = (TuxAddAttrRef::ErrorCode)1;
200 CLEAR_ERROR_INSERT_VALUE;
205 const KeySpec& keySpec = indexPtr.p->m_keySpec;
207 unsigned bytes = keySpec.get_nullmask_len(
false);
208 unsigned maxAttrs = indexPtr.p->m_numAttrs;
211 const char* p = NdbEnv_GetEnv(
"MAX_TTREE_PREF_ATTRS", (
char*)0, 0);
212 if (p != 0 && p[0] != 0 && maxAttrs > (
unsigned)atoi(p))
216 while (attrs < maxAttrs) {
217 const KeyType& keyType = keySpec.get_type(attrs);
218 const unsigned newbytes = bytes + keyType.get_byte_size();
219 if (newbytes > (MAX_TTREE_PREF_SIZE << 2))
226 indexPtr.p->m_prefAttrs = attrs;
227 indexPtr.p->m_prefBytes = bytes;
230 if (debugFlags & DebugMeta) {
231 debugOut <<
"Release frag op " << fragOpPtr.i <<
" " << *fragOpPtr.p << endl;
234 c_fragOpPool.
release(fragOpPtr);
238 conf->userPtr = fragOpPtr.p->m_userPtr;
239 conf->lastAttr = lastAttr;
240 sendSignal(fragOpPtr.p->m_userRef, GSN_TUX_ADD_ATTRCONF,
241 signal, TuxAddAttrConf::SignalLength, JBB);
246 ref->userPtr = fragOpPtr.p->m_userPtr;
247 ref->errorCode = errorCode;
248 sendSignal(fragOpPtr.p->m_userRef, GSN_TUX_ADD_ATTRREF,
249 signal, TuxAddAttrRef::SignalLength, JBB);
251 if (debugFlags & DebugMeta) {
252 debugOut <<
"Release on attr error frag op " << fragOpPtr.i <<
" " << *fragOpPtr.p << endl;
259 Dbtux::execTUXFRAGREQ(
Signal* signal)
263 if (signal->theData[0] == (Uint32)-1) {
265 abortAddFragOp(signal);
273 TuxFragRef::ErrorCode errorCode = TuxFragRef::NoError;
276 if (req->tableId >= c_indexPool.getSize()) {
278 errorCode = TuxFragRef::InvalidRequest;
281 c_indexPool.
getPtr(indexPtr, req->tableId);
282 if (
false && indexPtr.p->m_state != Index::Defining) {
284 errorCode = TuxFragRef::InvalidRequest;
290 ndbrequire(indexPtr.p->m_numFrags < MaxIndexFragments);
292 if (ERROR_INSERTED(12008))
294 CLEAR_ERROR_INSERT_VALUE;
295 errorCode = TuxFragRef::InvalidRequest;
300 c_fragPool.
seize(fragPtr);
301 if (fragPtr.i == RNIL) {
303 errorCode = TuxFragRef::NoFreeFragment;
306 new (fragPtr.p) Frag(c_scanOpPool);
307 fragPtr.p->m_tableId = req->primaryTableId;
308 fragPtr.p->m_indexId = req->tableId;
309 fragPtr.p->m_fragId = req->fragId;
310 fragPtr.p->m_tupIndexFragPtrI = req->tupIndexFragPtrI;
311 fragPtr.p->m_tupTableFragPtrI = req->tupTableFragPtrI;
312 fragPtr.p->m_accTableFragPtrI = req->accTableFragPtrI;
314 Uint32 fragNo = indexPtr.p->m_numFrags;
315 indexPtr.p->m_fragId[indexPtr.p->m_numFrags] = req->fragId;
316 indexPtr.p->m_fragPtrI[indexPtr.p->m_numFrags] = fragPtr.i;
317 indexPtr.p->m_numFrags++;
319 if (debugFlags & DebugMeta) {
320 debugOut <<
"Add frag " << fragPtr.i <<
" " << *fragPtr.p << endl;
324 if ((ERROR_INSERTED(12001) && fragNo == 0) ||
325 (ERROR_INSERTED(12002) && fragNo == 1)) {
327 errorCode = (TuxFragRef::ErrorCode)1;
328 CLEAR_ERROR_INSERT_VALUE;
333 TreeHead& tree = fragPtr.p->m_tree;
334 new (&tree) TreeHead();
336 tree.m_nodeSize = MAX_TTREE_NODE_SIZE;
337 tree.m_prefSize = (indexPtr.p->m_prefBytes + 3) / 4;
338 const unsigned maxSlack = MAX_TTREE_NODE_SLACK;
340 const unsigned fixedSize = NodeHeadSize + tree.m_prefSize;
341 if (! (fixedSize <= tree.m_nodeSize)) {
343 errorCode = (TuxFragRef::ErrorCode)TuxAddAttrRef::InvalidNodeSize;
346 const unsigned slots = (tree.m_nodeSize - fixedSize) / TreeEntSize;
347 tree.m_maxOccup = slots;
349 if (! (2 + maxSlack <= tree.m_maxOccup)) {
351 errorCode = (TuxFragRef::ErrorCode)TuxAddAttrRef::InvalidNodeSize;
354 tree.m_minOccup = tree.m_maxOccup - maxSlack;
356 tree.m_root = NullTupLoc;
358 if (debugFlags & DebugMeta) {
360 debugOut <<
"Index id=" << indexPtr.i;
361 debugOut <<
" nodeSize=" << tree.m_nodeSize;
362 debugOut <<
" headSize=" << NodeHeadSize;
363 debugOut <<
" prefSize=" << tree.m_prefSize;
364 debugOut <<
" entrySize=" << TreeEntSize;
365 debugOut <<
" minOccup=" << tree.m_minOccup;
366 debugOut <<
" maxOccup=" << tree.m_maxOccup;
374 conf->userPtr = req->userPtr;
375 conf->tuxConnectPtr = RNIL;
376 conf->fragPtr = fragPtr.i;
377 conf->fragId = fragPtr.p->m_fragId;
378 sendSignal(req->userRef, GSN_TUXFRAGCONF,
379 signal, TuxFragConf::SignalLength, JBB);
385 ref->userPtr = req->userPtr;
386 ref->errorCode = errorCode;
387 sendSignal(req->userRef, GSN_TUXFRAGREF,
388 signal, TuxFragRef::SignalLength, JBB);
390 if (indexPtr.i != RNIL) {
400 Dbtux::abortAddFragOp(
Signal* signal)
404 c_fragOpPool.
getPtr(fragOpPtr, signal->theData[1]);
405 c_indexPool.
getPtr(indexPtr, fragOpPtr.p->m_indexId);
407 if (debugFlags & DebugMeta) {
408 debugOut <<
"Release on abort frag op " << fragOpPtr.i <<
" " << *fragOpPtr.p << endl;
411 c_fragOpPool.
release(fragOpPtr);
420 Dbtux::execALTER_INDX_IMPL_REQ(
Signal* signal)
427 c_indexPool.
getPtr(indexPtr, req->indexId);
430 if (! (refToBlock(req->senderRef) == DBDICT) &&
431 ! (isNdbMt() && refToMain(req->senderRef) == DBTUX &&
432 refToInstance(req->senderRef) == 0))
439 switch(req->requestType){
440 case AlterIndxImplReq::AlterIndexOffline:
446 indexPtr.p->m_state = Index::Dropping;
448 case AlterIndxImplReq::AlterIndexBuilding:
450 indexPtr.p->m_state = Index::Building;
454 case AlterIndxImplReq::AlterIndexOnline:
456 indexPtr.p->m_state = Index::Online;
463 conf->senderRef = reference();
464 conf->senderData = req->senderData;
465 if (req->senderRef != 0)
472 sendSignal(req->senderRef, GSN_ALTER_INDX_IMPL_CONF,
473 signal, AlterIndxImplConf::SignalLength, JBB);
484 Dbtux::execDROP_TAB_REQ(
Signal* signal)
491 Uint32 tableId = req->tableId;
492 Uint32 senderRef = req->senderRef;
493 Uint32 senderData = req->senderData;
494 if (tableId >= c_indexPool.getSize()) {
498 conf->senderRef = reference();
499 conf->senderData = senderData;
500 conf->tableId = tableId;
501 sendSignal(senderRef, GSN_DROP_TAB_CONF,
502 signal, DropTabConf::SignalLength, JBB);
506 c_indexPool.
getPtr(indexPtr, req->tableId);
509 if (debugFlags & DebugMeta) {
510 debugOut <<
"Drop index " << indexPtr.i <<
" " << *indexPtr.p << endl;
513 ndbrequire(req->senderRef != 0);
514 dropIndex(signal, indexPtr, req->senderRef, req->senderData);
518 Dbtux::dropIndex(
Signal* signal, IndexPtr indexPtr, Uint32 senderRef, Uint32 senderData)
527 while (indexPtr.p->m_numFrags > 0) {
529 Uint32
i = --indexPtr.p->m_numFrags;
531 c_fragPool.
getPtr(fragPtr, indexPtr.p->m_fragPtrI[i]);
537 bool b = fragPtr.p->m_scanList.first(scanPtr);
542 if (indexPtr.p->m_descPage != RNIL) {
544 freeDescEnt(indexPtr);
545 indexPtr.p->m_descPage = RNIL;
547 if (senderRef != 0) {
551 conf->senderRef = reference();
552 conf->senderData = senderData;
553 conf->tableId = indexPtr.i;
554 sendSignal(senderRef, GSN_DROP_TAB_CONF,
555 signal, DropTabConf::SignalLength, JBB);
557 new (indexPtr.p) Index();
565 Dbtux::allocDescEnt(IndexPtr indexPtr)
568 const Uint32
size = getDescSize(*indexPtr.p);
570 pagePtr.i = c_descPageList;
571 while (pagePtr.i != RNIL) {
573 c_descPagePool.
getPtr(pagePtr);
574 if (pagePtr.p->m_numFree >= size) {
578 pagePtr.i = pagePtr.p->m_nextPage;
580 if (pagePtr.i == RNIL) {
582 if (! c_descPagePool.
seize(pagePtr)) {
586 new (pagePtr.p) DescPage();
588 pagePtr.p->m_nextPage = c_descPageList;
589 c_descPageList = pagePtr.i;
590 pagePtr.p->m_numFree = DescPageSize;
592 ndbrequire(pagePtr.p->m_numFree >= size);
593 indexPtr.p->m_descPage = pagePtr.i;
594 indexPtr.p->m_descOff = DescPageSize - pagePtr.p->m_numFree;
595 pagePtr.p->m_numFree -=
size;
596 DescHead& descHead = *(DescHead*)&pagePtr.p->m_data[indexPtr.p->m_descOff];
597 descHead.m_indexId = indexPtr.i;
598 descHead.m_numAttrs = indexPtr.p->m_numAttrs;
599 descHead.m_magic = DescHead::Magic;
600 KeySpec& keySpec = indexPtr.p->m_keySpec;
601 KeyType* keyTypes = getKeyTypes(descHead);
602 keySpec.set_buf(keyTypes, indexPtr.p->m_numAttrs);
607 Dbtux::freeDescEnt(IndexPtr indexPtr)
610 c_descPagePool.
getPtr(pagePtr, indexPtr.p->m_descPage);
611 Uint32*
const data = pagePtr.p->m_data;
612 const Uint32 size = getDescSize(*indexPtr.p);
613 Uint32 off = indexPtr.p->m_descOff;
615 while (off + size < DescPageSize - pagePtr.p->m_numFree) {
618 DescHead& descHead2 = *(DescHead*)&data[off + size];
619 Uint32 indexId2 = descHead2.m_indexId;
620 Index& index2 = *c_indexPool.
getPtr(indexId2);
621 Uint32 size2 = getDescSize(index2);
623 index2.m_descPage == pagePtr.i &&
624 index2.m_descOff == off + size &&
625 index2.m_numAttrs == descHead2.m_numAttrs);
628 for (i = 0; i < size2; i++) {
630 data[off +
i] = data[off + size +
i];
634 index2.m_descOff -=
size;
637 DescHead& descHead2 = getDescHead(index2);
638 KeyType* keyType2 = getKeyTypes(descHead2);
639 index2.m_keySpec.set_buf(keyType2);
640 ndbrequire(index2.m_keySpec.validate() == 0);
643 ndbrequire(off + size == DescPageSize - pagePtr.p->m_numFree);
644 pagePtr.p->m_numFree +=
size;
648 Dbtux::execDROP_FRAG_REQ(
Signal* signal)
654 c_indexPool.
getPtr(indexPtr, req->tableId);
656 for (i = 0; i < indexPtr.p->m_numFrags; i++)
659 if (indexPtr.p->m_fragId[i] == req->fragId)
663 c_fragPool.
getPtr(fragPtr, indexPtr.p->m_fragPtrI[i]);
666 for (i++; i < indexPtr.p->m_numFrags; i++)
669 indexPtr.p->m_fragPtrI[i-1] = indexPtr.p->m_fragPtrI[
i];
670 indexPtr.p->m_fragId[i-1] = indexPtr.p->m_fragId[
i];
672 indexPtr.p->m_numFrags--;
680 conf->senderRef = reference();
681 conf->senderData = req->senderData;
682 conf->tableId = req->tableId;
683 sendSignal(req->senderRef, GSN_DROP_FRAG_CONF,
684 signal, DropFragConf::SignalLength, JBB);