forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdbOperation.cpp
More file actions
626 lines (559 loc) · 14.9 KB
/
NdbOperation.cpp
File metadata and controls
626 lines (559 loc) · 14.9 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*
Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "API.hpp"
#include <signaldata/TcKeyReq.hpp>
/******************************************************************************
* NdbOperation(Ndb* aNdb, Table* aTable);
*
* Return Value: None
* Parameters: aNdb: Pointers to the Ndb object.
* aTable: Pointers to the Table object
* Remark: Creat an object of NdbOperation.
****************************************************************************/
NdbOperation::NdbOperation(Ndb* aNdb, NdbOperation::Type aType) :
m_type(aType),
theReceiver(aNdb),
theErrorLine(0),
theNdb(aNdb),
//theTable(aTable),
theNdbCon(NULL),
theNext(NULL),
theTCREQ(NULL),
theFirstATTRINFO(NULL),
theCurrentATTRINFO(NULL),
theTotalCurrAI_Len(0),
theAI_LenInCurrAI(0),
theLastKEYINFO(NULL),
theFirstLabel(NULL),
theLastLabel(NULL),
theFirstBranch(NULL),
theLastBranch(NULL),
theFirstCall(NULL),
theLastCall(NULL),
theFirstSubroutine(NULL),
theLastSubroutine(NULL),
theNoOfLabels(0),
theNoOfSubroutines(0),
m_currentTable(NULL), //theTableId(0xFFFF),
m_accessTable(NULL), //theAccessTableId(0xFFFF),
//theSchemaVersion(0),
theTotalNrOfKeyWordInSignal(8),
theTupKeyLen(0),
theNoOfTupKeyLeft(0),
theOperationType(NotDefined),
theStatus(Init),
theMagicNumber(0xFE11D0),
theScanInfo(0),
m_tcReqGSN(GSN_TCKEYREQ),
m_keyInfoGSN(GSN_KEYINFO),
m_attrInfoGSN(GSN_ATTRINFO),
theBlobList(NULL),
m_abortOption(-1),
m_noErrorPropagation(false),
theLockHandle(NULL),
m_blob_lock_upgraded(false)
{
theReceiver.init(NdbReceiver::NDB_OPERATION, false, this);
theError.code = 0;
m_customData = NULL;
}
/*****************************************************************************
* ~NdbOperation();
*
* Remark: Delete tables for connection pointers (id).
*****************************************************************************/
NdbOperation::~NdbOperation( )
{
}
/******************************************************************************
*void setErrorCode(int anErrorCode);
*
* Remark: Set an Error Code on operation and
* on connection set an error status.
*****************************************************************************/
void
NdbOperation::setErrorCode(int anErrorCode) const
{
/* Setting an error is considered to be a const
operation, hence the nasty cast here */
NdbOperation *pnonConstThis=const_cast<NdbOperation *>(this);
pnonConstThis->theError.code = anErrorCode;
theNdbCon->theErrorLine = theErrorLine;
theNdbCon->theErrorOperation = pnonConstThis;
if (!(m_abortOption == AO_IgnoreError && m_noErrorPropagation))
theNdbCon->setOperationErrorCode(anErrorCode);
}
/******************************************************************************
* void setErrorCodeAbort(int anErrorCode);
*
* Remark: Set an Error Code on operation and on connection set
* an error status.
*****************************************************************************/
void
NdbOperation::setErrorCodeAbort(int anErrorCode) const
{
/* Setting an error is considered to be a const
operation, hence the nasty cast here */
NdbOperation *pnonConstThis=const_cast<NdbOperation *>(this);
pnonConstThis->theError.code = anErrorCode;
theNdbCon->theErrorLine = theErrorLine;
theNdbCon->theErrorOperation = pnonConstThis;
// ignore m_noErrorPropagation
theNdbCon->setOperationErrorCodeAbort(anErrorCode);
}
/*****************************************************************************
* int init();
*
* Return Value: Return 0 : init was successful.
* Return -1: In all other case.
* Remark: Initiates operation record after allocation.
*****************************************************************************/
int
NdbOperation::init(const NdbTableImpl* tab, NdbTransaction* myConnection,
bool useRec){
NdbApiSignal* tSignal;
theStatus = Init;
theError.code = 0;
theErrorLine = 1;
m_currentTable = m_accessTable = tab;
theNdbCon = myConnection;
for (Uint32 i=0; i<NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY; i++)
for (int j=0; j<3; j++)
theTupleKeyDefined[i][j] = 0;
theFirstATTRINFO = NULL;
theCurrentATTRINFO = NULL;
theLastKEYINFO = NULL;
theTupKeyLen = 0;
theNoOfTupKeyLeft = tab->getNoOfPrimaryKeys();
theTotalCurrAI_Len = 0;
theAI_LenInCurrAI = 0;
theStartIndicator = 0;
theCommitIndicator = 0;
theSimpleIndicator = 0;
theDirtyIndicator = 0;
theInterpretIndicator = 0;
theDistrKeyIndicator_ = 0;
theScanInfo = 0;
theTotalNrOfKeyWordInSignal = 8;
theMagicNumber = 0xABCDEF01;
m_attribute_record= NULL;
theBlobList = NULL;
m_abortOption = -1;
m_noErrorPropagation = false;
m_flags = 0;
m_flags |= OF_NO_DISK;
m_interpreted_code = NULL;
m_extraSetValues = NULL;
m_numExtraSetValues = 0;
tSignal = theNdb->getSignal();
if (tSignal == NULL)
{
setErrorCode(4000);
return -1;
}
theTCREQ = tSignal;
theTCREQ->setSignal(m_tcReqGSN, refToBlock(theNdbCon->m_tcRef));
theAI_LenInCurrAI = 20;
TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
tcKeyReq->scanInfo = 0;
theKEYINFOptr = &tcKeyReq->keyInfo[0];
theATTRINFOptr = &tcKeyReq->attrInfo[0];
if (theReceiver.init(NdbReceiver::NDB_OPERATION, useRec, this))
{
// theReceiver sets the error code of its owner
return -1;
}
m_customData = NULL;
if (theNdb->theImpl->get_ndbapi_config_parameters().m_default_queue_option)
m_flags |= OF_QUEUEABLE;
return 0;
}
/******************************************************************************
* void release();
*
* Remark: Release all objects connected to the operation object.
*****************************************************************************/
void
NdbOperation::release()
{
NdbBlob* tBlob;
NdbBlob* tSaveBlob;
/* In case we didn't execute... */
postExecuteRelease();
tBlob = theBlobList;
while (tBlob != NULL)
{
tSaveBlob = tBlob;
tBlob = tBlob->theNext;
theNdb->releaseNdbBlob(tSaveBlob);
}
theBlobList = NULL;
theReceiver.release();
theLockHandle = NULL;
m_blob_lock_upgraded = false;
}
void
NdbOperation::postExecuteRelease()
{
NdbApiSignal* tSignal;
NdbApiSignal* tSaveSignal;
NdbBranch* tBranch;
NdbBranch* tSaveBranch;
NdbLabel* tLabel;
NdbLabel* tSaveLabel;
NdbCall* tCall;
NdbCall* tSaveCall;
NdbSubroutine* tSubroutine;
NdbSubroutine* tSaveSubroutine;
tSignal = theRequest; /* TCKEYREQ/TCINDXREQ/SCANTABREQ */
while (tSignal != NULL)
{
tSaveSignal = tSignal;
tSignal = tSignal->next();
theNdb->releaseSignal(tSaveSignal);
}
theRequest = NULL;
theLastKEYINFO = NULL;
#ifdef TODO
/**
* Compute correct #cnt signals between theFirstATTRINFO/theCurrentATTRINFO
*/
if (theFirstATTRINFO)
{
theNdb->releaseSignals(1, theFirstATTRINFO, theCurrentATTRINFO);
}
#else
tSignal = theFirstATTRINFO;
while (tSignal != NULL)
{
tSaveSignal = tSignal;
tSignal = tSignal->next();
theNdb->releaseSignal(tSaveSignal);
}
#endif
theFirstATTRINFO = NULL;
theCurrentATTRINFO = NULL;
if (theInterpretIndicator == 1)
{
tBranch = theFirstBranch;
while (tBranch != NULL)
{
tSaveBranch = tBranch;
tBranch = tBranch->theNext;
theNdb->releaseNdbBranch(tSaveBranch);
}
tLabel = theFirstLabel;
while (tLabel != NULL)
{
tSaveLabel = tLabel;
tLabel = tLabel->theNext;
theNdb->releaseNdbLabel(tSaveLabel);
}
tCall = theFirstCall;
while (tCall != NULL)
{
tSaveCall = tCall;
tCall = tCall->theNext;
theNdb->releaseNdbCall(tSaveCall);
}
tSubroutine = theFirstSubroutine;
while (tSubroutine != NULL)
{
tSaveSubroutine = tSubroutine;
tSubroutine = tSubroutine->theNext;
theNdb->releaseNdbSubroutine(tSaveSubroutine);
}
}
}
NdbRecAttr*
NdbOperation::getValue(const char* anAttrName, char* aValue)
{
return getValue_impl(m_currentTable->getColumn(anAttrName), aValue);
}
NdbRecAttr*
NdbOperation::getValue(Uint32 anAttrId, char* aValue)
{
return getValue_impl(m_currentTable->getColumn(anAttrId), aValue);
}
NdbRecAttr*
NdbOperation::getValue(const NdbDictionary::Column* col, char* aValue)
{
if (theStatus != UseNdbRecord)
return getValue_impl(&NdbColumnImpl::getImpl(*col), aValue);
setErrorCodeAbort(4508);
/* GetValue not allowed for NdbRecord defined operation */
return NULL;
}
int
NdbOperation::equal(const char* anAttrName, const char* aValuePassed)
{
const NdbColumnImpl* col = m_accessTable->getColumn(anAttrName);
if (col == NULL)
{
setErrorCode(4004);
return -1;
}
else
{
return equal_impl(col, aValuePassed);
}
}
int
NdbOperation::equal(Uint32 anAttrId, const char* aValuePassed)
{
const NdbColumnImpl* col = m_accessTable->getColumn(anAttrId);
if (col == NULL)
{
setErrorCode(4004);
return -1;
}
else
{
return equal_impl(col, aValuePassed);
}
}
int
NdbOperation::setValue(const char* anAttrName, const char* aValuePassed)
{
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrName);
if (col == NULL)
{
setErrorCode(4004);
return -1;
}
else
{
return setValue(col, aValuePassed);
}
}
int
NdbOperation::setValue(Uint32 anAttrId, const char* aValuePassed)
{
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrId);
if (col == NULL)
{
setErrorCode(4004);
return -1;
}
else
{
return setValue(col, aValuePassed);
}
}
NdbBlob*
NdbOperation::getBlobHandle(const char* anAttrName)
{
// semantics differs from overloaded 'getBlobHandle(const char*) const'
// by delegating to the non-const variant of internal getBlobHandle(...),
// which may create a new BlobHandle
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrName);
if (col == NULL)
{
setErrorCode(4004);
return NULL;
}
else
{
return getBlobHandle(theNdbCon, col);
}
}
NdbBlob*
NdbOperation::getBlobHandle(Uint32 anAttrId)
{
// semantics differs from overloaded 'getBlobHandle(Uint32) const'
// by delegating to the non-const variant of internal getBlobHandle(...),
// which may create a new BlobHandle
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrId);
if (col == NULL)
{
setErrorCode(4004);
return NULL;
}
else
{
return getBlobHandle(theNdbCon, col);
}
}
NdbBlob*
NdbOperation::getBlobHandle(const char* anAttrName) const
{
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrName);
if (col == NULL)
{
setErrorCode(4004);
return NULL;
}
else
{
return getBlobHandle(theNdbCon, col);
}
}
NdbBlob*
NdbOperation::getBlobHandle(Uint32 anAttrId) const
{
const NdbColumnImpl* col = m_currentTable->getColumn(anAttrId);
if (col == NULL)
{
setErrorCode(4004);
return NULL;
}
else
{
return getBlobHandle(theNdbCon, col);
}
}
int
NdbOperation::incValue(const char* anAttrName, Uint32 aValue)
{
return incValue(m_currentTable->getColumn(anAttrName), aValue);
}
int
NdbOperation::incValue(const char* anAttrName, Uint64 aValue)
{
return incValue(m_currentTable->getColumn(anAttrName), aValue);
}
int
NdbOperation::incValue(Uint32 anAttrId, Uint32 aValue)
{
return incValue(m_currentTable->getColumn(anAttrId), aValue);
}
int
NdbOperation::incValue(Uint32 anAttrId, Uint64 aValue)
{
return incValue(m_currentTable->getColumn(anAttrId), aValue);
}
int
NdbOperation::subValue( const char* anAttrName, Uint32 aValue)
{
return subValue(m_currentTable->getColumn(anAttrName), aValue);
}
int
NdbOperation::subValue( const char* anAttrName, Uint64 aValue)
{
return subValue(m_currentTable->getColumn(anAttrName), aValue);
}
int
NdbOperation::subValue(Uint32 anAttrId, Uint32 aValue)
{
return subValue(m_currentTable->getColumn(anAttrId), aValue);
}
int
NdbOperation::subValue(Uint32 anAttrId, Uint64 aValue)
{
return subValue(m_currentTable->getColumn(anAttrId), aValue);
}
int
NdbOperation::read_attr(const char* anAttrName, Uint32 RegDest)
{
return read_attr(m_currentTable->getColumn(anAttrName), RegDest);
}
int
NdbOperation::read_attr(Uint32 anAttrId, Uint32 RegDest)
{
return read_attr(m_currentTable->getColumn(anAttrId), RegDest);
}
int
NdbOperation::write_attr(const char* anAttrName, Uint32 RegDest)
{
return write_attr(m_currentTable->getColumn(anAttrName), RegDest);
}
int
NdbOperation::write_attr(Uint32 anAttrId, Uint32 RegDest)
{
return write_attr(m_currentTable->getColumn(anAttrId), RegDest);
}
const char*
NdbOperation::getTableName() const
{
return m_currentTable->m_externalName.c_str();
}
const NdbDictionary::Table*
NdbOperation::getTable() const
{
return m_currentTable;
}
NdbTransaction*
NdbOperation::getNdbTransaction() const
{
return theNdbCon;
}
int
NdbOperation::getLockHandleImpl()
{
assert(! theLockHandle);
if (unlikely(theNdb->getMinDbNodeVersion() <
NDBD_UNLOCK_OP_SUPPORTED))
{
/* Function not implemented yet */
return 4003;
}
if (likely(((theOperationType == ReadRequest) ||
(theOperationType == ReadExclusive)) &&
(m_type == PrimaryKeyAccess) &&
((theLockMode == LM_Read) |
(theLockMode == LM_Exclusive))))
{
theLockHandle = theNdbCon->getLockHandle();
if (!theLockHandle)
{
return 4000;
}
/* Now operation has a LockHandle - it'll be
* filled-in when the operation is prepared prior
* to execution.
*/
assert(theLockHandle->m_state == NdbLockHandle::ALLOCATED);
assert(! theLockHandle->isLockRefValid());
return 0;
}
else
{
/* getLockHandle only supported for primary key read with a lock */
return 4549;
}
}
const NdbLockHandle*
NdbOperation::getLockHandle()
{
if (likely (! m_blob_lock_upgraded))
{
if (theLockHandle == NULL)
{
int rc = getLockHandleImpl();
if (likely(rc == 0))
return theLockHandle;
else
{
setErrorCode(rc);
return NULL;
}
}
/* Return existing LockHandle */
return theLockHandle;
}
else
{
/* Not allowed to call getLockHandle() on a Blob-upgraded
* read
*/
setErrorCode(4549);
return NULL;
}
}
const NdbLockHandle*
NdbOperation::getLockHandle() const
{
/* NdbRecord / handle already exists variant */
return theLockHandle;
}