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 #include <stdio.h>
41
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <memory.h>
45 #include <sys/stat.h>
46 #include <db.h>
47
48 static void
test_txn_abort(void)49 test_txn_abort (void) {
50
51 int r;
52 toku_os_recursive_delete(TOKU_TEST_FILENAME);
53 toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
54
55 int i;
56 DB_ENV *env;
57 DBT key, val;
58 DB_TXN* txn_all = NULL;
59 DB_TXN* txn_stmt = NULL;
60 DB_TXN* txn_sp = NULL;
61 r = db_env_create(&env, 0); CKERR(r);
62 r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN | DB_PRIVATE | DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
63 CKERR(r);
64
65 DB_TXN *txn = 0;
66 r = env->txn_begin(env, 0, &txn, 0); CKERR(r);
67
68 DB *db;
69 r = db_create(&db, env, 0); CKERR(r);
70 r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
71 r = txn->commit(txn, 0); CKERR(r);
72
73
74 r = env->txn_begin(env, 0, &txn_all, 0); CKERR(r);
75
76 r = env->txn_begin(env, txn_all, &txn_stmt, 0); CKERR(r);
77 i = 1;
78 r = db->put(db, txn_stmt, dbt_init(&key, &i, sizeof i), dbt_init(&val, &i, sizeof i), 0);
79 CKERR(r);
80 r = txn_stmt->commit(txn_stmt,DB_TXN_NOSYNC);
81 txn_stmt = NULL;
82
83 r = env->txn_begin(env, txn_all, &txn_sp, 0); CKERR(r);
84
85 r = env->txn_begin(env, txn_sp, &txn_stmt, 0); CKERR(r);
86 i = 2;
87 r = db->put(db, txn_stmt, dbt_init(&key, &i, sizeof i), dbt_init(&val, &i, sizeof i), 0);
88 CKERR(r);
89 r = txn_stmt->commit(txn_stmt,DB_TXN_NOSYNC);
90 txn_stmt = NULL;
91
92
93 r = txn_all->abort(txn_all);
94 CKERR(r);
95
96
97 /* walk the db, should be empty */
98 r = env->txn_begin(env, 0, &txn, 0); CKERR(r);
99 DBC *cursor;
100 r = db->cursor(db, txn, &cursor, 0); CKERR(r);
101 memset(&key, 0, sizeof key);
102 memset(&val, 0, sizeof val);
103 r = cursor->c_get(cursor, &key, &val, DB_FIRST);
104 CKERR2(r, DB_NOTFOUND);
105 r = cursor->c_close(cursor); CKERR(r);
106 r = txn->commit(txn, 0);
107
108 r = db->close(db, 0); CKERR(r);
109 r = env->close(env, 0); CKERR(r);
110 }
111
112 int
test_main(int argc,char * const argv[])113 test_main(int argc, char *const argv[]) {
114 parse_args(argc, argv);
115 test_txn_abort();
116 return 0;
117 }
118