1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6 
7 
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9 
10     PerconaFT is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License, version 2,
12     as published by the Free Software Foundation.
13 
14     PerconaFT is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
21 
22 ----------------------------------------
23 
24     PerconaFT is free software: you can redistribute it and/or modify
25     it under the terms of the GNU Affero General Public License, version 3,
26     as published by the Free Software Foundation.
27 
28     PerconaFT is distributed in the hope that it will be useful,
29     but WITHOUT ANY WARRANTY; without even the implied warranty of
30     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31     GNU Affero General Public License for more details.
32 
33     You should have received a copy of the GNU Affero General Public License
34     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36 
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38 
39 // Generate a recovery log with a checkpoint and an optional shutdown log entry.
40 // These logs will be used later to test recovery.
41 
42 #include "test.h"
43 
generate_recovery_log(const char * testdir,bool do_shutdown)44 static void generate_recovery_log(const char *testdir, bool do_shutdown) {
45     int r;
46 
47     // setup the test dir
48     toku_os_recursive_delete(testdir);
49     r = toku_os_mkdir(testdir, S_IRWXU);
50     CKERR(r);
51 
52     // open the log
53     TOKULOGGER logger;
54     r = toku_logger_create(&logger);
55     CKERR(r);
56     r = toku_logger_open(testdir, logger);
57     CKERR(r);
58 
59     // log checkpoint
60     LSN beginlsn;
61     toku_log_begin_checkpoint(logger, &beginlsn, false, 0, 0);
62     toku_log_end_checkpoint(logger, nullptr, false, beginlsn, 0, 0, 0);
63 
64     // log shutdown
65     if (do_shutdown) {
66         toku_log_shutdown(logger, nullptr, true, 0, 0);
67     }
68 
69     r = toku_logger_close(&logger);
70     CKERR(r);
71 }
72 
test_main(int argc,const char * argv[])73 int test_main(int argc, const char *argv[]) {
74     bool do_shutdown = true;
75     for (int i = 1; i < argc; i++) {
76         if (strcmp(argv[i], "-v") == 0) {
77             verbose++;
78             continue;
79         }
80         if (strcmp(argv[i], "-q") == 0) {
81             if (verbose > 0)
82                 verbose--;
83             continue;
84         }
85         if (strcmp(argv[i], "--clean") == 0) {
86             do_shutdown = true;
87             continue;
88         }
89         if (strcmp(argv[i], "--dirty") == 0) {
90             do_shutdown = false;
91             continue;
92         }
93     }
94     char testdir[256];
95     sprintf(testdir, "upgrade-recovery-logs-%d-%s", TOKU_LOG_VERSION, do_shutdown ? "clean" : "dirty");
96     generate_recovery_log(testdir, do_shutdown);
97     return 0;
98 }
99