~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-set.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 cursor set operations suspend the conflicting threads when another transaction 
 
92
// owns a lock on the key.  
 
93
 
 
94
#include "test.h"
 
95
#include "toku_pthread.h"
 
96
 
 
97
static void populate(DB_ENV *db_env, DB *db, uint64_t nrows) {
 
98
    int r;
 
99
 
 
100
    DB_TXN *txn = NULL;
 
101
    r = db_env->txn_begin(db_env, NULL, &txn, 0); assert(r == 0);
 
102
 
 
103
    for (uint64_t i = 0; i < nrows; i++) {
 
104
 
 
105
        uint64_t k = htonl(i);
 
106
        uint64_t v = i;
 
107
        DBT key = { .data = &k, .size = sizeof k };
 
108
        DBT val = { .data = &v, .size = sizeof v };
 
109
        r = db->put(db, txn, &key, &val, 0); assert(r == 0);
 
110
    }
 
111
 
 
112
    r = txn->commit(txn, 0); assert(r == 0);
 
113
}
 
114
 
 
115
#if TOKUDB
 
116
static int blocking_set_callback(DBT const *a UU(), DBT const *b UU(), void *e UU()) {
 
117
    // DBT const *found_key = a;
 
118
    DBT const *found_val = b;
 
119
    DBT *my_val = (DBT *) e;
 
120
    assert(my_val->flags == DB_DBT_REALLOC);
 
121
    my_val->data = toku_xrealloc(my_val->data, found_val->size);
 
122
    my_val->size = found_val->size;
 
123
    memcpy(my_val->data, found_val->data, found_val->size);
 
124
    return 0;
 
125
}
 
126
#endif
 
127
 
 
128
static void blocking_set(DB_ENV *db_env, DB *db, uint64_t nrows, long sleeptime) {
 
129
    int r;
 
130
 
 
131
    DBT val;
 
132
    dbt_init_realloc(&val);
 
133
 
 
134
    for (uint64_t i = 0; i < nrows; i++) {
 
135
        DB_TXN *txn = NULL;
 
136
        r = db_env->txn_begin(db_env, NULL, &txn, 0); assert(r == 0);
 
137
 
 
138
        DBC *cursor = NULL;
 
139
        r = db->cursor(db, txn, &cursor, 0); assert(r == 0); // get a write lock on the key
 
140
 
 
141
        uint64_t k = htonl(0); // set to key 0
 
142
        DBT key = { .data = &k, .size = sizeof k };
 
143
#if TOKUDB
 
144
        r = cursor->c_getf_set(cursor, DB_RMW, &key, blocking_set_callback, &val); assert(r == 0);
 
145
#else
 
146
        r = cursor->c_get(cursor, &key, &val, DB_SET + DB_RMW); assert(r == 0);
 
147
#endif
 
148
        uint64_t v;
 
149
        assert(val.size == sizeof v);
 
150
        memcpy(&v, val.data, val.size);
 
151
        assert(v == 0); // verify the value
 
152
 
 
153
        usleep(sleeptime);
 
154
 
 
155
        r = cursor->c_close(cursor); assert(r == 0);
 
156
 
 
157
        r = txn->commit(txn, 0); assert(r == 0);
 
158
        if (verbose)
 
159
            printf("%lu %" PRIu64 "\n", (unsigned long) toku_pthread_self(), i);
 
160
    }
 
161
 
 
162
    toku_free(val.data);
 
163
}
 
164
 
 
165
struct blocking_set_args {
 
166
    DB_ENV *db_env;
 
167
    DB *db;
 
168
    uint64_t nrows;
 
169
    long sleeptime;
 
170
};
 
171
 
 
172
static void *blocking_set_thread(void *arg) {
 
173
    struct blocking_set_args *a = (struct blocking_set_args *) arg;
 
174
    blocking_set(a->db_env, a->db, a->nrows, a->sleeptime);
 
175
    return arg;
 
176
}
 
177
 
 
178
int test_main(int argc, char * const argv[]) {
 
179
    uint64_t cachesize = 0;
 
180
    uint32_t pagesize = 0;
 
181
    uint64_t nrows = 100;
 
182
    int nthreads = 2;
 
183
    long sleeptime = 100000;
 
184
    const char *db_env_dir = TOKU_TEST_FILENAME;
 
185
    const char *db_filename = "test.db";
 
186
    int db_env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_THREAD;
 
187
 
 
188
    // parse_args(argc, argv);
 
189
    for (int i = 1; i < argc; i++) {
 
190
        if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
 
191
            verbose++;
 
192
            continue;
 
193
        }
 
194
        if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) {
 
195
            if (verbose > 0)
 
196
                verbose--;
 
197
            continue;
 
198
        }
 
199
        if (strcmp(argv[i], "--nrows") == 0 && i+1 < argc) {
 
200
            nrows = atoll(argv[++i]);
 
201
            continue;
 
202
        }
 
203
        if (strcmp(argv[i], "--nthreads") == 0 && i+1 < argc) {
 
204
            nthreads = atoi(argv[++i]);
 
205
            continue;
 
206
        }
 
207
        if (strcmp(argv[i], "--sleeptime") == 0 && i+1 < argc) {
 
208
            sleeptime = atol(argv[++i]);
 
209
            continue;
 
210
        }
 
211
        assert(0);
 
212
    }
 
213
 
 
214
    // setup env
 
215
    int r;
 
216
    char rm_cmd[strlen(db_env_dir) + strlen("rm -rf ") + 1];
 
217
    snprintf(rm_cmd, sizeof(rm_cmd), "rm -rf %s", db_env_dir);
 
218
    r = system(rm_cmd); assert(r == 0);
 
219
 
 
220
    r = toku_os_mkdir(db_env_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); assert(r == 0);
 
221
 
 
222
    DB_ENV *db_env = NULL;
 
223
    r = db_env_create(&db_env, 0); assert(r == 0);
 
224
    if (cachesize) {
 
225
        const uint64_t gig = 1 << 30;
 
226
        r = db_env->set_cachesize(db_env, cachesize / gig, cachesize % gig, 1); assert(r == 0);
 
227
    }
 
228
    r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
 
229
#if TOKUDB
 
230
    r = db_env->set_lock_timeout(db_env, 30 * 1000); assert(r == 0);
 
231
#endif
 
232
 
 
233
    // create the db
 
234
    DB *db = NULL;
 
235
    r = db_create(&db, db_env, 0); assert(r == 0);
 
236
    if (pagesize) {
 
237
        r = db->set_pagesize(db, pagesize); assert(r == 0);
 
238
    }
 
239
    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);
 
240
 
 
241
    // populate the db
 
242
    populate(db_env, db, nrows);
 
243
 
 
244
    toku_pthread_t tids[nthreads];
 
245
    struct blocking_set_args a = { db_env, db, nrows, sleeptime };
 
246
    for (int i = 0; i < nthreads-1; i++) {
 
247
        r = toku_pthread_create(&tids[i], NULL, blocking_set_thread, &a); assert(r == 0);
 
248
    }
 
249
    blocking_set(db_env, db, nrows, sleeptime);
 
250
    for (int i = 0; i < nthreads-1; i++) {
 
251
        void *ret;
 
252
        r = toku_pthread_join(tids[i], &ret); assert(r == 0);
 
253
    }
 
254
 
 
255
    // close env
 
256
    r = db->close(db, 0); assert(r == 0); db = NULL;
 
257
    r = db_env->close(db_env, 0); assert(r == 0); db_env = NULL;
 
258
 
 
259
    return 0;
 
260
}