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 // verify that the env close aborts open txns
40
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include "test.h"
44
45 const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE;
46
run_test(void)47 static void run_test (void) {
48 int r;
49
50 toku_os_recursive_delete(TOKU_TEST_FILENAME);
51 toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
52
53 DB_ENV *env;
54 r = db_env_create(&env, 0); CKERR(r);
55 r = env->open(env, TOKU_TEST_FILENAME, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
56
57 DB_TXN *txn;
58 r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
59
60 DB_TXN *txnb;
61 r = env->txn_begin(env, txn, &txnb, 0); CKERR(r);
62
63 r = env->close(env, 0);
64 assert(r == EINVAL);
65
66 #if 0
67 r = txn->abort(txn); CKERR(r);
68 r = env->close(env, 0); CKERR(r);
69 #endif
70 }
71
run_recover(void)72 static void run_recover (void) {
73 DB_ENV *env;
74 int r;
75
76 // run recovery
77 r = db_env_create(&env, 0); CKERR(r);
78 r = env->open(env, TOKU_TEST_FILENAME, envflags + DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
79 r = env->close(env, 0); CKERR(r);
80 exit(0);
81 }
82
run_no_recover(void)83 static void run_no_recover (void) {
84 DB_ENV *env;
85 int r;
86
87 r = db_env_create(&env, 0); CKERR(r);
88 r = env->open(env, TOKU_TEST_FILENAME, envflags & ~DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
89 r = env->close(env, 0); CKERR(r);
90 exit(0);
91 }
92
93 const char *cmd;
94
95 bool do_test=false, do_recover=false, do_recover_only=false, do_no_recover = false;
96
test_parse_args(int argc,char * const argv[])97 static void test_parse_args (int argc, char *const argv[]) {
98 int resultcode;
99 cmd = argv[0];
100 argc--; argv++;
101 while (argc>0) {
102 if (strcmp(argv[0], "-v") == 0) {
103 verbose++;
104 } else if (strcmp(argv[0],"-q")==0) {
105 verbose--;
106 if (verbose<0) verbose=0;
107 } else if (strcmp(argv[0], "--test")==0) {
108 do_test=true;
109 } else if (strcmp(argv[0], "--recover") == 0) {
110 do_recover=true;
111 } else if (strcmp(argv[0], "--recover-only") == 0) {
112 do_recover_only=true;
113 } else if (strcmp(argv[0], "--no-recover") == 0) {
114 do_no_recover=true;
115 } else if (strcmp(argv[0], "-h")==0) {
116 resultcode=0;
117 do_usage:
118 fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--test | --recover } \n", cmd);
119 exit(resultcode);
120 } else {
121 fprintf(stderr, "Unknown arg: %s\n", argv[0]);
122 resultcode=1;
123 goto do_usage;
124 }
125 argc--;
126 argv++;
127 }
128 }
129
test_main(int argc,char * const argv[])130 int test_main (int argc, char *const argv[]) {
131 test_parse_args(argc, argv);
132 if (do_test) {
133 run_test();
134 } else if (do_recover) {
135 run_recover();
136 } else if (do_recover_only) {
137 run_recover();
138 } else if (do_no_recover) {
139 run_no_recover();
140 }
141 return 0;
142 }
143