forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdbEventOperationImpl.cpp
More file actions
3675 lines (3262 loc) · 95.7 KB
/
NdbEventOperationImpl.cpp
File metadata and controls
3675 lines (3262 loc) · 95.7 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, 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 <ndb_global.h>
#include <kernel_types.h>
#include "API.hpp"
#include <NdbOut.hpp>
#include <signaldata/CreateEvnt.hpp>
#include <signaldata/SumaImpl.hpp>
#include <SimpleProperties.hpp>
#include <Bitmask.hpp>
#include <AttributeHeader.hpp>
#include <AttributeList.hpp>
#include <NdbError.hpp>
#include <BaseString.hpp>
#include <UtilBuffer.hpp>
#include <portlib/NdbMem.h>
#include <signaldata/AlterTable.hpp>
#include "ndb_internal.hpp"
#include <EventLogger.hpp>
extern EventLogger * g_eventLogger;
#define TOTAL_BUCKETS_INIT (1 << 15)
static Gci_container_pod g_empty_gci_container;
#if defined(VM_TRACE) && defined(NOT_USED)
static void
print_std(const SubTableData * sdata, LinearSectionPtr ptr[3])
{
printf("addr=%p gci{hi/lo}hi=%u/%u op=%d\n", (void*)sdata,
sdata->gci_hi, sdata->gci_lo,
SubTableData::getOperation(sdata->requestInfo));
for (int i = 0; i <= 2; i++) {
printf("sec=%d addr=%p sz=%d\n", i, (void*)ptr[i].p, ptr[i].sz);
for (int j = 0; (uint) j < ptr[i].sz; j++)
printf("%08x ", ptr[i].p[j]);
printf("\n");
}
}
#endif
// EventBufData
void
EventBufData::add_part_size(Uint32 & full_count, Uint32 & full_sz) const
{
Uint32 tmp_count = 0;
Uint32 tmp_sz = 0;
const EventBufData* data2 = m_next_blob;
while (data2 != 0) {
tmp_count++;
tmp_sz += data2->sz;
const EventBufData* data3 = data2->m_next;
while (data3 != 0) {
tmp_count++;
tmp_sz += data3->sz;
data3 = data3->m_next;
}
data2 = data2->m_next_blob;
}
full_count += tmp_count;
full_sz += tmp_sz;
}
/*
* Class NdbEventOperationImpl
*
*
*/
// todo handle several ndb objects
// todo free allocated data when closing NdbEventBuffer
NdbEventOperationImpl::NdbEventOperationImpl(NdbEventOperation &f,
Ndb *theNdb,
const char* eventName) :
NdbEventOperation(*this),
m_facade(&f),
m_ndb(theNdb),
m_state(EO_ERROR),
m_oid(~(Uint32)0)
{
DBUG_ENTER("NdbEventOperationImpl::NdbEventOperationImpl");
assert(m_ndb != NULL);
NdbDictionary::Dictionary *myDict = m_ndb->getDictionary();
assert(myDict != NULL);
const NdbDictionary::Event *myEvnt = myDict->getEvent(eventName);
if (!myEvnt)
{
m_error.code= myDict->getNdbError().code;
DBUG_VOID_RETURN;
}
init(myEvnt->m_impl);
DBUG_VOID_RETURN;
}
NdbEventOperationImpl::NdbEventOperationImpl(Ndb *theNdb,
NdbEventImpl& evnt) :
NdbEventOperation(*this),
m_facade(this),
m_ndb(theNdb),
m_state(EO_ERROR),
m_oid(~(Uint32)0)
{
DBUG_ENTER("NdbEventOperationImpl::NdbEventOperationImpl [evnt]");
init(evnt);
DBUG_VOID_RETURN;
}
void
NdbEventOperationImpl::init(NdbEventImpl& evnt)
{
DBUG_ENTER("NdbEventOperationImpl::init");
m_magic_number = 0;
mi_type = 0;
m_change_mask = 0;
#ifdef VM_TRACE
m_data_done_count = 0;
m_data_count = 0;
#endif
m_next = 0;
m_prev = 0;
m_eventId = 0;
theFirstPkAttrs[0] = NULL;
theCurrentPkAttrs[0] = NULL;
theFirstPkAttrs[1] = NULL;
theCurrentPkAttrs[1] = NULL;
theFirstDataAttrs[0] = NULL;
theCurrentDataAttrs[0] = NULL;
theFirstDataAttrs[1] = NULL;
theCurrentDataAttrs[1] = NULL;
theBlobList = NULL;
theBlobOpList = NULL;
theMainOp = NULL;
theBlobVersion = 0;
m_data_item= NULL;
m_eventImpl = NULL;
m_custom_data= 0;
m_has_error= 1;
// we should lookup id in Dictionary, TODO
// also make sure we only have one listener on each event
m_eventImpl = &evnt;
m_eventId = m_eventImpl->m_eventId;
m_oid= m_ndb->theImpl->theNdbObjectIdMap.map(this);
m_state= EO_CREATED;
m_stop_gci = 0;
#ifdef ndb_event_stores_merge_events_flag
m_mergeEvents = m_eventImpl->m_mergeEvents;
#else
m_mergeEvents = false;
#endif
m_ref_count = 0;
DBUG_PRINT("info", ("m_ref_count = 0 for op: 0x%lx", (long) this));
m_has_error= 0;
DBUG_PRINT("exit",("this: 0x%lx oid: %u", (long) this, m_oid));
DBUG_VOID_RETURN;
}
NdbEventOperationImpl::~NdbEventOperationImpl()
{
DBUG_ENTER("NdbEventOperationImpl::~NdbEventOperationImpl");
m_magic_number= 0;
if (m_oid == ~(Uint32)0)
DBUG_VOID_RETURN;
stop();
if (theMainOp == NULL)
{
NdbEventOperationImpl* tBlobOp = theBlobOpList;
while (tBlobOp != NULL)
{
NdbEventOperationImpl *op = tBlobOp;
tBlobOp = tBlobOp->m_next;
delete op;
}
}
m_ndb->theImpl->theNdbObjectIdMap.unmap(m_oid, this);
DBUG_PRINT("exit",("this: %p/%p oid: %u main: %p",
this, m_facade, m_oid, theMainOp));
if (m_eventImpl)
{
delete m_eventImpl->m_facade;
m_eventImpl= 0;
}
DBUG_VOID_RETURN;
}
NdbEventOperation::State
NdbEventOperationImpl::getState()
{
return m_state;
}
NdbRecAttr*
NdbEventOperationImpl::getValue(const char *colName, char *aValue, int n)
{
DBUG_ENTER("NdbEventOperationImpl::getValue");
if (m_state != EO_CREATED) {
ndbout_c("NdbEventOperationImpl::getValue may only be called between "
"instantiation and execute()");
DBUG_RETURN(NULL);
}
NdbColumnImpl *tAttrInfo = m_eventImpl->m_tableImpl->getColumn(colName);
if (tAttrInfo == NULL) {
ndbout_c("NdbEventOperationImpl::getValue attribute %s not found",colName);
DBUG_RETURN(NULL);
}
DBUG_RETURN(NdbEventOperationImpl::getValue(tAttrInfo, aValue, n));
}
NdbRecAttr*
NdbEventOperationImpl::getValue(const NdbColumnImpl *tAttrInfo, char *aValue, int n)
{
DBUG_ENTER("NdbEventOperationImpl::getValue");
// Insert Attribute Id into ATTRINFO part.
NdbRecAttr **theFirstAttr;
NdbRecAttr **theCurrentAttr;
if (tAttrInfo->getPrimaryKey())
{
theFirstAttr = &theFirstPkAttrs[n];
theCurrentAttr = &theCurrentPkAttrs[n];
}
else
{
theFirstAttr = &theFirstDataAttrs[n];
theCurrentAttr = &theCurrentDataAttrs[n];
}
/************************************************************************
* Get a Receive Attribute object and link it into the operation object.
************************************************************************/
NdbRecAttr *tAttr = m_ndb->getRecAttr();
if (tAttr == NULL) {
exit(-1);
//setErrorCodeAbort(4000);
DBUG_RETURN(NULL);
}
/**********************************************************************
* Now set the attribute identity and the pointer to the data in
* the RecAttr object
* Also set attribute size, array size and attribute type
********************************************************************/
if (tAttr->setup(tAttrInfo, aValue)) {
//setErrorCodeAbort(4000);
m_ndb->releaseRecAttr(tAttr);
exit(-1);
DBUG_RETURN(NULL);
}
//theErrorLine++;
tAttr->setUNDEFINED();
// We want to keep the list sorted to make data insertion easier later
if (*theFirstAttr == NULL) {
*theFirstAttr = tAttr;
*theCurrentAttr = tAttr;
tAttr->next(NULL);
} else {
Uint32 tAttrId = tAttrInfo->m_attrId;
if (tAttrId > (*theCurrentAttr)->attrId()) { // right order
(*theCurrentAttr)->next(tAttr);
tAttr->next(NULL);
*theCurrentAttr = tAttr;
} else if ((*theFirstAttr)->next() == NULL || // only one in list
(*theFirstAttr)->attrId() > tAttrId) {// or first
tAttr->next(*theFirstAttr);
*theFirstAttr = tAttr;
} else { // at least 2 in list and not first and not last
NdbRecAttr *p = *theFirstAttr;
NdbRecAttr *p_next = p->next();
while (tAttrId > p_next->attrId()) {
p = p_next;
p_next = p->next();
}
if (tAttrId == p_next->attrId()) { // Using same attribute twice
tAttr->release(); // do I need to do this?
m_ndb->releaseRecAttr(tAttr);
exit(-1);
DBUG_RETURN(NULL);
}
// this is it, between p and p_next
p->next(tAttr);
tAttr->next(p_next);
}
}
DBUG_RETURN(tAttr);
}
NdbBlob*
NdbEventOperationImpl::getBlobHandle(const char *colName, int n)
{
DBUG_ENTER("NdbEventOperationImpl::getBlobHandle (colName)");
assert(m_mergeEvents);
if (m_state != EO_CREATED) {
ndbout_c("NdbEventOperationImpl::getBlobHandle may only be called between "
"instantiation and execute()");
DBUG_RETURN(NULL);
}
NdbColumnImpl *tAttrInfo = m_eventImpl->m_tableImpl->getColumn(colName);
if (tAttrInfo == NULL) {
ndbout_c("NdbEventOperationImpl::getBlobHandle attribute %s not found",colName);
DBUG_RETURN(NULL);
}
NdbBlob* bh = getBlobHandle(tAttrInfo, n);
DBUG_RETURN(bh);
}
NdbBlob*
NdbEventOperationImpl::getBlobHandle(const NdbColumnImpl *tAttrInfo, int n)
{
DBUG_ENTER("NdbEventOperationImpl::getBlobHandle");
DBUG_PRINT("info", ("attr=%s post/pre=%d", tAttrInfo->m_name.c_str(), n));
// as in NdbOperation, create only one instance
NdbBlob* tBlob = theBlobList;
NdbBlob* tLastBlob = NULL;
while (tBlob != NULL) {
if (tBlob->theColumn == tAttrInfo && tBlob->theEventBlobVersion == n)
DBUG_RETURN(tBlob);
tLastBlob = tBlob;
tBlob = tBlob->theNext;
}
NdbEventOperationImpl* tBlobOp = NULL;
const bool is_tinyblob = (tAttrInfo->getPartSize() == 0);
assert(is_tinyblob == (tAttrInfo->m_blobTable == NULL));
if (! is_tinyblob) {
// blob event name
char bename[MAX_TAB_NAME_SIZE];
NdbBlob::getBlobEventName(bename, m_eventImpl, tAttrInfo);
// find blob event op if any (it serves both post and pre handles)
tBlobOp = theBlobOpList;
NdbEventOperationImpl* tLastBlopOp = NULL;
while (tBlobOp != NULL) {
if (strcmp(tBlobOp->m_eventImpl->m_name.c_str(), bename) == 0) {
break;
}
tLastBlopOp = tBlobOp;
tBlobOp = tBlobOp->m_next;
}
DBUG_PRINT("info", ("%s blob event op for %s",
tBlobOp ? " reuse" : " create", bename));
// create blob event op if not found
if (tBlobOp == NULL) {
// get blob event
NdbDictionaryImpl& dict =
NdbDictionaryImpl::getImpl(*m_ndb->getDictionary());
NdbEventImpl* blobEvnt =
dict.getBlobEvent(*this->m_eventImpl, tAttrInfo->m_column_no);
if (blobEvnt == NULL) {
m_error.code = dict.m_error.code;
DBUG_RETURN(NULL);
}
// create blob event operation
tBlobOp =
m_ndb->theEventBuffer->createEventOperationImpl(*blobEvnt, m_error);
if (tBlobOp == NULL)
DBUG_RETURN(NULL);
// pointer to main table op
tBlobOp->theMainOp = this;
tBlobOp->m_mergeEvents = m_mergeEvents;
tBlobOp->theBlobVersion = tAttrInfo->m_blobVersion;
// to hide blob op it is linked under main op, not under m_ndb
if (tLastBlopOp == NULL)
theBlobOpList = tBlobOp;
else
tLastBlopOp->m_next = tBlobOp;
tBlobOp->m_next = NULL;
}
}
tBlob = m_ndb->getNdbBlob();
if (tBlob == NULL) {
m_error.code = m_ndb->getNdbError().code;
DBUG_RETURN(NULL);
}
// calls getValue on inline and blob part
if (tBlob->atPrepare(this, tBlobOp, tAttrInfo, n) == -1) {
m_error.code = tBlob->getNdbError().code;
m_ndb->releaseNdbBlob(tBlob);
DBUG_RETURN(NULL);
}
// add to list end
if (tLastBlob == NULL)
theBlobList = tBlob;
else
tLastBlob->theNext = tBlob;
tBlob->theNext = NULL;
DBUG_RETURN(tBlob);
}
Uint32
NdbEventOperationImpl::get_blob_part_no(bool hasDist)
{
assert(theBlobVersion == 1 || theBlobVersion == 2);
assert(theMainOp != NULL);
const NdbTableImpl* mainTable = theMainOp->m_eventImpl->m_tableImpl;
assert(m_data_item != NULL);
LinearSectionPtr (&ptr)[3] = m_data_item->ptr;
uint pos = 0; // PK and possibly DIST to skip
if (unlikely(theBlobVersion == 1)) {
pos += AttributeHeader(ptr[0].p[0]).getDataSize();
assert(hasDist);
pos += AttributeHeader(ptr[0].p[1]).getDataSize();
} else {
uint n = mainTable->m_noOfKeys;
uint i;
for (i = 0; i < n; i++) {
pos += AttributeHeader(ptr[0].p[i]).getDataSize();
}
if (hasDist)
pos += AttributeHeader(ptr[0].p[n]).getDataSize();
}
assert(pos < ptr[1].sz);
Uint32 no = ptr[1].p[pos];
return no;
}
int
NdbEventOperationImpl::readBlobParts(char* buf, NdbBlob* blob,
Uint32 part, Uint32 count, Uint16* lenLoc)
{
DBUG_ENTER_EVENT("NdbEventOperationImpl::readBlobParts");
DBUG_PRINT_EVENT("info", ("part=%u count=%u post/pre=%d",
part, count, blob->theEventBlobVersion));
NdbEventOperationImpl* blob_op = blob->theBlobEventOp;
const bool hasDist = (blob->theStripeSize != 0);
EventBufData* main_data = m_data_item;
DBUG_PRINT_EVENT("info", ("main_data=%p", main_data));
assert(main_data != NULL);
// search for blob parts list head
EventBufData* head;
assert(m_data_item != NULL);
head = m_data_item->m_next_blob;
while (head != NULL)
{
if (head->m_event_op == blob_op)
{
DBUG_PRINT_EVENT("info", ("found blob parts head %p", head));
break;
}
head = head->m_next_blob;
}
Uint32 nparts = 0;
Uint32 noutside = 0;
EventBufData* data = head;
// XXX optimize using part no ordering
while (data != NULL)
{
/*
* Hack part no directly out of buffer since it is not returned
* in pre data (PK buglet). For part data use receive_event().
* This means extra copy. XXX fix
*/
blob_op->m_data_item = data;
int r = blob_op->receive_event();
assert(r > 0);
// XXX should be: no = blob->theBlobEventPartValue
Uint32 no = blob_op->get_blob_part_no(hasDist);
DBUG_PRINT_EVENT("info", ("part_data=%p part no=%u part", data, no));
if (part <= no && no < part + count)
{
DBUG_PRINT_EVENT("info", ("part within read range"));
const char* src = blob->theBlobEventDataBuf.data;
Uint32 sz = 0;
if (blob->theFixedDataFlag) {
sz = blob->thePartSize;
} else {
const uchar* p = (const uchar*)blob->theBlobEventDataBuf.data;
sz = p[0] + (p[1] << 8);
src += 2;
}
memcpy(buf + (no - part) * sz, src, sz);
nparts++;
if (lenLoc != NULL) {
assert(count == 1);
*lenLoc = sz;
} else {
assert(sz == blob->thePartSize);
}
}
else
{
DBUG_PRINT_EVENT("info", ("part outside read range"));
noutside++;
}
data = data->m_next;
}
if (unlikely(nparts != count))
{
ndbout_c("nparts: %u count: %u noutside: %u", nparts, count, noutside);
}
assert(nparts == count);
DBUG_RETURN_EVENT(0);
}
int
NdbEventOperationImpl::execute()
{
DBUG_ENTER("NdbEventOperationImpl::execute");
m_ndb->theEventBuffer->add_drop_lock();
int r = execute_nolock();
m_ndb->theEventBuffer->add_drop_unlock();
DBUG_RETURN(r);
}
int
NdbEventOperationImpl::execute_nolock()
{
DBUG_ENTER("NdbEventOperationImpl::execute_nolock");
DBUG_PRINT("info", ("this=%p type=%s", this, !theMainOp ? "main" : "blob"));
NdbDictionary::Dictionary *myDict = m_ndb->getDictionary();
if (!myDict) {
m_error.code= m_ndb->getNdbError().code;
DBUG_RETURN(-1);
}
bool schemaTrans = false;
if (m_ndb->theEventBuffer->m_total_buckets == TOTAL_BUCKETS_INIT)
{
int res = NdbDictionaryImpl::getImpl(* myDict).beginSchemaTrans(false);
if (res != 0)
{
switch(myDict->getNdbError().code){
case 711:
case 763:
// ignore;
break;
default:
m_error.code= myDict->getNdbError().code;
DBUG_RETURN(-1);
}
}
else
{
schemaTrans = true;
}
}
if (theFirstPkAttrs[0] == NULL &&
theFirstDataAttrs[0] == NULL) { // defaults to get all
}
m_magic_number= NDB_EVENT_OP_MAGIC_NUMBER;
m_state= EO_EXECUTING;
mi_type= m_eventImpl->mi_type;
m_ndb->theEventBuffer->add_op();
// add kernel reference
// removed on TE_STOP, TE_CLUSTER_FAILURE, or error below
m_ref_count++;
m_stop_gci= ~(Uint64)0;
DBUG_PRINT("info", ("m_ref_count: %u for op: %p", m_ref_count, this));
Uint32 buckets = 0;
int r= NdbDictionaryImpl::getImpl(*myDict).executeSubscribeEvent(*this,
buckets);
if (r == 0)
{
/* Pre-7.0 kernel nodes do not return the number of buckets
* Assume it's == theNoOfDBnodes as was the case in 6.3
*/
if (buckets == ~ (Uint32)0)
buckets = m_ndb->theImpl->theNoOfDBnodes;
m_ndb->theEventBuffer->set_total_buckets(buckets);
if (schemaTrans)
{
schemaTrans = false;
myDict->endSchemaTrans(1);
}
if (theMainOp == NULL) {
DBUG_PRINT("info", ("execute blob ops"));
NdbEventOperationImpl* blob_op = theBlobOpList;
while (blob_op != NULL) {
r = blob_op->execute_nolock();
if (r != 0) {
// since main op is running and possibly some blob ops as well
// we can't just reset the main op. Instead return with error,
// main op (and blob ops) will be cleaned up when user calls
// dropEventOperation
m_error.code= myDict->getNdbError().code;
DBUG_RETURN(r);
}
blob_op = blob_op->m_next;
}
}
if (r == 0)
{
DBUG_RETURN(0);
}
}
// Error
// remove kernel reference
// added above
m_ref_count--;
m_stop_gci = 0;
DBUG_PRINT("info", ("m_ref_count: %u for op: %p", m_ref_count, this));
m_state= EO_ERROR;
mi_type= 0;
m_magic_number= 0;
m_error.code= myDict->getNdbError().code;
m_ndb->theEventBuffer->remove_op();
if (schemaTrans)
{
schemaTrans = false;
myDict->endSchemaTrans(1);
}
DBUG_RETURN(r);
}
int
NdbEventOperationImpl::stop()
{
DBUG_ENTER("NdbEventOperationImpl::stop");
int i;
for (i=0 ; i<2; i++) {
NdbRecAttr *p = theFirstPkAttrs[i];
while (p) {
NdbRecAttr *p_next = p->next();
m_ndb->releaseRecAttr(p);
p = p_next;
}
theFirstPkAttrs[i]= 0;
}
for (i=0 ; i<2; i++) {
NdbRecAttr *p = theFirstDataAttrs[i];
while (p) {
NdbRecAttr *p_next = p->next();
m_ndb->releaseRecAttr(p);
p = p_next;
}
theFirstDataAttrs[i]= 0;
}
if (m_state != EO_EXECUTING)
{
DBUG_RETURN(-1);
}
NdbDictionary::Dictionary *myDict = m_ndb->getDictionary();
if (!myDict) {
m_error.code= m_ndb->getNdbError().code;
DBUG_RETURN(-1);
}
m_ndb->theEventBuffer->add_drop_lock();
int r= NdbDictionaryImpl::getImpl(*myDict).stopSubscribeEvent(*this);
m_ndb->theEventBuffer->remove_op();
m_state= EO_DROPPED;
mi_type= 0;
if (r == 0) {
if (m_stop_gci == 0)
{
// response from old kernel
Uint64 gci= m_ndb->theEventBuffer->m_highest_sub_gcp_complete_GCI;
if (gci)
{
// calculate a "safe" gci in the future to remove event op.
gci += Uint64(3) << 32;
}
else
{
// set highest value to ensure that operation does not get dropped
// too early. Note '-1' as ~Uint64(0) indicates active event
gci = ~Uint64(0)-1;
}
m_stop_gci = gci;
}
m_ndb->theEventBuffer->add_drop_unlock();
DBUG_RETURN(0);
}
//Error
m_error.code= NdbDictionaryImpl::getImpl(*myDict).m_error.code;
m_state= EO_ERROR;
m_ndb->theEventBuffer->add_drop_unlock();
DBUG_RETURN(r);
}
bool NdbEventOperationImpl::tableNameChanged() const
{
return (bool)AlterTableReq::getNameFlag(m_change_mask);
}
bool NdbEventOperationImpl::tableFrmChanged() const
{
return (bool)AlterTableReq::getFrmFlag(m_change_mask);
}
bool NdbEventOperationImpl::tableFragmentationChanged() const
{
return (bool)AlterTableReq::getFragDataFlag(m_change_mask);
}
bool NdbEventOperationImpl::tableRangeListChanged() const
{
return (bool)AlterTableReq::getRangeListFlag(m_change_mask);
}
Uint64
NdbEventOperationImpl::getGCI()
{
Uint32 gci_hi = m_data_item->sdata->gci_hi;
Uint32 gci_lo = m_data_item->sdata->gci_lo;
return gci_lo | (Uint64(gci_hi) << 32);
}
Uint32
NdbEventOperationImpl::getAnyValue() const
{
return m_data_item->sdata->anyValue;
}
Uint64
NdbEventOperationImpl::getLatestGCI()
{
return m_ndb->theEventBuffer->getLatestGCI();
}
Uint64
NdbEventOperationImpl::getTransId() const
{
/* Return 64 bit composite */
Uint32 transId1 = m_data_item->sdata->transId1;
Uint32 transId2 = m_data_item->sdata->transId2;
return Uint64(transId1) << 32 | transId2;
}
bool
NdbEventOperationImpl::execSUB_TABLE_DATA(const NdbApiSignal * signal,
const LinearSectionPtr ptr[3])
{
DBUG_ENTER("NdbEventOperationImpl::execSUB_TABLE_DATA");
const SubTableData * const sdata=
CAST_CONSTPTR(SubTableData, signal->getDataPtr());
if(signal->isFirstFragment()){
m_fragmentId = signal->getFragmentId();
m_buffer.grow(4 * sdata->totalLen);
} else {
if(m_fragmentId != signal->getFragmentId()){
abort();
}
}
const Uint32 i = SubTableData::DICT_TAB_INFO;
DBUG_PRINT("info", ("Accumulated %u bytes for fragment %u",
4 * ptr[i].sz, m_fragmentId));
m_buffer.append(ptr[i].p, 4 * ptr[i].sz);
if(!signal->isLastFragment()){
DBUG_RETURN(FALSE);
}
DBUG_RETURN(TRUE);
}
int
NdbEventOperationImpl::receive_event()
{
Uint32 operation=
SubTableData::getOperation(m_data_item->sdata->requestInfo);
if (unlikely(operation >= NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT))
{
DBUG_ENTER("NdbEventOperationImpl::receive_event");
DBUG_PRINT("info",("sdata->operation %u this: %p", operation, this));
m_ndb->theImpl->incClientStat(Ndb::NonDataEventsRecvdCount, 1);
if (operation == NdbDictionary::Event::_TE_ALTER)
{
// Parse the new table definition and
// create a table object
NdbDictInterface::Tx tx_unused;
NdbError error;
int warn;
NdbDictInterface dif(tx_unused, error, warn);
NdbTableImpl *at;
m_change_mask = m_data_item->sdata->changeMask;
error.code = dif.parseTableInfo(&at,
(Uint32*)m_buffer.get_data(),
m_buffer.length() / 4,
true);
m_buffer.clear();
if (unlikely(error.code))
{
DBUG_PRINT("info", ("Failed to parse DictTabInfo error %u",
error.code));
ndbout_c("Failed to parse DictTabInfo error %u", error.code);
DBUG_RETURN(1);
}
at->buildColumnHash();
NdbTableImpl *tmp_table_impl= m_eventImpl->m_tableImpl;
m_eventImpl->m_tableImpl = at;
DBUG_PRINT("info", ("switching table impl 0x%lx -> 0x%lx",
(long) tmp_table_impl, (long) at));
// change the rec attrs to refer to the new table object
int i;
for (i = 0; i < 2; i++)
{
NdbRecAttr *p = theFirstPkAttrs[i];
while (p)
{
int no = p->getColumn()->getColumnNo();
NdbColumnImpl *tAttrInfo = at->getColumn(no);
DBUG_PRINT("info", ("rec_attr: 0x%lx "
"switching column impl 0x%lx -> 0x%lx",
(long) p, (long) p->m_column, (long) tAttrInfo));
p->m_column = tAttrInfo;
p = p->next();
}
}
for (i = 0; i < 2; i++)
{
NdbRecAttr *p = theFirstDataAttrs[i];
while (p)
{
int no = p->getColumn()->getColumnNo();
NdbColumnImpl *tAttrInfo = at->getColumn(no);
DBUG_PRINT("info", ("rec_attr: 0x%lx "
"switching column impl 0x%lx -> 0x%lx",
(long) p, (long) p->m_column, (long) tAttrInfo));
p->m_column = tAttrInfo;
p = p->next();
}
}
// change the blobHandle's to refer to the new table object.
NdbBlob *p = theBlobList;
while (p)
{
int no = p->getColumn()->getColumnNo();
NdbColumnImpl *tAttrInfo = at->getColumn(no);
DBUG_PRINT("info", ("blob_handle: 0x%lx "
"switching column impl 0x%lx -> 0x%lx",
(long) p, (long) p->theColumn, (long) tAttrInfo));
p->theColumn = tAttrInfo;
p = p->next();
}
if (tmp_table_impl)
delete tmp_table_impl;
}
DBUG_RETURN(1);
}
DBUG_ENTER_EVENT("NdbEventOperationImpl::receive_event");
DBUG_PRINT_EVENT("info",("sdata->operation %u this: %p", operation, this));
// now move the data into the RecAttrs
m_ndb->theImpl->incClientStat(Ndb::DataEventsRecvdCount, 1);
int is_insert= operation == NdbDictionary::Event::_TE_INSERT;
Uint32 *aAttrPtr = m_data_item->ptr[0].p;
Uint32 *aAttrEndPtr = aAttrPtr + m_data_item->ptr[0].sz;
Uint32 *aDataPtr = m_data_item->ptr[1].p;
DBUG_DUMP_EVENT("after",(char*)m_data_item->ptr[1].p, m_data_item->ptr[1].sz*4);
DBUG_DUMP_EVENT("before",(char*)m_data_item->ptr[2].p, m_data_item->ptr[2].sz*4);
// copy data into the RecAttr's
// we assume that the respective attribute lists are sorted
// first the pk's
{
NdbRecAttr *tAttr= theFirstPkAttrs[0];
NdbRecAttr *tAttr1= theFirstPkAttrs[1];
while(tAttr)
{
assert(aAttrPtr < aAttrEndPtr);
unsigned tDataSz= AttributeHeader(*aAttrPtr).getByteSize();
assert(tAttr->attrId() ==
AttributeHeader(*aAttrPtr).getAttributeId());
receive_data(tAttr, aDataPtr, tDataSz);
if (!is_insert)
receive_data(tAttr1, aDataPtr, tDataSz);
else
tAttr1->setUNDEFINED(); // do not leave unspecified
tAttr1= tAttr1->next();
// next
aAttrPtr++;
aDataPtr+= (tDataSz + 3) >> 2;
tAttr= tAttr->next();
}
}
NdbRecAttr *tWorkingRecAttr = theFirstDataAttrs[0];
Uint32 tRecAttrId;
Uint32 tAttrId;
Uint32 tDataSz;
int hasSomeData= (operation != NdbDictionary::Event::_TE_UPDATE);
while ((aAttrPtr < aAttrEndPtr) && (tWorkingRecAttr != NULL)) {
tRecAttrId = tWorkingRecAttr->attrId();
tAttrId = AttributeHeader(*aAttrPtr).getAttributeId();
tDataSz = AttributeHeader(*aAttrPtr).getByteSize();
while (tAttrId > tRecAttrId) {
DBUG_PRINT_EVENT("info",("undef [%u] %u 0x%x [%u] 0x%x",
tAttrId, tDataSz, *aDataPtr, tRecAttrId, aDataPtr));
tWorkingRecAttr->setUNDEFINED();
tWorkingRecAttr = tWorkingRecAttr->next();
if (tWorkingRecAttr == NULL)
break;
tRecAttrId = tWorkingRecAttr->attrId();
}
if (tWorkingRecAttr == NULL)
break;
if (tAttrId == tRecAttrId) {
hasSomeData=1;
DBUG_PRINT_EVENT("info",("set [%u] %u 0x%x [%u] 0x%x",
tAttrId, tDataSz, *aDataPtr, tRecAttrId, aDataPtr));
receive_data(tWorkingRecAttr, aDataPtr, tDataSz);
tWorkingRecAttr = tWorkingRecAttr->next();
}
aAttrPtr++;
aDataPtr += (tDataSz + 3) >> 2;
}
while (tWorkingRecAttr != NULL) {
tRecAttrId = tWorkingRecAttr->attrId();
//printf("set undefined [%u] %u %u [%u]\n",