~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/ft/tests/test-txn-child-manager.cc

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 $"
 
4
/*
 
5
COPYING CONDITIONS NOTICE:
 
6
 
 
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:
 
11
 
 
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
 
16
        GRANT (below).
 
17
 
 
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.
 
24
 
 
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
 
28
  02110-1301, USA.
 
29
 
 
30
COPYRIGHT NOTICE:
 
31
 
 
32
  TokuDB, Tokutek Fractal Tree Indexing Library.
 
33
  Copyright (C) 2007-2013 Tokutek, Inc.
 
34
 
 
35
DISCLAIMER:
 
36
 
 
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.
 
41
 
 
42
UNIVERSITY PATENT NOTICE:
 
43
 
 
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.
 
49
 
 
50
PATENT MARKING NOTICE:
 
51
 
 
52
  This software is covered by US Patent No. 8,185,551.
 
53
  This software is covered by US Patent No. 8,489,638.
 
54
 
 
55
PATENT RIGHTS GRANT:
 
56
 
 
57
  "THIS IMPLEMENTATION" means the copyrightable works distributed by
 
58
  Tokutek as part of the Fractal Tree project.
 
59
 
 
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.
 
64
 
 
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.
 
68
 
 
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
 
86
  under this License.
 
87
*/
 
88
 
 
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."
 
91
 
 
92
#include "test.h"
 
93
 
 
94
#include "toku_os.h"
 
95
#include "checkpoint.h"
 
96
 
 
97
#include "test-ft-txns.h"
 
98
 
 
99
static int txn_child_manager_test_cb(TOKUTXN txn, void* extra) {
 
100
    TOKUTXN* ptxn = (TOKUTXN *)extra;
 
101
    assert(txn == *ptxn);
 
102
    *ptxn = txn->child;
 
103
    return 0;
 
104
}
 
105
 
 
106
static int txn_child_manager_test_cb2(TOKUTXN txn, void* extra) {
 
107
    TOKUTXN extra_txn = (TOKUTXN)extra;
 
108
    if (txn == extra_txn) {
 
109
        return -1;
 
110
    }
 
111
    return 0;
 
112
}
 
113
 
 
114
 
 
115
class txn_child_manager_unit_test {
 
116
public:
 
117
    void run_test();
 
118
    void run_child_txn_test();
 
119
};
 
120
 
 
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() {
 
124
    TOKULOGGER logger;
 
125
    CACHETABLE ct;
 
126
    int r = 0;
 
127
    test_setup(TOKU_TEST_FILENAME, &logger, &ct);
 
128
    // create the root transaction
 
129
    TOKUTXN root_txn = NULL;
 
130
    r = toku_txn_begin_txn(
 
131
        (DB_TXN *)NULL,
 
132
        NULL,
 
133
        &root_txn,
 
134
        logger,
 
135
        TXN_SNAPSHOT_CHILD,
 
136
        false
 
137
        );
 
138
    CKERR(r);
 
139
    // test starting a child txn
 
140
    TOKUTXN child_txn = NULL;
 
141
    r = toku_txn_begin_txn(
 
142
        NULL,
 
143
        root_txn,
 
144
        &child_txn,
 
145
        logger,
 
146
        TXN_SNAPSHOT_CHILD,
 
147
        false
 
148
        );
 
149
    CKERR(r);
 
150
 
 
151
    // assert that the child has a later snapshot
 
152
    assert(child_txn->snapshot_txnid64 > root_txn->snapshot_txnid64);
 
153
 
 
154
    r = toku_txn_commit_txn(child_txn, true, NULL, NULL);
 
155
    CKERR(r);
 
156
    toku_txn_close_txn(child_txn);
 
157
    assert(root_txn->child == NULL);
 
158
 
 
159
    r = toku_txn_commit_txn(root_txn, true, NULL, NULL);
 
160
    CKERR(r);
 
161
    toku_txn_close_txn(root_txn);
 
162
 
 
163
    
 
164
    clean_shutdown(&logger, &ct);
 
165
}
 
166
 
 
167
void txn_child_manager_unit_test::run_test() {
 
168
    TOKULOGGER logger;
 
169
    CACHETABLE ct;
 
170
    int r = 0;
 
171
    test_setup(TOKU_TEST_FILENAME, &logger, &ct);
 
172
    // create the root transaction
 
173
    TOKUTXN root_txn = NULL;
 
174
    r = toku_txn_begin_txn(
 
175
        (DB_TXN *)NULL,
 
176
        NULL,
 
177
        &root_txn,
 
178
        logger,
 
179
        TXN_SNAPSHOT_ROOT,
 
180
        false
 
181
        );
 
182
    CKERR(r);
 
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);
 
