-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtestBlobs.cpp
More file actions
5202 lines (4816 loc) · 147 KB
/
Copy pathtestBlobs.cpp
File metadata and controls
5202 lines (4816 loc) · 147 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
*/
/*
* testBlobs
*/
#include <ndb_global.h>
#include <NdbMain.h>
#include <NdbOut.hpp>
#include <OutputStream.hpp>
#include <NdbTest.hpp>
#include <NdbTick.h>
#include <my_sys.h>
#include <NdbRestarter.hpp>
#include <ndb_rand.h>
struct Chr {
NdbDictionary::Column::Type m_type;
bool m_fixed;
bool m_binary;
uint m_len; // native
uint m_bytelen; // in bytes
uint m_totlen; // plus length bytes
const char* m_cs;
CHARSET_INFO* m_csinfo;
uint m_mblen;
bool m_caseins; // for latin letters
Chr() :
m_type(NdbDictionary::Column::Varchar),
m_fixed(false),
m_binary(false),
m_len(55),
m_bytelen(0),
m_totlen(0),
m_cs("latin1"),
m_csinfo(0),
m_caseins(true)
{}
};
struct Opt {
unsigned m_batch;
bool m_core;
bool m_dbg;
const char* m_debug;
bool m_fac;
bool m_full;
unsigned m_loop;
bool m_min;
unsigned m_parts;
unsigned m_rows;
int m_seed;
const char* m_skip;
const char* m_test;
int m_timeout_retries;
int m_blob_version;
// metadata
const char* m_tname;
const char* m_x1name; // hash index
const char* m_x2name; // ordered index
unsigned m_pk1off;
Chr m_pk2chr;
bool m_pk2part;
bool m_oneblob;
int m_rbatch;
int m_wbatch;
// perf
const char* m_tnameperf;
unsigned m_rowsperf;
// bugs
int m_bug;
int (*m_bugtest)();
Opt() :
m_batch(7),
m_core(false),
m_dbg(false),
m_debug(0),
m_fac(false),
m_full(false),
m_loop(1),
m_min(false),
m_parts(10),
m_rows(100),
m_seed(-1),
m_skip(0),
m_test(0),
m_timeout_retries(10),
m_blob_version(2),
// metadata
m_tname("TB1"),
m_x1name("TB1X1"),
m_x2name("TB1X2"),
m_pk1off(0x12340000),
m_pk2chr(),
m_pk2part(false),
m_oneblob(false),
m_rbatch(-1),
m_wbatch(-1),
// perf
m_tnameperf("TB2"),
m_rowsperf(10000),
// bugs
m_bug(0),
m_bugtest(0)
{}
};
static void
printusage()
{
Opt d;
ndbout
<< "usage: testBlobs options [default/max]" << endl
<< " -batch N number of pk ops in batch [" << d.m_batch << "]" << endl
<< " -core dump core on error" << endl
<< " -dbg print program debug" << endl
<< " -debug opt also ndb api DBUG (if no ':' becomes d:t:F:L:o,opt)" << endl
<< " -fac fetch across commit in scan delete" << endl
<< " -full read/write only full blob values" << endl
<< " -loop N loop N times 0=forever [" << d.m_loop << "]" << endl
<< " -min small blob sizes" << endl
<< " -parts N max parts in blob value [" << d.m_parts << "]" << endl
<< " -rows N number of rows [" << d.m_rows << "]" << endl
<< " -rowsperf N rows for performace test [" << d.m_rowsperf << "]" << endl
<< " -seed N random seed 0=loop number -1=random [" << d.m_seed << "]" << endl
<< " -skip xxx skip given tests (see list) [no tests]" << endl
<< " -test xxx only given tests (see list) [all tests]" << endl
<< " -timeoutretries N Number of times to retry in deadlock situations ["
<< d.m_timeout_retries << "]" << endl
<< " -version N blob version 1 or 2 [" << d.m_blob_version << "]" << endl
<< "metadata" << endl
<< " -pk2len N native length of PK2, zero omits PK2,PK3 [" << d.m_pk2chr.m_len << "]" << endl
<< " -pk2fixed PK2 is Char [default Varchar]" << endl
<< " -pk2binary PK2 is Binary or Varbinary" << endl
<< " -pk2cs PK2 charset or collation [" << d.m_pk2chr.m_cs << "]" << endl
<< " -pk2part partition primary table by PK2" << endl
<< " -oneblob only 1 blob attribute [default 2]" << endl
<< " -rbatch N Read parts batchsize (bytes) [default -1] -1=random" << endl
<< " -wbatch N Write parts batchsize (bytes) [default -1] -1=random" << endl
<< "disk or memory storage for blobs. Don't apply to performance test" << endl
<< " m Blob columns stored in memory" << endl
<< " h Blob columns stored on disk" << endl
<< "api styles for test/skip. Don't apply to performance test" << endl
<< " a NdbRecAttr(old) interface" << endl
<< " b NdbRecord interface" << endl
<< "test cases for test/skip" << endl
<< " k primary key ops" << endl
<< " i hash index ops" << endl
<< " s table scans" << endl
<< " r ordered index scans" << endl
<< " p performance test" << endl
<< "operations for test/skip" << endl
<< " u update existing blob value" << endl
<< " n normal insert and update" << endl
<< " w insert and update using writeTuple" << endl
<< " d delete, can skip only for one subtest" << endl
<< " l read with lock and unlock" << endl
<< "blob operation styles for test/skip" << endl
<< " 0 getValue / setValue" << endl
<< " 1 setActiveHook" << endl
<< " 2 readData / writeData" << endl
<< "example: -test makn0 (need all 4 parts)" << endl
<< "example: -test mhabkisrunwd012 (Everything except performance tests" << endl
<< "bug tests" << endl
<< " -bug 4088 ndb api hang with mixed ops on index table" << endl
<< " -bug 27018 middle partial part write clobbers rest of part" << endl
<< " -bug 27370 Potential inconsistent blob reads for ReadCommitted reads" << endl
<< " -bug 36756 Handling execute(.., abortOption) and Blobs " << endl
<< " -bug 45768 execute(Commit) after failing blob batch " << endl
<< " -bug 62321 Blob obscures ignored error codes in batch" << endl
;
}
static Opt g_opt;
static bool
testcase(char x)
{
if (x < 10)
x += '0';
return
(g_opt.m_test == 0 || strchr(g_opt.m_test, x) != 0) &&
(g_opt.m_skip == 0 || strchr(g_opt.m_skip, x) == 0);
}
static Ndb_cluster_connection* g_ncc = 0;
static Ndb* g_ndb = 0;
static NdbDictionary::Dictionary* g_dic = 0;
static NdbConnection* g_con = 0;
static NdbOperation* g_opr = 0;
static const NdbOperation* g_const_opr = 0;
static NdbIndexOperation* g_opx = 0;
static NdbScanOperation* g_ops = 0;
static NdbBlob* g_bh1 = 0;
static NdbBlob* g_bh2 = 0;
static bool g_printerror = true;
static unsigned g_loop = 0;
static NdbRecord *g_key_record= 0;
static NdbRecord *g_blob_record= 0;
static NdbRecord *g_full_record= 0;
static NdbRecord *g_idx_record= 0;
static NdbRecord *g_ord_record= 0;
static unsigned g_pk1_offset= 0;
static unsigned g_pk2_offset= 0;
static unsigned g_pk3_offset= 0;
static unsigned g_blob1_offset= 0;
static unsigned g_blob1_null_offset= 0;
static unsigned g_blob2_offset= 0;
static unsigned g_blob2_null_offset= 0;
static unsigned g_rowsize= 0;
static const char* g_tsName= "DEFAULT-TS";
static Uint32 g_batchSize= 0;
static Uint32 g_scanFlags= 0;
static Uint32 g_parallel= 0;
static Uint32 g_usingDisk= false;
static const Uint32 MAX_FRAGS=48 * 8 * 4; // e.g. 48 nodes, 8 frags/node, 4 replicas
static Uint32 frag_ng_mappings[MAX_FRAGS];
static const char* stylename[3] = {
"style=getValue/setValue",
"style=setActiveHook",
"style=readData/writeData"
};
// Blob API variants
static const char* apiName[2] = {
"api=NdbRecAttr",
"api=NdbRecord"
};
static const char apiSymbol[2] = {
'a', // RecAttr
'b' // NdbRecord
};
static const int API_RECATTR=0;
static const int API_NDBRECORD=1;
static const char* storageName[2] = {
"storage=memory",
"storage=disk"
};
static const char storageSymbol[2] = {
'm', // Memory storage
'h' // Disk storage
};
static const int STORAGE_MEM=0;
static const int STORAGE_DISK=1;
static void
printerror(int line, const char* msg)
{
ndbout << "line " << line << " FAIL " << msg << endl;
if (! g_printerror) {
return;
}
if (g_ndb != 0 && g_ndb->getNdbError().code != 0) {
ndbout << "ndb: " << g_ndb->getNdbError() << endl;
}
if (g_dic != 0 && g_dic->getNdbError().code != 0) {
ndbout << "dic: " << g_dic->getNdbError() << endl;
}
if (g_con != 0 && g_con->getNdbError().code != 0) {
ndbout << "con: " << g_con->getNdbError() << endl;
if (g_opr != 0 && g_opr->getNdbError().code != 0) {
ndbout << "opr: table=" << g_opr->getTableName() << " " << g_opr->getNdbError() << endl;
}
if (g_const_opr != 0 && g_const_opr->getNdbError().code !=0) {
ndbout << "const_opr: table=" << g_const_opr->getTableName() << " " << g_const_opr->getNdbError() << endl;
}
if (g_opx != 0 && g_opx->getNdbError().code != 0) {
ndbout << "opx: table=" << g_opx->getTableName() << " " << g_opx->getNdbError() << endl;
}
if (g_ops != 0 && g_ops->getNdbError().code != 0) {
ndbout << "ops: table=" << g_ops->getTableName() << " " << g_ops->getNdbError() << endl;
}
NdbOperation* ope = g_con->getNdbErrorOperation();
if (ope != 0 && ope->getNdbError().code != 0) {
if (ope != g_opr && ope != g_const_opr && ope != g_opx && ope != g_ops)
ndbout << "ope: ptr=" << ope << " table=" << ope->getTableName() << " type= "<< ope->getType() << " " << ope->getNdbError() << endl;
}
}
if (g_bh1 != 0 && g_bh1->getNdbError().code != 0) {
ndbout << "bh1: " << g_bh1->getNdbError() << endl;
}
if (g_bh2 != 0 && g_bh2->getNdbError().code != 0) {
ndbout << "bh2: " << g_bh2->getNdbError() << endl;
}
if (g_opt.m_core) {
abort();
}
g_printerror = false;
}
#define CHK(x) \
do { \
if (x) break; \
printerror(__LINE__, #x); return -1; \
} while (0)
#define DBG(x) \
do { \
if (! g_opt.m_dbg) break; \
ndbout << "line " << __LINE__ << " " << x << endl; \
} while (0)
#define DISP(x) \
do { \
ndbout << "line " << __LINE__ << " " << x << endl; \
} while (0)
struct Bcol {
int m_type;
int m_version;
bool m_nullable;
uint m_inline;
uint m_partsize;
uint m_stripe;
char m_btname[200];
Bcol() { memset(this, 0, sizeof(*this)); }
};
static Bcol g_blob1;
static Bcol g_blob2;
enum OpState {Normal, Retrying};
static void
initblobs()
{
{
Bcol& b = g_blob1;
b.m_type = NdbDictionary::Column::Text;
b.m_version = g_opt.m_blob_version;
b.m_nullable = false;
b.m_inline = g_opt.m_min ? 8 : 240;
b.m_partsize = g_opt.m_min ? 8 : 2000;
b.m_stripe = b.m_version == 1 ? 4 : 0;
}
{
Bcol& b = g_blob2;
b.m_type = NdbDictionary::Column::Blob;
b.m_version = g_opt.m_blob_version;
b.m_nullable = true;
b.m_inline = g_opt.m_min ? 9 : 99;
b.m_partsize = g_opt.m_min ? 5 : 55;
b.m_stripe = 3;
}
}
static void
initConstants()
{
g_pk1_offset= 0;
g_pk2_offset= g_pk1_offset + 4;
g_pk3_offset= g_pk2_offset + g_opt.m_pk2chr.m_totlen;
g_blob1_offset= g_pk3_offset + 2;
g_blob2_offset= g_blob1_offset + sizeof(NdbBlob *);
g_blob1_null_offset= g_blob2_offset + sizeof(NdbBlob *);
g_blob2_null_offset= g_blob1_null_offset + 1;
g_rowsize= g_blob2_null_offset + 1;
}
static int
createDefaultTableSpace()
{
/* 'Inspired' by NDBT_Tables::create_default_tablespace */
int res;
NdbDictionary::LogfileGroup lg = g_dic->getLogfileGroup("DEFAULT-LG");
if (strcmp(lg.getName(), "DEFAULT-LG") != 0)
{
lg.setName("DEFAULT-LG");
lg.setUndoBufferSize(8*1024*1024);
res = g_dic->createLogfileGroup(lg);
if(res != 0){
DBG("Failed to create logfilegroup:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
{
NdbDictionary::Undofile uf = g_dic->getUndofile(0, "undofile01.dat");
if (strcmp(uf.getPath(), "undofile01.dat") != 0)
{
uf.setPath("undofile01.dat");
uf.setSize(32*1024*1024);
uf.setLogfileGroup("DEFAULT-LG");
res = g_dic->createUndofile(uf, true);
if(res != 0){
DBG("Failed to create undofile:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
}
{
NdbDictionary::Undofile uf = g_dic->getUndofile(0, "undofile02.dat");
if (strcmp(uf.getPath(), "undofile02.dat") != 0)
{
uf.setPath("undofile02.dat");
uf.setSize(32*1024*1024);
uf.setLogfileGroup("DEFAULT-LG");
res = g_dic->createUndofile(uf, true);
if(res != 0){
DBG("Failed to create undofile:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
}
NdbDictionary::Tablespace ts = g_dic->getTablespace(g_tsName);
if (strcmp(ts.getName(), g_tsName) != 0)
{
ts.setName(g_tsName);
ts.setExtentSize(1024*1024);
ts.setDefaultLogfileGroup("DEFAULT-LG");
res = g_dic->createTablespace(ts);
if(res != 0){
DBG("Failed to create tablespace:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
{
NdbDictionary::Datafile df = g_dic->getDatafile(0, "datafile01.dat");
if (strcmp(df.getPath(), "datafile01.dat") != 0)
{
df.setPath("datafile01.dat");
df.setSize(64*1024*1024);
df.setTablespace(g_tsName);
res = g_dic->createDatafile(df, true);
if(res != 0){
DBG("Failed to create datafile:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
}
{
NdbDictionary::Datafile df = g_dic->getDatafile(0, "datafile02.dat");
if (strcmp(df.getPath(), "datafile02.dat") != 0)
{
df.setPath("datafile02.dat");
df.setSize(64*1024*1024);
df.setTablespace(g_tsName);
res = g_dic->createDatafile(df, true);
if(res != 0){
DBG("Failed to create datafile:"
<< endl << g_dic->getNdbError() << endl);
return -1;
}
}
}
return 0;
}
static int
dropTable()
{
NdbDictionary::Table tab(g_opt.m_tname);
if (g_dic->getTable(g_opt.m_tname) != 0)
CHK(g_dic->dropTable(g_opt.m_tname) == 0);
if (g_key_record != NULL)
g_dic->releaseRecord(g_key_record);
if (g_blob_record != NULL)
g_dic->releaseRecord(g_blob_record);
if (g_full_record != NULL)
g_dic->releaseRecord(g_full_record);
if (g_opt.m_pk2chr.m_len != 0)
{
if (g_idx_record != NULL)
g_dic->releaseRecord(g_idx_record);
if (g_ord_record != NULL)
g_dic->releaseRecord(g_ord_record);
}
g_key_record= NULL;
g_blob_record= NULL;
g_full_record= NULL;
g_idx_record= NULL;
g_ord_record= NULL;
return 0;
}
static unsigned
urandom(unsigned n)
{
return n == 0 ? 0 : ndb_rand() % n;
}
static int
createTable(int storageType)
{
/* No logging for memory tables */
bool loggingRequired=(storageType == STORAGE_DISK);
NdbDictionary::Column::StorageType blobStorageType=
(storageType == STORAGE_MEM)?
NdbDictionary::Column::StorageTypeMemory :
NdbDictionary::Column::StorageTypeDisk;
NdbDictionary::Table tab(g_opt.m_tname);
if (storageType == STORAGE_DISK)
tab.setTablespaceName(g_tsName);
tab.setLogging(loggingRequired);
/* Choose from the interesting fragmentation types :
* DistrKeyHash, DistrKeyLin, UserDefined, HashMapPartitioned
* Others are obsolete fragment-count setting variants
* of DistrKeyLin
* For UserDefined partitioning, we need to set the partition
* id for all PK operations.
*/
Uint32 fragTypeRange= 1 + (NdbDictionary::Object::HashMapPartition -
NdbDictionary::Object::DistrKeyHash);
Uint32 fragType= NdbDictionary::Object::DistrKeyHash + urandom(fragTypeRange);
/* Value 8 is unused currently, map it to something else */
if (fragType == 8)
fragType= NdbDictionary::Object::UserDefined;
tab.setFragmentType((NdbDictionary::Object::FragmentType)fragType);
if (fragType == NdbDictionary::Object::UserDefined)
{
/* Need to set the FragmentCount and fragment to NG mapping
* for this partitioning type
*/
const Uint32 numNodes= g_ncc->no_db_nodes();
const Uint32 numReplicas= 2; // Assumption
const Uint32 guessNumNgs= numNodes/2;
const Uint32 numNgs= guessNumNgs?guessNumNgs : 1;
const Uint32 numFragsPerNode= 2 + (rand() % 3);
const Uint32 numPartitions= numReplicas * numNgs * numFragsPerNode;
tab.setFragmentCount(numPartitions);
for (Uint32 i=0; i<numPartitions; i++)
{
frag_ng_mappings[i]= i % numNgs;
}
tab.setFragmentData(frag_ng_mappings, numPartitions);
}
const Chr& pk2chr = g_opt.m_pk2chr;
// col PK1 - Uint32
{ NdbDictionary::Column col("PK1");
col.setType(NdbDictionary::Column::Unsigned);
col.setPrimaryKey(true);
tab.addColumn(col);
}
// col BL1 - Text not-nullable
{ NdbDictionary::Column col("BL1");
const Bcol& b = g_blob1;
col.setType((NdbDictionary::Column::Type)b.m_type);
col.setBlobVersion(b.m_version);
col.setNullable(b.m_nullable);
col.setInlineSize(b.m_inline);
col.setPartSize(b.m_partsize);
col.setStripeSize(b.m_stripe);
col.setStorageType(blobStorageType);
tab.addColumn(col);
}
// col PK2 - Char or Varchar
if (pk2chr.m_len != 0)
{ NdbDictionary::Column col("PK2");
col.setType(pk2chr.m_type);
col.setPrimaryKey(true);
col.setLength(pk2chr.m_bytelen);
if (pk2chr.m_csinfo != 0)
col.setCharset(pk2chr.m_csinfo);
if (g_opt.m_pk2part)
col.setPartitionKey(true);
tab.addColumn(col);
}
// col BL2 - Blob nullable
if (! g_opt.m_oneblob)
{ NdbDictionary::Column col("BL2");
const Bcol& b = g_blob2;
col.setType((NdbDictionary::Column::Type)b.m_type);
col.setBlobVersion(b.m_version);
col.setNullable(b.m_nullable);
col.setInlineSize(b.m_inline);
col.setPartSize(b.m_partsize);
col.setStripeSize(b.m_stripe);
col.setStorageType(blobStorageType);
tab.addColumn(col);
}
// col PK3 - puts the Var* key PK2 between PK1 and PK3
if (pk2chr.m_len != 0)
{ NdbDictionary::Column col("PK3");
col.setType(NdbDictionary::Column::Smallunsigned);
col.setPrimaryKey(true);
tab.addColumn(col);
}
// create table
CHK(g_dic->createTable(tab) == 0);
// unique hash index on PK2,PK3
if (g_opt.m_pk2chr.m_len != 0)
{ NdbDictionary::Index idx(g_opt.m_x1name);
idx.setType(NdbDictionary::Index::UniqueHashIndex);
idx.setLogging(loggingRequired);
idx.setTable(g_opt.m_tname);
idx.addColumnName("PK2");
idx.addColumnName("PK3");
CHK(g_dic->createIndex(idx) == 0);
}
// ordered index on PK2
if (g_opt.m_pk2chr.m_len != 0)
{ NdbDictionary::Index idx(g_opt.m_x2name);
idx.setType(NdbDictionary::Index::OrderedIndex);
idx.setLogging(false);
idx.setTable(g_opt.m_tname);
idx.addColumnName("PK2");
CHK(g_dic->createIndex(idx) == 0);
}
NdbDictionary::RecordSpecification spec[5];
unsigned numpks= g_opt.m_pk2chr.m_len == 0 ? 1 : 3;
unsigned numblobs= g_opt.m_oneblob ? 1 : 2;
const NdbDictionary::Table *dict_table;
CHK((dict_table= g_dic->getTable(g_opt.m_tname)) != 0);
memset(spec, 0, sizeof(spec));
spec[0].column= dict_table->getColumn("PK1");
spec[0].offset= g_pk1_offset;
spec[numpks].column= dict_table->getColumn("BL1");
spec[numpks].offset= g_blob1_offset;
spec[numpks].nullbit_byte_offset= g_blob1_null_offset;
spec[numpks].nullbit_bit_in_byte= 0;
if (g_opt.m_pk2chr.m_len != 0)
{
spec[1].column= dict_table->getColumn("PK2");
spec[1].offset= g_pk2_offset;
spec[2].column= dict_table->getColumn("PK3");
spec[2].offset= g_pk3_offset;
}
if (! g_opt.m_oneblob)
{
spec[numpks+1].column= dict_table->getColumn("BL2");
spec[numpks+1].offset= g_blob2_offset;
spec[numpks+1].nullbit_byte_offset= g_blob2_null_offset;
spec[numpks+1].nullbit_bit_in_byte= 0;
}
CHK((g_key_record= g_dic->createRecord(dict_table, &spec[0], numpks,
sizeof(spec[0]))) != 0);
CHK((g_blob_record= g_dic->createRecord(dict_table, &spec[numpks], numblobs,
sizeof(spec[0]))) != 0);
CHK((g_full_record= g_dic->createRecord(dict_table, &spec[0], numpks+numblobs,
sizeof(spec[0]))) != 0);
if (g_opt.m_pk2chr.m_len != 0)
{
const NdbDictionary::Index *dict_index;
CHK((dict_index= g_dic->getIndex(g_opt.m_x1name, g_opt.m_tname)) != 0);
CHK((g_idx_record= g_dic->createRecord(dict_index, &spec[1], 2,
sizeof(spec[0]))) != 0);
CHK((dict_index= g_dic->getIndex(g_opt.m_x2name, g_opt.m_tname)) != 0);
CHK((g_ord_record= g_dic->createRecord(dict_index, &spec[1], 1,
sizeof(spec[0]))) != 0);
}
return 0;
}
// tuples
struct Bval {
const Bcol& m_bcol;
char* m_val;
unsigned m_len;
char* m_buf; // read/write buffer
unsigned m_buflen;
int m_error_code; // for testing expected error code
Bval(const Bcol& bcol) :
m_bcol(bcol),
m_val(0),
m_len(0),
m_buf(0),
m_buflen(0),
m_error_code(0)
{}
~Bval() { delete [] m_val; delete [] m_buf; }
void alloc() {
alloc(m_bcol.m_inline + m_bcol.m_partsize * g_opt.m_parts);
}
void alloc(unsigned buflen) {
m_buflen = buflen;
delete [] m_buf;
m_buf = new char [m_buflen];
trash();
}
void copyfrom(const Bval& v) {
m_len = v.m_len;
delete [] m_val;
if (v.m_val == 0)
m_val = 0;
else
m_val = (char*)memcpy(new char [m_len], v.m_val, m_len);
}
void trash() const {
assert(m_buf != 0);
memset(m_buf, 'x', m_buflen);
}
private:
Bval(const Bval&);
Bval& operator=(const Bval&);
};
NdbOut&
operator<<(NdbOut& out, const Bval& v)
{
if (g_opt.m_min && v.m_val != 0) {
out << "[" << v.m_len << "]";
for (uint i = 0; i < v.m_len; i++) {
const Bcol& b = v.m_bcol;
if (i == b.m_inline ||
(i > b.m_inline && (i - b.m_inline) % b.m_partsize == 0))
out.print("|");
out.print("%c", v.m_val[i]);
}
}
return out;
}
struct Tup {
bool m_exists; // exists in table
Uint32 m_pk1; // in V1 primary keys concatenated like keyinfo
char* m_pk2;
char* m_pk2eq; // equivalent (if case independent)
Uint16 m_pk3;
Bval m_bval1;
Bval m_bval2;
char *m_key_row;
char *m_row;
Uint32 m_frag;
Tup() :
m_exists(false),
m_pk2(new char [g_opt.m_pk2chr.m_totlen + 1]), // nullterm for convenience
m_pk2eq(new char [g_opt.m_pk2chr.m_totlen + 1]),
m_bval1(g_blob1),
m_bval2(g_blob2),
m_key_row(new char[g_rowsize]),
m_row(new char[g_rowsize]),
m_frag(~(Uint32)0)
{}
~Tup() {
delete [] m_pk2;
m_pk2 = 0;
delete [] m_pk2eq;
m_pk2eq = 0;
delete [] m_key_row;
m_key_row= 0;
delete [] m_row;
m_row= 0;
}
// alloc buffers of max size
void alloc() {
m_bval1.alloc();
m_bval2.alloc();
}
void copyfrom(const Tup& tup) {
assert(m_pk1 == tup.m_pk1);
m_bval1.copyfrom(tup.m_bval1);
m_bval2.copyfrom(tup.m_bval2);
}
/*
* in V2 return pk2 or pk2eq at random
* in V1 mixed cases do not work in general due to key packing
* luckily they do work via mysql
*/
char* pk2() {
if (g_opt.m_blob_version == 1)
return m_pk2;
return urandom(2) == 0 ? m_pk2 : m_pk2eq;
}
Uint32 getPartitionId(Uint32 numParts) const {
/* Only for UserDefined tables really */
return m_pk1 % numParts; // MySQLD hash(PK1) style partitioning
}
private:
Tup(const Tup&);
Tup& operator=(const Tup&);
};
static Tup* g_tups;
static void
setUDpartId(const Tup& tup, NdbOperation* op)
{
const NdbDictionary::Table* tab= op->getTable();
if (tab->getFragmentType() == NdbDictionary::Object::UserDefined)
{
Uint32 partId= tup.getPartitionId(tab->getFragmentCount());
DBG("Setting partition id to " << partId << " out of " <<
tab->getFragmentCount());
op->setPartitionId(partId);
}
}
static void
setUDpartIdNdbRecord(const Tup& tup,
const NdbDictionary::Table* tab,
NdbOperation::OperationOptions& opts)
{
opts.optionsPresent= 0;
if (tab->getFragmentType() == NdbDictionary::Object::UserDefined)
{
opts.optionsPresent= NdbOperation::OperationOptions::OO_PARTITION_ID;
opts.partitionId= tup.getPartitionId(tab->getFragmentCount());
}
}
static void
calcBval(const Bcol& b, Bval& v, bool keepsize)
{
if (b.m_nullable && urandom(10) == 0) {
v.m_len = 0;
delete [] v.m_val;
v.m_val = 0;
v.m_buf = new char [1];
} else {
if (keepsize && v.m_val != 0)
;
else if (urandom(10) == 0)
v.m_len = urandom(b.m_inline);
else
v.m_len = urandom(b.m_inline + g_opt.m_parts * b.m_partsize + 1);
delete [] v.m_val;
v.m_val = new char [v.m_len + 1];
for (unsigned i = 0; i < v.m_len; i++)
v.m_val[i] = 'a' + urandom(26);
v.m_val[v.m_len] = 0;
v.m_buf = new char [v.m_len];
}
v.m_buflen = v.m_len;
v.trash();
}
static bool
conHasTimeoutError()
{
Uint32 code= g_con->getNdbError().code;
/* Indicate timeout for cases where LQH too slow responding
* (As can happen for disk based tuples with batching or
* lots of parts)
*/
// 296 == Application timeout waiting for SCAN_NEXTREQ from API
// 297 == Error code in response to SCAN_NEXTREQ for timed-out scan
bool isTimeout= ((code == 274) || // General TC connection timeout
(code == 266)); // TC Scan frag timeout
if (!isTimeout)
ndbout << "Connection error is not timeout, but is "
<< code << endl;
return isTimeout;
}
static
Uint32 conError()
{
return g_con->getNdbError().code;
}
static void
calcBval(Tup& tup, bool keepsize)
{
calcBval(g_blob1, tup.m_bval1, keepsize);
if (! g_opt.m_oneblob)
calcBval(g_blob2, tup.m_bval2, keepsize);
}
// dont remember what the keepsize was for..
static void
calcTups(bool keys, bool keepsize = false)
{
for (uint k = 0; k < g_opt.m_rows; k++) {
Tup& tup = g_tups[k];
if (keys) {
tup.m_pk1 = g_opt.m_pk1off + k;
{
const Chr& c = g_opt.m_pk2chr;
char* const p = tup.m_pk2;
char* const q = tup.m_pk2eq;
uint len = urandom(c.m_len + 1);
uint i = 0;
if (! c.m_fixed) {
*(uchar*)&p[0] = *(uchar*)&q[0] = len;
i++;
}
uint j = 0;
while (j < len) {
// mixed case for distribution check
if (urandom(3) == 0) {
uint u = urandom(26);
p[i] = 'A' + u;
q[i] = c.m_caseins ? 'a' + u : 'A' + u;
} else {
uint u = urandom(26);
p[i] = 'a' + u;
q[i] = c.m_caseins ? 'A' + u : 'a' + u;
}
i++;
j++;
}
while (j < c.m_bytelen) {
if (c.m_fixed)
p[i] = q[i] = 0x20;
else
p[i] = q[i] = '#'; // garbage
i++;
j++;
}
assert(i == c.m_totlen);
p[i] = q[i] = 0; // convenience
}
tup.m_pk3 = (Uint16)k;
}
calcBval(tup, keepsize);
}
}
static void setBatchSizes()
{
if (g_opt.m_rbatch != 0)
{
Uint32 byteSize = (g_opt.m_rbatch == -1) ?
urandom(~Uint32(0)) :
g_opt.m_rbatch;
DBG("Setting read batch size to " << byteSize
<< " bytes.");
g_con->setMaxPendingBlobReadBytes(byteSize);
}
if (g_opt.m_wbatch != 0)
{
Uint32 byteSize = (g_opt.m_wbatch == -1) ?
urandom(~Uint32(0)) :
g_opt.m_wbatch;
DBG("Setting write batch size to " << byteSize
<< " bytes.");
g_con->setMaxPendingBlobWriteBytes(byteSize);
}
}
// blob handle ops
// const version for NdbRecord defined operations
static int
getBlobHandles(const NdbOperation* opr)
{
CHK((g_bh1 = opr->getBlobHandle("BL1")) != 0);
if (! g_opt.m_oneblob)
CHK((g_bh2 = opr->getBlobHandle("BL2")) != 0);
setBatchSizes();
return 0;
}
// non-const version for NdbRecAttr defined operations
// and scans
static int
getBlobHandles(NdbOperation* opr)
{
CHK((g_bh1 = opr->getBlobHandle("BL1")) != 0);
if (! g_opt.m_oneblob)
CHK((g_bh2 = opr->getBlobHandle("BL2")) != 0);
setBatchSizes();
return 0;