-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathtransaction_impl.h
198 lines (154 loc) · 5.89 KB
/
transaction_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef DD__TRANSACTION_IMPL_INCLUDED
#define DD__TRANSACTION_IMPL_INCLUDED
#include <sys/types.h>
#include <map>
#include "my_inttypes.h"
#include "mysql/udf_registration_types.h"
#include "sql/dd/dd_kill_immunizer.h" // dd::DD_kill_immunizer
#include "sql/dd/impl/types/abstract_table_impl.h"
#include "sql/dd/impl/types/charset_impl.h"
#include "sql/dd/impl/types/collation_impl.h"
#include "sql/dd/impl/types/column_impl.h"
#include "sql/dd/impl/types/column_statistics_impl.h"
#include "sql/dd/impl/types/event_impl.h"
#include "sql/dd/impl/types/foreign_key_impl.h"
#include "sql/dd/impl/types/function_impl.h"
#include "sql/dd/impl/types/index_stat_impl.h"
#include "sql/dd/impl/types/parameter_impl.h"
#include "sql/dd/impl/types/partition_impl.h"
#include "sql/dd/impl/types/procedure_impl.h"
#include "sql/dd/impl/types/resource_group_impl.h"
#include "sql/dd/impl/types/routine_impl.h"
#include "sql/dd/impl/types/schema_impl.h"
#include "sql/dd/impl/types/spatial_reference_system_impl.h"
#include "sql/dd/impl/types/table_impl.h"
#include "sql/dd/impl/types/table_stat_impl.h"
#include "sql/dd/impl/types/tablespace_impl.h"
#include "sql/dd/impl/types/trigger_impl.h"
#include "sql/dd/impl/types/view_impl.h"
#include "sql/dd/impl/types/view_routine_impl.h"
#include "sql/dd/impl/types/view_table_impl.h"
#include "sql/dd/string_type.h" // dd::String_type
#include "sql/discrete_interval.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/set_var.h"
#include "sql/sql_class.h" // THD::killed_state
#include "thr_lock.h"
struct LEX;
namespace dd {
class Raw_table;
///////////////////////////////////////////////////////////////////////////
/**
Auxiliary class for opening dictionary tables.
*/
class Open_dictionary_tables_ctx {
public:
Open_dictionary_tables_ctx(THD *thd, thr_lock_type lock_type)
: m_thd(thd), m_lock_type(lock_type), m_ignore_global_read_lock(false) {}
~Open_dictionary_tables_ctx();
Raw_table *get_table(const String_type &name) const;
template <typename T>
Raw_table *get_table() const {
return get_table(T::DD_table::instance().name());
}
template <typename X>
void register_tables() {
X::Impl::register_tables(this);
}
template <typename X>
void add_table() {
this->add_table(X::instance().name());
}
/**
Open all the DD tables in list Open_dictionary_tables_ctx::m_tables.
@return true - On failure and error is reported.
@return false - On success.
*/
bool open_tables();
void add_table(const String_type &name);
THD *get_thd() const { return m_thd; }
/**
Ignore global read lock when opening the tables.
@returns void.
*/
void mark_ignore_global_read_lock() {
if (m_lock_type == TL_WRITE) m_ignore_global_read_lock = true;
}
private:
THD *m_thd;
thr_lock_type m_lock_type;
bool m_ignore_global_read_lock;
typedef std::map<String_type, Raw_table *> Object_table_map;
Object_table_map m_tables;
};
/**
Implementation of read-only data-dictionary transaction.
Relies on attachable transactions infrastructure.
*/
class Transaction_ro {
public:
Transaction_ro(THD *thd, enum_tx_isolation isolation)
: otx(thd, TL_READ), m_thd(thd), m_kill_immunizer(thd) {
thd->begin_attachable_ro_transaction();
thd->tx_isolation = isolation;
}
~Transaction_ro() { m_thd->end_attachable_transaction(); }
Open_dictionary_tables_ctx otx;
private:
THD *m_thd;
DD_kill_immunizer m_kill_immunizer;
};
///////////////////////////////////////////////////////////////////////////
/**
Class for storing/restoring state during dictionary update operations.
*/
class Update_dictionary_tables_ctx {
public:
Update_dictionary_tables_ctx(THD *thd);
~Update_dictionary_tables_ctx();
Open_dictionary_tables_ctx otx;
private:
THD *m_thd;
DD_kill_immunizer m_kill_immunizer;
LEX *m_lex_saved;
// Stores state before DD operations
Open_tables_backup m_open_tables_state_backup;
bool m_saved_binlog_row_based;
ulonglong m_saved_options;
sql_mode_t m_saved_mode;
long long m_latest_auto_incr_id;
enum_check_fields m_saved_check_for_truncated_fields;
uint m_saved_in_sub_stmt;
bool m_saved_time_zone_used;
/*
Save auto_increment_increment state.
Value of the auto_increment_increment is set to 1 in the constructor.
auto_increment_offset is used only when auto_increment_increment is greater
than 1. So saving only auto_increment_increment value.
*/
ulong m_saved_auto_increment_increment;
// Save auto_inc_intervals_in_cur_stmt_for_binlog
Discrete_intervals_list m_auto_inc_intervals_in_cur_stmt_for_binlog_saved;
Discrete_intervals_list m_auto_inc_intervals_forced_saved;
};
///////////////////////////////////////////////////////////////////////////
} // namespace dd
#endif // DD__TRANSACTION_IMPL_INCLUDED