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 This file is part of PerconaFT.
6 
7 
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9 
10     PerconaFT is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License, version 2,
12     as published by the Free Software Foundation.
13 
14     PerconaFT is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
21 
22 ----------------------------------------
23 
24     PerconaFT is free software: you can redistribute it and/or modify
25     it under the terms of the GNU Affero General Public License, version 3,
26     as published by the Free Software Foundation.
27 
28     PerconaFT is distributed in the hope that it will be useful,
29     but WITHOUT ANY WARRANTY; without even the implied warranty of
30     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31     GNU Affero General Public License for more details.
32 
33     You should have received a copy of the GNU Affero General Public License
34     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36 
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38 
39 #include "test.h"
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 #include <unistd.h>
45 #include <memory.h>
46 #include <errno.h>
47 #include <sys/stat.h>
48 #include <db.h>
49 
50 
51 //
52 // This test ensures that we can do many updates to a single key when the dictionary
53 // is just that key.
54 //
55 static void
run_test(void)56 run_test (void) {
57 
58     DB_ENV * env;
59     DB *db;
60     const char * const fname = "test.updates_single_key.ft_handle";
61     int r;
62 
63     r = db_env_create(&env, 0);        assert(r == 0);
64     env->set_errfile(env, stderr);
65     // no need to run with logging, so DB_INIT_LOG not passed in
66     r = env->open(env, TOKU_TEST_FILENAME, DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
67     r = db_create(&db, env, 0); assert(r == 0);
68     db->set_errfile(db,stderr); // Turn off those annoying errors
69     r = db->open(db, NULL, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
70 
71     int i;
72     for (i=0; i<1000000; i++) {
73         int k = 1;
74         int v = i;
75         DBT key, val;
76         DB_TXN* txn = NULL;
77         r = env->txn_begin(env, NULL, &txn, 0);
78         CKERR(r);
79         // want this test to go as fast as possible, so no need to use the lock tree
80         // we just care to see that #5700 is behaving better, that some garbage collection is happening
81         r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), DB_PRELOCKED_WRITE);
82         txn->commit(txn, DB_TXN_NOSYNC);
83         CKERR(r);
84     }
85 
86     r = db->close(db, 0); assert(r == 0);
87     r = env->close(env, 0); assert(r == 0);
88 }
89 
90 int
test_main(int argc,char * const argv[])91 test_main(int argc, char *const argv[]) {
92 
93     parse_args(argc, argv);
94 
95     toku_os_recursive_delete(TOKU_TEST_FILENAME);
96     toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
97 
98     run_test();
99 
100     return 0;
101 }
102