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
|
/*-
* Public Domain 2014-2020 MongoDB, Inc.
* Public Domain 2008-2014 WiredTiger, Inc.
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "format.h"
GLOBAL g;
static void format_die(void);
static void startup(void);
static void usage(void) WT_GCC_FUNC_DECL_ATTRIBUTE((noreturn));
extern int __wt_optind;
extern char *__wt_optarg;
/*
* signal_handler --
* Generic signal handler, report the signal and exit.
*/
static void signal_handler(int signo) WT_GCC_FUNC_DECL_ATTRIBUTE((noreturn));
static void
signal_handler(int signo)
{
fprintf(stderr, "format caught signal %d, exiting without error\n", signo);
fflush(stderr);
exit(EXIT_SUCCESS);
}
/*
* signal_timer --
* Alarm signal handler.
*/
static void signal_timer(int signo) WT_GCC_FUNC_DECL_ATTRIBUTE((noreturn));
static void
signal_timer(int signo)
{
/*
* Direct I/O configurations can result in really long run times depending on how the test
* machine is configured. If a direct I/O run timed out, don't bother dropping core.
*/
if (g.c_direct_io) {
fprintf(stderr, "format direct I/O configuration timed out\n");
fprintf(stderr, "format caught signal %d, exiting with error\n", signo);
fflush(stderr);
exit(EXIT_FAILURE);
}
/* Note, format.sh checks for this message, so be cautious in changing the format. */
fprintf(stderr, "format alarm timed out\n");
fprintf(stderr, "format caught signal %d, exiting with error\n", signo);
fprintf(stderr, "format attempting to create a core dump\n");
fflush(stderr);
__wt_abort(NULL);
/* NOTREACHED */
}
/*
* set_alarm --
* Set a timer.
*/
void
set_alarm(u_int seconds)
{
#ifdef HAVE_TIMER_CREATE
struct itimerspec timer_val;
timer_t timer_id;
testutil_check(timer_create(CLOCK_REALTIME, NULL, &timer_id));
memset(&timer_val, 0, sizeof(timer_val));
timer_val.it_value.tv_sec = seconds;
timer_val.it_value.tv_nsec = 0;
testutil_check(timer_settime(timer_id, 0, &timer_val, NULL));
#endif
(void)seconds;
}
/*
* TIMED_MAJOR_OP --
* Set a timer and perform a major operation (for example, verify or salvage).
*/
#define TIMED_MAJOR_OP(call) \
do { \
if (g.c_major_timeout != 0) \
set_alarm(g.c_major_timeout * 60); \
call; \
if (g.c_major_timeout != 0) \
set_alarm(0); \
} while (0)
int
main(int argc, char *argv[])
{
uint64_t now, start;
u_int ops_seconds;
int ch, reps;
const char *config, *home;
bool one_flag, quiet_flag;
custom_die = format_die; /* Local death handler. */
config = NULL;
(void)testutil_set_progname(argv);
/*
* Windows and Linux support different sets of signals, be conservative about installing handlers.
* If we time out unexpectedly, we want a core dump, otherwise, just exit.
*/
#ifdef SIGALRM
(void)signal(SIGALRM, signal_timer);
#endif
#ifdef SIGHUP
(void)signal(SIGHUP, signal_handler);
#endif
#ifdef SIGTERM
(void)signal(SIGTERM, signal_handler);
#endif
#if 0
/* Configure the GNU malloc for debugging. */
(void)setenv("MALLOC_CHECK_", "2", 1);
#endif
#if 0
/* Configure the FreeBSD malloc for debugging. */
(void)setenv("MALLOC_OPTIONS", "AJ", 1);
#endif
/* Set values from the command line. */
home = NULL;
one_flag = quiet_flag = false;
while ((ch = __wt_getopt(progname, argc, argv, "1C:c:h:lqrt:")) != EOF)
switch (ch) {
case '1': /* One run */
one_flag = true;
break;
case 'C': /* wiredtiger_open config */
g.config_open = __wt_optarg;
break;
case 'c': /* Configuration from a file */
config = __wt_optarg;
break;
case 'h':
home = __wt_optarg;
break;
case 'l': /* Log operations to a file */
g.logging = true;
break;
case 'q': /* Quiet */
quiet_flag = true;
break;
case 'r': /* Replay a run */
g.replay = true;
break;
default:
usage();
}
argv += __wt_optind;
/* Initialize the global RNG. */
__wt_random_init_seed(NULL, &g.rnd);
/* Set up paths. */
path_setup(home);
/* If it's a replay, use the home directory's CONFIG file. */
if (g.replay) {
if (config != NULL)
testutil_die(EINVAL, "-c incompatible with -r");
if (access(g.home_config, R_OK) != 0)
testutil_die(ENOENT, "%s", g.home_config);
config = g.home_config;
}
/*
* If we weren't given a configuration file, set values from "CONFIG", if it exists.
*
* Small hack to ignore any CONFIG file named ".", that just makes it possible to ignore any
* local CONFIG file, used when running checks.
*/
if (config == NULL && access("CONFIG", R_OK) == 0)
config = "CONFIG";
if (config != NULL && strcmp(config, ".") != 0)
config_file(config);
/*
* The rest of the arguments are individual configurations that modify the base configuration.
*/
for (; *argv != NULL; ++argv)
config_single(*argv, true);
/*
* Multithreaded runs can be replayed: it's useful and we'll get the configuration correct.
* Obviously the order of operations changes, warn the user.
*/
if (g.replay && !SINGLETHREADED)
printf("Warning: replaying a threaded run\n");
/*
* Single-threaded runs historically exited after a single replay, which makes sense when you're
* debugging, leave that semantic in place.
*/
if (g.replay && SINGLETHREADED)
g.c_runs = 1;
/*
* Let the command line -1 and -q flags override values configured from other sources.
* Regardless, don't go all verbose if we're not talking to a terminal.
*/
if (one_flag)
g.c_runs = 1;
if (quiet_flag || !isatty(1))
g.c_quiet = 1;
/*
* Initialize locks to single-thread named checkpoints and backups, last last-record updates,
* and failures.
*/
testutil_check(pthread_rwlock_init(&g.backup_lock, NULL));
testutil_check(pthread_rwlock_init(&g.death_lock, NULL));
testutil_check(pthread_rwlock_init(&g.ts_lock, NULL));
/*
* Calculate how long each operations loop should run. Take any timer value and convert it to
* seconds, then allocate 15 seconds to do initialization, verification, rebalance and/or
* salvage tasks after the operations loop finishes. This is not intended to be exact in any
* way, just enough to get us into an acceptable range of run times. The reason for this is
* because we want to consume the legitimate run-time, but we also need to do the end-of-run
* checking in all cases, even if we run out of time, otherwise it won't get done. So, in
* summary pick a reasonable time and then don't check for timer expiration once the main
* operations loop completes.
*/
ops_seconds = g.c_timer == 0 ? 0 : ((g.c_timer * 60) - 15) / FORMAT_OPERATION_REPS;
printf("%s: process %" PRIdMAX " running\n", progname, (intmax_t)getpid());
fflush(stdout);
while (++g.run_cnt <= g.c_runs || g.c_runs == 0) {
__wt_seconds(NULL, &start);
startup(); /* Start a run */
config_setup(); /* Run configuration */
config_print(false); /* Dump run configuration */
key_init(); /* Setup keys/values */
val_init();
track("starting up", 0ULL, NULL);
/* Load and verify initial records */
wts_open(g.home, true, &g.wts_conn);
wts_init();
TIMED_MAJOR_OP(wts_load());
TIMED_MAJOR_OP(wts_verify("post-bulk verify"));
TIMED_MAJOR_OP(wts_read_scan());
/* Operations. */
wts_checkpoints();
for (reps = 1; reps <= FORMAT_OPERATION_REPS; ++reps)
wts_ops(ops_seconds, reps == FORMAT_OPERATION_REPS);
/* Copy out the run's statistics. */
TIMED_MAJOR_OP(wts_stats());
/*
* Verify the objects. Verify closes the underlying handle and discards the statistics, read
* them first.
*/
TIMED_MAJOR_OP(wts_verify("post-ops verify"));
track("shutting down", 0ULL, NULL);
wts_close();
/*
* Rebalance testing.
*/
TIMED_MAJOR_OP(wts_rebalance());
/*
* Salvage testing.
*/
TIMED_MAJOR_OP(wts_salvage());
/* Overwrite the progress line with a completion line. */
if (!g.c_quiet)
printf("\r%78s\r", " ");
__wt_seconds(NULL, &now);
printf("%4" PRIu32 ": %s, %s (%" PRIu64 " seconds)\n", g.run_cnt, g.c_data_source,
g.c_file_type, now - start);
fflush(stdout);
}
/* Flush/close any logging information. */
fclose_and_clear(&g.logfp);
fclose_and_clear(&g.randfp);
config_print(false);
testutil_check(pthread_rwlock_destroy(&g.backup_lock));
testutil_check(pthread_rwlock_destroy(&g.death_lock));
testutil_check(pthread_rwlock_destroy(&g.ts_lock));
config_clear();
printf("%s: successful run completed\n", progname);
return (EXIT_SUCCESS);
}
/*
* startup --
* Initialize for a run.
*/
static void
startup(void)
{
WT_DECL_RET;
/* Flush/close any logging information. */
fclose_and_clear(&g.logfp);
fclose_and_clear(&g.randfp);
/* Create or initialize the home and data-source directories. */
if ((ret = system(g.home_init)) != 0)
testutil_die(ret, "home directory initialization failed");
/* Open/truncate the logging file. */
if (g.logging && (g.logfp = fopen(g.home_log, "w")) == NULL)
testutil_die(errno, "fopen: %s", g.home_log);
/* Open/truncate the random number logging file. */
if ((g.randfp = fopen(g.home_rand, g.replay ? "r" : "w")) == NULL)
testutil_die(errno, "%s", g.home_rand);
}
/*
* die --
* Report an error, dumping the configuration.
*/
static void
format_die(void)
{
/*
* Turn off tracking and logging so we don't obscure the error message. The lock we're about to
* acquire will act as a barrier to flush the writes. This is really a "best effort" more than a
* guarantee, there's too much stuff in flight to be sure.
*/
g.c_quiet = 1;
g.logging = false;
/*
* Single-thread error handling, our caller exits after calling us (we never release the lock).
*/
(void)pthread_rwlock_wrlock(&g.death_lock);
/* Flush/close any logging information. */
fclose_and_clear(&g.logfp);
fclose_and_clear(&g.randfp);
fprintf(stderr, "\n%s: run FAILED\n", progname);
/* Display the configuration that failed. */
if (g.run_cnt)
config_print(true);
}
/*
* usage --
* Display usage statement and exit failure.
*/
static void
usage(void)
{
fprintf(stderr,
"usage: %s [-1lqr] [-C wiredtiger-config]\n "
"[-c config-file] [-h home] [name=value ...]\n",
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-h home (default 'RUNDIR')\n"
"\t-l log operations to a file\n"
"\t-q run quietly\n"
"\t-r replay the last run\n");
config_error();
exit(EXIT_FAILURE);
}
|