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

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/src/tests/blocking-put-timeout.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$"
 
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) 2007-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
// verify that blocking lock waits eventually time out if the lock owner never releases the lock.
 
92
 
 
93
// A begin txn
 
94
// A write locks 0
 
95
// A sleeps
 
96
// B begin txn
 
97
// B tries to write lock 0, blocks
 
98
// B's write lock times out, B aborts its txn
 
99
// A wakes up and commits its txn
 
100
 
 
101
#include "test.h"
 
102
#include "toku_pthread.h"
 
103
 
 
104
struct test_seq {
 
105
    int state;
 
106
    toku_mutex_t lock;
 
107
    toku_cond_t cv;
 
108
};
 
109
 
 
110
static void test_seq_init(struct test_seq *seq) {
 
111
    seq->state = 0;
 
112
    toku_mutex_init(&seq->lock, NULL);
 
113
    toku_cond_init(&seq->cv, NULL);
 
114
}
 
115
 
 
116
static void test_seq_destroy(struct test_seq *seq) {
 
117
    toku_mutex_destroy(&seq->lock);
 
118
    toku_cond_destroy(&seq->cv);
 
119
}
 
120
 
 
121
static void test_seq_sleep(struct test_seq *seq, int new_state) {
 
122
    toku_mutex_lock(&seq->lock);
 
123
    while (seq->state != new_state) {
 
124
        toku_cond_wait(&seq->cv, &seq->lock);
 
125
    }
 
126
    toku_mutex_unlock(&seq->lock);
 
127
}
 
128
 
 
129
static void test_seq_next_state(struct test_seq *seq) {
 
130
    toku_mutex_lock(&seq->lock);
 
131
    seq->state++;
 
132
    toku_cond_broadcast(&seq->cv);
 
133
    toku_mutex_unlock(&seq->lock);
 
134
}
 
135
 
 
136
static void t_a(DB_ENV *db_env, DB *db, struct test_seq *seq) {
 
137
    int r;
 
138
    test_seq_sleep(seq, 0);
 
139
    int k = 0;
 
140
    DB_TXN *txn_a = NULL;
 
141
    r = db_env->txn_begin(db_env, NULL, &txn_a, 0); assert(r == 0);
 
142
    DBT key = { .data = &k, .size = sizeof k };
 
143
    DBT val = { .data = &k, .size = sizeof k };
 
144
    r = db->put(db, txn_a, &key, &val, 0); assert(r == 0);
 
145
    test_seq_next_state(seq);
 
146
    sleep(10);
 
147
    r = txn_a->commit(txn_a, 0); assert(r == 0);
 
148
}
 
149
 
 
150
static void t_b(DB_ENV *db_env, DB *db, struct test_seq *seq) {
 
151
    int r;
 
152
    test_seq_sleep(seq, 1);
 
153
    int k = 0;
 
154
    DB_TXN *txn_b = NULL;
 
155
    r = db_env->txn_begin(db_env, NULL, &txn_b, 0); assert(r == 0);
 
156
    DBT key = { .data = &k, .size = sizeof k };
 
157
    DBT val = { .data = &k, .size = sizeof k };
 
158
    r = db->put(db, txn_b, &key, &val, 0); 
 
159
#if USE_BDB
 
160
    assert(r == DB_LOCK_DEADLOCK);
 
161
#else
 
162
    assert(r == DB_LOCK_NOTGRANTED);
 
163
#endif
 
164
    r = txn_b->abort(txn_b); assert(r == 0);
 
165
}
 
166
 
 
167
struct t_a_args {
 
168
    DB_ENV *env;
 
169
    DB *db;
 
170
    struct test_seq *seq;
 
171
};
 
172
 
 
173
static void *t_a_thread(void *arg) {
 
174
    struct t_a_args *a = (struct t_a_args *) arg;
 
175
    t_a(a->env, a->db, a->seq);
 
176
    return arg;
 
177
}
 
178
 
 
179
int test_main(int argc, char * const argv[]) {
 
180
    uint64_t cachesize = 0;
 
181
    uint32_t pagesize = 0;
 
182
    const char *db_env_dir = TOKU_TEST_FILENAME;
 
183
    const char *db_filename = "test.db";
 
184
    int db_env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_THREAD;
 
185
 
 
186
    // parse_args(argc, argv);
 
187
    for (int i = 1; i < argc; i++) {
 
188
        if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
 
189
            verbose++;
 
190
            continue;
 
191
        }
 
192
        if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) {
 
193
            if (verbose > 0)
 
194
                verbose--;
 
195
            continue;
 
196
        }
 