191
 
 
192
    // test starting a child txn
 
193
    TOKUTXN child_txn = NULL;
 
194
    r = toku_txn_begin_txn(
 
195
        NULL,
 
196
        root_txn,
 
197
        &child_txn,
 
198
        logger,
 
199
        TXN_SNAPSHOT_ROOT,
 
200
        false
 
201
        );
 
202
    CKERR(r);
 
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);
 
210
 
 
211
    assert(cm->m_root == root_txn);
 
212
    assert(cm->m_last_xid == child_txn->txnid.child_id64);
 
213
 
 
214
    TOKUTXN grandchild_txn = NULL;
 
215
    r = toku_txn_begin_txn(
 
216
        NULL,
 
217
        child_txn,
 
218
        &grandchild_txn,
 
219
        logger,
 
220
        TXN_SNAPSHOT_ROOT,
 
221
        false
 
222
        );
 
223
    CKERR(r);
 
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);
 
231
 
 
232
    assert(cm->m_root == root_txn);
 
233
    assert(cm->m_last_xid == grandchild_txn->txnid.child_id64);
 
234
 
 
235
    r = toku_txn_commit_txn(grandchild_txn, true, NULL, NULL);
 
236
    CKERR(r);
 
237
    toku_txn_close_txn(grandchild_txn);
 
238
 
 
239
 
 
240
    // now after closing one grandchild txn, open another one
 
241
    r = toku_txn_begin_txn(
 
242
        NULL,
 
243
        child_txn,
 
244
        &grandchild_txn,
 
245
        logger,
 
246
        TXN_SNAPSHOT_ROOT,
 
247
        false
 
248
        );
 
249
    CKERR(r);
 
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);
 
257
 
 
258
    assert(cm->m_root == root_txn);
 
259
    assert(cm->m_last_xid == grandchild_txn->txnid.child_id64);
 
260
 
 
261
 
 
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(
 
265
        grandchild_txn,
 
266
        &recovery_txn,
 
267
        logger,
 
268
        xid,
 
269
        TXN_SNAPSHOT_NONE,
 
270
        NULL,
 
271
        true, // for recovery
 
272
        false // read_only
 
273
        );
 
274
 
 
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);
 
283
 
 
284
    assert(cm->m_root == root_txn);
 
285
    assert(cm->m_last_xid == recovery_txn->txnid.child_id64);
 
286
 
 
287
 
 
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);
 
302
 
 
303
 
 
304
    // now ensure that the iterator works
 
305
    found_txn = root_txn;
 
306
    r = cm->iterate(txn_child_manager_test_cb, &found_txn);
 
307
    CKERR(r);
 
308
    assert(found_txn == NULL);
 
309
 
 
310
    // now test that iterator properly stops
 
311
    found_txn = child_txn;
 
312
    r = cm->iterate(txn_child_manager_test_cb2, found_txn);
 
313
    assert(r == -1);
 
314
 
 
315
    r = toku_txn_commit_txn(recovery_txn, true, NULL, NULL);
 
316
    CKERR(r);
 
317
    toku_txn_close_txn(recovery_txn);
 
318
    assert(grandchild_txn->child == NULL);
 
319
 
 
320
    r = toku_txn_commit_txn(grandchild_txn, true, NULL, NULL);
 
321
    CKERR(r);
 
322
    toku_txn_close_txn(grandchild_txn);    
 
323
    assert(child_txn->child == NULL);
 
324
 
 
325
    r = toku_txn_commit_txn(child_txn, true, NULL, NULL);
 
326
    CKERR(r);
 
327
    toku_txn_close_txn(child_txn);
 
328
    assert(root_txn->child == NULL);
 
329
 
 
330
    r = toku_txn_commit_txn(root_txn, true, NULL, NULL);
 
331
    CKERR(r);
 
332
    toku_txn_close_txn(root_txn);
 
333
 
 
334
    
 
335
    clean_shutdown(&logger, &ct);
 
336
}
 
337
 
 
338
int test_main (int argc, const char *argv[]) {
 
339
    default_parse_args(argc, argv);
 
340
    txn_child_manager_unit_test foo;
 
341
    foo.run_test();
 
342
    return 0;
 
343
}