Repository navigation
Expand file tree
/
Copy patha2-test.cc
More file actions
152 lines (118 loc) · 3.04 KB
/
Copy patha2-test.cc
File metadata and controls
152 lines (118 loc) · 3.04 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
#include "a2-test.h"
#include "BigQ.h"
#include <pthread.h>
void *producer (void *arg) {
Pipe *myPipe = (Pipe *) arg;
Record temp;
int counter = 0;
DBFile dbfile;
dbfile.Open (rel->path ());
cout << " producer: opened DBFile " << rel->path () << endl;
dbfile.MoveFirst ();
while (dbfile.GetNext (temp) == 1) {
counter += 1;
if (counter%100000 == 0) {
cerr << " producer: " << counter << endl;
}
myPipe->Insert (&temp);
}
dbfile.Close ();
myPipe->ShutDown ();
cout << " producer: inserted " << counter << " recs into the pipe\n";
}
void *consumer (void *arg) {
testutil *t = (testutil *) arg;
ComparisonEngine ceng;
DBFile dbfile;
char outfile[100];
if (t->write) {
sprintf (outfile, "%s.bigq", rel->path ());
dbfile.Create (outfile, heap, NULL);
}
int err = 0;
int i = 0;
Record rec[2];
Record *last = NULL, *prev = NULL;
while (t->pipe->Remove (&rec[i%2])) {
prev = last;
last = &rec[i%2];
if (prev && last) {
if (ceng.Compare (prev, last, t->order) == 1) {
err++;
}
if (t->write) {
dbfile.Add (*prev);
}
}
if (t->print) {
last->Print (rel->schema ());
}
i++;
}
cout << " consumer: removed " << i << " recs from the pipe\n";
if (t->write) {
if (last) {
dbfile.Add (*last);
}
cerr << " consumer: recs removed written out as heap DBFile at " << outfile << endl;
dbfile.Close ();
}
cerr << " consumer: " << (i - err) << " recs out of " << i << " recs in sorted order \n";
if (err) {
cerr << " consumer: " << err << " recs failed sorted order test \n" << endl;
}
}
void test1 (int option, int runlen) {
// sort order for records
OrderMaker sortorder;
rel->get_sort_order (sortorder);
int buffsz = 100; // pipe cache size
Pipe input (buffsz);
Pipe output (buffsz);
// thread to dump data into the input pipe (for BigQ's consumption)
pthread_t thread1;
pthread_create (&thread1, NULL, producer, (void *)&input);
// thread to read sorted data from output pipe (dumped by BigQ)
pthread_t thread2;
testutil tutil = {&output, &sortorder, false, false};
if (option == 2) {
tutil.print = true;
}
else if (option == 3) {
tutil.write = true;
}
pthread_create (&thread2, NULL, consumer, (void *)&tutil);
BigQ bq (input, output, sortorder, runlen);
pthread_join (thread1, NULL);
pthread_join (thread2, NULL);
}
int main (int argc, char *argv[]) {
setup ();
relation *rel_ptr[] = {n, r, c, p, ps, o, li};
int tindx = 0;
while (tindx < 1 || tindx > 3) {
cout << " select test option: \n";
cout << " \t 1. sort \n";
cout << " \t 2. sort + display \n";
cout << " \t 3. sort + write \n\t ";
cin >> tindx;
}
int findx = 0;
while (findx < 1 || findx > 7) {
cout << "\n select dbfile to use: \n";
cout << "\t 1. nation \n";
cout << "\t 2. region \n";
cout << "\t 3. customer \n";
cout << "\t 4. part \n";
cout << "\t 5. partsupp \n";
cout << "\t 6. orders \n";
cout << "\t 7. lineitem \n \t ";
cin >> findx;
}
rel = rel_ptr [findx - 1];
int runlen;
cout << "\t\n specify runlength:\n\t ";
cin >> runlen;
test1 (tindx, runlen);
cleanup ();
}