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
40 /* Purpose of this test is to verify simplest part of upgrade logic.
41 * Start by creating two very simple 4.x environments,
42 * one in each of two states:
43 * - after a clean shutdown
44 * - without a clean shutdown
45 *
46 * The two different environments will be used to exercise upgrade logic
47 * for 5.x.
48 *
49 */
50
51
52 #include "test.h"
53 #include <db.h>
54
55 static DB_ENV *env;
56
57 #define FLAGS_NOLOG DB_INIT_LOCK|DB_INIT_MPOOL|DB_CREATE|DB_PRIVATE
58 #define FLAGS_LOG FLAGS_NOLOG|DB_INIT_TXN|DB_INIT_LOG
59
60 static int mode = S_IRWXU+S_IRWXG+S_IRWXO;
61
62 static void test_shutdown(void);
63
64 #define OLDDATADIR "../../../../tokudb.data/"
65
66 static char *env_dir = TOKU_TEST_FILENAME; // the default env_dir.
67
68 static char * dir_v41_clean = OLDDATADIR "env_simple.4.1.1.cleanshutdown";
69 static char * dir_v42_clean = OLDDATADIR "env_simple.4.2.0.cleanshutdown";
70 static char * dir_v42_dirty = OLDDATADIR "env_simple.4.2.0.dirtyshutdown";
71 static char * dir_v41_dirty_multilogfile = OLDDATADIR "env_preload.4.1.1.multilog.dirtyshutdown";
72 static char * dir_v42_dirty_multilogfile = OLDDATADIR "env_preload.4.2.0.multilog.dirtyshutdown";
73
74
75 static void
setup(uint32_t flags,bool clean,bool too_old,char * src_db_dir)76 setup (uint32_t flags, bool clean, bool too_old, char * src_db_dir) {
77 int r;
78 int len = 256;
79 char syscmd[len];
80
81 if (env)
82 test_shutdown();
83
84 r = snprintf(syscmd, len, "rm -rf %s", env_dir);
85 assert(r<len);
86 r = system(syscmd);
87 CKERR(r);
88
89 r = snprintf(syscmd, len, "cp -r %s %s", src_db_dir, env_dir);
90 assert(r<len);
91 r = system(syscmd);
92 CKERR(r);
93
94 r=db_env_create(&env, 0);
95 CKERR(r);
96 env->set_errfile(env, stderr);
97 r=env->open(env, TOKU_TEST_FILENAME, flags, mode);
98 if (clean)
99 CKERR(r);
100 else {
101 if (too_old)
102 CKERR2(r, TOKUDB_DICTIONARY_TOO_OLD);
103 else
104 CKERR2(r, TOKUDB_UPGRADE_FAILURE);
105 }
106 }
107
108
109
110 static void
test_shutdown(void)111 test_shutdown(void) {
112 int r;
113 r=env->close(env, 0); CKERR(r);
114 env = NULL;
115 }
116
117
118 static void
test_env_startup(void)119 test_env_startup(void) {
120 uint32_t flags;
121
122 flags = FLAGS_LOG;
123
124 setup(flags, true, false, dir_v42_clean);
125 print_engine_status(env);
126 test_shutdown();
127
128 setup(flags, false, true, dir_v41_clean);
129 print_engine_status(env);
130 test_shutdown();
131
132 setup(flags, false, false, dir_v42_dirty);
133 if (verbose) {
134 printf("\n\nEngine status after aborted env->open() will have some garbage values:\n");
135 }
136 print_engine_status(env);
137 test_shutdown();
138
139 setup(flags, false, true, dir_v41_dirty_multilogfile);
140 if (verbose) {
141 printf("\n\nEngine status after aborted env->open() will have some garbage values:\n");
142 }
143 print_engine_status(env);
144 test_shutdown();
145
146 setup(flags, false, false, dir_v42_dirty_multilogfile);
147 if (verbose) {
148 printf("\n\nEngine status after aborted env->open() will have some garbage values:\n");
149 }
150 print_engine_status(env);
151 test_shutdown();
152 }
153
154
155 int
test_main(int argc,char * const argv[])156 test_main (int argc, char * const argv[]) {
157 parse_args(argc, argv);
158 test_env_startup();
159 return 0;
160 }
161