20 #define DBTUP_STORE_PROC_DEF_CPP
22 #include <RefConvert.hpp>
23 #include <ndb_limits.h>
31 void Dbtup::execSTORED_PROCREQ(
Signal* signal)
33 OperationrecPtr regOperPtr;
34 TablerecPtr regTabPtr;
36 regOperPtr.i = signal->theData[0];
37 c_operation_pool.
getPtr(regOperPtr);
38 regTabPtr.i = signal->theData[1];
39 ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
41 Uint32 requestInfo = signal->theData[3];
42 TransState trans_state= get_trans_state(regOperPtr.p);
43 ndbrequire(trans_state == TRANS_IDLE ||
44 ((trans_state == TRANS_ERROR_WAIT_STORED_PROCREQ) &&
45 (requestInfo == ZSTORED_PROCEDURE_DELETE)));
46 ndbrequire(regTabPtr.p->tableStatus == DEFINED);
52 BlockReference apiBlockref = signal->theData[5];
53 switch (requestInfo) {
57 #if defined VM_TRACE || defined ERROR_INSERT
58 storedProcCountNonAPI(apiBlockref, +1);
61 ndbrequire(handle.m_cnt == 1);
71 #if defined VM_TRACE || defined ERROR_INSERT
72 storedProcCountNonAPI(apiBlockref, +1);
74 copyProcedure(signal, regTabPtr, regOperPtr.p);
76 case ZSTORED_PROCEDURE_DELETE:
78 #if defined VM_TRACE || defined ERROR_INSERT
79 storedProcCountNonAPI(apiBlockref, -1);
81 deleteScanProcedure(signal, regOperPtr.p);
88 void Dbtup::storedProcCountNonAPI(BlockReference apiBlockref,
int add_del)
90 BlockNumber apiBlockno = refToBlock(apiBlockref);
91 if (apiBlockno < MIN_API_BLOCK_NO) {
92 ndbassert(blockToMain(apiBlockno) == BACKUP ||
93 blockToMain(apiBlockno) == SUMA ||
94 blockToMain(apiBlockno) == DBLQH ||
95 blockToMain(apiBlockno) == DBSPJ);
98 c_storedProcCountNonAPI++;
99 }
else if (add_del == -1) {
101 ndbassert(c_storedProcCountNonAPI > 0);
102 c_storedProcCountNonAPI--;
109 void Dbtup::deleteScanProcedure(
Signal* signal,
110 Operationrec* regOperPtr)
112 StoredProcPtr storedPtr;
113 Uint32 storedProcId = signal->theData[4];
114 c_storedProcPool.
getPtr(storedPtr, storedProcId);
115 ndbrequire(storedPtr.p->storedCode != ZSTORED_PROCEDURE_FREE);
116 if (unlikely(storedPtr.p->storedCode == ZCOPY_PROCEDURE))
118 releaseCopyProcedure();
123 releaseSection(storedPtr.p->storedProcIVal);
125 storedPtr.p->storedCode = ZSTORED_PROCEDURE_FREE;
126 storedPtr.p->storedProcIVal= RNIL;
127 c_storedProcPool.
release(storedPtr);
129 set_trans_state(regOperPtr, TRANS_IDLE);
130 signal->theData[0] = regOperPtr->userpointer;
131 signal->theData[1] = storedProcId;
132 BlockReference lqhRef = calcInstanceBlockRef(DBLQH);
133 sendSignal(lqhRef, GSN_STORED_PROCCONF, signal, 2, JBB);
136 void Dbtup::scanProcedure(
Signal* signal,
137 Operationrec* regOperPtr,
144 ndbrequire( handle->m_cnt == 1 );
145 ndbrequire( handle->m_ptr[0].p->m_sz > 0 );
147 StoredProcPtr storedPtr;
148 c_storedProcPool.
seize(storedPtr);
149 ndbrequire(storedPtr.i != RNIL);
150 storedPtr.p->storedCode = (isCopy)? ZCOPY_PROCEDURE : ZSCAN_PROCEDURE;
151 Uint32 lenAttrInfo= handle->m_ptr[0].p->m_sz;
152 storedPtr.p->storedProcIVal= handle->m_ptr[0].i;
155 set_trans_state(regOperPtr, TRANS_IDLE);
157 if (lenAttrInfo >= ZATTR_BUFFER_SIZE) {
160 storedProcBufferSeizeErrorLab(signal,
163 ZSTORED_TOO_MUCH_ATTRINFO_ERROR);
167 signal->theData[0] = regOperPtr->userpointer;
168 signal->theData[1] = storedPtr.i;
170 BlockReference lqhRef = calcInstanceBlockRef(DBLQH);
171 sendSignal(lqhRef, GSN_STORED_PROCCONF, signal, 2, JBB);
174 void Dbtup::allocCopyProcedure()
186 for (Uint32 attrNum=0; attrNum < MAX_ATTRIBUTES_IN_TABLE; attrNum++)
189 ndbrequire(appendToSection(iVal, &ahWord, 1));
195 ndbrequire(appendToSection(iVal, &ahWord, 1));
197 cCopyProcedure= iVal;
200 cCopyOverwriteLen= 0;
203 void Dbtup::freeCopyProcedure()
207 releaseSection(cCopyProcedure);
211 void Dbtup::prepareCopyProcedure(Uint32 numAttrs,
217 ndbassert(numAttrs <= MAX_ATTRIBUTES_IN_TABLE);
218 ndbassert(cCopyProcedure != RNIL);
219 ndbassert(cCopyLastSeg == RNIL);
220 ndbassert(cCopyOverwrite == 0);
221 ndbassert(cCopyOverwriteLen == 0);
223 g_sectionSegmentPool.
getPtr(first, cCopyProcedure);
226 cCopyLastSeg= first.p->m_lastSegment;
229 Uint32 extraAttrIds[EXTRA_COPY_PROC_WORDS];
230 Uint32 extraReads = 0;
232 if (tableBits & Tablerec::TR_ExtraRowGCIBits)
235 extraAttrIds[extraReads++] = ah.m_value;
237 if (tableBits & Tablerec::TR_ExtraRowAuthorBits)
240 extraAttrIds[extraReads++] = ah.m_value;
246 Uint32 newSize = numAttrs + extraReads;
247 first.p->m_sz= newSize;
251 cCopyOverwrite= numAttrs;
252 cCopyOverwriteLen = extraReads;
254 ndbrequire(writeToSection(first.i, numAttrs, extraAttrIds, extraReads));
259 while(newSize > SectionSegment::DataLength)
261 g_sectionSegmentPool.
getPtr(curr, curr.p->m_nextSegment);
262 newSize-= SectionSegment::DataLength;
264 first.p->m_lastSegment= curr.i;
267 void Dbtup::releaseCopyProcedure()
270 ndbassert(cCopyProcedure != RNIL);
271 ndbassert(cCopyLastSeg != RNIL);
274 g_sectionSegmentPool.
getPtr(first, cCopyProcedure);
276 ndbassert(first.p->m_sz <= MAX_COPY_PROC_LEN);
277 first.p->m_sz= MAX_COPY_PROC_LEN;
278 first.p->m_lastSegment= cCopyLastSeg;
280 if (cCopyOverwriteLen)
282 ndbassert(cCopyOverwriteLen <= EXTRA_COPY_PROC_WORDS);
283 Uint32 attrids[EXTRA_COPY_PROC_WORDS];
284 for (Uint32
i=0;
i < cCopyOverwriteLen;
i++)
287 attrids[
i] = ah.m_value;
289 ndbrequire(writeToSection(first.i, cCopyOverwrite, attrids, cCopyOverwriteLen));
290 cCopyOverwriteLen= 0;
298 void Dbtup::copyProcedure(
Signal* signal,
299 TablerecPtr regTabPtr,
300 Operationrec* regOperPtr)
314 prepareCopyProcedure(regTabPtr.p->m_no_of_attributes,
315 regTabPtr.p->m_bits);
319 handle.m_ptr[0].i= cCopyProcedure;
320 getSections(handle.m_cnt, handle.m_ptr);
322 scanProcedure(signal,
328 void Dbtup::storedProcBufferSeizeErrorLab(
Signal* signal,
329 Operationrec* regOperPtr,
330 Uint32 storedProcPtr,
333 regOperPtr->m_any_value = 0;
334 set_trans_state(regOperPtr, TRANS_ERROR_WAIT_STORED_PROCREQ);
335 signal->theData[0] = regOperPtr->userpointer;
336 signal->theData[1] = errorCode;
337 signal->theData[2] = storedProcPtr;
338 BlockReference lqhRef = calcInstanceBlockRef(DBLQH);
339 sendSignal(lqhRef, GSN_STORED_PROCREF, signal, 3, JBB);