forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdbOperationExec.cpp
More file actions
1770 lines (1522 loc) · 52.8 KB
/
NdbOperationExec.cpp
File metadata and controls
1770 lines (1522 loc) · 52.8 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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2003, 2010, 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 <ndb_global.h>
#include "API.hpp"
#include "Interpreter.hpp"
#include <AttributeHeader.hpp>
#include <signaldata/TcKeyReq.hpp>
#include <signaldata/TcKeyRef.hpp>
#include <signaldata/KeyInfo.hpp>
#include <signaldata/AttrInfo.hpp>
#include <signaldata/ScanTab.hpp>
#include <ndb_version.h>
#include "API.hpp"
#include <NdbOut.hpp>
/**
* Old NdbApi KeyInfo Section Iterator
*
* This is an implementation of GenericSectionIterator
* that reads signal data from signal object chains
* prepared by old NdbApi code
* In those chains, some data is in the first
* (TCKEYREQ/TCINDXREQ) signal, and the rest is in linked
* KEYINFO / ATTRINFO chains.
* Longer term, the 'old' code should be modified to split
* operation definition from execution. The intermediate
* use of signal chains for KeyInfo and AttrInfo can be
* revisited.
*/
class OldNdbApiSectionIterator: public GenericSectionIterator
{
private :
STATIC_CONST(KeyAndAttrInfoHeaderLength = 3);
const Uint32 firstSigDataLen; // Num words in first signal
Uint32* firstDataPtr; // Ptr to start of data in first signal
NdbApiSignal* secondSignal; // Second signal
// Nasty void* for current iterator position
void* currentPos; // start == firstDataPtr
// middle == NdbApiSignal*
// end == NULL
void checkStaticAssertions()
{
STATIC_ASSERT(KeyInfo::HeaderLength == KeyAndAttrInfoHeaderLength);
STATIC_ASSERT(AttrInfo::HeaderLength == KeyAndAttrInfoHeaderLength);
};
public :
OldNdbApiSectionIterator(NdbApiSignal* TCREQ,
Uint32 dataOffset,
Uint32 dataLen,
NdbApiSignal* nextSignal) :
firstSigDataLen(dataLen),
firstDataPtr(TCREQ->getDataPtrSend()+dataOffset),
secondSignal(nextSignal),
currentPos(firstDataPtr)
{
assert((dataOffset + dataLen) <= NdbApiSignal::MaxSignalWords);
}
~OldNdbApiSectionIterator()
{};
void reset()
{
currentPos= firstDataPtr;
}
const Uint32* getNextWords(Uint32& sz)
{
/* In first TCKEY/INDXREQ, data is at offset depending
* on whether it's KEYINFO or ATTRINFO
* In following signals, data starts at offset 3
* regardless
*/
if (likely(currentPos != NULL))
{
if (currentPos == firstDataPtr)
{
currentPos= secondSignal;
sz= firstSigDataLen;
return firstDataPtr;
}
/* Second signal is KeyInfo or AttrInfo
* Ignore header words
*/
NdbApiSignal* sig= (NdbApiSignal*)currentPos;
assert(sig->getLength() >= KeyAndAttrInfoHeaderLength);
sz= sig->getLength() - KeyAndAttrInfoHeaderLength;
currentPos= sig->next();
return sig->getDataPtrSend() + KeyAndAttrInfoHeaderLength;
}
sz = 0;
return NULL;
}
};
void
NdbOperation::setLastFlag(NdbApiSignal* signal, Uint32 lastFlag)
{
TcKeyReq * const req = CAST_PTR(TcKeyReq, signal->getDataPtrSend());
TcKeyReq::setExecuteFlag(req->requestInfo, lastFlag);
}
int
NdbOperation::doSendKeyReq(int aNodeId,
GenericSectionPtr* secs,
Uint32 numSecs)
{
/* Send a KeyRequest - could be TCKEYREQ or TCINDXREQ
*
* Normally we send a single long signal with 1 or 2
* sections containing KeyInfo and AttrInfo.
* For backwards compatibility and testing purposes
* we can send signal trains instead.
*/
NdbApiSignal* request = theTCREQ;
NdbImpl* impl = theNdb->theImpl;
Uint32 tcNodeVersion = impl->getNodeNdbVersion(aNodeId);
bool forceShort = impl->forceShortRequests;
bool sendLong = ( tcNodeVersion >= NDBD_LONG_TCKEYREQ ) &&
! forceShort;
if (sendLong)
{
return impl->sendSignal(request, aNodeId, secs, numSecs);
}
else
{
/* Send signal as short request - either for backwards
* compatibility or testing
*/
Uint32 sigCount = 1;
Uint32 keyInfoLen = secs[0].sz;
Uint32 attrInfoLen = (numSecs == 2)?
secs[1].sz :
0;
Uint32 keyInfoInReq = MIN(keyInfoLen, TcKeyReq::MaxKeyInfo);
Uint32 attrInfoInReq = MIN(attrInfoLen, TcKeyReq::MaxAttrInfo);
TcKeyReq* tcKeyReq = (TcKeyReq*) request->getDataPtrSend();
Uint32 connectPtr = tcKeyReq->apiConnectPtr;
Uint32 transId1 = tcKeyReq->transId1;
Uint32 transId2 = tcKeyReq->transId2;
bool indexReq = (request->theVerId_signalNumber == GSN_TCINDXREQ);
Uint32 reqLen = request->theLength;
/* Set TCKEYREQ flags */
TcKeyReq::setKeyLength(tcKeyReq->requestInfo, keyInfoLen);
TcKeyReq::setAIInTcKeyReq(tcKeyReq->requestInfo , attrInfoInReq);
TcKeyReq::setAttrinfoLen(tcKeyReq->attrLen, attrInfoLen);
Uint32* writePtr = request->getDataPtrSend() + reqLen;
GSIReader keyInfoReader(secs[0].sectionIter);
GSIReader attrInfoReader(secs[1].sectionIter);
keyInfoReader.copyNWords(writePtr, keyInfoInReq);
writePtr += keyInfoInReq;
attrInfoReader.copyNWords(writePtr, attrInfoInReq);
reqLen += keyInfoInReq + attrInfoInReq;
assert( reqLen <= TcKeyReq::SignalLength );
request->setLength(reqLen);
if (impl->sendSignal(request, aNodeId) == -1)
return -1;
keyInfoLen -= keyInfoInReq;
attrInfoLen -= attrInfoInReq;
if (keyInfoLen)
{
request->theVerId_signalNumber = indexReq ?
GSN_INDXKEYINFO : GSN_KEYINFO;
KeyInfo* keyInfo = (KeyInfo*) request->getDataPtrSend();
keyInfo->connectPtr = connectPtr;
keyInfo->transId[0] = transId1;
keyInfo->transId[1] = transId2;
while(keyInfoLen)
{
Uint32 dataWords = MIN(keyInfoLen, KeyInfo::DataLength);
keyInfoReader.copyNWords(&keyInfo->keyData[0], dataWords);
request->setLength(KeyInfo::HeaderLength + dataWords);
if (impl->sendSignal(request, aNodeId) == -1)
return -1;
keyInfoLen-= dataWords;
sigCount++;
}
}
if (attrInfoLen)
{
request->theVerId_signalNumber = indexReq ?
GSN_INDXATTRINFO : GSN_ATTRINFO;
AttrInfo* attrInfo = (AttrInfo*) request->getDataPtrSend();
attrInfo->connectPtr = connectPtr;
attrInfo->transId[0] = transId1;
attrInfo->transId[1] = transId2;
while(attrInfoLen)
{
Uint32 dataWords = MIN(attrInfoLen, AttrInfo::DataLength);
attrInfoReader.copyNWords(&attrInfo->attrData[0], dataWords);
request->setLength(AttrInfo::HeaderLength + dataWords);
if (impl->sendSignal(request, aNodeId) == -1)
return -1;
attrInfoLen-= dataWords;
sigCount++;
}
}
return sigCount;
}
}
/******************************************************************************
int doSend()
Return Value: Return >0 : send was succesful, returns number of signals sent
Return -1: In all other case.
Parameters: aProcessorId: Receiving processor node
Remark: Sends the TCKEYREQ signal and optional KEYINFO and ATTRINFO
signals.
******************************************************************************/
int
NdbOperation::doSend(int aNodeId, Uint32 lastFlag)
{
assert(theTCREQ != NULL);
setLastFlag(theTCREQ, lastFlag);
Uint32 numSecs= 1;
GenericSectionPtr secs[2];
if (m_attribute_record != NULL)
{
/*
* NdbRecord signal building code puts all KeyInfo and
* AttrInfo into the KeyInfo and AttrInfo signal lists.
*/
SignalSectionIterator keyInfoIter(theTCREQ->next());
SignalSectionIterator attrInfoIter(theFirstATTRINFO);
/* KeyInfo - always present for TCKEY/INDXREQ*/
secs[0].sz= theTupKeyLen;
secs[0].sectionIter= &keyInfoIter;
/* AttrInfo - not always needed (e.g. Delete) */
if (theTotalCurrAI_Len != 0)
{
secs[1].sz= theTotalCurrAI_Len;
secs[1].sectionIter= &attrInfoIter;
numSecs++;
}
if (doSendKeyReq(aNodeId, &secs[0], numSecs) == -1)
return -1;
}
else
{
/*
* Old Api signal building code puts first words of KeyInfo
* and AttrInfo into the initial request signal
* We use special iterators to extract this
*/
TcKeyReq* tcKeyReq= (TcKeyReq*) theTCREQ->getDataPtrSend();
const Uint32 inlineKIOffset= Uint32(tcKeyReq->keyInfo - (Uint32*)tcKeyReq);
const Uint32 inlineKILength= MIN(TcKeyReq::MaxKeyInfo,
theTupKeyLen);
const Uint32 inlineAIOffset = Uint32(tcKeyReq->attrInfo -(Uint32*)tcKeyReq);
const Uint32 inlineAILength= MIN(TcKeyReq::MaxAttrInfo,
theTotalCurrAI_Len);
/* Create iterators which use the signal train to extract
* long sections from the short signal trains
*/
OldNdbApiSectionIterator keyInfoIter(theTCREQ,
inlineKIOffset,
inlineKILength,
theTCREQ->next());
OldNdbApiSectionIterator attrInfoIter(theTCREQ,
inlineAIOffset,
inlineAILength,
theFirstATTRINFO);
/* KeyInfo - always present for TCKEY/INDXREQ */
secs[0].sz= theTupKeyLen;
secs[0].sectionIter= &keyInfoIter;
/* AttrInfo - not always needed (e.g. Delete) */
if (theTotalCurrAI_Len != 0)
{
secs[1].sz= theTotalCurrAI_Len;
secs[1].sectionIter= &attrInfoIter;
numSecs++;
}
if (doSendKeyReq(aNodeId, &secs[0], numSecs) == -1)
return -1;
}
/* Todo : Consider calling NdbOperation::postExecuteRelease()
* Ideally it should be called outside TP mutex, so not added
* here yet
*/
theNdbCon->OpSent();
return 1;
}//NdbOperation::doSend()
int
NdbOperation::prepareGetLockHandle()
{
/* Read LOCK_REF pseudo column */
assert(! theLockHandle->isLockRefValid() );
theLockHandle->m_table = m_currentTable;
/* Add read of TC_LOCKREF pseudo column */
NdbRecAttr* ra = getValue(NdbDictionary::Column::LOCK_REF,
(char*) &theLockHandle->m_lockRef);
if (!ra)
{
/* Assume error code set */
return -1;
}
theLockHandle->m_state = NdbLockHandle::PREPARED;
/* Count Blob handles associated with this operation
* for LockHandle open Blob handles ref count
*/
NdbBlob* blobHandle = theBlobList;
while (blobHandle != NULL)
{
theLockHandle->m_openBlobCount ++;
blobHandle = blobHandle->theNext;
}
return 0;
}
/***************************************************************************
int prepareSend(Uint32 aTC_ConnectPtr,
Uint64 aTransactionId)
Return Value: Return 0 : preparation of send was succesful.
Return -1: In all other case.
Parameters: aTC_ConnectPtr: the Connect pointer to TC.
aTransactionId: the Transaction identity of the transaction.
Remark: Puts the the data into TCKEYREQ signal and optional KEYINFO and ATTRINFO signals.
***************************************************************************/
int
NdbOperation::prepareSend(Uint32 aTC_ConnectPtr,
Uint64 aTransId,
AbortOption ao)
{
Uint32 tTransId1, tTransId2;
Uint32 tReqInfo;
Uint8 tInterpretInd = theInterpretIndicator;
Uint8 tDirtyIndicator = theDirtyIndicator;
Uint32 tTotalCurrAI_Len = theTotalCurrAI_Len;
theErrorLine = 0;
if (tInterpretInd != 1) {
OperationType tOpType = theOperationType;
OperationStatus tStatus = theStatus;
if ((tOpType == UpdateRequest) ||
(tOpType == InsertRequest) ||
(tOpType == WriteRequest)) {
if (tStatus != SetValue) {
setErrorCodeAbort(4116);
return -1;
}//if
} else if ((tOpType == ReadRequest) || (tOpType == ReadExclusive) ||
(tOpType == DeleteRequest)) {
if (tStatus != GetValue) {
setErrorCodeAbort(4116);
return -1;
}
else if(unlikely(tDirtyIndicator && tTotalCurrAI_Len == 0))
{
getValue(NdbDictionary::Column::FRAGMENT);
tTotalCurrAI_Len = theTotalCurrAI_Len;
assert(theTotalCurrAI_Len);
}
else if (tOpType != DeleteRequest)
{
assert(tOpType == ReadRequest || tOpType == ReadExclusive);
if (theLockHandle)
{
/* Take steps to read LockHandle info as part of read */
if (prepareGetLockHandle() != 0)
return -1;
tTotalCurrAI_Len = theTotalCurrAI_Len;
}
tTotalCurrAI_Len = repack_read(tTotalCurrAI_Len);
}
} else {
setErrorCodeAbort(4005);
return -1;
}//if
} else {
if (prepareSendInterpreted() == -1) {
return -1;
}//if
tTotalCurrAI_Len = theTotalCurrAI_Len;
}//if
//-------------------------------------------------------------
// We start by filling in the first 9 unconditional words of the
// TCKEYREQ signal.
//-------------------------------------------------------------
TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
Uint32 tTableId = m_accessTable->m_id;
Uint32 tSchemaVersion = m_accessTable->m_version;
tcKeyReq->apiConnectPtr = aTC_ConnectPtr;
tcKeyReq->apiOperationPtr = ptr2int();
// Check if too much attrinfo have been defined
if (tTotalCurrAI_Len > TcKeyReq::MaxTotalAttrInfo){
setErrorCodeAbort(4257);
return -1;
}
Uint32 TattrLen = 0;
tcKeyReq->setAttrinfoLen(TattrLen, 0); // Not required for long signals.
tcKeyReq->setAPIVersion(TattrLen, NDB_VERSION);
tcKeyReq->attrLen = TattrLen;
tcKeyReq->tableId = tTableId;
tcKeyReq->tableSchemaVersion = tSchemaVersion;
tTransId1 = (Uint32) aTransId;
tTransId2 = (Uint32) (aTransId >> 32);
Uint8 tSimpleIndicator = theSimpleIndicator;
Uint8 tCommitIndicator = theCommitIndicator;
Uint8 tStartIndicator = theStartIndicator;
Uint8 tInterpretIndicator = theInterpretIndicator;
Uint8 tNoDisk = (m_flags & OF_NO_DISK) != 0;
Uint8 tQueable = (m_flags & OF_QUEUEABLE) != 0;
Uint8 tDeferred = (m_flags & OF_DEFERRED_CONSTRAINTS) != 0;
/**
* A dirty read, can not abort the transaction
*/
Uint8 tReadInd = (theOperationType == ReadRequest);
Uint8 tDirtyState = tReadInd & tDirtyIndicator;
tcKeyReq->transId1 = tTransId1;
tcKeyReq->transId2 = tTransId2;
tReqInfo = 0;
tcKeyReq->setAIInTcKeyReq(tReqInfo, 0); // Not needed
tcKeyReq->setSimpleFlag(tReqInfo, tSimpleIndicator);
tcKeyReq->setCommitFlag(tReqInfo, tCommitIndicator);
tcKeyReq->setStartFlag(tReqInfo, tStartIndicator);
tcKeyReq->setInterpretedFlag(tReqInfo, tInterpretIndicator);
tcKeyReq->setNoDiskFlag(tReqInfo, tNoDisk);
tcKeyReq->setQueueOnRedoProblemFlag(tReqInfo, tQueable);
tcKeyReq->setDeferredConstraints(tReqInfo, tDeferred);
OperationType tOperationType = theOperationType;
Uint8 abortOption = (ao == DefaultAbortOption) ? (Uint8) m_abortOption : (Uint8) ao;
tcKeyReq->setDirtyFlag(tReqInfo, tDirtyIndicator);
tcKeyReq->setOperationType(tReqInfo, tOperationType);
tcKeyReq->setKeyLength(tReqInfo, 0); // Not needed
tcKeyReq->setViaSPJFlag(tReqInfo, 0);
// A dirty read is always ignore error
abortOption = tDirtyState ? (Uint8) AO_IgnoreError : (Uint8) abortOption;
tcKeyReq->setAbortOption(tReqInfo, abortOption);
m_abortOption = abortOption;
Uint8 tDistrKeyIndicator = theDistrKeyIndicator_;
Uint8 tScanIndicator = theScanInfo & 1;
tcKeyReq->setDistributionKeyFlag(tReqInfo, tDistrKeyIndicator);
tcKeyReq->setScanIndFlag(tReqInfo, tScanIndicator);
tcKeyReq->requestInfo = tReqInfo;
//-------------------------------------------------------------
// The next step is to fill in the upto three conditional words.
//-------------------------------------------------------------
Uint32* tOptionalDataPtr = &tcKeyReq->scanInfo;
Uint32 tDistrGHIndex = tScanIndicator;
Uint32 tDistrKeyIndex = tDistrGHIndex;
Uint32 tScanInfo = theScanInfo;
Uint32 tDistrKey = theDistributionKey;
tOptionalDataPtr[0] = tScanInfo;
tOptionalDataPtr[tDistrKeyIndex] = tDistrKey;
theTCREQ->setLength(TcKeyReq::StaticLength +
tDistrKeyIndex + // 1 for scan info present
theDistrKeyIndicator_); // 1 for distr key present
/* Ensure the signal objects have the correct length
* information
*/
if (theTupKeyLen > TcKeyReq::MaxKeyInfo) {
/**
* Set correct length on last KeyInfo signal
*/
if (theLastKEYINFO == NULL)
theLastKEYINFO= theTCREQ->next();
assert(theLastKEYINFO != NULL);
Uint32 lastKeyInfoLen= ((theTupKeyLen - TcKeyReq::MaxKeyInfo)
% KeyInfo::DataLength);
theLastKEYINFO->setLength(lastKeyInfoLen ?
KeyInfo::HeaderLength + lastKeyInfoLen :
KeyInfo::MaxSignalLength);
}
/* Set the length on the last AttrInfo signal */
if (tTotalCurrAI_Len > TcKeyReq::MaxAttrInfo) {
// Set the last signal's length.
theCurrentATTRINFO->setLength(theAI_LenInCurrAI);
}//if
theTotalCurrAI_Len= tTotalCurrAI_Len;
theStatus = WaitResponse;
theReceiver.prepareSend();
return 0;
}//NdbOperation::prepareSend()
Uint32
NdbOperation::repack_read(Uint32 len)
{
Uint32 i;
Uint32 check = 0, prevId = 0;
Uint32 save = len;
Bitmask<MAXNROFATTRIBUTESINWORDS> mask;
NdbApiSignal *tSignal = theFirstATTRINFO;
TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
Uint32 cols = m_currentTable->m_columns.size();
Uint32 *ptr = tcKeyReq->attrInfo;
for (i = 0; len && i < 5; i++, len--)
{
AttributeHeader tmp(* ptr++);
Uint32 id = tmp.getAttributeId();
if (((i > 0) && // No prevId for first attrId
(id <= prevId)) ||
(id >= NDB_MAX_ATTRIBUTES_IN_TABLE))
{
// AttrIds not strictly ascending with no duplicates
// and no pseudo-columns == fallback
return save;
}
prevId = id;
mask.set(id);
}
Uint32 cnt = 0;
while (len)
{
cnt++;
assert(tSignal);
ptr = tSignal->getDataPtrSend() + AttrInfo::HeaderLength;
for (i = 0; len && i<AttrInfo::DataLength; i++, len--)
{
AttributeHeader tmp(* ptr++);
Uint32 id = tmp.getAttributeId();
if ((id <= prevId) ||
(id >= NDB_MAX_ATTRIBUTES_IN_TABLE))
{
// AttrIds not strictly ascending with no duplicates
// and no pseudo-columns == fallback
return save;
}
prevId = id;
mask.set(id);
}
tSignal = tSignal->next();
}
const Uint32 newlen = 1 + (prevId >> 5);
const bool all = cols == save;
if (check == 0)
{
/* AttrInfos are in ascending order, ok to use READ_ALL
* or READ_PACKED
* (Correct NdbRecAttrs will be used when data is received)
*/
if (all == false && ((1 + newlen) > TcKeyReq::MaxAttrInfo))
{
return save;
}
theNdb->releaseSignals(cnt, theFirstATTRINFO, theCurrentATTRINFO);
theFirstATTRINFO = 0;
theCurrentATTRINFO = 0;
ptr = tcKeyReq->attrInfo;
if (all)
{
AttributeHeader::init(ptr, AttributeHeader::READ_ALL, cols);
return 1;
}
else
{
AttributeHeader::init(ptr, AttributeHeader::READ_PACKED, 4*newlen);
memcpy(ptr + 1, &mask, 4*newlen);
return 1+newlen;
}
}
return save;
}
/***************************************************************************
int prepareSendInterpreted()
Make preparations to send an interpreted operation.
Return Value: Return 0 : succesful.
Return -1: In all other case.
***************************************************************************/
int
NdbOperation::prepareSendInterpreted()
{
Uint32 tTotalCurrAI_Len = theTotalCurrAI_Len;
Uint32 tInitReadSize = theInitialReadSize;
assert (theStatus != UseNdbRecord); // Should never get here for NdbRecord.
if (theStatus == ExecInterpretedValue) {
if (insertATTRINFO(Interpreter::EXIT_OK) != -1) {
//-------------------------------------------------------------------------
// Since we read the total length before inserting the last entry in the
// signals we need to add one to the total length.
//-------------------------------------------------------------------------
theInterpretedSize = (tTotalCurrAI_Len + 1) -
(tInitReadSize + AttrInfo::SectionSizeInfoLength);
} else {
return -1;
}//if
} else if (theStatus == FinalGetValue) {
theFinalReadSize = tTotalCurrAI_Len -
(tInitReadSize + theInterpretedSize + theFinalUpdateSize
+ AttrInfo::SectionSizeInfoLength);
} else if (theStatus == SetValueInterpreted) {
theFinalUpdateSize = tTotalCurrAI_Len -
(tInitReadSize + theInterpretedSize
+ AttrInfo::SectionSizeInfoLength);
} else if (theStatus == SubroutineEnd) {
theSubroutineSize = tTotalCurrAI_Len -
(tInitReadSize + theInterpretedSize +
theFinalUpdateSize + theFinalReadSize
+ AttrInfo::SectionSizeInfoLength);
} else if (theStatus == GetValue) {
theInitialReadSize = tTotalCurrAI_Len - AttrInfo::SectionSizeInfoLength;
} else {
setErrorCodeAbort(4116);
return -1;
}
/*
Fix jumps by patching in the correct address for the corresponding label.
*/
while (theFirstBranch != NULL) {
Uint32 tRelAddress;
Uint32 tLabelAddress = 0;
int tAddress = -1;
NdbBranch* tNdbBranch = theFirstBranch;
Uint32 tBranchLabel = tNdbBranch->theBranchLabel;
NdbLabel* tNdbLabel = theFirstLabel;
if (tBranchLabel >= theNoOfLabels) {
setErrorCodeAbort(4221);
return -1;
}//if
// Find the label address
while (tNdbLabel != NULL) {
for(tLabelAddress = 0; tLabelAddress<16; tLabelAddress++){
const Uint32 labelNo = tNdbLabel->theLabelNo[tLabelAddress];
if(tBranchLabel == labelNo){
tAddress = tNdbLabel->theLabelAddress[tLabelAddress];
break;
}
}
if(tAddress != -1)
break;
tNdbLabel = tNdbLabel->theNext;
}//while
if (tAddress == -1) {
//-------------------------------------------------------------------------
// We were unable to find any label which the branch refers to. This means
// that the application have not programmed the interpreter program correctly.
//-------------------------------------------------------------------------
setErrorCodeAbort(4222);
return -1;
}//if
if (tNdbLabel->theSubroutine[tLabelAddress] != tNdbBranch->theSubroutine) {
setErrorCodeAbort(4224);
return -1;
}//if
// Now it is time to update the signal data with the relative branch jump.
if (tAddress < int(tNdbBranch->theBranchAddress)) {
tRelAddress = (tNdbBranch->theBranchAddress - tAddress) << 16;
// Indicate backward jump direction
tRelAddress = tRelAddress + (1 << 31);
} else if (tAddress > int(tNdbBranch->theBranchAddress)) {
tRelAddress = (tAddress - tNdbBranch->theBranchAddress) << 16;
} else {
setErrorCodeAbort(4223);
return -1;
}//if
NdbApiSignal* tSignal = tNdbBranch->theSignal;
Uint32 tReadData = tSignal->readData(tNdbBranch->theSignalAddress);
tSignal->setData((tRelAddress + tReadData), tNdbBranch->theSignalAddress);
theFirstBranch = theFirstBranch->theNext;
theNdb->releaseNdbBranch(tNdbBranch);
}//while
while (theFirstCall != NULL) {
Uint32 tSubroutineCount = 0;
int tAddress = -1;
NdbSubroutine* tNdbSubroutine;
NdbCall* tNdbCall = theFirstCall;
if (tNdbCall->theSubroutine >= theNoOfSubroutines) {
setErrorCodeAbort(4221);
return -1;
}//if
// Find the subroutine address
tNdbSubroutine = theFirstSubroutine;
while (tNdbSubroutine != NULL) {
tSubroutineCount += 16;
if (tNdbCall->theSubroutine < tSubroutineCount) {
// Subroutine Found
Uint32 tSubroutineAddress = tNdbCall->theSubroutine - (tSubroutineCount - 16);
tAddress = tNdbSubroutine->theSubroutineAddress[tSubroutineAddress];
break;
}//if
tNdbSubroutine = tNdbSubroutine->theNext;
}//while
if (tAddress == -1) {
setErrorCodeAbort(4222);
return -1;
}//if
// Now it is time to update the signal data with the relative branch jump.
NdbApiSignal* tSignal = tNdbCall->theSignal;
Uint32 tReadData = tSignal->readData(tNdbCall->theSignalAddress);
tSignal->setData(((tAddress << 16) + (tReadData & 0xffff)),
tNdbCall->theSignalAddress);
theFirstCall = theFirstCall->theNext;
theNdb->releaseNdbCall(tNdbCall);
}//while
Uint32 tInitialReadSize = theInitialReadSize;
Uint32 tInterpretedSize = theInterpretedSize;
Uint32 tFinalUpdateSize = theFinalUpdateSize;
Uint32 tFinalReadSize = theFinalReadSize;
Uint32 tSubroutineSize = theSubroutineSize;
if (theOperationType != OpenScanRequest &&
theOperationType != OpenRangeScanRequest) {
TcKeyReq * const tcKeyReq = CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
tcKeyReq->attrInfo[0] = tInitialReadSize;
tcKeyReq->attrInfo[1] = tInterpretedSize;
tcKeyReq->attrInfo[2] = tFinalUpdateSize;
tcKeyReq->attrInfo[3] = tFinalReadSize;
tcKeyReq->attrInfo[4] = tSubroutineSize;
} else {
// If a scan is defined we use the first ATTRINFO instead of TCKEYREQ.
theFirstATTRINFO->setData(tInitialReadSize, 4);
theFirstATTRINFO->setData(tInterpretedSize, 5);
theFirstATTRINFO->setData(tFinalUpdateSize, 6);
theFirstATTRINFO->setData(tFinalReadSize, 7);
theFirstATTRINFO->setData(tSubroutineSize, 8);
}//if
theReceiver.prepareSend();
return 0;
}//NdbOperation::prepareSendInterpreted()
/*
Prepares TCKEYREQ and (if needed) KEYINFO and ATTRINFO signals for
operations using the NdbRecord API
Executed when the operation is defined for both PK, Unique index
and scan takeover operations.
@returns 0 for success
*/
int
NdbOperation::buildSignalsNdbRecord(Uint32 aTC_ConnectPtr,
Uint64 aTransId,
const Uint32 * m_read_mask)
{
char buf[NdbRecord::Attr::SHRINK_VARCHAR_BUFFSIZE];
int res;
Uint32 no_disk_flag;
Uint32 *attrinfo_section_sizes_ptr= NULL;
assert(theStatus==UseNdbRecord);
/* Interpreted operations not supported with NdbRecord
* use NdbInterpretedCode instead
*/
assert(!theInterpretIndicator);
const NdbRecord *key_rec= m_key_record;
const char *key_row= m_key_row;
const NdbRecord *attr_rec= m_attribute_record;
const char *updRow;
const bool isScanTakeover= (key_rec == NULL);
const bool isUnlock = (theOperationType == UnlockRequest);
TcKeyReq *tcKeyReq= CAST_PTR(TcKeyReq, theTCREQ->getDataPtrSend());
Uint32 hdrSize= fillTcKeyReqHdr(tcKeyReq, aTC_ConnectPtr, aTransId);
/* No KeyInfo goes in the TCKEYREQ signal - it all goes into
* a separate KeyInfo section
*/
assert(theTCREQ->next() == NULL);
theKEYINFOptr= NULL;
keyInfoRemain= 0;
/* Fill in keyinfo */
if (isScanTakeover)
{
/* This means that key_row contains the KEYINFO20 data. */
/* i.e. lock takeover */
tcKeyReq->tableId= attr_rec->tableId;
tcKeyReq->tableSchemaVersion= attr_rec->tableVersion;
res= insertKEYINFO_NdbRecord(key_row, m_keyinfo_length*4);
if (res)
return res;
}
else if (!isUnlock)
{
/* Normal PK / unique index read */
tcKeyReq->tableId= key_rec->tableId;
tcKeyReq->tableSchemaVersion= key_rec->tableVersion;
theTotalNrOfKeyWordInSignal= 0;
for (Uint32 i= 0; i<key_rec->key_index_length; i++)
{
const NdbRecord::Attr *col;
col= &key_rec->columns[key_rec->key_indexes[i]];
/*
A unique index can index a nullable column (the primary key index
cannot). So we can get NULL here (but it is an error if we do).
*/
if (col->is_null(key_row))
{
setErrorCodeAbort(4316);
return -1;
}
Uint32 length=0;
bool len_ok;
const char *src;
if (col->flags & NdbRecord::IsMysqldShrinkVarchar)
{
/* Used to support special varchar format for mysqld keys. */
len_ok= col->shrink_varchar(key_row, length, buf);
src= buf;
}
else
{
len_ok= col->get_var_length(key_row, length);
src= &key_row[col->offset];
}
if (!len_ok)
{
/* Hm, corrupt varchar length. */
setErrorCodeAbort(4209);
return -1;
}
res= insertKEYINFO_NdbRecord(src, length);
if (res)
return res;
}
}
else
{
assert(isUnlock);
assert(theLockHandle);
assert(attr_rec);
assert(theLockHandle->isLockRefValid());
tcKeyReq->tableId= attr_rec->tableId;
tcKeyReq->tableSchemaVersion= attr_rec->tableVersion;
/* Copy key data from NdbLockHandle */
Uint32 keyInfoWords = 0;
const Uint32* keyInfoSrc = theLockHandle->getKeyInfoWords(keyInfoWords);
assert( keyInfoWords );
res = insertKEYINFO_NdbRecord((const char*)keyInfoSrc,
keyInfoWords << 2);
if (res)
return res;
}
/* For long TCKEYREQ, we don't need to set the key length in the
* header, as it is passed as the length of the KeyInfo section
*/
/* Fill in attrinfo
* If ATTRINFO includes interpreted code then the first 5 words are
* length information for 5 sections.
* If there is no interpreted code then there's only one section, and
* no length information
*/
/* All ATTRINFO goes into a separate ATTRINFO section - none is placed
* into the TCKEYREQ signal
*/
assert(theFirstATTRINFO == NULL);
attrInfoRemain= 0;
theATTRINFOptr= NULL;
no_disk_flag = (m_flags & OF_NO_DISK) != 0;
/* If we have an interpreted program then we add 5 words
* of section length information at the start of the
* ATTRINFO
*/
const NdbInterpretedCode *code= m_interpreted_code;
if (code)
{
if (code->m_flags & NdbInterpretedCode::UsesDisk)
no_disk_flag = 0;
/* Need to add section lengths info to the signal */
Uint32 sizes[AttrInfo::SectionSizeInfoLength];
sizes[0] = 0; // Initial read.
sizes[1] = 0; // Interpreted program
sizes[2] = 0; // Final update size.
sizes[3] = 0; // Final read size
sizes[4] = 0; // Subroutine size
res = insertATTRINFOData_NdbRecord((const char *)sizes,
sizeof(sizes));
if (res)
return res;
/* So that we can go back to set the actual sizes later... */
attrinfo_section_sizes_ptr= (theATTRINFOptr -
AttrInfo::SectionSizeInfoLength);
}
OperationType tOpType= theOperationType;
/* Initial read signal words */
if (tOpType == ReadRequest || tOpType == ReadExclusive ||
(tOpType == DeleteRequest &&