1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
4
COPYING CONDITIONS NOTICE:
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of version 2 of the GNU General Public License as
8
published by the Free Software Foundation, and provided that the
9
following conditions are met:
11
* Redistributions of source code must retain this COPYING
12
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
13
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
14
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
17
* Redistributions in binary form must reproduce this COPYING
18
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
19
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
20
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
21
GRANT (below) in the documentation and/or other materials
22
provided with the distribution.
24
You should have received a copy of the GNU General Public License
25
along with this program; if not, write to the Free Software
26
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31
TokuDB, Tokutek Fractal Tree Indexing Library.
32
Copyright (C) 2007-2013 Tokutek, Inc.
36
This program is distributed in the hope that it will be useful, but
37
WITHOUT ANY WARRANTY; without even the implied warranty of
38
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39
General Public License for more details.
41
UNIVERSITY PATENT NOTICE:
43
The technology is licensed by the Massachusetts Institute of
44
Technology, Rutgers State University of New Jersey, and the Research
45
Foundation of State University of New York at Stony Brook under
46
United States of America Serial No. 11/760379 and to the patents
47
and/or patent applications resulting from it.
49
PATENT MARKING NOTICE:
51
This software is covered by US Patent No. 8,185,551.
52
This software is covered by US Patent No. 8,489,638.
56
"THIS IMPLEMENTATION" means the copyrightable works distributed by
57
Tokutek as part of the Fractal Tree project.
59
"PATENT CLAIMS" means the claims of patents that are owned or
60
licensable by Tokutek, both currently or in the future; and that in
61
the absence of this license would be infringed by THIS
62
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
64
"PATENT CHALLENGE" shall mean a challenge to the validity,
65
patentability, enforceability and/or non-infringement of any of the
66
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
68
Tokutek hereby grants to you, for the term and geographical scope of
69
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
70
irrevocable (except as stated in this section) patent license to
71
make, have made, use, offer to sell, sell, import, transfer, and
72
otherwise run, modify, and propagate the contents of THIS
73
IMPLEMENTATION, where such license applies only to the PATENT
74
CLAIMS. This grant does not include claims that would be infringed
75
only as a consequence of further modifications of THIS
76
IMPLEMENTATION. If you or your agent or licensee institute or order
77
or agree to the institution of patent litigation against any entity
78
(including a cross-claim or counterclaim in a lawsuit) alleging that
79
THIS IMPLEMENTATION constitutes direct or contributory patent
80
infringement, or inducement of patent infringement, then any rights
81
granted to you under this License shall terminate as of the date
82
such litigation is filed. If you or your agent or exclusive
83
licensee institute or order or agree to the institution of a PATENT
84
CHALLENGE, then Tokutek may terminate any rights granted to you
88
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
96
* Purpose: Verify fix for 3113
97
* Bug: Rollback log is checkpointed along with other cachefiles,
98
* but system crashes before checkpoint_end is written to recovery log.
99
* When recovery runs, it uses latest rollback log, which is out of synch
100
* with recovery log. Latest version of rollback log would be correct for
101
* last checkpoint if it completed, but version of rollback log needed
102
* is for last complete checkpoint.
103
* Fix: When opening rollback log for recovery, do not use latest, but use
104
* latest that is no newer than last complete checkpoint.
108
* complete checkpoint (no live txns in checkpoint)
111
* begin checkpoint (txn in checkpointed rollback log)
112
* crash using callback2 (just before checkpoint_end is written to disk)
113
* attempt to recover, should crash with 3113
116
static const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE;
117
static const char *namea="a.db";
118
static void checkpoint_callback_2(void * UU(extra));
120
static bool do_test=false, do_recover=false;
126
toku_os_recursive_delete(TOKU_TEST_FILENAME);
127
toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
129
r = db_env_create(&env, 0); CKERR(r);
130
r = env->open(env, TOKU_TEST_FILENAME, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
133
r = db_create(&db, env, 0); CKERR(r);
134
r = db->open(db, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
136
// txn_begin; insert <a,a>; txn_abort
139
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
141
dbt_init(&k, "a", 2);
142
dbt_init(&v, "a", 2);
143
r = db->put(db, txn, &k, &v, 0); CKERR(r);
144
r = txn->commit(txn, 0); CKERR(r);
147
// checkpoint, no live txns in rollback log
148
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
152
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
154
dbt_init(&k, "b", 2);
155
dbt_init(&v, "b", 2);
156
r = db->put(db, txn, &k, &v, 0); CKERR(r);
159
// cause crash at next checkpoint, after xstillopen written, before checkpoint_end is written
160
db_env_set_checkpoint_callback2(checkpoint_callback_2, NULL);
162
// checkpoint, putting xstillopen in recovery log (txn is still active)
163
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
168
static void checkpoint_callback_2(void * UU(extra)) {
169
toku_hard_crash_on_purpose();
173
static void run_recover (void) {
176
// Recovery starts from oldest_living_txn, which is older than any inserts done in run_test,
177
// so recovery always runs over the entire log.
180
r = db_env_create(&env, 0); CKERR(r);
181
r = env->open(env, TOKU_TEST_FILENAME, envflags + DB_RECOVER, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
182
r = env->close(env, 0); CKERR(r);
187
static void test_parse_args (int argc, char * const argv[]) {
189
char * cmd = argv[0];
192
if (strcmp(argv[0], "-v") == 0) {
194
} else if (strcmp(argv[0],"-q")==0) {
196
if (verbose<0) verbose=0;
197
} else if (strcmp(argv[0], "--test")==0) {
199
} else if (strcmp(argv[0], "--recover") == 0) {
201
} else if (strcmp(argv[0], "-h")==0) {
204
fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--test | --recover } \n", cmd);
207
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
219
test_main (int argc, char * const argv[]) {
220
test_parse_args(argc, argv);