1 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
2 | // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: |
3 | /* -*- mode: C; c-basic-offset: 4 -*- */ |
4 | #ident "$Id$" |
5 | /*====== |
6 | This file is part of TokuDB |
7 | |
8 | |
9 | Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. |
10 | |
11 | TokuDBis is free software: you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License, version 2, |
13 | as published by the Free Software Foundation. |
14 | |
15 | TokuDB is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with TokuDB. If not, see <http://www.gnu.org/licenses/>. |
22 | |
23 | ======= */ |
24 | |
25 | #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." |
26 | |
27 | #ifndef _TOKUDB_TXN_H |
28 | #define _TOKUDB_TXN_H |
29 | |
30 | #include "hatoku_defines.h" |
31 | #include "tokudb_debug.h" |
32 | #include "tokudb_sysvars.h" |
33 | |
34 | typedef enum { |
35 | hatoku_iso_not_set = 0, |
36 | hatoku_iso_read_uncommitted, |
37 | hatoku_iso_read_committed, |
38 | hatoku_iso_repeatable_read, |
39 | hatoku_iso_serializable |
40 | } HA_TOKU_ISO_LEVEL; |
41 | |
42 | typedef struct st_tokudb_stmt_progress { |
43 | ulonglong inserted; |
44 | ulonglong updated; |
45 | ulonglong deleted; |
46 | ulonglong queried; |
47 | bool using_loader; |
48 | } tokudb_stmt_progress; |
49 | |
50 | typedef struct st_tokudb_trx_data { |
51 | DB_TXN* all; |
52 | DB_TXN* stmt; |
53 | DB_TXN* sp_level; |
54 | DB_TXN* sub_sp_level; |
55 | uint tokudb_lock_count; |
56 | uint create_lock_count; |
57 | tokudb_stmt_progress stmt_progress; |
58 | bool checkpoint_lock_taken; |
59 | LIST* handlers; |
60 | } tokudb_trx_data; |
61 | |
62 | extern char* tokudb_data_dir; |
63 | extern const char* ha_tokudb_ext; |
64 | |
65 | inline void reset_stmt_progress(tokudb_stmt_progress* val) { |
66 | val->deleted = 0; |
67 | val->inserted = 0; |
68 | val->updated = 0; |
69 | val->queried = 0; |
70 | } |
71 | |
72 | inline int get_name_length(const char* name) { |
73 | int n = 0; |
74 | const char* newname = name; |
75 | n += strlen(newname); |
76 | n += strlen(ha_tokudb_ext); |
77 | return n; |
78 | } |
79 | |
80 | // |
81 | // returns maximum length of path to a dictionary |
82 | // |
83 | inline int get_max_dict_name_path_length(const char* tablename) { |
84 | int n = 0; |
85 | n += get_name_length(tablename); |
86 | n += 1; //for the '-' |
87 | n += MAX_DICT_NAME_LEN; |
88 | return n; |
89 | } |
90 | |
91 | inline void make_name( |
92 | char* newname, |
93 | size_t newname_len, |
94 | const char* tablename, |
95 | const char* dictname) { |
96 | |
97 | assert_always(tablename); |
98 | assert_always(dictname); |
99 | size_t real_size = snprintf( |
100 | newname, |
101 | newname_len, |
102 | "%s-%s" , |
103 | tablename, |
104 | dictname); |
105 | assert_always(real_size < newname_len); |
106 | } |
107 | |
108 | inline int txn_begin( |
109 | DB_ENV* env, |
110 | DB_TXN* parent, |
111 | DB_TXN** txn, |
112 | uint32_t flags, |
113 | THD* thd) { |
114 | |
115 | *txn = NULL; |
116 | int r = env->txn_begin(env, parent, txn, flags); |
117 | if (r == 0 && thd) { |
118 | DB_TXN* this_txn = *txn; |
119 | this_txn->set_client_id(this_txn, thd_get_thread_id(thd), thd); |
120 | } |
121 | TOKUDB_TRACE_FOR_FLAGS( |
122 | TOKUDB_DEBUG_TXN, |
123 | "begin txn %p %p %u r=%d" , |
124 | parent, |
125 | *txn, |
126 | flags, |
127 | r); |
128 | return r; |
129 | } |
130 | |
131 | inline void commit_txn(DB_TXN* txn, uint32_t flags) { |
132 | TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_TXN, "commit txn %p" , txn); |
133 | int r = txn->commit(txn, flags); |
134 | if (r != 0) { |
135 | sql_print_error( |
136 | "tried committing transaction %p and got error code %d" , |
137 | txn, |
138 | r); |
139 | } |
140 | assert_always(r == 0); |
141 | } |
142 | |
143 | inline void abort_txn(DB_TXN* txn) { |
144 | TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_TXN, "abort txn %p" , txn); |
145 | int r = txn->abort(txn); |
146 | if (r != 0) { |
147 | sql_print_error( |
148 | "tried aborting transaction %p and got error code %d" , |
149 | txn, |
150 | r); |
151 | } |
152 | assert_always(r == 0); |
153 | } |
154 | |
155 | #endif // _TOKUDB_TXN_H |
156 | |