20 #define DBTUP_META_CPP
22 #include <RefConvert.hpp>
23 #include <ndb_limits.h>
26 #include <signaldata/CreateTable.hpp>
27 #include <signaldata/CreateTab.hpp>
28 #include <signaldata/TupFrag.hpp>
29 #include <signaldata/FsRef.hpp>
30 #include <signaldata/FsConf.hpp>
31 #include <signaldata/FsRemoveReq.hpp>
32 #include <signaldata/DropTab.hpp>
33 #include <signaldata/AlterTab.hpp>
34 #include <signaldata/AlterTable.hpp>
35 #include <signaldata/CreateFilegroupImpl.hpp>
36 #include <AttributeDescriptor.hpp>
37 #include "AttributeOffset.hpp"
39 #include <signaldata/LqhFrag.hpp>
40 #include <signaldata/AttrInfo.hpp>
42 #include <EventLogger.hpp>
46 Dbtup::execCREATE_TAB_REQ(
Signal* signal)
53 TablerecPtr regTabPtr;
54 regTabPtr.i = req->tableId;
55 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
57 if (regTabPtr.p->tableStatus != NOT_DEFINED)
60 ndbout_c(
"regTabPtr.p->tableStatus : %u", regTabPtr.p->tableStatus);
61 terrorCode = CreateTableRef::TableAlreadyExist;
65 if (cfirstfreeFragopr == RNIL)
68 terrorCode = ZNOFREE_FRAGOP_ERROR;
72 FragoperrecPtr fragOperPtr;
73 seizeFragoperrec(fragOperPtr);
74 fragOperPtr.p->tableidFrag = regTabPtr.i;
75 fragOperPtr.p->attributeCount = req->noOfAttributes;
76 memset(fragOperPtr.p->m_null_bits, 0,
sizeof(fragOperPtr.p->m_null_bits));
77 fragOperPtr.p->charsetIndex = 0;
78 fragOperPtr.p->lqhBlockrefFrag = req->senderRef;
79 fragOperPtr.p->m_extra_row_gci_bits =
80 req->GCPIndicator > 1 ? req->GCPIndicator - 1 : 0;
81 fragOperPtr.p->m_extra_row_author_bits = req->extraRowAuthorBits;
83 regTabPtr.p->m_createTable.m_fragOpPtrI = fragOperPtr.i;
84 regTabPtr.p->m_createTable.defValSectionI = RNIL;
85 regTabPtr.p->tableStatus= DEFINING;
86 regTabPtr.p->m_bits = 0;
87 regTabPtr.p->m_bits |= (req->checksumIndicator ? Tablerec::TR_Checksum : 0);
88 regTabPtr.p->m_bits |= (req->GCPIndicator ? Tablerec::TR_RowGCI : 0);
89 regTabPtr.p->m_bits |= (req->forceVarPartFlag? Tablerec::TR_ForceVarPart : 0);
90 regTabPtr.p->m_bits |=
91 (req->GCPIndicator > 1 ? Tablerec::TR_ExtraRowGCIBits : 0);
92 regTabPtr.p->m_bits |= (req->extraRowAuthorBits ? Tablerec::TR_ExtraRowAuthorBits : 0);
94 regTabPtr.p->m_offsets[MM].m_disk_ref_offset= 0;
95 regTabPtr.p->m_offsets[MM].m_null_words= 0;
96 regTabPtr.p->m_offsets[MM].m_fix_header_size= 0;
97 regTabPtr.p->m_offsets[MM].m_max_var_offset= 0;
98 regTabPtr.p->m_offsets[MM].m_max_dyn_offset= 0;
99 regTabPtr.p->m_offsets[MM].m_dyn_null_words= 0;
101 regTabPtr.p->m_offsets[DD].m_disk_ref_offset= 0;
102 regTabPtr.p->m_offsets[DD].m_null_words= 0;
103 regTabPtr.p->m_offsets[DD].m_fix_header_size= 0;
104 regTabPtr.p->m_offsets[DD].m_max_var_offset= 0;
105 regTabPtr.p->m_offsets[DD].m_max_dyn_offset= 0;
106 regTabPtr.p->m_offsets[DD].m_dyn_null_words= 0;
108 regTabPtr.p->m_attributes[MM].m_no_of_fixsize= 0;
109 regTabPtr.p->m_attributes[MM].m_no_of_varsize= 0;
110 regTabPtr.p->m_attributes[MM].m_no_of_dynamic= 0;
111 regTabPtr.p->m_attributes[MM].m_no_of_dyn_fix= 0;
112 regTabPtr.p->m_attributes[MM].m_no_of_dyn_var= 0;
113 regTabPtr.p->m_attributes[DD].m_no_of_fixsize= 0;
114 regTabPtr.p->m_attributes[DD].m_no_of_varsize= 0;
115 regTabPtr.p->m_attributes[DD].m_no_of_dynamic= 0;
116 regTabPtr.p->m_attributes[DD].m_no_of_dyn_fix= 0;
117 regTabPtr.p->m_attributes[DD].m_no_of_dyn_var= 0;
120 regTabPtr.p->m_dyn_null_bits[MM]= DYN_BM_LEN_BITS;
121 regTabPtr.p->m_dyn_null_bits[DD]= DYN_BM_LEN_BITS;
122 regTabPtr.p->noOfKeyAttr= req->noOfKeyAttr;
124 regTabPtr.p->m_no_of_attributes= req->noOfAttributes;
125 regTabPtr.p->dynTabDescriptor[MM]= RNIL;
126 regTabPtr.p->dynTabDescriptor[DD]= RNIL;
127 regTabPtr.p->m_no_of_extra_columns = 0;
129 if (regTabPtr.p->m_bits & Tablerec::TR_ExtraRowGCIBits)
132 regTabPtr.p->m_no_of_extra_columns++;
135 if (regTabPtr.p->m_bits & Tablerec::TR_ExtraRowAuthorBits)
138 regTabPtr.p->m_no_of_extra_columns++;
143 Uint32 allocSize= getTabDescrOffsets(req->noOfAttributes,
146 regTabPtr.p->m_no_of_extra_columns,
148 Uint32 tableDescriptorRef= allocTabDescr(allocSize);
149 if (tableDescriptorRef == RNIL)
154 setUpDescriptorReferences(tableDescriptorRef, regTabPtr.p, offset);
159 conf->senderData = req->senderData;
160 conf->senderRef = reference();
161 conf->tupConnectPtr = fragOperPtr.i;
162 sendSignal(req->senderRef, GSN_CREATE_TAB_CONF, signal,
163 CreateTabConf::SignalLength, JBB);
169 regTabPtr.p->tableStatus = NOT_DEFINED;
170 releaseFragoperrec(fragOperPtr);
174 ref->senderData = req->senderData;
175 ref->senderRef = reference();
176 ref->errorCode = terrorCode;
177 sendSignal(req->senderRef, GSN_CREATE_TAB_REF, signal,
178 CreateTabRef::SignalLength, JBB);
181 void Dbtup::execTUP_ADD_ATTRREQ(
Signal* signal)
183 FragoperrecPtr fragOperPtr;
184 TablerecPtr regTabPtr;
187 fragOperPtr.i= signal->theData[0];
188 ptrCheckGuard(fragOperPtr, cnoOfFragoprec, fragoperrec);
189 Uint32 attrId = signal->theData[2];
190 Uint32 attrDescriptor = signal->theData[3];
192 Uint32 csNumber = (signal->theData[4] >> 16);
194 regTabPtr.i= fragOperPtr.p->tableidFrag;
195 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
197 ndbrequire(fragOperPtr.p->attributeCount > 0);
198 fragOperPtr.p->attributeCount--;
199 const bool lastAttr = (fragOperPtr.p->attributeCount == 0);
201 Uint32 extraAttrId = 0;
203 Uint32 firstTabDesIndex= regTabPtr.p->tabDescriptor + (attrId * ZAD_SIZE);
204 setTabDescrWord(firstTabDesIndex, attrDescriptor);
205 Uint32 attrLen = AttributeDescriptor::getSize(attrDescriptor);
208 Uint32 bytes= AttributeDescriptor::getSizeInBytes(attrDescriptor);
209 Uint32 words= (bytes + 3) / 4;
210 Uint32 ind= AttributeDescriptor::getDiskBased(attrDescriptor);
211 if (!AttributeDescriptor::getDynamic(attrDescriptor)) {
214 ndbrequire(ind <= 1);
215 null_pos= fragOperPtr.p->m_null_bits[ind];
217 if (AttributeDescriptor::getNullable(attrDescriptor))
220 fragOperPtr.p->m_null_bits[ind]++;
223 if (AttributeDescriptor::getArrayType(attrDescriptor)==NDB_ARRAYTYPE_FIXED
227 regTabPtr.p->m_attributes[ind].m_no_of_fixsize++;
232 Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
233 fragOperPtr.p->m_null_bits[ind] += bitCount;
239 regTabPtr.p->m_attributes[ind].m_no_of_varsize++;
241 if (null_pos > AO_NULL_FLAG_POS_MASK)
244 terrorCode = ZTOO_MANY_BITS_ERROR;
247 AttributeOffset::setNullFlagPos(attrDes2, null_pos);
251 regTabPtr.p->m_attributes[ind].m_no_of_dynamic++;
260 Uint32 null_pos= regTabPtr.p->m_dyn_null_bits[ind];
262 if (AttributeDescriptor::getArrayType(attrDescriptor)==NDB_ARRAYTYPE_FIXED)
266 if (AttributeDescriptor::getSize(attrDescriptor)==0)
273 Uint32 bits= AttributeDescriptor::getArraySize(attrDescriptor);
279 regTabPtr.p->m_dyn_null_bits[ind]+= bits+1;
289 if(words > InternalMaxDynFix)
290 goto treat_as_varsize;
292 regTabPtr.p->m_attributes[ind].m_no_of_dyn_fix++;
293 Uint32 null_bits= (bytes+3) >> 2;
294 regTabPtr.p->m_dyn_null_bits[ind]+= null_bits;
302 regTabPtr.p->m_attributes[ind].m_no_of_dyn_var++;
303 regTabPtr.p->m_dyn_null_bits[ind]++;
305 AttributeOffset::setNullFlagPos(attrDes2, null_pos);
307 ndbassert((regTabPtr.p->m_attributes[ind].m_no_of_dyn_var +
308 regTabPtr.p->m_attributes[ind].m_no_of_dyn_fix) <=
309 regTabPtr.p->m_attributes[ind].m_no_of_dynamic);
311 handleCharsetPos(csNumber, regTabPtr.p->charsetArray,
312 regTabPtr.p->noOfCharsets,
313 fragOperPtr.p->charsetIndex, attrDes2);
314 setTabDescrWord(firstTabDesIndex + 1, attrDes2);
316 if ((ERROR_INSERTED(4009) && attrId == 0) ||
317 (ERROR_INSERTED(4010) && lastAttr))
320 CLEAR_ERROR_INSERT_VALUE;
325 if (!receive_defvalue(signal, regTabPtr))
328 if ((ERROR_INSERTED(4032) && (attrId == 0)) ||
329 (ERROR_INSERTED(4033) && lastAttr))
332 CLEAR_ERROR_INSERT_VALUE;
340 signal->theData[0] = fragOperPtr.p->lqhPtrFrag;
341 signal->theData[1] = lastAttr;
342 sendSignal(fragOperPtr.p->lqhBlockrefFrag, GSN_TUP_ADD_ATTCONF,
347 if (fragOperPtr.p->m_extra_row_gci_bits)
351 const Uint32 bits = fragOperPtr.p->m_extra_row_gci_bits;
359 AttributeDescriptor::setSize(desc, 0);
360 AttributeDescriptor::setArraySize(desc, bits);
361 AttributeOffset::setNullFlagPos(off, fragOperPtr.p->m_null_bits[MM]);
362 fragOperPtr.p->m_null_bits[MM] += bits;
364 if (fragOperPtr.p->m_null_bits[MM] > AO_NULL_FLAG_POS_MASK)
367 terrorCode = ZTOO_MANY_BITS_ERROR;
371 Uint32 idx = regTabPtr.p->tabDescriptor;
372 idx += ZAD_SIZE * (regTabPtr.p->m_no_of_attributes + extraAttrId);
373 setTabDescrWord(idx, desc);
374 setTabDescrWord(idx + 1, off);
379 if (fragOperPtr.p->m_extra_row_author_bits)
383 const Uint32 bits = fragOperPtr.p->m_extra_row_author_bits;
391 AttributeDescriptor::setSize(desc, 0);
392 AttributeDescriptor::setArraySize(desc, bits);
393 AttributeOffset::setNullFlagPos(off, fragOperPtr.p->m_null_bits[MM]);
394 fragOperPtr.p->m_null_bits[MM] += bits;
396 if (fragOperPtr.p->m_null_bits[MM] > AO_NULL_FLAG_POS_MASK)
399 terrorCode = ZTOO_MANY_BITS_ERROR;
403 Uint32 idx = regTabPtr.p->tabDescriptor;
404 idx += ZAD_SIZE * (regTabPtr.p->m_no_of_attributes + extraAttrId);
405 setTabDescrWord(idx, desc);
406 setTabDescrWord(idx + 1, off);
411 #define BTW(x) ((x+31) >> 5)
412 regTabPtr.p->m_offsets[MM].m_null_words= BTW(fragOperPtr.p->m_null_bits[MM]);
413 regTabPtr.p->m_offsets[DD].m_null_words= BTW(fragOperPtr.p->m_null_bits[DD]);
418 for (Uint32
i = 0;
i < NO_DYNAMICS; ++
i)
422 Uint32 allocSize= getDynTabDescrOffsets(
423 (regTabPtr.p->m_dyn_null_bits[
i]+31)>>5,
425 Uint32 dynTableDescriptorRef= allocTabDescr(allocSize);
426 if (dynTableDescriptorRef == RNIL)
431 setupDynDescriptorReferences(dynTableDescriptorRef,
432 regTabPtr.p, offset,
i);
437 terrorCode = computeTableMetaData(regTabPtr.p);
445 ndbout << *regTabPtr.p << endl;
446 Uint32 idx= regTabPtr.p->tabDescriptor;
447 for(Uint32
i = 0;
i<regTabPtr.p->m_no_of_attributes;
i++)
449 ndbout <<
i <<
": " << endl;
457 if (regTabPtr.p->m_no_of_disk_attributes)
466 cb.m_callbackData= fragOperPtr.i;
467 cb.m_callbackIndex = UNDO_CREATETABLE_CALLBACK;
468 Uint32 sz=
sizeof(Disk_undo::Create) >> 2;
470 D(
"Logfile_client - execTUP_ADD_ATTRREQ");
471 Logfile_client lgman(
this, c_lgman, regFragPtr.p->m_logfile_group_id);
472 if((terrorCode = lgman.alloc_log_space(sz)))
475 addattrrefuseLab(signal, regFragPtr, fragOperPtr, regTabPtr.p, fragId);
480 int res= lgman.get_log_buffer(signal, sz, &cb);
485 signal->theData[0] = 1;
488 ndbrequire(
"NOT YET IMPLEMENTED" == 0);
491 execute(signal, cb, regFragPtr.p->m_logfile_group_id);
497 if (store_default_record(regTabPtr) < 0)
503 ndbrequire(regTabPtr.p->tableStatus == DEFINING);
504 regTabPtr.p->tableStatus= DEFINED;
506 signal->theData[0] = fragOperPtr.p->lqhPtrFrag;
507 signal->theData[1] = lastAttr;
508 sendSignal(fragOperPtr.p->lqhBlockrefFrag, GSN_TUP_ADD_ATTCONF,
511 releaseFragoperrec(fragOperPtr);
517 releaseSections(handle);
520 releaseSection(regTabPtr.p->m_createTable.defValSectionI);
521 regTabPtr.p->m_createTable.defValSectionI = RNIL;
522 free_var_part(DefaultValuesFragment.p, regTabPtr.p, ®TabPtr.p->m_default_value_location);
523 regTabPtr.p->m_default_value_location.setNull();
525 signal->theData[0]= fragOperPtr.p->lqhPtrFrag;
526 signal->theData[1]= terrorCode;
527 sendSignal(fragOperPtr.p->lqhBlockrefFrag,
528 GSN_TUP_ADD_ATTRREF, signal, 2, JBB);
533 bool Dbtup::receive_defvalue(
Signal* signal,
const TablerecPtr& regTabPtr)
536 Uint32 defValueBytes = 0;
537 Uint32 defValueWords = 0;
538 Uint32 attrId = signal->theData[2];
539 Uint32 attrDescriptor = signal->theData[3];
541 Uint32 attrLen = AttributeDescriptor::getSize(attrDescriptor);
542 Uint32 arrayType = AttributeDescriptor::getArrayType(attrDescriptor);
543 Uint32 arraySize = AttributeDescriptor::getArraySize(attrDescriptor);
545 const Uint32 numSections = signal->getNoOfSections();
547 if (numSections == 0)
553 handle.getSection(ptr, TupAddAttrReq::DEFAULT_VALUE_SECTION_NUM);
559 ndbrequire(r.getWord(&ahIn));
561 defValueBytes = AttributeHeader::getByteSize(ahIn);
562 defValueWords = (defValueBytes + 3) / 4;
567 if (defValueBytes == 0)
570 releaseSections(handle);
577 if (AttributeDescriptor::getPrimaryKey(attrDescriptor))
580 releaseSections(handle);
588 bytes= AttributeDescriptor::getSizeInBytes(attrDescriptor);
590 bytes= ((arraySize + AD_SIZE_IN_WORDS_OFFSET)
591 >> AD_SIZE_IN_WORDS_SHIFT) * 4;
597 if (arrayType == NDB_ARRAYTYPE_FIXED)
599 if (defValueBytes != bytes)
601 terrorCode = ZBAD_DEFAULT_VALUE_LEN;
606 if (defValueBytes > bytes)
608 terrorCode = ZBAD_DEFAULT_VALUE_LEN;
620 if (defValueBytes > bytes)
622 terrorCode = ZBAD_DEFAULT_VALUE_LEN;
628 if (likely( !terrorCode ))
632 ndbrequire(r.getWords(dst, defValueWords));
636 (arrayType != NDB_ARRAYTYPE_FIXED))
639 const uchar* valPtr = (
const uchar*) dst;
640 Uint32 internalVarSize = 0;
642 if (arrayType == NDB_ARRAYTYPE_SHORT_VAR)
644 internalVarSize = 1 + valPtr[0];
646 else if (arrayType == NDB_ARRAYTYPE_MEDIUM_VAR)
648 internalVarSize = 2 + valPtr[0] + (256 * Uint32(valPtr[1]));
655 if (unlikely(internalVarSize != defValueBytes))
658 terrorCode = ZBAD_DEFAULT_VALUE_LEN;
659 releaseSections(handle);
664 if (likely( appendToSection(regTabPtr.p->m_createTable.defValSectionI,
665 (
const Uint32 *)&ah, 1) ))
667 if (likely( appendToSection(regTabPtr.p->m_createTable.defValSectionI,
672 releaseSections(handle);
676 terrorCode = ZMEM_NOMEM_ERROR;
679 releaseSections(handle);
683 void Dbtup::execTUPFRAGREQ(
Signal* signal)
690 FragrecordPtr regFragPtr;
692 Uint32 tableId = req->tableId;
693 Uint32 userptr = req->userPtr;
694 Uint32 userRef = req->userRef;
695 Uint32 reqinfo = req->reqInfo;
696 Uint32 fragId = req->fragId;
697 Uint32 tablespace_id = req->tablespaceid;
698 Uint32 changeMask = req->changeMask;
701 (((Uint64)req->maxRowsHigh) << 32) + req->maxRowsLow;
703 (((Uint64)req->minRowsHigh) << 32) + req->minRowsLow;
709 if (req->userPtr == (Uint32)-1)
712 abortAddFragOp(signal);
718 if (tableId >= cnoOfTablerec)
726 TablerecPtr regTabPtr;
727 regTabPtr.i = tableId;
728 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
730 getFragmentrec(regFragPtr, fragId, regTabPtr.p);
731 if (regFragPtr.i != RNIL)
734 terrorCode= ZEXIST_FRAG_ERROR;
738 if (cfirstfreefrag != RNIL)
741 seizeFragrecord(regFragPtr);
746 terrorCode= ZFULL_FRAGRECORD_ERROR;
751 #ifdef MIN_ROWS_NOT_SUPPORTED
752 Uint32 fix_tupheader = regTabPtr.p->m_offsets[MM].m_fix_header_size;
753 ndbassert(fix_tupheader > 0);
754 Uint32 noRowsPerPage = ZWORDS_ON_PAGE / fix_tupheader;
755 Uint32 noAllocatedPages = (minRows + noRowsPerPage - 1 )/ noRowsPerPage;
757 noAllocatedPages = 2;
758 else if (noAllocatedPages == 0)
759 noAllocatedPages = 2;
762 Uint32 noAllocatedPages = 1;
764 if (noAllocatedPages == 0)
767 releaseFragrec(regFragPtr);
768 terrorCode = ZNO_PAGES_ALLOCATED_ERROR;
773 if (!addfragtotab(regTabPtr.p, fragId, regFragPtr.i))
776 releaseFragrec(regFragPtr);
777 terrorCode= ZNO_FREE_TAB_ENTRY_ERROR;
781 if ((ERROR_INSERTED(4007) && regTabPtr.p->fragid[0] == fragId) ||
782 (ERROR_INSERTED(4008) && regTabPtr.p->fragid[1] == fragId) ||
783 ERROR_INSERTED(4050))
786 CLEAR_ERROR_INSERT_VALUE;
791 regFragPtr.p->fragStatus = Fragrecord::FS_ONLINE;
792 regFragPtr.p->fragTableId= regTabPtr.i;
793 regFragPtr.p->fragmentId= fragId;
794 regFragPtr.p->m_tablespace_id= tablespace_id;
795 regFragPtr.p->m_undo_complete=
false;
796 regFragPtr.p->m_lcp_scan_op = RNIL;
797 regFragPtr.p->m_lcp_keep_list_head.setNull();
798 regFragPtr.p->m_lcp_keep_list_tail.setNull();
799 regFragPtr.p->noOfPages = 0;
800 regFragPtr.p->noOfVarPages = 0;
801 regFragPtr.p->m_max_page_no = 0;
802 regFragPtr.p->m_free_page_id_list = FREE_PAGE_RNIL;
803 ndbrequire(regFragPtr.p->m_page_map.isEmpty());
804 regFragPtr.p->m_restore_lcp_id = RNIL;
805 for (Uint32
i = 0;
i<MAX_FREE_LIST+1;
i++)
806 ndbrequire(regFragPtr.p->free_var_page_array[
i].isEmpty());
809 bzero(&rep,
sizeof(rep));
810 if(regTabPtr.p->m_no_of_disk_attributes)
812 D(
"Tablespace_client - execTUPFRAGREQ");
814 regFragPtr.p->m_tablespace_id);
815 ndbrequire(tsman.get_tablespace_info(&rep) == 0);
816 regFragPtr.p->m_logfile_group_id= rep.tablespace.logfile_group_id;
821 regFragPtr.p->m_logfile_group_id = RNIL;
823 new (®FragPtr.p->m_disk_alloc_info)
824 Disk_alloc_info(regTabPtr.p, rep.tablespace.extent_size);
826 if (AlterTableReq::getReorgFragFlag(changeMask))
829 regFragPtr.p->fragStatus = Fragrecord::FS_REORG_NEW;
832 signal->theData[0]= userptr;
833 signal->theData[1]= fragId;
834 signal->theData[2]= regFragPtr.i;
835 sendSignal(userRef, GSN_TUPFRAGCONF, signal, 3, JBB);
840 signal->theData[0]= userptr;
841 signal->theData[1]= terrorCode;
842 sendSignal(userRef, GSN_TUPFRAGREF, signal, 2, JBB);
855 int Dbtup::store_default_record(
const TablerecPtr& regTabPtr)
857 Uint32 RdefValSectionI = regTabPtr.p->m_createTable.defValSectionI;
860 if (RdefValSectionI == RNIL)
863 if (ERROR_INSERTED(4034))
866 CLEAR_ERROR_INSERT_VALUE;
875 getSection(defValSection, RdefValSectionI);
876 Uint32 sizes = defValSection.p->m_sz;
880 Uint32* var_data_ptr= alloc_var_part(&terrorCode,
881 DefaultValuesFragment.p,
884 ®TabPtr.p->m_default_value_location);
885 if (unlikely( var_data_ptr == 0 ))
892 if (ERROR_INSERTED(4034))
895 CLEAR_ERROR_INSERT_VALUE;
901 copy(var_data_ptr, RdefValSectionI);
902 releaseSection(RdefValSectionI);
903 regTabPtr.p->m_createTable.defValSectionI= RNIL;
909 bool Dbtup::addfragtotab(Tablerec*
const regTabPtr,
913 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++) {
915 if (regTabPtr->fragid[
i] == RNIL) {
917 regTabPtr->fragid[
i]= fragId;
918 regTabPtr->fragrec[
i]= fragIndex;
925 void Dbtup::getFragmentrec(FragrecordPtr& regFragPtr,
927 Tablerec*
const regTabPtr)
929 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++) {
931 if (regTabPtr->fragid[
i] == fragId) {
933 regFragPtr.i= regTabPtr->fragrec[
i];
934 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
942 void Dbtup::seizeFragrecord(FragrecordPtr& regFragPtr)
944 regFragPtr.i= cfirstfreefrag;
945 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
946 cfirstfreefrag= regFragPtr.p->nextfreefrag;
947 regFragPtr.p->nextfreefrag= RNIL;
948 RSS_OP_ALLOC(cnoOfFreeFragrec);
951 void Dbtup::seizeFragoperrec(FragoperrecPtr& fragOperPtr)
953 fragOperPtr.i= cfirstfreeFragopr;
954 ptrCheckGuard(fragOperPtr, cnoOfFragoprec, fragoperrec);
955 cfirstfreeFragopr = fragOperPtr.p->nextFragoprec;
956 fragOperPtr.p->nextFragoprec = RNIL;
957 fragOperPtr.p->inUse =
true;
958 RSS_OP_ALLOC(cnoOfFreeFragoprec);
961 void Dbtup::seizeAlterTabOperation(AlterTabOperationPtr& alterTabOpPtr)
963 alterTabOpPtr.i= cfirstfreeAlterTabOp;
964 ptrCheckGuard(alterTabOpPtr, cnoOfAlterTabOps, alterTabOperRec);
965 cfirstfreeAlterTabOp= alterTabOpPtr.p->nextAlterTabOp;
966 alterTabOpPtr.p->nextAlterTabOp= RNIL;
970 Dbtup::execALTER_TAB_REQ(
Signal *signal)
977 TablerecPtr regTabPtr;
978 regTabPtr.i= req->tableId;
979 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
981 switch((AlterTabReq::RequestType)req->requestType){
982 case AlterTabReq::AlterTablePrepare:
986 if (AlterTableReq::getAddAttrFlag(req->changeMask))
990 ndbrequire(handle.m_cnt == 1);
991 ::copy(signal->theData+25, handle.m_ptr[0]);
992 releaseSections(handle);
994 handleAlterTablePrepare(signal, req, regTabPtr.p);
997 case AlterTabReq::AlterTableCommit:
1000 handleAlterTableCommit(signal, req, regTabPtr.p);
1003 case AlterTabReq::AlterTableRevert:
1006 handleAlterTableAbort(signal, req, regTabPtr.p);
1009 case AlterTabReq::AlterTableComplete:
1012 handleAlterTableComplete(signal, req, regTabPtr.p);
1015 case AlterTabReq::AlterTableSumaEnable:
1017 FragrecordPtr regFragPtr;
1018 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++)
1021 if ((regFragPtr.i = regTabPtr.p->fragrec[
i]) != RNIL)
1024 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
1025 switch(regFragPtr.p->fragStatus){
1026 case Fragrecord::FS_REORG_COMMIT_NEW:
1029 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s",
1030 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1031 "FS_REORG_COMMIT_NEW",
"FS_REORG_COMPLETE_NEW");
1032 regFragPtr.p->fragStatus = Fragrecord::FS_REORG_COMPLETE_NEW;
1039 sendAlterTabConf(signal, RNIL);
1042 case AlterTabReq::AlterTableSumaFilter:
1044 Uint32 gci = signal->theData[signal->getLength() - 1];
1045 regTabPtr.p->m_reorg_suma_filter.m_gci_hi = gci;
1046 FragrecordPtr regFragPtr;
1047 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++)
1050 if ((regFragPtr.i = regTabPtr.p->fragrec[
i]) != RNIL)
1053 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
1054 switch(regFragPtr.p->fragStatus){
1055 case Fragrecord::FS_REORG_COMMIT:
1058 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s (gci: %u)",
1059 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1060 "FS_REORG_COMMIT",
"FS_REORG_COMPLETE",
1062 regFragPtr.p->fragStatus = Fragrecord::FS_REORG_COMPLETE;
1069 signal->theData[0] = ~Uint32(0);
1072 case AlterTabReq::AlterTableReadOnly:
1073 case AlterTabReq::AlterTableReadWrite:
1074 signal->theData[0] = 0;
1075 signal->theData[1] = RNIL;
1084 Dbtup::handleAlterTablePrepare(
Signal *signal,
1086 const Tablerec *regTabPtr)
1088 Uint32 connectPtr = RNIL;
1089 if (AlterTableReq::getAddAttrFlag(req->changeMask))
1093 Uint32 noOfNewAttr= req->noOfNewAttr;
1094 Uint32 newNoOfCharsets= req->newNoOfCharsets;
1095 Uint32 newNoOfKeyAttrs= req->newNoOfKeyAttrs;
1097 Uint32 *attrInfo= signal->theData+25;
1099 Uint32 oldNoOfAttr= regTabPtr->m_no_of_attributes;
1100 Uint32 newNoOfAttr= oldNoOfAttr+noOfNewAttr;
1103 if((regTabPtr->m_attributes[MM].m_no_of_varsize +
1104 regTabPtr->m_attributes[MM].m_no_of_dynamic +
1105 (regTabPtr->m_bits & Tablerec::TR_ForceVarPart)) == 0)
1107 sendAlterTabRef(signal, ZINVALID_ALTER_TAB);
1111 AlterTabOperationPtr regAlterTabOpPtr;
1112 seizeAlterTabOperation(regAlterTabOpPtr);
1114 regAlterTabOpPtr.p->newNoOfAttrs= newNoOfAttr;
1115 regAlterTabOpPtr.p->newNoOfCharsets= newNoOfCharsets;
1116 regAlterTabOpPtr.p->newNoOfKeyAttrs= newNoOfKeyAttrs;
1119 Uint32 allocSize= getTabDescrOffsets(newNoOfAttr, newNoOfCharsets,
1121 regTabPtr->m_no_of_extra_columns,
1122 regAlterTabOpPtr.p->tabDesOffset);
1123 Uint32 tableDescriptorRef= allocTabDescr(allocSize);
1124 if (tableDescriptorRef == RNIL) {
1126 releaseAlterTabOpRec(regAlterTabOpPtr);
1127 sendAlterTabRef(signal, terrorCode);
1130 regAlterTabOpPtr.p->tableDescriptor= tableDescriptorRef;
1137 Uint32* desc= &tableDescriptor[tableDescriptorRef].tabDescr;
1139 (
CHARSET_INFO**)(desc + regAlterTabOpPtr.p->tabDesOffset[2]);
1140 memcpy(CharsetArray, regTabPtr->charsetArray,
1141 sizeof(*CharsetArray)*regTabPtr->noOfCharsets);
1142 Uint32 *
const attrDesPtrStart = desc + regAlterTabOpPtr.p->tabDesOffset[4];
1143 Uint32 * attrDesPtr = attrDesPtrStart;
1145 &tableDescriptor[regTabPtr->tabDescriptor].tabDescr,
1146 4 * ZAD_SIZE * oldNoOfAttr);
1152 const Uint32 * src = &tableDescriptor[regTabPtr->tabDescriptor].tabDescr;
1153 src += ZAD_SIZE * oldNoOfAttr;
1155 Uint32 * dst = attrDesPtr + (ZAD_SIZE * newNoOfAttr);
1156 memcpy(dst, src, 4 * ZAD_SIZE * regTabPtr->m_no_of_extra_columns);
1159 attrDesPtr+= ZAD_SIZE * oldNoOfAttr;
1169 Uint32 charsetIndex= regTabPtr->noOfCharsets;
1170 Uint32 dyn_nullbits= regTabPtr->m_dyn_null_bits[MM];
1171 if (dyn_nullbits == 0)
1174 dyn_nullbits = DYN_BM_LEN_BITS;
1177 Uint32 noDynFix= regTabPtr->m_attributes[MM].m_no_of_dyn_fix;
1178 Uint32 noDynVar= regTabPtr->m_attributes[MM].m_no_of_dyn_var;
1179 Uint32 noDynamic= regTabPtr->m_attributes[MM].m_no_of_dynamic;
1180 for (Uint32
i= 0;
i<noOfNewAttr;
i++)
1182 Uint32 attrDescriptor= *attrInfo++;
1183 Uint32 csNumber= (*attrInfo++ >> 16);
1187 ndbrequire(AttributeDescriptor::getDynamic(attrDescriptor));
1188 ndbrequire(!AttributeDescriptor::getDiskBased(attrDescriptor));
1190 handleCharsetPos(csNumber, CharsetArray, newNoOfCharsets,
1191 charsetIndex, attrDes2);
1193 Uint32 null_pos= dyn_nullbits;
1194 Uint32 arrType= AttributeDescriptor::getArrayType(attrDescriptor);
1196 if (arrType==NDB_ARRAYTYPE_FIXED)
1198 Uint32 words= AttributeDescriptor::getSizeInWords(attrDescriptor);
1200 if(AttributeDescriptor::getSize(attrDescriptor) > 0)
1203 if(words > InternalMaxDynFix)
1204 goto treat_as_varsize;
1206 dyn_nullbits+= words;
1212 Uint32 bits= AttributeDescriptor::getArraySize(attrDescriptor);
1214 dyn_nullbits+= bits+1;
1224 AttributeOffset::setNullFlagPos(attrDes2, null_pos);
1226 *attrDesPtr++= attrDescriptor;
1227 *attrDesPtr++= attrDes2;
1229 ndbassert(newNoOfCharsets==charsetIndex);
1230 ndbrequire(attrDesPtr == attrDesPtrStart + (ZAD_SIZE * newNoOfAttr));
1232 regAlterTabOpPtr.p->noOfDynNullBits= dyn_nullbits;
1233 ndbassert(noDynamic ==
1234 regTabPtr->m_attributes[MM].m_no_of_dynamic + noOfNewAttr);
1235 regAlterTabOpPtr.p->noOfDynFix= noDynFix;
1236 regAlterTabOpPtr.p->noOfDynVar= noDynVar;
1237 regAlterTabOpPtr.p->noOfDynamic= noDynamic;
1240 allocSize= getDynTabDescrOffsets((dyn_nullbits+31)>>5,
1241 regAlterTabOpPtr.p->dynTabDesOffset);
1242 Uint32 dynTableDescriptorRef = RNIL;
1243 if (ERROR_INSERTED(4029))
1246 dynTableDescriptorRef = RNIL;
1247 terrorCode = ZMEM_NOTABDESCR_ERROR;
1248 CLEAR_ERROR_INSERT_VALUE;
1253 dynTableDescriptorRef = allocTabDescr(allocSize);
1255 if (dynTableDescriptorRef == RNIL) {
1257 releaseTabDescr(tableDescriptorRef);
1258 releaseAlterTabOpRec(regAlterTabOpPtr);
1259 sendAlterTabRef(signal, terrorCode);
1262 regAlterTabOpPtr.p->dynTableDescriptor= dynTableDescriptorRef;
1263 connectPtr = regAlterTabOpPtr.i;
1266 sendAlterTabConf(signal, connectPtr);
1270 Dbtup::sendAlterTabRef(
Signal *signal, Uint32 errorCode)
1272 signal->theData[0] = errorCode;
1273 signal->theData[1] = RNIL;
1277 Dbtup::sendAlterTabConf(
Signal *signal, Uint32 connectPtr)
1279 signal->theData[0] = 0;
1280 signal->theData[1] = connectPtr;
1284 Dbtup::handleAlterTableCommit(
Signal *signal,
1286 Tablerec *regTabPtr)
1288 if (AlterTableReq::getAddAttrFlag(req->changeMask))
1290 AlterTabOperationPtr regAlterTabOpPtr;
1291 regAlterTabOpPtr.i= req->connectPtr;
1292 ptrCheckGuard(regAlterTabOpPtr, cnoOfAlterTabOps, alterTabOperRec);
1295 releaseTabDescr(regTabPtr);
1298 regTabPtr->m_no_of_attributes= regAlterTabOpPtr.p->newNoOfAttrs;
1299 regTabPtr->noOfCharsets= regAlterTabOpPtr.p->newNoOfCharsets;
1300 regTabPtr->noOfKeyAttr= regAlterTabOpPtr.p->newNoOfKeyAttrs;
1301 regTabPtr->m_attributes[MM].m_no_of_dyn_fix= regAlterTabOpPtr.p->noOfDynFix;
1302 regTabPtr->m_attributes[MM].m_no_of_dyn_var= regAlterTabOpPtr.p->noOfDynVar;
1303 regTabPtr->m_attributes[MM].m_no_of_dynamic= regAlterTabOpPtr.p->noOfDynamic;
1304 regTabPtr->m_dyn_null_bits[MM]= regAlterTabOpPtr.p->noOfDynNullBits;
1307 setUpDescriptorReferences(regAlterTabOpPtr.p->tableDescriptor,
1309 regAlterTabOpPtr.p->tabDesOffset);
1310 setupDynDescriptorReferences(regAlterTabOpPtr.p->dynTableDescriptor,
1312 regAlterTabOpPtr.p->dynTabDesOffset);
1314 releaseAlterTabOpRec(regAlterTabOpPtr);
1317 computeTableMetaData(regTabPtr);
1320 if (AlterTableReq::getReorgFragFlag(req->changeMask))
1322 FragrecordPtr regFragPtr;
1323 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++)
1326 if ((regFragPtr.i = regTabPtr->fragrec[
i]) != RNIL)
1329 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
1330 switch(regFragPtr.p->fragStatus){
1331 case Fragrecord::FS_ONLINE:
1333 regFragPtr.p->fragStatus = Fragrecord::FS_REORG_COMMIT;
1335 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s",
1336 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1337 "FS_ONLINE",
"FS_REORG_COMMIT");
1339 case Fragrecord::FS_REORG_NEW:
1341 regFragPtr.p->fragStatus = Fragrecord::FS_REORG_COMMIT_NEW;
1343 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s",
1344 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1345 "FS_REORG_NEW",
"FS_REORG_COMMIT_NEW");
1348 jamLine(regFragPtr.p->fragStatus);
1355 sendAlterTabConf(signal, RNIL);
1359 Dbtup::handleAlterTableComplete(
Signal *signal,
1361 Tablerec *regTabPtr)
1363 if (AlterTableReq::getReorgCompleteFlag(req->changeMask))
1365 FragrecordPtr regFragPtr;
1366 for (Uint32
i = 0;
i < MAX_FRAG_PER_NODE;
i++)
1369 if ((regFragPtr.i = regTabPtr->fragrec[
i]) != RNIL)
1372 ptrCheckGuard(regFragPtr, cnoOfFragrec, fragrecord);
1373 switch(regFragPtr.p->fragStatus){
1374 case Fragrecord::FS_REORG_COMPLETE:
1377 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s",
1378 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1379 "FS_REORG_COMPLETE",
"FS_ONLINE");
1380 regFragPtr.p->fragStatus = Fragrecord::FS_ONLINE;
1382 case Fragrecord::FS_REORG_COMPLETE_NEW:
1385 ndbout_c(
"tab: %u frag: %u toggle fragstate from %s to %s",
1386 regFragPtr.p->fragTableId, regFragPtr.p->fragmentId,
1387 "FS_REORG_COMPLETE_NEW",
"FS_ONLINE");
1388 regFragPtr.p->fragStatus = Fragrecord::FS_ONLINE;
1391 jamLine(regFragPtr.p->fragStatus);
1398 sendAlterTabConf(signal, RNIL);
1402 Dbtup::handleAlterTableAbort(
Signal *signal,
1404 const Tablerec *regTabPtr)
1406 if (AlterTableReq::getAddAttrFlag(req->changeMask))
1409 if (req->connectPtr != RNIL)
1412 AlterTabOperationPtr regAlterTabOpPtr;
1413 regAlterTabOpPtr.i= req->connectPtr;
1414 ptrCheckGuard(regAlterTabOpPtr, cnoOfAlterTabOps, alterTabOperRec);
1416 releaseTabDescr(regAlterTabOpPtr.p->tableDescriptor);
1417 releaseTabDescr(regAlterTabOpPtr.p->dynTableDescriptor);
1418 releaseAlterTabOpRec(regAlterTabOpPtr);
1422 sendAlterTabConf(signal, RNIL);
1431 Dbtup::handleCharsetPos(Uint32 csNumber,
CHARSET_INFO** charsetArray,
1432 Uint32 noOfCharsets,
1433 Uint32 & charsetIndex, Uint32 & attrDes2)
1438 ndbrequire(cs != NULL);
1440 while (i < charsetIndex)
1443 if (charsetArray[i] == cs)
1447 if (i == charsetIndex) {
1449 ndbrequire(i < noOfCharsets);
1450 charsetArray[
i]= cs;
1453 AttributeOffset::setCharsetPos(attrDes2, i);
1462 Dbtup::computeTableMetaData(Tablerec *regTabPtr)
1464 Uint32 dyn_null_words[2];
1466 for (Uint32 i = 0; i < NO_DYNAMICS; ++
i)
1468 if (regTabPtr->m_dyn_null_bits[i] == DYN_BM_LEN_BITS)
1470 regTabPtr->m_dyn_null_bits[
i] = 0;
1472 dyn_null_words[
i] = (regTabPtr->m_dyn_null_bits[
i]+31)>>5;
1473 regTabPtr->m_offsets[
i].m_dyn_null_words = dyn_null_words[
i];
1477 Uint32 pos[2] = { 0, 0 };
1478 if (regTabPtr->m_bits & Tablerec::TR_Checksum)
1483 if (regTabPtr->m_bits & Tablerec::TR_RowGCI)
1489 regTabPtr->m_no_of_disk_attributes=
1490 regTabPtr->m_attributes[DD].m_no_of_fixsize +
1491 regTabPtr->m_attributes[DD].m_no_of_varsize;
1492 if(regTabPtr->m_no_of_disk_attributes > 0)
1495 regTabPtr->m_offsets[MM].m_disk_ref_offset= pos[MM];
1496 pos[MM] += Disk_part_ref::SZ32;
1497 regTabPtr->m_bits |= Tablerec::TR_DiskPart;
1501 regTabPtr->m_offsets[MM].m_disk_ref_offset= pos[MM] - Disk_part_ref::SZ32;
1504 if (regTabPtr->m_attributes[MM].m_no_of_varsize ||
1505 regTabPtr->m_attributes[MM].m_no_of_dynamic)
1507 pos[MM] += Var_part_ref::SZ32;
1508 regTabPtr->m_bits &= ~(Uint32)Tablerec::TR_ForceVarPart;
1510 else if (regTabPtr->m_bits & Tablerec::TR_ForceVarPart)
1512 pos[MM] += Var_part_ref::SZ32;
1515 regTabPtr->m_offsets[MM].m_null_offset= pos[MM];
1516 regTabPtr->m_offsets[DD].m_null_offset= pos[DD];
1517 pos[MM]+= regTabPtr->m_offsets[MM].m_null_words;
1518 pos[DD]+= regTabPtr->m_offsets[DD].m_null_words;
1528 Uint32 *tabDesc= (Uint32*)(tableDescriptor+regTabPtr->tabDescriptor);
1529 Uint32 fix_size[2]= {0, 0};
1530 Uint32 var_size[2]= {0, 0};
1531 Uint32 dyn_size[2]= {0, 0};
1532 Uint32 statvar_count= 0;
1533 Uint32 dynfix_count= 0;
1534 Uint32 dynvar_count= 0;
1535 Uint32 dynamic_count= 0;
1536 regTabPtr->blobAttributeMask.clear();
1537 regTabPtr->notNullAttributeMask.clear();
1538 for (Uint32 i = 0; i < NO_DYNAMICS; ++
i)
1540 bzero(regTabPtr->dynVarSizeMask[i], dyn_null_words[i]<<2);
1541 bzero(regTabPtr->dynFixSizeMask[i], dyn_null_words[i]<<2);
1544 for(Uint32 i= 0; i<regTabPtr->m_no_of_attributes; i++)
1546 Uint32 attrDescriptor= *tabDesc++;
1547 Uint32 attrDes2= *tabDesc;
1548 Uint32 ind= AttributeDescriptor::getDiskBased(attrDescriptor);
1549 Uint32 attrLen = AttributeDescriptor::getSize(attrDescriptor);
1550 Uint32 arr= AttributeDescriptor::getArrayType(attrDescriptor);
1551 Uint32 size_in_words= AttributeDescriptor::getSizeInWords(attrDescriptor);
1552 Uint32 size_in_bytes= AttributeDescriptor::getSizeInBytes(attrDescriptor);
1556 if (extType == NDB_TYPE_BLOB || extType == NDB_TYPE_TEXT)
1557 regTabPtr->blobAttributeMask.set(i);
1558 if(!AttributeDescriptor::getNullable(attrDescriptor))
1559 regTabPtr->notNullAttributeMask.set(i);
1560 if (!AttributeDescriptor::getDynamic(attrDescriptor))
1562 if(arr == NDB_ARRAYTYPE_FIXED || ind==DD)
1566 off= fix_size[ind] + pos[ind];
1567 fix_size[ind]+= size_in_words;
1576 off= statvar_count++;
1577 var_size[ind]+= size_in_bytes;
1584 ndbrequire(ind==MM);
1585 Uint32 null_pos= AttributeOffset::getNullFlagPos(attrDes2);
1586 dyn_size[ind]+= (size_in_words<<2);
1587 if(arr == NDB_ARRAYTYPE_FIXED)
1597 if(size_in_words>InternalMaxDynFix)
1598 goto treat_as_varsize;
1600 off= dynfix_count++ + regTabPtr->m_attributes[ind].m_no_of_dyn_var;
1601 while(size_in_words-- > 0)
1604 regTabPtr->dynFixSizeMask[ind], null_pos++);
1614 off= dynvar_count++;
1615 BitmaskImpl::set(dyn_null_words[ind], regTabPtr->dynVarSizeMask[ind], null_pos);
1618 if (off > AttributeOffset::getMaxOffset())
1620 return ZTOO_LARGE_TUPLE_ERROR;
1622 AttributeOffset::setOffset(attrDes2, off);
1623 *tabDesc++= attrDes2;
1625 ndbassert(dynvar_count==regTabPtr->m_attributes[MM].m_no_of_dyn_var);
1626 ndbassert(dynfix_count==regTabPtr->m_attributes[MM].m_no_of_dyn_fix);
1627 ndbassert(dynamic_count==regTabPtr->m_attributes[MM].m_no_of_dynamic);
1628 ndbassert(statvar_count==regTabPtr->m_attributes[MM].m_no_of_varsize);
1630 regTabPtr->m_offsets[MM].m_fix_header_size=
1631 Tuple_header::HeaderSize + fix_size[MM] + pos[MM];
1632 regTabPtr->m_offsets[DD].m_fix_header_size=
1633 fix_size[DD] + pos[DD];
1635 if(regTabPtr->m_attributes[DD].m_no_of_varsize == 0 &&
1636 regTabPtr->m_attributes[DD].m_no_of_fixsize > 0)
1637 regTabPtr->m_offsets[DD].m_fix_header_size += Tuple_header::HeaderSize;
1639 Uint32 mm_vars= regTabPtr->m_attributes[MM].m_no_of_varsize;
1640 Uint32 mm_dyns= regTabPtr->m_attributes[MM].m_no_of_dyn_fix +
1641 regTabPtr->m_attributes[MM].m_no_of_dyn_var;
1642 Uint32 dd_vars= regTabPtr->m_attributes[MM].m_no_of_varsize;
1643 Uint32 dd_dyns= regTabPtr->m_attributes[DD].m_no_of_dynamic;
1645 regTabPtr->m_offsets[MM].m_max_var_offset= var_size[MM];
1650 regTabPtr->m_offsets[MM].m_max_dyn_offset=
1651 (regTabPtr->m_offsets[MM].m_dyn_null_words<<2) + 4*((mm_dyns+2)>>1) +
1654 regTabPtr->m_offsets[DD].m_max_var_offset= var_size[DD];
1655 regTabPtr->m_offsets[DD].m_max_dyn_offset=
1656 (regTabPtr->m_offsets[DD].m_dyn_null_words<<2) + 4*((dd_dyns+2)>>1) +
1660 Uint32 total_rec_size=
1661 pos[MM] + fix_size[MM] + pos[DD] + fix_size[DD] +
1662 ((var_size[MM] + 3) >> 2) + ((dyn_size[MM] + 3) >> 2) +
1663 ((var_size[DD] + 3) >> 2) + ((dyn_size[DD] + 3) >> 2);
1669 if(mm_vars + regTabPtr->m_attributes[MM].m_no_of_dynamic)
1671 total_rec_size+= (mm_vars + 2) >> 1;
1672 total_rec_size+= regTabPtr->m_offsets[MM].m_dyn_null_words;
1673 total_rec_size+= (mm_dyns + 2) >> 1;
1678 total_rec_size+= (dd_vars + 2) >> 1;
1680 total_rec_size+= Tuple_header::HeaderSize;
1681 if(regTabPtr->m_no_of_disk_attributes)
1682 total_rec_size+= Tuple_header::HeaderSize;
1685 total_rec_size += 1 + ((regTabPtr->m_no_of_attributes + 31) >> 5);
1687 total_rec_size += COPY_TUPLE_HEADER32;
1689 regTabPtr->total_rec_size= total_rec_size;
1691 setUpQueryRoutines(regTabPtr);
1692 setUpKeyArray(regTabPtr);
1697 Dbtup::undo_createtable_callback(
Signal* signal, Uint32 opPtrI, Uint32 unused)
1699 FragrecordPtr regFragPtr;
1700 FragoperrecPtr fragOperPtr;
1701 TablerecPtr regTabPtr;
1703 fragOperPtr.i= opPtrI;
1704 ptrCheckGuard(fragOperPtr, cnoOfFragoprec, fragoperrec);
1706 regTabPtr.i= fragOperPtr.p->tableidFrag;
1707 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
1709 getFragmentrec(regFragPtr, fragOperPtr.p->fragidFrag, regTabPtr.p);
1710 ndbrequire(regFragPtr.i != RNIL);
1712 D(
"Logfile_client - undo_createtable_callback");
1713 Logfile_client lgman(
this, c_lgman, regFragPtr.p->m_logfile_group_id);
1715 Disk_undo::Create create;
1716 create.m_type_length= Disk_undo::UNDO_CREATE << 16 | (sizeof(create) >> 2);
1717 create.m_table = regTabPtr.i;
1721 Uint64
lsn= lgman.add_entry(c, 1);
1725 req.m_callback.m_callbackData= fragOperPtr.i;
1726 req.m_callback.m_callbackIndex = UNDO_CREATETABLE_LOGSYNC_CALLBACK;
1728 int ret = lgman.sync_lsn(signal, lsn, &req, 0);
1734 warningEvent(
"Failed to sync log for create of table: %u", regTabPtr.i);
1736 execute(signal, req.m_callback, regFragPtr.p->m_logfile_group_id);
1741 Dbtup::undo_createtable_logsync_callback(
Signal* signal, Uint32 ptrI,
1745 FragoperrecPtr fragOperPtr;
1746 fragOperPtr.i= ptrI;
1747 ptrCheckGuard(fragOperPtr, cnoOfFragoprec, fragoperrec);
1749 signal->theData[0] = fragOperPtr.p->lqhPtrFrag;
1750 signal->theData[1] = 1;
1751 sendSignal(fragOperPtr.p->lqhBlockrefFrag, GSN_TUP_ADD_ATTCONF,
1754 releaseFragoperrec(fragOperPtr);
1766 void Dbtup::setUpDescriptorReferences(Uint32 descriptorReference,
1767 Tablerec*
const regTabPtr,
1768 const Uint32* offset)
1770 Uint32* desc= &tableDescriptor[descriptorReference].tabDescr;
1771 regTabPtr->readFunctionArray= (ReadFunction*)(desc + offset[0]);
1772 regTabPtr->updateFunctionArray= (UpdateFunction*)(desc + offset[1]);
1773 regTabPtr->charsetArray= (
CHARSET_INFO**)(desc + offset[2]);
1774 regTabPtr->readKeyArray= descriptorReference + offset[3];
1775 regTabPtr->tabDescriptor= descriptorReference + offset[4];
1776 regTabPtr->m_real_order_descriptor = descriptorReference + offset[5];
1779 void Dbtup::setupDynDescriptorReferences(Uint32 dynDescr,
1780 Tablerec*
const regTabPtr,
1781 const Uint32* offset,
1784 regTabPtr->dynTabDescriptor[ind]= dynDescr;
1785 Uint32* desc= &tableDescriptor[dynDescr].tabDescr;
1786 regTabPtr->dynVarSizeMask[ind] = desc+offset[0];
1787 regTabPtr->dynFixSizeMask[ind] = desc+offset[1];
1791 Dbtup::sizeOfReadFunction()
1793 ReadFunction* tmp= (ReadFunction*)&tableDescriptor[0];
1794 TableDescriptor* start= &tableDescriptor[0];
1795 TableDescriptor * end= (TableDescriptor*)(tmp + 1);
1796 return (Uint32)(end - start);
1799 void Dbtup::setUpKeyArray(Tablerec*
const regTabPtr)
1801 ndbrequire((regTabPtr->readKeyArray + regTabPtr->noOfKeyAttr) <
1803 Uint32* keyArray= &tableDescriptor[regTabPtr->readKeyArray].tabDescr;
1804 Uint32 countKeyAttr= 0;
1805 for (Uint32 i= 0; i < regTabPtr->m_no_of_attributes; i++) {
1807 Uint32 refAttr= regTabPtr->tabDescriptor + (i * ZAD_SIZE);
1808 Uint32 attrDescriptor= getTabDescrWord(refAttr);
1809 if (AttributeDescriptor::getPrimaryKey(attrDescriptor)) {
1815 ndbrequire(countKeyAttr == regTabPtr->noOfKeyAttr);
1822 const Uint32 off= regTabPtr->m_real_order_descriptor;
1823 const Uint32 sz= (regTabPtr->m_no_of_attributes + 1) >> 1;
1824 ndbrequire((off + sz) < cnoOfTabDescrRec);
1827 Uint16* order= (Uint16*)&tableDescriptor[off].tabDescr;
1830 for (Uint32 i= 0; i < regTabPtr->m_no_of_attributes; i++)
1833 Uint32 refAttr= regTabPtr->tabDescriptor + (i * ZAD_SIZE);
1834 Uint32 desc = getTabDescrWord(refAttr);
1837 if (AttributeDescriptor::getDynamic(desc) &&
1838 AttributeDescriptor::getArrayType(desc) == NDB_ARRAYTYPE_FIXED &&
1839 AttributeDescriptor::getSize(desc) == 0)
1852 if ((AttributeDescriptor::getArrayType(desc) != NDB_ARRAYTYPE_FIXED
1853 && !AttributeDescriptor::getDiskBased(desc)) ||
1854 (AttributeDescriptor::getDynamic(desc) &&
1855 AttributeDescriptor::getArrayType(desc) == NDB_ARRAYTYPE_FIXED &&
1856 AttributeDescriptor::getSizeInWords(desc) > InternalMaxDynFix))
1860 if (AttributeDescriptor::getDynamic(desc))
1864 if (AttributeDescriptor::getDiskBased(desc))
1871 * order++ = i << ZAD_LOG_SIZE;
1876 ndbrequire(cnt == regTabPtr->m_no_of_attributes);
1879 void Dbtup::releaseFragoperrec(FragoperrecPtr fragOperPtr)
1881 fragOperPtr.p->inUse =
false;
1882 fragOperPtr.p->nextFragoprec = cfirstfreeFragopr;
1883 cfirstfreeFragopr = fragOperPtr.i;
1884 RSS_OP_FREE(cnoOfFreeFragoprec);
1887 void Dbtup::releaseAlterTabOpRec(AlterTabOperationPtr regAlterTabOpPtr)
1889 regAlterTabOpPtr.p->nextAlterTabOp= cfirstfreeAlterTabOp;
1890 cfirstfreeAlterTabOp= regAlterTabOpPtr.i;
1893 void Dbtup::deleteFragTab(Tablerec*
const regTabPtr, Uint32 fragId)
1895 for (Uint32 i = 0; i < MAX_FRAG_PER_NODE; i++) {
1897 if (regTabPtr->fragid[i] == fragId) {
1899 regTabPtr->fragid[
i]= RNIL;
1900 regTabPtr->fragrec[
i]= RNIL;
1911 void Dbtup::abortAddFragOp(
Signal* signal)
1913 FragoperrecPtr fragOperPtr;
1915 fragOperPtr.i = signal->theData[1];
1916 ptrCheckGuard(fragOperPtr, cnoOfFragoprec, fragoperrec);
1917 ndbrequire(fragOperPtr.p->inUse);
1918 releaseFragoperrec(fragOperPtr);
1922 Dbtup::execDROP_TAB_REQ(
Signal* signal)
1925 if (ERROR_INSERTED(4013)) {
1926 #if defined VM_TRACE || defined ERROR_INSERT
1933 tabPtr.i= req->tableId;
1934 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
1936 tabPtr.p->m_dropTable.tabUserRef = req->senderRef;
1937 tabPtr.p->m_dropTable.tabUserPtr = req->senderData;
1938 tabPtr.p->tableStatus = DROPPING;
1940 signal->theData[0]= ZREL_FRAG;
1941 signal->theData[1]= tabPtr.i;
1942 signal->theData[2]= RNIL;
1943 sendSignal(cownref, GSN_CONTINUEB, signal, 3, JBB);
1946 void Dbtup::releaseTabDescr(Tablerec*
const regTabPtr)
1948 Uint32 descriptor= regTabPtr->readKeyArray;
1949 if (descriptor != RNIL) {
1952 getTabDescrOffsets(regTabPtr->m_no_of_attributes,
1953 regTabPtr->noOfCharsets,
1954 regTabPtr->noOfKeyAttr,
1955 regTabPtr->m_no_of_extra_columns,
1958 regTabPtr->tabDescriptor= RNIL;
1959 regTabPtr->readKeyArray= RNIL;
1960 regTabPtr->readFunctionArray= NULL;
1961 regTabPtr->updateFunctionArray= NULL;
1962 regTabPtr->charsetArray= NULL;
1965 descriptor -= offset[3];
1966 releaseTabDescr(descriptor);
1971 for (Uint16 i = 0; i < NO_DYNAMICS; ++
i)
1974 descriptor= regTabPtr->dynTabDescriptor[
i];
1975 if(descriptor != RNIL)
1977 regTabPtr->dynTabDescriptor[
i]= RNIL;
1978 regTabPtr->dynVarSizeMask[
i]= NULL;
1979 regTabPtr->dynFixSizeMask[
i]= NULL;
1980 releaseTabDescr(descriptor);
1985 void Dbtup::releaseFragment(
Signal* signal, Uint32 tableId,
1986 Uint32 logfile_group_id)
1990 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
1991 Uint32 fragIndex = RNIL;
1992 Uint32 fragId = RNIL;
1994 for (i = 0; i < MAX_FRAG_PER_NODE; i++) {
1996 if (tabPtr.p->fragid[i] != RNIL) {
1998 fragIndex= tabPtr.p->fragrec[
i];
1999 fragId= tabPtr.p->fragid[
i];
2003 if (fragIndex != RNIL) {
2006 signal->theData[0] = ZUNMAP_PAGES;
2007 signal->theData[1] = tabPtr.i;
2008 signal->theData[2] = fragIndex;
2009 signal->theData[3] = 0;
2010 sendSignal(cownref, GSN_CONTINUEB, signal, 4, JBB);
2014 if (logfile_group_id != RNIL)
2017 cb.m_callbackData= tabPtr.i;
2018 cb.m_callbackIndex = DROP_TABLE_LOG_BUFFER_CALLBACK;
2019 Uint32 sz=
sizeof(Disk_undo::Drop) >> 2;
2020 D(
"Logfile_client - releaseFragment");
2022 int r0 = lgman.alloc_log_space(sz);
2027 warningEvent(
"Failed to alloc log space for drop table: %u",
2032 int res= lgman.get_log_buffer(signal, sz, &cb);
2039 warningEvent(
"Failed to get log buffer for drop table: %u",
2041 lgman.free_log_space(sz);
2046 execute(signal, cb, logfile_group_id);
2052 drop_table_logsync_callback(signal, tabPtr.i, RNIL);
2056 Dbtup::drop_fragment_unmap_pages(
Signal *signal,
2058 FragrecordPtr fragPtr,
2061 if (tabPtr.p->m_no_of_disk_attributes)
2064 Disk_alloc_info& alloc_info= fragPtr.p->m_disk_alloc_info;
2066 if (!alloc_info.m_unmap_pages.isEmpty())
2069 signal->theData[0] = ZUNMAP_PAGES;
2070 signal->theData[1] = tabPtr.i;
2071 signal->theData[2] = fragPtr.i;
2072 signal->theData[3] = pos;
2073 sendSignal(cownref, GSN_CONTINUEB, signal, 4, JBB);
2076 while(alloc_info.m_dirty_pages[pos].isEmpty() && pos < MAX_FREE_LIST)
2079 if (pos == MAX_FREE_LIST)
2081 if(alloc_info.m_curr_extent_info_ptr_i != RNIL)
2083 Local_extent_info_list
2084 list(c_extent_pool, alloc_info.m_free_extents[0]);
2086 c_extent_pool.
getPtr(ext_ptr, alloc_info.m_curr_extent_info_ptr_i);
2088 alloc_info.m_curr_extent_info_ptr_i= RNIL;
2091 drop_fragment_free_extent(signal, tabPtr, fragPtr, 0);
2099 list.first(pagePtr);
2100 list.remove(pagePtr);
2104 req.m_page.m_page_no = pagePtr.p->m_page_no;
2105 req.m_page.m_file_no = pagePtr.p->m_file_no;
2107 req.m_callback.m_callbackData= pos;
2108 req.m_callback.m_callbackFunction =
2109 safe_cast(&Dbtup::drop_fragment_unmap_page_callback);
2111 int flags= Page_cache_client::COMMIT_REQ;
2113 int res= pgman.get_page(signal, req, flags);
2115 m_pgman_ptr = pgman.m_ptr;
2122 ndbrequire((Uint32)res == pagePtr.i);
2123 drop_fragment_unmap_page_callback(signal, pos, res);
2127 drop_fragment_free_extent(signal, tabPtr, fragPtr, 0);
2131 Dbtup::drop_fragment_unmap_page_callback(
Signal* signal,
2132 Uint32 pos, Uint32 page_id)
2135 m_global_page_pool.
getPtr(page, page_id);
2138 key.m_page_no = ((Page*)page.p)->m_page_no;
2139 key.m_file_no = ((Page*)page.p)->m_file_no;
2141 Uint32 fragId = ((Page*)page.p)->m_fragment_id;
2142 Uint32 tableId = ((Page*)page.p)->m_table_id;
2144 pgman.drop_page(key, page_id);
2149 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2151 FragrecordPtr fragPtr;
2152 getFragmentrec(fragPtr, fragId, tabPtr.p);
2154 signal->theData[0] = ZUNMAP_PAGES;
2155 signal->theData[1] = tabPtr.i;
2156 signal->theData[2] = fragPtr.i;
2157 signal->theData[3] = pos;
2158 sendSignal(cownref, GSN_CONTINUEB, signal, 4, JBB);
2162 Dbtup::drop_fragment_free_extent(
Signal *signal,
2164 FragrecordPtr fragPtr,
2167 if (tabPtr.p->m_no_of_disk_attributes)
2169 Disk_alloc_info& alloc_info= fragPtr.p->m_disk_alloc_info;
2170 for(; pos<EXTENT_SEARCH_MATRIX_SIZE; pos++)
2172 if(!alloc_info.m_free_extents[pos].isEmpty())
2176 cb.m_callbackData= fragPtr.i;
2177 cb.m_callbackIndex = DROP_FRAGMENT_FREE_EXTENT_LOG_BUFFER_CALLBACK;
2178 #if NOT_YET_UNDO_FREE_EXTENT
2179 Uint32 sz=
sizeof(Disk_undo::FreeExtent) >> 2;
2180 (void) c_lgman->alloc_log_space(fragPtr.p->m_logfile_group_id, sz);
2183 Logfile_client lgman(
this, c_lgman, fragPtr.p->m_logfile_group_id);
2185 int res= lgman.get_log_buffer(signal, sz, &cb);
2192 ndbrequire(
"NOT YET IMPLEMENTED" == 0);
2195 execute(signal, cb, fragPtr.p->m_logfile_group_id);
2199 execute(signal, cb, fragPtr.p->m_logfile_group_id);
2206 for(pos= 0; pos<MAX_FREE_LIST; pos++)
2208 ndbrequire(alloc_info.m_page_requests[pos].isEmpty());
2214 signal->theData[0] = ZFREE_VAR_PAGES;
2215 signal->theData[1] = tabPtr.i;
2216 signal->theData[2] = fragPtr.i;
2217 sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
2221 Dbtup::drop_table_log_buffer_callback(
Signal* signal, Uint32 tablePtrI,
2222 Uint32 logfile_group_id)
2225 tabPtr.i = tablePtrI;
2226 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2228 ndbrequire(tabPtr.p->m_no_of_disk_attributes);
2230 Disk_undo::Drop drop;
2231 drop.m_table = tabPtr.i;
2232 drop.m_type_length =
2233 (Disk_undo::UNDO_DROP << 16) | (sizeof(drop) >> 2);
2234 D(
"Logfile_client - drop_table_log_buffer_callback");
2238 Uint64 lsn = lgman.add_entry(c, 1);
2242 req.m_callback.m_callbackData= tablePtrI;
2243 req.m_callback.m_callbackIndex = DROP_TABLE_LOGSYNC_CALLBACK;
2245 int ret = lgman.sync_lsn(signal, lsn, &req, 0);
2251 warningEvent(
"Failed to syn log for drop of table: %u", tablePtrI);
2253 execute(signal, req.m_callback, logfile_group_id);
2258 Dbtup::drop_table_logsync_callback(
Signal* signal,
2260 Uint32 logfile_group_id)
2264 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2267 dropConf->senderRef= reference();
2268 dropConf->senderData= tabPtr.p->m_dropTable.tabUserPtr;
2269 dropConf->tableId= tabPtr.i;
2270 sendSignal(tabPtr.p->m_dropTable.tabUserRef, GSN_DROP_TAB_CONF,
2271 signal, DropTabConf::SignalLength, JBB);
2273 releaseTabDescr(tabPtr.p);
2274 free_var_part(DefaultValuesFragment.p, tabPtr.p, &tabPtr.p->m_default_value_location);
2275 tabPtr.p->m_default_value_location.setNull();
2280 Dbtup::drop_fragment_free_extent_log_buffer_callback(
Signal* signal,
2284 FragrecordPtr fragPtr;
2285 fragPtr.i = fragPtrI;
2286 ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);
2289 tabPtr.i = fragPtr.p->fragTableId;
2290 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2292 ndbrequire(tabPtr.p->m_no_of_disk_attributes);
2293 Disk_alloc_info& alloc_info= fragPtr.p->m_disk_alloc_info;
2295 for(Uint32 pos = 0; pos<EXTENT_SEARCH_MATRIX_SIZE; pos++)
2297 if(!alloc_info.m_free_extents[pos].isEmpty())
2300 Local_extent_info_list
2301 list(c_extent_pool, alloc_info.m_free_extents[pos]);
2303 list.first(ext_ptr);
2305 #if NOT_YET_UNDO_FREE_EXTENT
2306 #error "This code is complete"
2307 #error "but not needed until we do dealloc of empty extents"
2308 Disk_undo::FreeExtent free;
2309 free.m_table = tabPtr.i;
2310 free.m_fragment = fragPtr.p->fragmentId;
2311 free.m_file_no = ext_ptr.p->m_key.m_file_no;
2312 free.m_page_no = ext_ptr.p->m_key.m_page_no;
2313 free.m_type_length =
2314 (Disk_undo::UNDO_FREE_EXTENT << 16) | (sizeof(free) >> 2);
2315 Logfile_client lgman(
this, c_lgman, fragPtr.p->m_logfile_group_id);
2318 Uint64 lsn = lgman.add_entry(c, 1);
2324 D(
"Tablespace_client - drop_fragment_free_extent_log_buffer_callback");
2326 fragPtr.p->fragmentId,
2327 fragPtr.p->m_tablespace_id);
2329 tsman.free_extent(&ext_ptr.p->m_key, lsn);
2331 c_extent_hash.
remove(ext_ptr);
2332 list.release(ext_ptr);
2334 signal->theData[0] = ZFREE_EXTENT;
2335 signal->theData[1] = tabPtr.i;
2336 signal->theData[2] = fragPtr.i;
2337 signal->theData[3] = pos;
2338 sendSignal(cownref, GSN_CONTINUEB, signal, 4, JBB);
2346 Dbtup::drop_fragment_free_var_pages(
Signal* signal)
2349 Uint32 tableId = signal->theData[1];
2350 Uint32 fragPtrI = signal->theData[2];
2354 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2356 FragrecordPtr fragPtr;
2357 fragPtr.i = fragPtrI;
2358 ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);
2361 for (Uint32 i = 0; i<MAX_FREE_LIST+1; i++)
2363 if (! fragPtr.p->free_var_page_array[i].isEmpty())
2366 ndbrequire(list.first(pagePtr));
2367 list.remove(pagePtr);
2368 returnCommonArea(pagePtr.i, 1);
2370 signal->theData[0] = ZFREE_VAR_PAGES;
2371 signal->theData[1] = tabPtr.i;
2372 signal->theData[2] = fragPtr.i;
2373 sendSignal(cownref, GSN_CONTINUEB, signal, 3, JBB);
2379 DynArr256 map(c_page_map_pool, fragPtr.p->m_page_map);
2381 signal->theData[0] = ZFREE_PAGES;
2382 signal->theData[1] = tabPtr.i;
2383 signal->theData[2] = fragPtrI;
2384 memcpy(signal->theData+3, &iter,
sizeof(iter));
2385 sendSignal(reference(), GSN_CONTINUEB, signal, 3 +
sizeof(iter)/4, JBB);
2389 Dbtup::drop_fragment_free_pages(
Signal* signal)
2392 Uint32 tableId = signal->theData[1];
2393 Uint32 fragPtrI = signal->theData[2];
2395 memcpy(&iter, signal->theData+3,
sizeof(iter));
2397 FragrecordPtr fragPtr;
2398 fragPtr.i = fragPtrI;
2399 ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);
2401 DynArr256 map(c_page_map_pool, fragPtr.p->m_page_map);
2403 for (i = 0; i<16; i++)
2405 switch(map.release(iter, &realpid)){
2410 if (realpid != RNIL && ((realpid & FREE_PAGE_BIT) == 0))
2413 returnCommonArea(realpid, 1);
2422 signal->theData[0] = ZFREE_PAGES;
2423 signal->theData[1] = tableId;
2424 signal->theData[2] = fragPtrI;
2425 memcpy(signal->theData+3, &iter,
sizeof(iter));
2426 sendSignal(reference(), GSN_CONTINUEB, signal, 3 +
sizeof(iter)/4, JBB);
2430 for (i = 0; i<MAX_FREE_LIST+1; i++)
2432 ndbassert(fragPtr.p->free_var_page_array[i].isEmpty());
2445 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2450 tabPtr.p->m_dropTable.m_lcpno = 0;
2451 tabPtr.p->m_dropTable.m_fragPtrI = fragPtr.i;
2452 drop_fragment_fsremove(signal, tabPtr, fragPtr);
2456 Dbtup::drop_fragment_fsremove_done(
Signal* signal,
2458 FragrecordPtr fragPtr)
2464 Uint32 logfile_group_id = fragPtr.p->m_logfile_group_id ;
2467 for(i= 0; i<MAX_FRAG_PER_NODE; i++)
2468 if(tabPtr.p->fragrec[i] == fragPtr.i)
2471 ndbrequire(i != MAX_FRAG_PER_NODE);
2472 tabPtr.p->fragid[
i]= RNIL;
2473 tabPtr.p->fragrec[
i]= RNIL;
2474 releaseFragrec(fragPtr);
2476 if (tabPtr.p->tableStatus == DROPPING)
2479 signal->theData[0]= ZREL_FRAG;
2480 signal->theData[1]= tabPtr.i;
2481 signal->theData[2]= logfile_group_id;
2482 sendSignal(cownref, GSN_CONTINUEB, signal, 3, JBB);
2488 conf->senderRef = reference();
2489 conf->senderData = tabPtr.p->m_dropTable.tabUserPtr;
2490 conf->tableId = tabPtr.i;
2491 sendSignal(tabPtr.p->m_dropTable.tabUserRef, GSN_DROP_FRAG_CONF,
2492 signal, DropFragConf::SignalLength, JBB);
2499 Dbtup::drop_fragment_fsremove(
Signal* signal,
2501 FragrecordPtr fragPtr)
2504 req->userReference = reference();
2505 req->userPointer = tabPtr.i;
2507 req->ownDirectory = 0;
2509 Uint32 lcpno = tabPtr.p->m_dropTable.m_lcpno;
2510 Uint32 fragId = fragPtr.p->fragmentId;
2511 Uint32 tableId = fragPtr.p->fragTableId;
2513 FsOpenReq::setVersion(req->fileNumber, 5);
2514 FsOpenReq::setSuffix(req->fileNumber, FsOpenReq::S_DATA);
2515 FsOpenReq::v5_setLcpNo(req->fileNumber, lcpno);
2516 FsOpenReq::v5_setTableId(req->fileNumber, tableId);
2517 FsOpenReq::v5_setFragmentId(req->fileNumber, fragId);
2518 sendSignal(NDBFS_REF, GSN_FSREMOVEREQ, signal,
2519 FsRemoveReq::SignalLength, JBB);
2523 Dbtup::execFSREMOVEREF(
Signal* signal)
2529 conf->userPointer = userPointer;
2530 execFSREMOVECONF(signal);
2534 Dbtup::execFSREMOVECONF(
Signal* signal)
2540 FragrecordPtr fragPtr;
2542 tabPtr.i = conf->userPointer;
2543 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2545 fragPtr.i = tabPtr.p->m_dropTable.m_fragPtrI;
2546 ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);
2548 tabPtr.p->m_dropTable.m_lcpno++;
2549 if (tabPtr.p->m_dropTable.m_lcpno < 3)
2552 drop_fragment_fsremove(signal, tabPtr, fragPtr);
2557 drop_fragment_fsremove_done(signal, tabPtr, fragPtr);
2562 Dbtup::get_max_lcp_record_size(Uint32 tableId)
2566 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2568 return tabPtr.p->total_rec_size;
2573 Dbtup::start_restore_lcp(Uint32 tableId, Uint32 fragId)
2577 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2579 ndbassert(Uint16(tabPtr.p->m_attributes[DD].m_no_of_fixsize << 16) == 0);
2580 ndbassert(Uint16(tabPtr.p->m_attributes[DD].m_no_of_varsize << 16) == 0);
2582 Uint32 saveAttrCounts =
2583 (Uint32(tabPtr.p->m_attributes[DD].m_no_of_fixsize) << 16) |
2584 (Uint32(tabPtr.p->m_attributes[DD].m_no_of_varsize) << 0);
2586 tabPtr.p->m_dropTable.tabUserPtr= saveAttrCounts;
2587 tabPtr.p->m_dropTable.tabUserRef= (tabPtr.p->m_bits & Tablerec::TR_RowGCI)? 1 : 0;
2588 tabPtr.p->m_createTable.defValLocation = tabPtr.p->m_default_value_location;
2590 Uint32 *tabDesc = (Uint32*)(tableDescriptor+tabPtr.p->tabDescriptor);
2591 for(Uint32 i= 0; i<tabPtr.p->m_no_of_attributes; i++)
2593 Uint32 disk= AttributeDescriptor::getDiskBased(* tabDesc);
2594 Uint32 null= AttributeDescriptor::getNullable(* tabDesc);
2596 ndbrequire(tabPtr.p->notNullAttributeMask.get(i) != null);
2598 tabPtr.p->notNullAttributeMask.clear(i);
2602 tabPtr.p->m_no_of_disk_attributes = 0;
2603 tabPtr.p->m_attributes[DD].m_no_of_fixsize = 0;
2604 tabPtr.p->m_attributes[DD].m_no_of_varsize = 0;
2606 tabPtr.p->m_bits &= ~((Uint16) Tablerec::TR_RowGCI);
2607 tabPtr.p->m_default_value_location.setNull();
2611 Uint32 senderRef, Uint32 senderData,
2612 Uint32 tableId, Uint32 fragId)
2616 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2618 Uint32 restoreAttrCounts = tabPtr.p->m_dropTable.tabUserPtr;
2620 tabPtr.p->m_attributes[DD].m_no_of_fixsize= restoreAttrCounts >> 16;
2621 tabPtr.p->m_attributes[DD].m_no_of_varsize= restoreAttrCounts & 0xffff;
2622 tabPtr.p->m_bits |= ((tabPtr.p->m_dropTable.tabUserRef & 1) ? Tablerec::TR_RowGCI : 0);
2624 tabPtr.p->m_no_of_disk_attributes =
2625 tabPtr.p->m_attributes[DD].m_no_of_fixsize +
2626 tabPtr.p->m_attributes[DD].m_no_of_varsize;
2627 tabPtr.p->m_default_value_location = tabPtr.p->m_createTable.defValLocation;
2629 Uint32 *tabDesc = (Uint32*)(tableDescriptor+tabPtr.p->tabDescriptor);
2632 Uint32 disk= AttributeDescriptor::getDiskBased(* tabDesc);
2633 Uint32 null= AttributeDescriptor::getNullable(* tabDesc);
2636 tabPtr.p->notNullAttributeMask.
set(i);
2645 seizeFragoperrec(fragOpPtr);
2646 fragOpPtr.p->m_senderRef = senderRef;
2647 fragOpPtr.p->m_senderData = senderData;
2649 getFragmentrec(fragPtr, fragId, tabPtr.p);
2650 fragOpPtr.p->fragPointer = fragPtr.i;
2652 signal->theData[0] = ZREBUILD_FREE_PAGE_LIST;
2653 signal->theData[1] = fragOpPtr.i;
2654 signal->theData[2] = 0;
2655 signal->theData[3] = RNIL;
2656 rebuild_page_free_list(signal);
2660 Dbtup::get_frag_info(Uint32 tableId, Uint32 fragId, Uint32* maxPage)
2665 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2667 FragrecordPtr fragPtr;
2668 getFragmentrec(fragPtr, fragId, tabPtr.p);
2672 * maxPage = fragPtr.p->m_max_page_no;
2679 Dbtup::execDROP_FRAG_REQ(
Signal* signal)
2682 if (ERROR_INSERTED(4013)) {
2683 #if defined VM_TRACE || defined ERROR_INSERT
2690 tabPtr.i= req->tableId;
2691 ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec);
2693 tabPtr.p->m_dropTable.tabUserRef = req->senderRef;
2694 tabPtr.p->m_dropTable.tabUserPtr = req->senderData;
2696 Uint32 fragIndex = RNIL;
2697 for (Uint32 i = 0; i < MAX_FRAG_PER_NODE; i++)
2700 if (tabPtr.p->fragid[i] == req->fragId)
2703 fragIndex= tabPtr.p->fragrec[
i];
2707 if (fragIndex != RNIL)
2711 signal->theData[0] = ZUNMAP_PAGES;
2712 signal->theData[1] = tabPtr.i;
2713 signal->theData[2] = fragIndex;
2714 signal->theData[3] = 0;
2715 sendSignal(cownref, GSN_CONTINUEB, signal, 4, JBB);
2720 conf->senderRef = reference();
2721 conf->senderData = tabPtr.p->m_dropTable.tabUserPtr;
2722 conf->tableId = tabPtr.i;
2723 sendSignal(tabPtr.p->m_dropTable.tabUserRef, GSN_DROP_FRAG_CONF,
2724 signal, DropFragConf::SignalLength, JBB);