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
|
/*-
* Copyright (c) 2008-2012 WiredTiger, Inc.
* All rights reserved.
*
* See the file LICENSE for redistribution information.
*/
#include "format.h"
GLOBAL g;
static void onint(int);
static void startup(void);
static void usage(void);
int
main(int argc, char *argv[])
{
int ch, reps, ret;
ret = 0;
if ((g.progname = strrchr(argv[0], '/')) == NULL)
g.progname = argv[0];
else
++g.progname;
/* Configure the FreeBSD malloc for debugging. */
(void)setenv("MALLOC_OPTIONS", "AJZ", 1);
/* Set values from the "CONFIG" file, if it exists. */
if (access("CONFIG", R_OK) == 0) {
printf("... reading CONFIG file\n");
config_file("CONFIG");
}
/* Track progress unless we're re-directing output to a file. */
g.track = isatty(STDOUT_FILENO) ? 1 : 0;
/* Set values from the command line. */
while ((ch = getopt(argc, argv, "1C:c:Llqr")) != EOF)
switch (ch) {
case '1': /* One run */
g.c_runs = 1;
break;
case 'C': /* wiredtiger_open config */
g.config_open = optarg;
break;
case 'c': /* Configuration from a file */
config_file(optarg);
break;
case 'L': /* Re-direct output to a log */
/*
* The -l option is a superset of -L, ignore -L if we
* have already configured logging for operations.
*/
if (g.logging == 0)
g.logging = LOG_FILE;
break;
case 'l': /* Turn on operation logging */
g.logging = LOG_OPS;
break;
case 'q': /* Quiet */
g.track = 0;
break;
case 'r': /* Replay a run */
g.replay = 1;
g.c_runs = 1;
break;
default:
usage();
}
argc -= optind;
argv += optind;
for (; *argv != NULL; ++argv)
config_single(*argv, 1);
/* Clean up on signal. */
(void)signal(SIGINT, onint);
printf("%s: process %" PRIdMAX "\n", g.progname, (intmax_t)getpid());
while (++g.run_cnt <= g.c_runs || g.c_runs == 0 ) {
startup(); /* Start a run */
config_setup(); /* Run configuration */
config_print(0); /* Dump run configuration */
bdb_startup(); /* Initial file config */
if (wts_startup(0))
return (EXIT_FAILURE);
key_gen_setup(); /* Setup keys */
if (wts_bulk_load()) /* Load initial records */
goto err;
/* Close, verify */
if (wts_teardown() || wts_verify("post-bulk verify"))
goto err;
/* Loop reading & operations */
for (reps = 0; reps < 3; ++reps) {
if (wts_startup(1))
goto err;
if (wts_read_scan()) /* Read scan */
goto err;
/* Random operations */
if (g.c_ops != 0 && wts_ops())
goto err;
/* Statistics */
if ((g.c_ops == 0 || reps == 2) && wts_stats())
goto err;
/* Close, verify */
if (wts_teardown() || wts_verify("post-ops verify"))
goto err;
/*
* If no operations scheduled, quit after a single
* read pass.
*/
if (g.c_ops == 0)
break;
}
track("shutting down BDB", 0ULL);
bdb_teardown();
if (wts_dump("standard", 1)) /* Dump the file */
goto err;
/*
* If we don't delete any records, we can salvage the file. The
* problem with deleting records is that salvage will restore
* deleted records if a page fragments leaving a deleted record
* on one side of the split.
*
* Save a copy, salvage, verify, dump.
*/
if (g.c_delete_pct == 0) {
/*
* Save a copy of the interesting files so we can replay
* the salvage step as necessary.
*/
if (system(
"rm -rf __slvg.copy && "
"mkdir __slvg.copy && "
"cp WiredTiger* __wt __slvg.copy/") != 0)
goto err;
if (wts_salvage() ||
wts_verify("post-salvage verify") ||
wts_dump("salvage", 0))
goto err;
}
printf("%4d: %-40s\n", g.run_cnt, config_dtype());
}
if (0) {
err: ret = 1;
}
if (g.logfp != NULL)
(void)fclose(g.logfp);
if (g.rand_log != NULL)
(void)fclose(g.rand_log);
config_print(ret);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
/*
* startup --
* Initialize for a run.
*/
static void
startup(void)
{
/* Close the logging file. */
if (g.logfp != NULL) {
(void)fclose(g.logfp);
g.logfp = NULL;
}
/* Close the random number file. */
if (g.rand_log != NULL) {
(void)fclose(g.rand_log);
g.rand_log = NULL;
}
/* Remove the run's files except for __rand. */
(void)system("rm -rf WiredTiger WiredTiger.* __[a-qs-z]* __run");
/* Open/truncate the logging file. */
if (g.logging != 0) {
if ((g.logfp = fopen("__log", "w")) == NULL)
die("__log", errno);
(void)setvbuf(g.logfp, NULL, _IOLBF, 0);
}
}
/*
* onint --
* Interrupt signal handler.
*/
static void
onint(int signo)
{
UNUSED(signo);
/* Remove the run's files except for __rand. */
(void)system("rm -rf WiredTiger WiredTiger.* __[a-qs-z]* __run");
fprintf(stderr, "\n");
exit (EXIT_FAILURE);
}
/*
* die --
* Report an error and quit.
*/
void
die(const char *m, int e)
{
fprintf(stderr, "%s: %s: %s\n", g.progname, m, wiredtiger_strerror(e));
exit (EXIT_FAILURE);
}
/*
* usage --
* Display usage statement and exit failure.
*/
static void
usage(void)
{
fprintf(stderr,
"usage: %s [-1Llqr] [-C wiredtiger-config] [-c config-file] "
"[name=value ...]\n",
g.progname);
fprintf(stderr, "%s",
"\t-1 run once\n"
"\t-C specify wiredtiger_open configuration arguments\n"
"\t-c read test program configuration from a file\n"
"\t-L output to a log file\n"
"\t-l log operations (implies -L)\n"
"\t-q run quietly\n"
"\t-r replay the last run\n");
fprintf(stderr, "\n");
config_error();
exit(EXIT_FAILURE);
}
|