1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
#define DBTUP_C
#define DBTUP_STORE_PROC_DEF_CPP
#include "Dbtup.hpp"
#include <RefConvert.hpp>
#include <ndb_limits.h>
#include <pc.hpp>
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* ------------ADD/DROP STORED PROCEDURE MODULE ------------------- */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
void Dbtup::execSTORED_PROCREQ(Signal* signal)
{
OperationrecPtr regOperPtr;
TablerecPtr regTabPtr;
jamEntry();
regOperPtr.i = signal->theData[0];
c_operation_pool.getPtr(regOperPtr);
regTabPtr.i = signal->theData[1];
ptrCheckGuard(regTabPtr, cnoOfTablerec, tablerec);
Uint32 requestInfo = signal->theData[3];
TransState trans_state= get_trans_state(regOperPtr.p);
ndbrequire(trans_state == TRANS_IDLE ||
((trans_state == TRANS_ERROR_WAIT_STORED_PROCREQ) &&
(requestInfo == ZSTORED_PROCEDURE_DELETE)));
ndbrequire(regTabPtr.p->tableStatus == DEFINED);
switch (requestInfo) {
case ZSCAN_PROCEDURE:
jam();
scanProcedure(signal,
regOperPtr.p,
signal->theData[4]);
break;
case ZCOPY_PROCEDURE:
jam();
copyProcedure(signal, regTabPtr, regOperPtr.p);
break;
case ZSTORED_PROCEDURE_DELETE:
jam();
deleteScanProcedure(signal, regOperPtr.p);
break;
default:
ndbrequire(false);
}//switch
}//Dbtup::execSTORED_PROCREQ()
void Dbtup::deleteScanProcedure(Signal* signal,
Operationrec* regOperPtr)
{
StoredProcPtr storedPtr;
Uint32 storedProcId = signal->theData[4];
c_storedProcPool.getPtr(storedPtr, storedProcId);
ndbrequire(storedPtr.p->storedCode == ZSCAN_PROCEDURE);
ndbrequire(storedPtr.p->storedCounter == 0);
Uint32 firstAttrinbuf = storedPtr.p->storedLinkFirst;
storedPtr.p->storedCode = ZSTORED_PROCEDURE_FREE;
storedPtr.p->storedLinkFirst = RNIL;
storedPtr.p->storedLinkLast = RNIL;
storedPtr.p->storedProcLength = 0;
c_storedProcPool.release(storedPtr);
freeAttrinbufrec(firstAttrinbuf);
regOperPtr->currentAttrinbufLen = 0;
set_trans_state(regOperPtr, TRANS_IDLE);
signal->theData[0] = regOperPtr->userpointer;
signal->theData[1] = storedProcId;
sendSignal(DBLQH_REF, GSN_STORED_PROCCONF, signal, 2, JBB);
}//Dbtup::deleteScanProcedure()
void Dbtup::scanProcedure(Signal* signal,
Operationrec* regOperPtr,
Uint32 lenAttrInfo)
{
//--------------------------------------------------------
// We introduce the maxCheck so that there is always one
// stored procedure entry free for copy procedures. Thus
// no amount of scanning can cause problems for the node
// recovery functionality.
//--------------------------------------------------------
StoredProcPtr storedPtr;
c_storedProcPool.seize(storedPtr);
ndbrequire(storedPtr.i != RNIL);
storedPtr.p->storedCode = ZSCAN_PROCEDURE;
storedPtr.p->storedCounter = 0;
storedPtr.p->storedProcLength = lenAttrInfo;
storedPtr.p->storedLinkFirst = RNIL;
storedPtr.p->storedLinkLast = RNIL;
set_trans_state(regOperPtr, TRANS_WAIT_STORED_PROCEDURE_ATTR_INFO);
regOperPtr->attrinbufLen = lenAttrInfo;
regOperPtr->currentAttrinbufLen = 0;
regOperPtr->storedProcPtr = storedPtr.i;
if (lenAttrInfo >= ZATTR_BUFFER_SIZE) { // yes ">="
jam();
// send REF and change state to ignore the ATTRINFO to come
storedSeizeAttrinbufrecErrorLab(signal, regOperPtr, ZSTORED_TOO_MUCH_ATTRINFO_ERROR);
}
}//Dbtup::scanProcedure()
void Dbtup::copyProcedure(Signal* signal,
TablerecPtr regTabPtr,
Operationrec* regOperPtr)
{
Uint32 TnoOfAttributes = regTabPtr.p->m_no_of_attributes;
scanProcedure(signal,
regOperPtr,
TnoOfAttributes);
Uint32 length = 0;
for (Uint32 Ti = 0; Ti < TnoOfAttributes; Ti++) {
AttributeHeader::init(&signal->theData[length + 1], Ti, 0);
length++;
if (length == 24) {
jam();
ndbrequire(storedProcedureAttrInfo(signal, regOperPtr,
signal->theData+1, length, true));
length = 0;
}//if
}//for
if (length != 0) {
jam();
ndbrequire(storedProcedureAttrInfo(signal, regOperPtr,
signal->theData+1, length, true));
}//if
ndbrequire(regOperPtr->currentAttrinbufLen == 0);
}//Dbtup::copyProcedure()
bool Dbtup::storedProcedureAttrInfo(Signal* signal,
Operationrec* regOperPtr,
const Uint32 *data,
Uint32 length,
bool copyProcedure)
{
AttrbufrecPtr regAttrPtr;
Uint32 RnoFree = cnoFreeAttrbufrec;
if (ERROR_INSERTED(4004) && !copyProcedure) {
CLEAR_ERROR_INSERT_VALUE;
storedSeizeAttrinbufrecErrorLab(signal, regOperPtr, ZSTORED_SEIZE_ATTRINBUFREC_ERROR);
return false;
}//if
regOperPtr->currentAttrinbufLen += length;
ndbrequire(regOperPtr->currentAttrinbufLen <= regOperPtr->attrinbufLen);
if ((RnoFree > MIN_ATTRBUF) ||
(copyProcedure)) {
jam();
regAttrPtr.i = cfirstfreeAttrbufrec;
ptrCheckGuard(regAttrPtr, cnoOfAttrbufrec, attrbufrec);
regAttrPtr.p->attrbuf[ZBUF_DATA_LEN] = 0;
cfirstfreeAttrbufrec = regAttrPtr.p->attrbuf[ZBUF_NEXT];
cnoFreeAttrbufrec = RnoFree - 1;
regAttrPtr.p->attrbuf[ZBUF_NEXT] = RNIL;
} else {
jam();
storedSeizeAttrinbufrecErrorLab(signal, regOperPtr, ZSTORED_SEIZE_ATTRINBUFREC_ERROR);
return false;
}//if
if (regOperPtr->firstAttrinbufrec == RNIL) {
jam();
regOperPtr->firstAttrinbufrec = regAttrPtr.i;
}//if
regAttrPtr.p->attrbuf[ZBUF_NEXT] = RNIL;
if (regOperPtr->lastAttrinbufrec != RNIL) {
AttrbufrecPtr tempAttrinbufptr;
jam();
tempAttrinbufptr.i = regOperPtr->lastAttrinbufrec;
ptrCheckGuard(tempAttrinbufptr, cnoOfAttrbufrec, attrbufrec);
tempAttrinbufptr.p->attrbuf[ZBUF_NEXT] = regAttrPtr.i;
}//if
regOperPtr->lastAttrinbufrec = regAttrPtr.i;
regAttrPtr.p->attrbuf[ZBUF_DATA_LEN] = length;
MEMCOPY_NO_WORDS(®AttrPtr.p->attrbuf[0],
data,
length);
if (regOperPtr->currentAttrinbufLen < regOperPtr->attrinbufLen) {
jam();
return true;
}//if
if (ERROR_INSERTED(4005) && !copyProcedure) {
CLEAR_ERROR_INSERT_VALUE;
storedSeizeAttrinbufrecErrorLab(signal, regOperPtr, ZSTORED_SEIZE_ATTRINBUFREC_ERROR);
return false;
}//if
StoredProcPtr storedPtr;
c_storedProcPool.getPtr(storedPtr, (Uint32)regOperPtr->storedProcPtr);
ndbrequire(storedPtr.p->storedCode == ZSCAN_PROCEDURE);
regOperPtr->currentAttrinbufLen = 0;
storedPtr.p->storedLinkFirst = regOperPtr->firstAttrinbufrec;
storedPtr.p->storedLinkLast = regOperPtr->lastAttrinbufrec;
regOperPtr->firstAttrinbufrec = RNIL;
regOperPtr->lastAttrinbufrec = RNIL;
regOperPtr->m_any_value = 0;
set_trans_state(regOperPtr, TRANS_IDLE);
signal->theData[0] = regOperPtr->userpointer;
signal->theData[1] = storedPtr.i;
sendSignal(DBLQH_REF, GSN_STORED_PROCCONF, signal, 2, JBB);
return true;
}//Dbtup::storedProcedureAttrInfo()
void Dbtup::storedSeizeAttrinbufrecErrorLab(Signal* signal,
Operationrec* regOperPtr,
Uint32 errorCode)
{
StoredProcPtr storedPtr;
c_storedProcPool.getPtr(storedPtr, regOperPtr->storedProcPtr);
ndbrequire(storedPtr.p->storedCode == ZSCAN_PROCEDURE);
storedPtr.p->storedLinkFirst = regOperPtr->firstAttrinbufrec;
regOperPtr->firstAttrinbufrec = RNIL;
regOperPtr->lastAttrinbufrec = RNIL;
regOperPtr->m_any_value = 0;
set_trans_state(regOperPtr, TRANS_ERROR_WAIT_STORED_PROCREQ);
signal->theData[0] = regOperPtr->userpointer;
signal->theData[1] = errorCode;
signal->theData[2] = regOperPtr->storedProcPtr;
sendSignal(DBLQH_REF, GSN_STORED_PROCREF, signal, 3, JBB);
}//Dbtup::storedSeizeAttrinbufrecErrorLab()
|