197
        assert(0);
 
198
    }
 
199
 
 
200
    // setup env
 
201
    int r;
 
202
    char rm_cmd[strlen(db_env_dir) + strlen("rm -rf ") + 1];
 
203
    snprintf(rm_cmd, sizeof(rm_cmd), "rm -rf %s", db_env_dir);
 
204
    r = system(rm_cmd); assert(r == 0);
 
205
 
 
206
    r = toku_os_mkdir(db_env_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); assert(r == 0);
 
207
 
 
208
    DB_ENV *db_env = NULL;
 
209
    r = db_env_create(&db_env, 0); assert(r == 0);
 
210
    if (cachesize) {
 
211
        const uint64_t gig = 1 << 30;
 
212
        r = db_env->set_cachesize(db_env, cachesize / gig, cachesize % gig, 1); assert(r == 0);
 
213
    }
 
214
    r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
 
215
#if USE_BDB
 
216
    db_timeout_t t;
 
217
    r = db_env->get_timeout(db_env, &t, DB_SET_LOCK_TIMEOUT); assert(r == 0);
 
218
    if (verbose) printf("lock %d\n", t);
 
219
    r = db_env->get_timeout(db_env, &t, DB_SET_TXN_TIMEOUT); assert(r == 0);
 
220
    if (verbose) printf("txn %d\n", t);
 
221
 
 
222
    r = db_env->set_timeout(db_env, 5000000, DB_SET_LOCK_TIMEOUT); assert(r == 0);
 
223
    r = db_env->set_timeout(db_env, 5000000, DB_SET_TXN_TIMEOUT); assert(r == 0);
 
224
 
 
225
    r = db_env->get_timeout(db_env, &t, DB_SET_LOCK_TIMEOUT); assert(r == 0);
 
226
    if (verbose) printf("lock %d\n", t);
 
227
    r = db_env->get_timeout(db_env, &t, DB_SET_TXN_TIMEOUT); assert(r == 0);
 
228
    if (verbose) printf("txn %d\n", t);
 
229
 
 
230
    r = db_env->set_lk_detect(db_env, DB_LOCK_EXPIRE); assert(r == 0);
 
231
#endif
 
232
#if USE_TDB
 
233
    uint64_t lock_timeout_msec;
 
234
    r = db_env->get_lock_timeout(db_env, &lock_timeout_msec); assert(r == 0);
 
235
    if (verbose) printf("lock timeout: %" PRIu64 "\n", lock_timeout_msec);
 
236
    r = db_env->set_lock_timeout(db_env, 5000); assert(r == 0);
 
237
    r = db_env->get_lock_timeout(db_env, &lock_timeout_msec); assert(r == 0);
 
238
    if (verbose) printf("lock timeout: %" PRIu64 "\n", lock_timeout_msec);
 
239
#endif
 
240
 
 
241
    // create the db
 
242
    DB *db = NULL;
 
243
    r = db_create(&db, db_env, 0); assert(r == 0);
 
244
    if (pagesize) {
 
245
        r = db->set_pagesize(db, pagesize); assert(r == 0);
 
246
    }
 
247
    r = db->open(db, NULL, db_filename, NULL, DB_BTREE, DB_CREATE|DB_AUTO_COMMIT|DB_THREAD, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
 
248
 
 
249
    // run test
 
250
    struct test_seq seq; ZERO_STRUCT(seq); test_seq_init(&seq);
 
251
    toku_pthread_t t_a_id;
 
252
    struct t_a_args t_a_args = { db_env, db, &seq };
 
253
    r = toku_pthread_create(&t_a_id, NULL, t_a_thread, &t_a_args); assert(r == 0);
 
254
    t_b(db_env, db, &seq);
 
255
    void *ret;
 
256
    r = toku_pthread_join(t_a_id, &ret); assert(r == 0);
 
257
    test_seq_destroy(&seq);
 
258
 
 
259
    // close env
 
260
    r = db->close(db, 0); assert(r == 0); db = NULL;
 
261
    r = db_env->close(db_env, 0); assert(r == 0); db_env = NULL;
 
262
 
 
263
    return 0;
 
264
}