-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_event.cpp
More file actions
3676 lines (3210 loc) · 88.7 KB
/
Copy pathtest_event.cpp
File metadata and controls
3676 lines (3210 loc) · 88.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, 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 <NDBT_Test.hpp>
#include <NDBT_ReturnCodes.h>
#include <HugoTransactions.hpp>
#include <UtilTransactions.hpp>
#include <TestNdbEventOperation.hpp>
#include <NdbAutoPtr.hpp>
#include <NdbRestarter.hpp>
#include <NdbRestarts.hpp>
#include <signaldata/DumpStateOrd.hpp>
#include <NdbEnv.h>
#include <Bitmask.hpp>
static int createEvent(Ndb *pNdb,
const NdbDictionary::Table &tab,
bool merge_events,
bool report)
{
char eventName[1024];
sprintf(eventName,"%s_EVENT",tab.getName());
NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
if (!myDict) {
g_err << "Dictionary not found "
<< pNdb->getNdbError().code << " "
<< pNdb->getNdbError().message << endl;
return NDBT_FAILED;
}
myDict->dropEvent(eventName);
NdbDictionary::Event myEvent(eventName);
myEvent.setTable(tab.getName());
myEvent.addTableEvent(NdbDictionary::Event::TE_ALL);
for(int a = 0; a < tab.getNoOfColumns(); a++){
myEvent.addEventColumn(a);
}
myEvent.mergeEvents(merge_events);
if (report)
myEvent.setReport(NdbDictionary::Event::ER_SUBSCRIBE);
int res = myDict->createEvent(myEvent); // Add event to database
if (res == 0)
myEvent.print();
else if (myDict->getNdbError().classification ==
NdbError::SchemaObjectExists)
{
g_info << "Event creation failed event exists\n";
res = myDict->dropEvent(eventName);
if (res) {
g_err << "Failed to drop event: "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
// try again
res = myDict->createEvent(myEvent); // Add event to database
if (res) {
g_err << "Failed to create event (1): "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
}
else
{
g_err << "Failed to create event (2): "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}
static int createEvent(Ndb *pNdb,
const NdbDictionary::Table &tab,
NDBT_Context* ctx)
{
bool merge_events = ctx->getProperty("MergeEvents");
bool report = ctx->getProperty("ReportSubscribe");
return createEvent(pNdb, tab, merge_events, report);
}
static int dropEvent(Ndb *pNdb, const NdbDictionary::Table &tab)
{
char eventName[1024];
sprintf(eventName,"%s_EVENT",tab.getName());
NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
if (!myDict) {
g_err << "Dictionary not found "
<< pNdb->getNdbError().code << " "
<< pNdb->getNdbError().message << endl;
return NDBT_FAILED;
}
if (myDict->dropEvent(eventName)) {
g_err << "Failed to drop event: "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}
static
NdbEventOperation *createEventOperation(Ndb *ndb,
const NdbDictionary::Table &tab,
int do_report_error = 1)
{
char buf[1024];
sprintf(buf, "%s_EVENT", tab.getName());
NdbEventOperation *pOp= ndb->createEventOperation(buf);
if (pOp == 0)
{
if (do_report_error)
g_err << "createEventOperation: "
<< ndb->getNdbError().code << " "
<< ndb->getNdbError().message << endl;
return 0;
}
int n_columns= tab.getNoOfColumns();
for (int j = 0; j < n_columns; j++)
{
pOp->getValue(tab.getColumn(j)->getName());
pOp->getPreValue(tab.getColumn(j)->getName());
}
if ( pOp->execute() )
{
if (do_report_error)
g_err << "pOp->execute(): "
<< pOp->getNdbError().code << " "
<< pOp->getNdbError().message << endl;
ndb->dropEventOperation(pOp);
return 0;
}
return pOp;
}
static int runCreateEvent(NDBT_Context* ctx, NDBT_Step* step)
{
if (createEvent(GETNDB(step),* ctx->getTab(), ctx) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
Uint32 setAnyValue(Ndb* ndb, NdbTransaction* trans, int rowid, int updVal)
{
/* XOR 2 32bit words of transid together */
Uint64 transId = trans->getTransactionId();
return transId ^ (transId >> 32);
}
bool checkAnyValueTransId(Uint64 transId, Uint32 anyValue)
{
return transId && (anyValue == Uint32(transId ^ (transId >> 32)));
}
struct receivedEvent {
Uint32 pk;
Uint32 count;
Uint32 event;
};
static int
eventOperation(Ndb* pNdb, const NdbDictionary::Table &tab, void* pstats, int records)
{
const char function[] = "HugoTransactions::eventOperation: ";
struct receivedEvent* recInsertEvent;
NdbAutoObjArrayPtr<struct receivedEvent>
p00( recInsertEvent = new struct receivedEvent[3*records] );
struct receivedEvent* recUpdateEvent = &recInsertEvent[records];
struct receivedEvent* recDeleteEvent = &recInsertEvent[2*records];
EventOperationStats &stats = *(EventOperationStats*)pstats;
stats.n_inserts = 0;
stats.n_deletes = 0;
stats.n_updates = 0;
stats.n_consecutive = 0;
stats.n_duplicates = 0;
stats.n_inconsistent_gcis = 0;
for (int i = 0; i < records; i++) {
recInsertEvent[i].pk = 0xFFFFFFFF;
recInsertEvent[i].count = 0;
recInsertEvent[i].event = 0xFFFFFFFF;
recUpdateEvent[i].pk = 0xFFFFFFFF;
recUpdateEvent[i].count = 0;
recUpdateEvent[i].event = 0xFFFFFFFF;
recDeleteEvent[i].pk = 0xFFFFFFFF;
recDeleteEvent[i].count = 0;
recDeleteEvent[i].event = 0xFFFFFFFF;
}
NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
if (!myDict) {
g_err << function << "Event Creation failedDictionary not found\n";
return NDBT_FAILED;
}
int r = 0;
NdbEventOperation *pOp;
char eventName[1024];
sprintf(eventName,"%s_EVENT",tab.getName());
int noEventColumnName = tab.getNoOfColumns();
g_info << function << "create EventOperation\n";
pOp = pNdb->createEventOperation(eventName);
if ( pOp == NULL ) {
g_err << function << "Event operation creation failed\n";
return NDBT_FAILED;
}
g_info << function << "get values\n";
NdbRecAttr* recAttr[1024];
NdbRecAttr* recAttrPre[1024];
const NdbDictionary::Table *_table = myDict->getTable(tab.getName());
for (int a = 0; a < (int)noEventColumnName; a++) {
recAttr[a] = pOp->getValue(_table->getColumn(a)->getName());
recAttrPre[a] = pOp->getPreValue(_table->getColumn(a)->getName());
}
// set up the callbacks
g_info << function << "execute\n";
if (pOp->execute()) { // This starts changes to "start flowing"
g_err << function << "operation execution failed: \n";
g_err << pOp->getNdbError().code << " "
<< pOp->getNdbError().message << endl;
return NDBT_FAILED;
}
g_info << function << "ok\n";
int count = 0;
Uint64 last_inconsitant_gci = (Uint64)-1;
while (r < records){
//printf("now waiting for event...\n");
int res = pNdb->pollEvents(1000); // wait for event or 1000 ms
if (res > 0) {
//printf("got data! %d\n", r);
NdbEventOperation *tmp;
while ((tmp= pNdb->nextEvent()))
{
assert(tmp == pOp);
r++;
count++;
Uint64 gci = pOp->getGCI();
Uint32 pk = recAttr[0]->u_32_value();
if (!pOp->isConsistent()) {
if (last_inconsitant_gci != gci) {
last_inconsitant_gci = gci;
stats.n_inconsistent_gcis++;
}
g_warning << "A node failure has occured and events might be missing\n";
}
g_info << function << "GCI " << gci << ": " << count;
struct receivedEvent* recEvent;
switch (pOp->getEventType()) {
case NdbDictionary::Event::TE_INSERT:
stats.n_inserts++;
g_info << " INSERT: ";
recEvent = recInsertEvent;
break;
case NdbDictionary::Event::TE_DELETE:
stats.n_deletes++;
g_info << " DELETE: ";
recEvent = recDeleteEvent;
break;
case NdbDictionary::Event::TE_UPDATE:
stats.n_updates++;
g_info << " UPDATE: ";
recEvent = recUpdateEvent;
break;
default:
case NdbDictionary::Event::TE_ALL:
abort();
}
/* Check event transaction id */
Uint32 anyValue = pOp->getAnyValue();
Uint64 transId = pOp->getTransId();
if (anyValue)
{
if (!checkAnyValueTransId(transId, anyValue))
{
g_err << "ERROR : TransId and AnyValue mismatch. "
<< "Transid : " << transId
<< ", AnyValue : " << anyValue
<< ", Expected AnyValue : "
<< (Uint32) ((transId >> 32) ^ transId)
<< endl;
abort();
return NDBT_FAILED;
}
}
if ((int)pk < records) {
recEvent[pk].pk = pk;
recEvent[pk].count++;
}
for (int i = 1; i < (int)noEventColumnName; i++) {
if (recAttr[i]->isNULL() >= 0) { // we have a value
g_info << " post[" << i << "]=";
if (recAttr[i]->isNULL() == 0) // we have a non-null value
g_info << recAttr[i]->u_32_value();
else // we have a null value
g_info << "NULL";
}
if (recAttrPre[i]->isNULL() >= 0) { // we have a value
g_info << " pre[" << i << "]=";
if (recAttrPre[i]->isNULL() == 0) // we have a non-null value
g_info << recAttrPre[i]->u_32_value();
else // we have a null value
g_info << "NULL";
}
}
g_info << endl;
}
}
else
{
;//printf("timed out\n");
}
}
g_info << "dropping event operation" << endl;
int res = pNdb->dropEventOperation(pOp);
if (res != 0) {
g_err << "operation execution failed\n";
return NDBT_FAILED;
}
g_info << " ok" << endl;
if (stats.n_inserts > 0) {
stats.n_consecutive++;
}
if (stats.n_deletes > 0) {
stats.n_consecutive++;
}
if (stats.n_updates > 0) {
stats.n_consecutive++;
}
for (int i = 0; i < (int)records/3; i++) {
if (recInsertEvent[i].pk != Uint32(i)) {
stats.n_consecutive ++;
ndbout << "missing insert pk " << i << endl;
} else if (recInsertEvent[i].count > 1) {
ndbout << "duplicates insert pk " << i
<< " count " << recInsertEvent[i].count << endl;
stats.n_duplicates += recInsertEvent[i].count-1;
}
if (recUpdateEvent[i].pk != Uint32(i)) {
stats.n_consecutive ++;
ndbout << "missing update pk " << i << endl;
} else if (recUpdateEvent[i].count > 1) {
ndbout << "duplicates update pk " << i
<< " count " << recUpdateEvent[i].count << endl;
stats.n_duplicates += recUpdateEvent[i].count-1;
}
if (recDeleteEvent[i].pk != Uint32(i)) {
stats.n_consecutive ++;
ndbout << "missing delete pk " << i << endl;
} else if (recDeleteEvent[i].count > 1) {
ndbout << "duplicates delete pk " << i
<< " count " << recDeleteEvent[i].count << endl;
stats.n_duplicates += recDeleteEvent[i].count-1;
}
}
return NDBT_OK;
}
int runCreateShadowTable(NDBT_Context* ctx, NDBT_Step* step)
{
const NdbDictionary::Table *table= ctx->getTab();
char buf[1024];
sprintf(buf, "%s_SHADOW", table->getName());
GETNDB(step)->getDictionary()->dropTable(buf);
if (GETNDB(step)->getDictionary()->getTable(buf))
{
g_err << "unsucessful drop of " << buf << endl;
return NDBT_FAILED;
}
NdbDictionary::Table table_shadow(*table);
table_shadow.setName(buf);
// TODO should be removed
// This should work wo/ next line
//table_shadow.setNodeGroupIds(0, 0);
GETNDB(step)->getDictionary()->createTable(table_shadow);
if (GETNDB(step)->getDictionary()->getTable(buf))
return NDBT_OK;
g_err << "unsucessful create of " << buf << endl;
return NDBT_FAILED;
}
int runDropShadowTable(NDBT_Context* ctx, NDBT_Step* step)
{
const NdbDictionary::Table *table= ctx->getTab();
char buf[1024];
sprintf(buf, "%s_SHADOW", table->getName());
GETNDB(step)->getDictionary()->dropTable(buf);
return NDBT_OK;
}
int runCreateDropEventOperation(NDBT_Context* ctx, NDBT_Step* step)
{
int loops = ctx->getNumLoops();
//int records = ctx->getNumRecords();
HugoTransactions hugoTrans(*ctx->getTab());
EventOperationStats stats;
//Ndb *pNdb=GETNDB(step);
const NdbDictionary::Table& tab= *ctx->getTab();
//NdbEventOperation *pOp;
char eventName[1024];
sprintf(eventName,"%s_EVENT",tab.getName());
//int noEventColumnName = tab.getNoOfColumns();
for (int i= 0; i < loops; i++)
{
#if 1
if (eventOperation(GETNDB(step), tab, (void*)&stats, 0) != 0){
return NDBT_FAILED;
}
#else
g_info << "create EventOperation\n";
pOp = pNdb->createEventOperation(eventName);
if ( pOp == NULL ) {
g_err << "Event operation creation failed\n";
return NDBT_FAILED;
}
g_info << "dropping event operation" << endl;
int res = pNdb->dropEventOperation(pOp);
if (res != 0) {
g_err << "operation execution failed\n";
return NDBT_FAILED;
}
#endif
}
return NDBT_OK;
}
int theThreadIdCounter = 0;
int runEventOperation(NDBT_Context* ctx, NDBT_Step* step)
{
int tId = theThreadIdCounter++;
//int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
HugoTransactions hugoTrans(*ctx->getTab());
EventOperationStats stats;
g_info << "***** start Id " << tId << endl;
// sleep(tId);
if (eventOperation(GETNDB(step), *ctx->getTab(), (void*)&stats, 3*records) != 0){
return NDBT_FAILED;
}
int ret;
if (stats.n_inserts == records &&
stats.n_deletes == records &&
stats.n_updates == records &&
stats.n_consecutive == 3 &&
stats.n_duplicates == 0)
ret = NDBT_OK;
else
ret = NDBT_FAILED;
if (ret == NDBT_FAILED) {
g_info << "***** end Id " << tId << endl;
ndbout_c("n_inserts = %d (%d)", stats.n_inserts, records);
ndbout_c("n_deletes = %d (%d)", stats.n_deletes, records);
ndbout_c("n_updates = %d (%d)", stats.n_updates, records);
ndbout_c("n_consecutive = %d (%d)", stats.n_consecutive, 3);
ndbout_c("n_duplicates = %d (%d)", stats.n_duplicates, 0);
ndbout_c("n_inconsistent_gcis = %d (%d)", stats.n_inconsistent_gcis, 0);
}
return ret;
}
int runEventLoad(NDBT_Context* ctx, NDBT_Step* step)
{
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
HugoTransactions hugoTrans(*ctx->getTab());
hugoTrans.setAnyValueCallback(setAnyValue);
sleep(1);
#if 0
sleep(5);
sleep(theThreadIdCounter);
#endif
if (hugoTrans.loadTable(GETNDB(step), records, 1, true, loops) != 0){
return NDBT_FAILED;
}
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, loops) != 0){
return NDBT_FAILED;
}
if (hugoTrans.pkDelRecords(GETNDB(step), records, 1, true, loops) != 0){
return NDBT_FAILED;
}
return NDBT_OK;
}
int runEventMixedLoad(NDBT_Context* ctx, NDBT_Step* step)
{
int loops = ctx->getNumLoops();
int records = ctx->getNumRecords();
HugoTransactions hugoTrans(*ctx->getTab());
hugoTrans.setAnyValueCallback(setAnyValue);
if(ctx->getPropertyWait("LastGCI_hi", ~(Uint32)0))
{
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
while(loops -- && !ctx->isTestStopped())
{
hugoTrans.clearTable(GETNDB(step), 0);
if (hugoTrans.loadTable(GETNDB(step), 3*records, 1, true, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
if (hugoTrans.pkDelRecords(GETNDB(step), 3*records, 1, true, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
if (hugoTrans.loadTable(GETNDB(step), records, 1, true, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
if (hugoTrans.pkUpdateRecords(GETNDB(step), records, 1, 1) != 0){
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
ndbout_c("set(LastGCI_hi): %u/%u",
Uint32(hugoTrans.m_latest_gci >> 32),
Uint32(hugoTrans.m_latest_gci));
ctx->setProperty("LastGCI_lo", Uint32(hugoTrans.m_latest_gci));
ctx->setProperty("LastGCI_hi", Uint32(hugoTrans.m_latest_gci >> 32));
if(ctx->getPropertyWait("LastGCI_hi", ~(Uint32)0))
{
g_err << "FAIL " << __LINE__ << endl;
return NDBT_FAILED;
}
}
ctx->stopTest();
return NDBT_OK;
}
int runDropEvent(NDBT_Context* ctx, NDBT_Step* step)
{
return dropEvent(GETNDB(step), * ctx->getTab());
}
int runVerify(NDBT_Context* ctx, NDBT_Step* step)
{
const NdbDictionary::Table * table= ctx->getTab();
char buf[1024];
sprintf(buf, "%s_SHADOW", table->getName());
HugoTransactions hugoTrans(*table);
if (hugoTrans.compare(GETNDB(step), buf, 0))
{
return NDBT_FAILED;
}
return NDBT_OK;
}
int runEventApplier(NDBT_Context* ctx, NDBT_Step* step)
{
DBUG_ENTER("runEventApplier");
int result = NDBT_OK;
const NdbDictionary::Table * table= ctx->getTab();
HugoTransactions hugoTrans(* table);
char shadow[1024], buf[1024];
sprintf(shadow, "%s_SHADOW", table->getName());
const NdbDictionary::Table * table_shadow;
if ((table_shadow = GETNDB(step)->getDictionary()->getTable(shadow)) == 0)
{
g_err << "Unable to get table " << shadow << endl;
DBUG_RETURN(NDBT_FAILED);
}
sprintf(buf, "%s_EVENT", table->getName());
NdbEventOperation *pOp, *pCreate = 0;
pCreate = pOp = GETNDB(step)->createEventOperation(buf);
if ( pOp == NULL ) {
g_err << "Event operation creation failed on %s" << buf << endl;
DBUG_RETURN(NDBT_FAILED);
}
bool merge_events = ctx->getProperty("MergeEvents");
pOp->mergeEvents(merge_events);
int i;
int n_columns= table->getNoOfColumns();
NdbRecAttr* recAttr[1024];
NdbRecAttr* recAttrPre[1024];
for (i = 0; i < n_columns; i++) {
recAttr[i] = pOp->getValue(table->getColumn(i)->getName());
recAttrPre[i] = pOp->getPreValue(table->getColumn(i)->getName());
}
if (pOp->execute()) { // This starts changes to "start flowing"
g_err << "execute operation execution failed: \n";
g_err << pOp->getNdbError().code << " "
<< pOp->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
ctx->setProperty("LastGCI_hi", ~(Uint32)0);
ctx->broadcast();
while(!ctx->isTestStopped())
{
int count= 0;
Uint64 stop_gci= ~(Uint64)0;
Uint64 curr_gci = 0;
Ndb* ndb= GETNDB(step);
while(!ctx->isTestStopped() && curr_gci <= stop_gci)
{
ndb->pollEvents(100, &curr_gci);
while ((pOp= ndb->nextEvent()) != 0)
{
assert(pOp == pCreate);
if (pOp->getEventType() >=
NdbDictionary::Event::TE_FIRST_NON_DATA_EVENT)
continue;
int noRetries= 0;
do
{
NdbTransaction *trans= GETNDB(step)->startTransaction();
if (trans == 0)
{
g_err << "startTransaction failed "
<< GETNDB(step)->getNdbError().code << " "
<< GETNDB(step)->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
NdbOperation *op= trans->getNdbOperation(table_shadow);
if (op == 0)
{
g_err << "getNdbOperation failed "
<< trans->getNdbError().code << " "
<< trans->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
switch (pOp->getEventType()) {
case NdbDictionary::Event::TE_INSERT:
if (op->writeTuple())
{
g_err << "insertTuple "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
break;
case NdbDictionary::Event::TE_DELETE:
if (op->deleteTuple())
{
g_err << "deleteTuple "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
break;
case NdbDictionary::Event::TE_UPDATE:
if (op->writeTuple())
{
g_err << "updateTuple "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
break;
default:
abort();
}
/* Check event transaction id */
Uint32 anyValue = pOp->getAnyValue();
Uint64 transId = pOp->getTransId();
if (anyValue)
{
if (!checkAnyValueTransId(transId, anyValue))
{
g_err << "ERROR : TransId and AnyValue mismatch. "
<< "Transid : " << transId
<< ", AnyValue : " << anyValue
<< ", Expected AnyValue : "
<< (Uint32) ((transId >> 32) ^ transId)
<< endl;
abort();
return NDBT_FAILED;
}
}
for (i= 0; i < n_columns; i++)
{
if (recAttr[i]->isNULL())
{
if (table->getColumn(i)->getPrimaryKey())
{
g_err << "internal error: primary key isNull()="
<< recAttr[i]->isNULL() << endl;
result = NDBT_FAILED;
goto end;
}
switch (pOp->getEventType()) {
case NdbDictionary::Event::TE_INSERT:
if (recAttr[i]->isNULL() < 0)
{
g_err << "internal error: missing value for insert\n";
result = NDBT_FAILED;
goto end;
}
break;
case NdbDictionary::Event::TE_DELETE:
break;
case NdbDictionary::Event::TE_UPDATE:
break;
default:
abort();
}
}
if (table->getColumn(i)->getPrimaryKey() &&
op->equal(i,recAttr[i]->aRef()))
{
g_err << "equal " << i << " "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
}
switch (pOp->getEventType()) {
case NdbDictionary::Event::TE_INSERT:
for (i= 0; i < n_columns; i++)
{
if (!table->getColumn(i)->getPrimaryKey() &&
op->setValue(i,recAttr[i]->isNULL() ? 0:recAttr[i]->aRef()))
{
g_err << "setValue(insert) " << i << " "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
}
break;
case NdbDictionary::Event::TE_DELETE:
break;
case NdbDictionary::Event::TE_UPDATE:
for (i= 0; i < n_columns; i++)
{
if (!table->getColumn(i)->getPrimaryKey() &&
recAttr[i]->isNULL() >= 0 &&
op->setValue(i,recAttr[i]->isNULL() ? 0:recAttr[i]->aRef()))
{
g_err << "setValue(update) " << i << " "
<< op->getNdbError().code << " "
<< op->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
}
break;
default:
case NdbDictionary::Event::TE_ALL:
abort();
}
if (trans->execute(Commit) == 0)
{
trans->close();
count++;
// everything ok
break;
}
if (trans->getNdbError().status == NdbError::PermanentError)
{
g_err << "Ignoring execute failed "
<< trans->getNdbError().code << " "
<< trans->getNdbError().message << endl;
trans->close();
count++;
break;
}
else if (noRetries++ == 10)
{
g_err << "execute failed "
<< trans->getNdbError().code << " "
<< trans->getNdbError().message << endl;
trans->close();
result = NDBT_FAILED;
goto end;
}
trans->close();
NdbSleep_MilliSleep(100); // sleep before retying
} while(1);
}
Uint32 stop_gci_hi = ctx->getProperty("LastGCI_hi", ~(Uint32)0);
Uint32 stop_gci_lo = ctx->getProperty("LastGCI_lo", ~(Uint32)0);
stop_gci = Uint64(stop_gci_lo) | (Uint64(stop_gci_hi) << 32);
}
ndbout_c("Applied gci: %u/%u, %d events",
Uint32(stop_gci >> 32), Uint32(stop_gci), count);
if (hugoTrans.compare(GETNDB(step), shadow, 0))
{
g_err << "compare failed" << endl;
result = NDBT_FAILED;
goto end;
}
ctx->setProperty("LastGCI_hi", ~(Uint32)0);
ctx->broadcast();
}
end:
if(pCreate)
{
if (GETNDB(step)->dropEventOperation(pCreate)) {
g_err << "dropEventOperation execution failed "
<< GETNDB(step)->getNdbError().code << " "
<< GETNDB(step)->getNdbError().message << endl;
result = NDBT_FAILED;
}
}
ctx->stopTest();
DBUG_RETURN(result);
}
int runEventConsumer(NDBT_Context* ctx, NDBT_Step* step)
{
DBUG_ENTER("runEventConsumer");
int result = NDBT_OK;
const NdbDictionary::Table * table= ctx->getTab();
HugoTransactions hugoTrans(* table);
char buf[1024];
sprintf(buf, "%s_EVENT", table->getName());
NdbEventOperation *pOp, *pCreate = 0;
pCreate = pOp = GETNDB(step)->createEventOperation(buf);
if ( pOp == NULL ) {
g_err << "Event operation creation failed on %s" << buf << endl;
DBUG_RETURN(NDBT_FAILED);
}
bool merge_events = ctx->getProperty("MergeEvents");
pOp->mergeEvents(merge_events);
int i;
int n_columns= table->getNoOfColumns();
NdbRecAttr* recAttr[1024];
NdbRecAttr* recAttrPre[1024];
for (i = 0; i < n_columns; i++) {
recAttr[i] = pOp->getValue(table->getColumn(i)->getName());
recAttrPre[i] = pOp->getPreValue(table->getColumn(i)->getName());
}
if (pOp->execute()) { // This starts changes to "start flowing"
g_err << "execute operation execution failed: \n";
g_err << pOp->getNdbError().code << " "
<< pOp->getNdbError().message << endl;
result = NDBT_FAILED;
goto end;
}
ctx->setProperty("LastGCI_hi", ~(Uint32)0);
ctx->broadcast();
while(!ctx->isTestStopped())
{
//int count= 0;
Ndb* ndb= GETNDB(step);
Uint64 last_gci = 0;
while(!ctx->isTestStopped())
{
Uint32 count = 0;
Uint64 curr_gci;
ndb->pollEvents(100, &curr_gci);
if (curr_gci != last_gci)
{
while ((pOp= ndb->nextEvent()) != 0)
{
count++;
}
last_gci = curr_gci;
}
ndbout_c("Consumed gci: %u/%u, %d events",
Uint32(last_gci >> 32), Uint32(last_gci), count);
}
}
end:
if(pCreate)
{
if (GETNDB(step)->dropEventOperation(pCreate)) {
g_err << "dropEventOperation execution failed "
<< GETNDB(step)->getNdbError().code << " "
<< GETNDB(step)->getNdbError().message << endl;
result = NDBT_FAILED;
}
}
ctx->stopTest();
DBUG_RETURN(result);
}
int runEventListenerUntilStopped(NDBT_Context* ctx, NDBT_Step* step)
{
int result = NDBT_OK;
const NdbDictionary::Table * table= ctx->getTab();
HugoTransactions hugoTrans(* table);
Ndb* ndb= GETNDB(step);