forked from electrum/ssb-dbgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.c
1157 lines (1058 loc) · 28.4 KB
/
driver.c
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
/* @(#)driver.c 2.1.8.4 */
/* main driver for dss banchmark */
#define DECLARER /* EXTERN references get defined here */
#define NO_FUNC (int (*) ()) NULL /* to clean up tdefs */
#define NO_LFUNC (long (*) ()) NULL /* to clean up tdefs */
#include "config.h"
#include <stdlib.h>
#if (defined(_POSIX_)||!defined(WIN32)) /* Change for Windows NT */
#ifndef DOS
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <getopt.h>
#endif
#endif /* WIN32 */
#include <stdio.h> /* */
#include <limits.h>
#include <math.h>
#include <ctype.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#ifdef HP
#include <strings.h>
#endif
#if (defined(WIN32)&&!defined(_POSIX_))
#include <process.h>
#pragma warning(disable:4201)
#pragma warning(disable:4214)
#pragma warning(disable:4514)
#define WIN32_LEAN_AND_MEAN
#define NOATOM
#define NOGDICAPMASKS
#define NOMETAFILE
#define NOMINMAX
#define NOMSG
#define NOOPENFILE
#define NORASTEROPS
#define NOSCROLL
#define NOSOUND
#define NOSYSMETRICS
#define NOTEXTMETRIC
#define NOWH
#define NOCOMM
#define NOKANJI
#define NOMCX
#include "windows.h"
#pragma warning(default:4201)
#pragma warning(default:4214)
#endif
#include "dss.h"
#include "dsstypes.h"
#include "bcd2.h"
/*
* Function prototypes
*/
void usage (void);
int prep_direct (char *);
int close_direct (void);
void kill_load (void);
int pload (int tbl);
void gen_tbl (int tnum, long start, long count, long upd_num);
int pr_drange (int tbl, long min, long cnt, long num);
int set_files (int t, int pload);
int partial (int, int);
extern int optind, opterr;
extern char *optarg;
long rowcnt = 0, minrow = 0, upd_num = 0;
double flt_scale;
#if (defined(WIN32)&&!defined(_POSIX_))
char *spawn_args[25];
#endif
/*
* general table descriptions. See dss.h for details on structure
* NOTE: tables with no scaling info are scaled according to
* another table
*
*
* the following is based on the tdef structure defined in dss.h as:
* typedef struct
* {
* char *name; -- name of the table;
* flat file output in <name>.tbl
* long base; -- base scale rowcount of table;
* 0 if derived
* int (*header) (); -- function to prep output
* int (*loader[2]) (); -- functions to present output
* long (*gen_seed) (); -- functions to seed the RNG
* int (*verify) (); -- function to verfiy the data set without building it
* int child; -- non-zero if there is an associated detail table
* unsigned long vtotal; -- "checksum" total
* } tdef;
*
*/
/*
* flat file print functions; used with -F(lat) option
*/
#ifdef SSBM
// HYRISE: change first parameter to void pointer so the tdef loader member can have a function prototype
// (C2x compatibility).
int pr_cust (void * c, int mode);
int pr_part (void * p, int mode);
int pr_supp (void * s, int mode);
int pr_line (void * t, int mode);
#else
int pr_cust (customer_t * c, int mode);
int pr_line (order_t * o, int mode);
int pr_order (order_t * o, int mode);
int pr_part (part_t * p, int mode);
int pr_psupp (part_t * p, int mode);
int pr_supp (supplier_t * s, int mode);
int pr_order_line (order_t * o, int mode);
int pr_part_psupp (part_t * p, int mode);
int pr_nation (code_t * c, int mode);
int pr_region (code_t * c, int mode);
#endif
/*
* inline load functions; used with -D(irect) option
*/
#ifdef SSBM
// HYRISE: change first parameter to void pointer so the tdef loader member can have a function prototype
// (C2x compatibility).
int ld_cust (void * c, int mode);
int ld_part (void * p, int mode);
int ld_supp (void * s, int mode);
/*todo: get rid of ld_order*/
int ld_line (void * o, int mode);
int ld_order (void * o, int mode);
#else
int ld_cust (customer_t * c, int mode);
int ld_line (order_t * o, int mode);
int ld_order (order_t * o, int mode);
int ld_part (part_t * p, int mode);
int ld_psupp (part_t * p, int mode);
int ld_supp (supplier_t * s, int mode);
int ld_order_line (order_t * o, int mode);
int ld_part_psupp (part_t * p, int mode);
int ld_nation (code_t * c, int mode);
int ld_region (code_t * c, int mode);
#endif
/*
* seed generation functions; used with '-O s' option
*/
#ifdef SSBM
long sd_cust (int child, long skip_count);
long sd_part (int child, long skip_count);
long sd_supp (int child, long skip_count);
long sd_line (int child, long skip_count);
long sd_order (int child, long skip_count);
#else
long sd_cust (int child, long skip_count);
long sd_line (int child, long skip_count);
long sd_order (int child, long skip_count);
long sd_part (int child, long skip_count);
long sd_psupp (int child, long skip_count);
long sd_supp (int child, long skip_count);
long sd_order_line (int child, long skip_count);
long sd_part_psupp (int child, long skip_count);
#endif
/*
* header output functions); used with -h(eader) option
*/
#ifdef SSBM
int hd_cust (FILE * f);
int hd_part (FILE * f);
int hd_supp (FILE * f);
int hd_line (FILE * f);
#else
int hd_cust (FILE * f);
int hd_line (FILE * f);
int hd_order (FILE * f);
int hd_part (FILE * f);
int hd_psupp (FILE * f);
int hd_supp (FILE * f);
int hd_order_line (FILE * f);
int hd_part_psupp (FILE * f);
int hd_nation (FILE * f);
int hd_region (FILE * f);
#endif
/*
* data verfication functions; used with -O v option
*/
#ifdef SSBM
// HYRISE: change first parameter to void pointer so the tdef verify member can have a function prototype
// (C2x compatibility).
int vrf_cust (void * c, int mode);
int vrf_part (void * p, int mode);
int vrf_supp (void * s, int mode);
int vrf_line (void * o, int mode);
int vrf_order (void * o, int mode);
int vrf_date (void * d, int mode);
#else
int vrf_cust (customer_t * c, int mode);
int vrf_line (order_t * o, int mode);
int vrf_order (order_t * o, int mode);
int vrf_part (part_t * p, int mode);
int vrf_psupp (part_t * p, int mode);
int vrf_supp (supplier_t * s, int mode);
int vrf_order_line (order_t * o, int mode);
int vrf_part_psupp (part_t * p, int mode);
int vrf_nation (code_t * c, int mode);
int vrf_region (code_t * c, int mode);
#endif
#ifdef SSBM
tdef tdefs[] =
{
{"part.tbl", "part table", 200000, hd_part,
{pr_part, ld_part}, sd_part, vrf_part, PSUPP, 0},
{0,0,0,0,{0,0}, 0,0,0,0},
{"supplier.tbl", "suppliers table", 2000, hd_supp,
{pr_supp, ld_supp}, sd_supp, vrf_supp, NONE, 0},
{"customer.tbl", "customers table", 30000, hd_cust,
{pr_cust, ld_cust}, sd_cust, vrf_cust, NONE, 0},
{"date.tbl","date table",2556,0,{pr_date,ld_date}, 0,vrf_date, NONE,0},
/*line order is SF*1,500,000, however due to the implementation
the base here is 150,000 instead if 1500,000*/
{"lineorder.tbl", "lineorder table", 150000, hd_line,
{pr_line, ld_line}, sd_line, vrf_line, NONE, 0},
{0,0,0,0,{0,0}, 0,0,0,0},
{0,0,0,0,{0,0}, 0,0,0,0},
{0,0,0,0,{0,0}, 0,0,0,0},
{0,0,0,0,{0,0}, 0,0,0,0},
};
#else
tdef tdefs[] =
{
{"part.tbl", "part table", 200000, hd_part,
{pr_part, ld_part}, sd_part, vrf_part, PSUPP, 0},
{"partsupp.tbl", "partsupplier table", 200000, hd_psupp,
{pr_psupp, ld_psupp}, sd_psupp, vrf_psupp, NONE, 0},
{"supplier.tbl", "suppliers table", 10000, hd_supp,
{pr_supp, ld_supp}, sd_supp, vrf_supp, NONE, 0},
{"customer.tbl", "customers table", 150000, hd_cust,
{pr_cust, ld_cust}, sd_cust, vrf_cust, NONE, 0},
{"orders.tbl", "order table", 150000, hd_order,
{pr_order, ld_order}, sd_order, vrf_order, LINE, 0},
{"lineitem.tbl", "lineitem table", 150000, hd_line,
{pr_line, ld_line}, sd_line, vrf_line, NONE, 0},
{"orders.tbl", "orders/lineitem tables", 150000, hd_order_line,
{pr_order_line, ld_order_line}, sd_order, vrf_order_line, LINE, 0},
{"part.tbl", "part/partsupplier tables", 200000, hd_part_psupp,
{pr_part_psupp, ld_part_psupp}, sd_part, vrf_part_psupp, PSUPP, 0},
{"nation.tbl", "nation table", NATIONS_MAX, hd_nation,
{pr_nation, ld_nation}, NO_LFUNC, vrf_nation, NONE, 0},
{"region.tbl", "region table", NATIONS_MAX, hd_region,
{pr_region, ld_region}, NO_LFUNC, vrf_region, NONE, 0},
};
#endif
int *pids;
/*
* routines to handle the graceful cleanup of multi-process loads
*/
void
stop_proc (int signum)
{
exit (0);
}
void
kill_load (void)
{
int i;
#if !defined(U2200) && !defined(DOS)
for (i = 0; i < children; i++)
if (pids[i])
KILL (pids[i]);
#endif /* !U2200 && !DOS */
return;
}
/*
* re-set default output file names
*/
int
set_files (int i, int pload)
{
char line[80], *new_name;
if (table & (1 << i))
child_table:
{
if (pload != -1)
sprintf (line, "%s.%d", tdefs[i].name, pload);
else
{
printf ("Enter new destination for %s data: ",
tdefs[i].name);
if (fgets (line, sizeof (line), stdin) == NULL)
return (-1);;
if ((new_name = strchr (line, '\n')) != NULL)
*new_name = '\0';
if (strlen (line) == 0)
return (0);
}
new_name = (char *) malloc (strlen (line) + 1);
MALLOC_CHECK (new_name);
strcpy (new_name, line);
tdefs[i].name = new_name;
if (tdefs[i].child != NONE)
{
i = tdefs[i].child;
tdefs[i].child = NONE;
goto child_table;
}
}
return (0);
}
/*
* read the distributions needed in the benchamrk
*/
void
load_dists (void)
{
read_dist (env_config (DIST_TAG, DIST_DFLT), "p_cntr", &p_cntr_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "colors", &colors);
read_dist (env_config (DIST_TAG, DIST_DFLT), "p_types", &p_types_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "nations", &nations);
read_dist (env_config (DIST_TAG, DIST_DFLT), "regions", ®ions);
read_dist (env_config (DIST_TAG, DIST_DFLT), "o_oprio",
&o_priority_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "instruct",
&l_instruct_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "smode", &l_smode_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "category",
&l_category_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "rflag", &l_rflag_set);
read_dist (env_config (DIST_TAG, DIST_DFLT), "msegmnt", &c_mseg_set);
/* load the distributions that contain text generation */
read_dist (env_config (DIST_TAG, DIST_DFLT), "nouns", &nouns);
read_dist (env_config (DIST_TAG, DIST_DFLT), "verbs", &verbs);
read_dist (env_config (DIST_TAG, DIST_DFLT), "adjectives", &adjectives);
read_dist (env_config (DIST_TAG, DIST_DFLT), "adverbs", &adverbs);
read_dist (env_config (DIST_TAG, DIST_DFLT), "auxillaries", &auxillaries);
read_dist (env_config (DIST_TAG, DIST_DFLT), "terminators", &terminators);
read_dist (env_config (DIST_TAG, DIST_DFLT), "articles", &articles);
read_dist (env_config (DIST_TAG, DIST_DFLT), "prepositions", &prepositions);
read_dist (env_config (DIST_TAG, DIST_DFLT), "grammar", &grammar);
read_dist (env_config (DIST_TAG, DIST_DFLT), "np", &np);
read_dist (env_config (DIST_TAG, DIST_DFLT), "vp", &vp);
}
/*
* generate a particular table
*/
void
gen_tbl (int tnum, long start, long count, long upd_num)
{
static order_t o;
supplier_t supp;
customer_t cust;
part_t part;
#ifdef SSBM
date_t dt;
#else
code_t code;
#endif
static int completed = 0;
static int init = 0;
long i;
int rows_per_segment=0;
int rows_this_segment=-1;
int residual_rows=0;
if (insert_segments)
{
rows_per_segment = count / insert_segments;
residual_rows = count - (rows_per_segment * insert_segments);
}
if (init == 0)
{
INIT_HUGE(o.okey);
for (i=0; i < O_LCNT_MAX; i++)
#ifdef SSBM
INIT_HUGE(o.lineorders[i].okey);
#else
INIT_HUGE(o.l[i].okey);
#endif
init = 1;
}
for (i = start; count; count--, i++)
{
LIFENOISE (1000, i);
row_start(tnum);
switch (tnum)
{
case LINE:
#ifdef SSBM
#else
case ORDER:
case ORDER_LINE:
#endif
mk_order (i, &o, upd_num % 10000);
if (insert_segments && (upd_num > 0))
if((upd_num / 10000) < residual_rows)
{
if((++rows_this_segment) > rows_per_segment)
{
rows_this_segment=0;
upd_num += 10000;
}
}
else
{
if((++rows_this_segment) >= rows_per_segment)
{
rows_this_segment=0;
upd_num += 10000;
}
}
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&o, 0);
else
tdefs[tnum].loader[direct] (&o, upd_num);
break;
case SUPP:
mk_supp (i, &supp);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&supp, 0);
else
tdefs[tnum].loader[direct] (&supp, upd_num);
break;
case CUST:
mk_cust (i, &cust);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&cust, 0);
else
tdefs[tnum].loader[direct] (&cust, upd_num);
break;
#ifdef SSBM
case PART:
#else
case PSUPP:
case PART:
case PART_PSUPP:
#endif
mk_part (i, &part);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&part, 0);
else
tdefs[tnum].loader[direct] (&part, upd_num);
break;
#ifdef SSBM
case DATE:
mk_date (i, &dt);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&dt, 0);
else
tdefs[tnum].loader[direct] (&dt, 0);
break;
#else
case NATION:
mk_nation (i, &code);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&code, 0);
else
tdefs[tnum].loader[direct] (&code, 0);
break;
case REGION:
mk_region (i, &code);
if (set_seeds == 0)
if (validate)
tdefs[tnum].verify(&code, 0);
else
tdefs[tnum].loader[direct] (&code, 0);
break;
#endif
}
row_stop(tnum);
if (set_seeds && (i % tdefs[tnum].base) < 2)
{
printf("\nSeeds for %s at rowcount %ld\n", tdefs[tnum].comment, i);
dump_seeds(tnum);
}
}
completed |= 1 << tnum;
}
void
usage (void)
{
#ifdef SSBM
fprintf (stderr, "%s\n%s\n\t%s\n%s %s\n\n",
"USAGE:",
"dbgen [-{vfFD}] [-O {fhmsv}][-T {pcsdla}]",
"[-s <scale>][-C <procs>][-S <step>]",
"dbgen [-v] [-O {dfhmr}] [-s <scale>]",
"[-U <updates>] [-r <percent>]");
#else
fprintf (stderr, "%s\n%s\n\t%s\n%s %s\n\n",
"USAGE:",
"dbgen [-{vfFD}] [-O {fhmsv}][-T {pcsoPSOL}]",
"[-s <scale>][-C <procs>][-S <step>]",
"dbgen [-v] [-O {dfhmr}] [-s <scale>]",
"[-U <updates>] [-r <percent>]");
#endif
fprintf (stderr, "-b <s> -- load distributions for <s>\n");
fprintf (stderr, "-C <n> -- use <n> processes to generate data\n");
fprintf (stderr, " [Under DOS, must be used with -S]\n");
fprintf (stderr, "-D -- do database load in line\n");
fprintf (stderr, "-d <n> -- split deletes between <n> files\n");
fprintf (stderr, "-f -- force. Overwrite existing files\n");
fprintf (stderr, "-F -- generate flat files output\n");
fprintf (stderr, "-h -- display this message\n");
fprintf (stderr, "-i <n> -- split inserts between <n> files\n");
fprintf (stderr, "-n <s> -- inline load into database <s>\n");
fprintf (stderr, "-O d -- generate SQL syntax for deletes\n");
fprintf (stderr, "-O f -- over-ride default output file names\n");
fprintf (stderr, "-O h -- output files with headers\n");
fprintf (stderr, "-O m -- produce columnar output\n");
fprintf (stderr, "-O r -- generate key ranges for deletes.\n");
fprintf (stderr, "-O v -- Verify data set without generating it.\n");
fprintf (stderr, "-q -- enable QUIET mode\n");
fprintf (stderr, "-r <n> -- updates refresh (n/100)%% of the\n");
fprintf (stderr, " data set\n");
fprintf (stderr, "-s <n> -- set Scale Factor (SF) to <n> \n");
fprintf (stderr, "-S <n> -- build the <n>th step of the data/update set\n");
#ifdef SSBM
fprintf (stderr, "-T c -- generate cutomers dimension table ONLY\n");
fprintf (stderr, "-T p -- generate parts dimension table ONLY\n");
fprintf (stderr, "-T s -- generate suppliers dimension table ONLY\n");
fprintf (stderr, "-T d -- generate date dimension table ONLY\n");
fprintf (stderr, "-T l -- generate lineorder fact table ONLY\n");
#else
fprintf (stderr, "-T c -- generate cutomers ONLY\n");
fprintf (stderr, "-T l -- generate nation/region ONLY\n");
fprintf (stderr, "-T L -- generate lineitem ONLY\n");
fprintf (stderr, "-T n -- generate nation ONLY\n");
fprintf (stderr, "-T o -- generate orders/lineitem ONLY\n");
fprintf (stderr, "-T O -- generate orders ONLY\n");
fprintf (stderr, "-T p -- generate parts/partsupp ONLY\n");
fprintf (stderr, "-T P -- generate parts ONLY\n");
fprintf (stderr, "-T r -- generate region ONLY\n");
fprintf (stderr, "-T s -- generate suppliers ONLY\n");
fprintf (stderr, "-T S -- generate partsupp ONLY\n");
#endif
fprintf (stderr, "-U <s> -- generate <s> update sets\n");
fprintf (stderr, "-v -- enable VERBOSE mode\n");
fprintf (stderr,
"\nTo generate the SF=1 (1GB), validation database population, use:\n");
fprintf (stderr, "\tdbgen -vfF -s 1\n");
fprintf (stderr, "\nTo generate updates for a SF=1 (1GB), use:\n");
fprintf (stderr, "\tdbgen -v -U 1 -s 1\n");
}
/*
* pload() -- handle the parallel loading of tables
*/
/*
* int partial(int tbl, int s) -- generate the s-th part of the named tables data
*/
int
partial (int tbl, int s)
{
long rowcnt;
long extra;
if (verbose > 0)
{
// HYRISE: Change format specifier.
fprintf (stderr, "\tStarting to load stage %d of %ld for %s...",
s, children, tdefs[tbl].comment);
}
if (direct == 0)
set_files (tbl, s);
rowcnt = set_state(tbl, scale, children, s, &extra);
if (s == children)
gen_tbl (tbl, rowcnt * (s - 1) + 1, rowcnt + extra, upd_num);
else
gen_tbl (tbl, rowcnt * (s - 1) + 1, rowcnt, upd_num);
if (verbose > 0)
fprintf (stderr, "done.\n");
return (0);
}
#ifndef DOS
int
pload (int tbl)
{
int c = 0, i, status;
if (verbose > 0)
{
// HYRISE: Change format specifier.
fprintf (stderr, "Starting %ld children to load %s",
children, tdefs[tbl].comment);
}
for (c = 0; c < children; c++)
{
pids[c] = SPAWN ();
if (pids[c] == -1)
{
perror ("Child loader not created");
kill_load ();
exit (-1);
}
else if (pids[c] == 0) /* CHILD */
{
SET_HANDLER (stop_proc);
verbose = 0;
partial (tbl, c+1);
exit (0);
}
else if (verbose > 0) /* PARENT */
fprintf (stderr, ".");
}
if (verbose > 0)
fprintf (stderr, "waiting...");
c = children;
while (c)
{
i = WAIT (&status, pids[c - 1]);
if (i == -1 && children)
{
if (errno == ECHILD)
fprintf (stderr, "\nCould not wait on pid %d\n", pids[c - 1]);
else if (errno == EINTR)
fprintf (stderr, "\nProcess %d stopped abnormally\n", pids[c - 1]);
else if (errno == EINVAL)
fprintf (stderr, "\nProgram bug\n");
}
if (! WIFEXITED(status)) {
(void) fprintf(stderr, "\nProcess %d: ", i);
if (WIFSIGNALED(status)) {
(void) fprintf(stderr, "rcvd signal %d\n",
WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
(void) fprintf(stderr, "stopped, signal %d\n",
WSTOPSIG(status));
}
}
c--;
}
if (verbose > 0)
fprintf (stderr, "done\n");
return (0);
}
#endif
void
process_options (int count, char **vector)
{
int option;
while ((option = getopt (count, vector,
"b:C:Dd:Ffi:hn:O:P:qr:s:S:T:U:v")) != -1)
switch (option)
{
case 'b': /* load distributions from named file */
d_path = (char *)malloc(strlen(optarg) + 1);
MALLOC_CHECK(d_path);
strcpy(d_path, optarg);
break;
case 'q': /* all prompts disabled */
verbose = -1;
break;
case 'i':
insert_segments = atoi (optarg);
break;
case 'd':
delete_segments = atoi (optarg);
break;
case 'S': /* generate a particular STEP */
step = atoi (optarg);
break;
case 'v': /* life noises enabled */
verbose = 1;
break;
case 'f': /* blind overwrites; Force */
force = 1;
break;
case 'T': /* generate a specifc table */
switch (*optarg)
{
#ifdef SSBM
case 'c': /* generate customer ONLY */
table = 1 << CUST;
break;
case 'p': /* generate part ONLY */
table = 1 << PART;
break;
case 's': /* generate partsupp ONLY */
table = 1 << SUPP;
break;
case 'd': /* generate date ONLY */
table = 1 << DATE;
break;
case 'l': /* generate lineorder table ONLY */
table = 1 << LINE;
break;
case 'a':
table = 1 << CUST;
table |= 1 << PART;
table |= 1 << SUPP;
table |= 1 << DATE;
table |= 1 << LINE;
break;
#else
case 'c': /* generate customer ONLY */
table = 1 << CUST;
break;
case 'L': /* generate lineitems ONLY */
table = 1 << LINE;
break;
case 'l': /* generate code table ONLY */
table = 1 << NATION;
table |= 1 << REGION;
break;
case 'n': /* generate nation table ONLY */
table = 1 << NATION;
break;
case 'O': /* generate orders ONLY */
table = 1 << ORDER;
break;
case 'o': /* generate orders/lineitems ONLY */
table = 1 << ORDER_LINE;
break;
case 'P': /* generate part ONLY */
table = 1 << PART;
break;
case 'p': /* generate part/partsupp ONLY */
table = 1 << PART_PSUPP;
break;
case 'r': /* generate region table ONLY */
table = 1 << REGION;
break;
case 'S': /* generate partsupp ONLY */
table = 1 << PSUPP;
break;
case 's': /* generate suppliers ONLY */
table = 1 << SUPP;
break;
#endif
default:
fprintf (stderr, "Unknown table name %s\n",
optarg);
usage ();
exit (1);
}
break;
case 's': /* scale by Percentage of base rowcount */
case 'P': /* for backward compatibility */
flt_scale = atof (optarg);
if (flt_scale < MIN_SCALE)
{
int i;
scale = 1;
for (i = PART; i < REGION; i++)
{
tdefs[i].base *= flt_scale;
if (tdefs[i].base < 1)
tdefs[i].base = 1;
}
}
else
scale = (long) flt_scale;
if (scale > MAX_SCALE)
{
fprintf (stderr, "%s %5.0f %s\n\t%s\n\n",
"NOTE: Data generation for scale factors >",
MAX_SCALE,
"GB is still in development,",
"and is not yet supported.\n");
fprintf (stderr,
"Your resulting data set MAY NOT BE COMPLIANT!\n");
}
break;
case 'O': /* optional actions */
switch (tolower (*optarg))
{
case 'd': /* generate SQL for deletes */
gen_sql = 1;
break;
case 'f': /* over-ride default file names */
fnames = 1;
break;
case 'h': /* generate headers */
header = 1;
break;
case 'm': /* generate columnar output */
columnar = 1;
break;
case 'r': /* generate key ranges for delete */
gen_rng = 1;
break;
case 's': /* calibrate the RNG usage */
set_seeds = 1;
break;
case 'v': /* validate the data set */
validate = 1;
break;
default:
fprintf (stderr, "Unknown option name %s\n",
optarg);
usage ();
exit (1);
}
break;
case 'D': /* direct load of generated data */
direct = 1;
break;
case 'F': /* generate flat files for later loading */
direct = 0;
break;
case 'U': /* generate flat files for update stream */
updates = atoi (optarg);
break;
case 'r': /* set the refresh (update) percentage */
refresh = atoi (optarg);
break;
#ifndef DOS
case 'C':
children = atoi (optarg);
break;
#endif /* !DOS */
case 'n': /* set name of database for direct load */
db_name = (char *) malloc (strlen (optarg) + 1);
MALLOC_CHECK (db_name);
strcpy (db_name, optarg);
break;
default:
printf ("ERROR: option '%c' unknown.\n",
*(vector[optind] + 1));
case 'h': /* something unexpected */
fprintf (stderr,
"%s Population Generator (Version %d.%d.%d%s)\n",
NAME, VERSION, RELEASE,
MODIFICATION, PATCH);
fprintf (stderr, "Copyright %s %s\n", TPC, C_DATES);
usage ();
exit (1);
}
#ifndef DOS
if (children != 1 && step == -1)
{
pids = malloc(children * sizeof(pid_t));
MALLOC_CHECK(pids)
}
#else
if (children != 1 && step < 0)
{
fprintf(stderr, "ERROR: -C must be accompanied by -S on this platform\n");
exit(1);
}
#endif /* DOS */
return;
}
/*
* MAIN
*
* assumes the existance of getopt() to clean up the command
* line handling
*/
int
main (int ac, char **av)
{
int i;
table = (1 << CUST) |
(1 << SUPP) |
(1 << NATION) |
(1 << REGION) |
(1 << PART_PSUPP) |
(1 << ORDER_LINE);
force = 0;
insert_segments=0;
delete_segments=0;
insert_orders_segment=0;
insert_lineitem_segment=0;
delete_segment=0;
verbose = 0;
columnar = 0;
set_seeds = 0;
header = 0;
direct = 0;
scale = 1;
flt_scale = 1.0;
updates = 0;
refresh = UPD_PCT;
step = -1;
#ifdef SSBM
tdefs[LINE].base *=
ORDERS_PER_CUST; /* have to do this after init */
#else
tdefs[ORDER].base *=
ORDERS_PER_CUST; /* have to do this after init */
tdefs[LINE].base *=
ORDERS_PER_CUST; /* have to do this after init */
tdefs[ORDER_LINE].base *=
ORDERS_PER_CUST; /* have to do this after init */
#endif
fnames = 0;
db_name = NULL;
gen_sql = 0;
gen_rng = 0;
children = 1;
d_path = NULL;
#ifdef NO_SUPPORT
signal (SIGINT, exit);
#endif /* NO_SUPPORT */
process_options (ac, av);
#if (defined(WIN32)&&!defined(_POSIX_))
for (i = 0; i < ac; i++)
{
spawn_args[i] = malloc ((strlen (av[i]) + 1) * sizeof (char));
MALLOC_CHECK (spawn_args[i]);
strcpy (spawn_args[i], av[i]);
}
spawn_args[ac] = NULL;
#endif
if (verbose >= 0)
{
fprintf (stderr,
"%s Population Generator (Version %d.%d.%d%s)\n",
NAME, VERSION, RELEASE, MODIFICATION, PATCH);
fprintf (stderr, "Copyright %s %s\n", TPC, C_DATES);
}
load_dists ();
/* have to do this after init */
tdefs[NATION].base = nations.count;
tdefs[REGION].base = regions.count;
/*
* updates are never parallelized
*/
if (updates)
{
/*
* set RNG to start generating rows beyond SF=scale