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: xid_lsn_independent.cc 49853 2012-11-12 04:26:30Z zardosht $"
5
COPYING CONDITIONS NOTICE:
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of version 2 of the GNU General Public License as
9
published by the Free Software Foundation, and provided that the
10
following conditions are met:
12
* Redistributions of source code must retain this COPYING
13
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
14
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
15
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
18
* Redistributions in binary form must reproduce this COPYING
19
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
20
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
21
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
22
GRANT (below) in the documentation and/or other materials
23
provided with the distribution.
25
You should have received a copy of the GNU General Public License
26
along with this program; if not, write to the Free Software
27
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32
TokuDB, Tokutek Fractal Tree Indexing Library.
33
Copyright (C) 2007-2013 Tokutek, Inc.
37
This program is distributed in the hope that it will be useful, but
38
WITHOUT ANY WARRANTY; without even the implied warranty of
39
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40
General Public License for more details.
42
UNIVERSITY PATENT NOTICE:
44
The technology is licensed by the Massachusetts Institute of
45
Technology, Rutgers State University of New Jersey, and the Research
46
Foundation of State University of New York at Stony Brook under
47
United States of America Serial No. 11/760379 and to the patents
48
and/or patent applications resulting from it.
50
PATENT MARKING NOTICE:
52
This software is covered by US Patent No. 8,185,551.
53
This software is covered by US Patent No. 8,489,638.
57
"THIS IMPLEMENTATION" means the copyrightable works distributed by
58
Tokutek as part of the Fractal Tree project.
60
"PATENT CLAIMS" means the claims of patents that are owned or
61
licensable by Tokutek, both currently or in the future; and that in
62
the absence of this license would be infringed by THIS
63
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
65
"PATENT CHALLENGE" shall mean a challenge to the validity,
66
patentability, enforceability and/or non-infringement of any of the
67
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
69
Tokutek hereby grants to you, for the term and geographical scope of
70
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
71
irrevocable (except as stated in this section) patent license to
72
make, have made, use, offer to sell, sell, import, transfer, and
73
otherwise run, modify, and propagate the contents of THIS
74
IMPLEMENTATION, where such license applies only to the PATENT
75
CLAIMS. This grant does not include claims that would be infringed
76
only as a consequence of further modifications of THIS
77
IMPLEMENTATION. If you or your agent or licensee institute or order
78
or agree to the institution of patent litigation against any entity
79
(including a cross-claim or counterclaim in a lawsuit) alleging that
80
THIS IMPLEMENTATION constitutes direct or contributory patent
81
infringement, or inducement of patent infringement, then any rights
82
granted to you under this License shall terminate as of the date
83
such litigation is filed. If you or your agent or exclusive
84
licensee institute or order or agree to the institution of a PATENT
85
CHALLENGE, then Tokutek may terminate any rights granted to you
89
#ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved."
90
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
95
#include "checkpoint.h"
97
#include "test-ft-txns.h"
99
static int txn_child_manager_test_cb(TOKUTXN txn, void* extra) {
100
TOKUTXN* ptxn = (TOKUTXN *)extra;
101
assert(txn == *ptxn);
106
static int txn_child_manager_test_cb2(TOKUTXN txn, void* extra) {
107
TOKUTXN extra_txn = (TOKUTXN)extra;
108
if (txn == extra_txn) {
115
class txn_child_manager_unit_test {
118
void run_child_txn_test();
121
// simple test that verifies that creating a TXN_CHILD_SNAPSHOT tokutxn
122
// creates its own snapshot
123
void txn_child_manager_unit_test::run_child_txn_test() {
127
test_setup(TOKU_TEST_FILENAME, &logger, &ct);
128
// create the root transaction
129
TOKUTXN root_txn = NULL;
130
r = toku_txn_begin_txn(
139
// test starting a child txn
140
TOKUTXN child_txn = NULL;
141
r = toku_txn_begin_txn(
151
// assert that the child has a later snapshot
152
assert(child_txn->snapshot_txnid64 > root_txn->snapshot_txnid64);
154
r = toku_txn_commit_txn(child_txn, true, NULL, NULL);
156
toku_txn_close_txn(child_txn);
157
assert(root_txn->child == NULL);
159
r = toku_txn_commit_txn(root_txn, true, NULL, NULL);
161
toku_txn_close_txn(root_txn);
164
clean_shutdown(&logger, &ct);
167
void txn_child_manager_unit_test::run_test() {
171
test_setup(TOKU_TEST_FILENAME, &logger, &ct);
172
// create the root transaction
173
TOKUTXN root_txn = NULL;
174
r = toku_txn_begin_txn(
183
txn_child_manager* cm = root_txn->child_manager;
184
assert(cm == &root_txn->child_manager_s);
185
assert(cm->m_root == root_txn);
186
assert(cm->m_last_xid == TXNID_NONE);
187
assert(root_txn->child == NULL);
188
// this assumption implies our assumptions of child_id values below,
189
// because the parent id cannot be the child id
190
assert(root_txn->txnid.parent_id64 == 1);
192
// test starting a child txn
193
TOKUTXN child_txn = NULL;
194
r = toku_txn_begin_txn(
203
assert(child_txn->child_manager == cm);
204
assert(child_txn->parent == root_txn);
205
assert(root_txn->child == child_txn);
206
assert(child_txn->txnid.parent_id64 == root_txn->txnid.parent_id64);
207
assert(child_txn->txnid.child_id64 == 2);
208
assert(child_txn->live_root_txn_list == root_txn->live_root_txn_list);
209
assert(child_txn->snapshot_txnid64 == root_txn->snapshot_txnid64);
211
assert(cm->m_root == root_txn);
212
assert(cm->m_last_xid == child_txn->txnid.child_id64);
214
TOKUTXN grandchild_txn = NULL;
215
r = toku_txn_begin_txn(
224
assert(grandchild_txn->child_manager == cm);
225
assert(grandchild_txn->parent == child_txn);
226
assert(child_txn->child == grandchild_txn);
227
assert(grandchild_txn->txnid.parent_id64 == root_txn->txnid.parent_id64);
228
assert(grandchild_txn->txnid.child_id64 == 3);
229
assert(grandchild_txn->live_root_txn_list == root_txn->live_root_txn_list);
230
assert(grandchild_txn->snapshot_txnid64 == root_txn->snapshot_txnid64);
232
assert(cm->m_root == root_txn);
233
assert(cm->m_last_xid == grandchild_txn->txnid.child_id64);
235
r = toku_txn_commit_txn(grandchild_txn, true, NULL, NULL);
237
toku_txn_close_txn(grandchild_txn);
240
// now after closing one grandchild txn, open another one
241
r = toku_txn_begin_txn(
250
assert(grandchild_txn->child_manager == cm);
251
assert(grandchild_txn->parent == child_txn);
252
assert(child_txn->child == grandchild_txn);
253
assert(grandchild_txn->txnid.parent_id64 == root_txn->txnid.parent_id64);
254
assert(grandchild_txn->txnid.child_id64 == 4);
255
assert(grandchild_txn->live_root_txn_list == root_txn->live_root_txn_list);
256
assert(grandchild_txn->snapshot_txnid64 == root_txn->snapshot_txnid64);
258
assert(cm->m_root == root_txn);
259
assert(cm->m_last_xid == grandchild_txn->txnid.child_id64);
262
TXNID_PAIR xid = {.parent_id64 = root_txn->txnid.parent_id64, .child_id64 = 100};
263
TOKUTXN recovery_txn = NULL;
264
r = toku_txn_begin_with_xid(
271
true, // for recovery
275
assert(recovery_txn->child_manager == cm);
276
assert(recovery_txn->parent == grandchild_txn);
277
assert(grandchild_txn->child == recovery_txn);
278
assert(recovery_txn->txnid.parent_id64 == root_txn->txnid.parent_id64);
279
assert(recovery_txn->txnid.child_id64 == 100);
280
// ensure that no snapshot is made
281
assert(recovery_txn->live_root_txn_list == NULL);
282
assert(recovery_txn->snapshot_txnid64 == TXNID_NONE);
284
assert(cm->m_root == root_txn);
285
assert(cm->m_last_xid == recovery_txn->txnid.child_id64);
288
// now ensure that txn_child_manager::find_tokutxn_by_xid_unlocked works
289
TOKUTXN found_txn = NULL;
290
// first ensure that a dummy TXNID_PAIR cannot be found
291
TXNID_PAIR dummy_pair = { .parent_id64 = root_txn->txnid.parent_id64, .child_id64 = 1000};
292
cm->find_tokutxn_by_xid_unlocked(dummy_pair, &found_txn);
293
assert(found_txn == NULL);
294
cm->find_tokutxn_by_xid_unlocked(root_txn->txnid, &found_txn);
295
assert(found_txn == root_txn);
296
cm->find_tokutxn_by_xid_unlocked(child_txn->txnid, &found_txn);
297
assert(found_txn == child_txn);
298
cm->find_tokutxn_by_xid_unlocked(grandchild_txn->txnid, &found_txn);
299
assert(found_txn == grandchild_txn);
300
cm->find_tokutxn_by_xid_unlocked(recovery_txn->txnid, &found_txn);
301
assert(found_txn == recovery_txn);
304
// now ensure that the iterator works
305
found_txn = root_txn;
306
r = cm->iterate(txn_child_manager_test_cb, &found_txn);
308
assert(found_txn == NULL);
310
// now test that iterator properly stops
311
found_txn = child_txn;
312
r = cm->iterate(txn_child_manager_test_cb2, found_txn);
315
r = toku_txn_commit_txn(recovery_txn, true, NULL, NULL);
317
toku_txn_close_txn(recovery_txn);
318
assert(grandchild_txn->child == NULL);
320
r = toku_txn_commit_txn(grandchild_txn, true, NULL, NULL);
322
toku_txn_close_txn(grandchild_txn);
323
assert(child_txn->child == NULL);
325
r = toku_txn_commit_txn(child_txn, true, NULL, NULL);
327
toku_txn_close_txn(child_txn);
328
assert(root_txn->child == NULL);
330
r = toku_txn_commit_txn(root_txn, true, NULL, NULL);
332
toku_txn_close_txn(root_txn);
335
clean_shutdown(&logger, &ct);
338
int test_main (int argc, const char *argv[]) {
339
default_parse_args(argc, argv);
340
txn_child_manager_unit_test foo;