17
17
18
18
#include " log.h"
19
19
#include " key.h"
20
- #include " sql_base.h"
21
20
#include " sql_parse.h"
22
21
#include " replication.h"
23
22
#include " rpl_gtid_persist.h"
@@ -72,9 +71,8 @@ static void deinit_thd(THD *thd)
72
71
73
72
THD *Gtid_table_access_context::create_thd ()
74
73
{
75
- THD *thd= NULL ;
76
- thd= new THD;
77
- init_thd (&thd);
74
+ THD *thd= Table_access::create_thd ();
75
+ thd->system_thread = SYSTEM_THREAD_COMPRESS_GTID_TABLE;
78
76
/*
79
77
This is equivalent to a new "statement". For that reason, we call
80
78
both lex_start() and mysql_reset_thd_for_next_command.
@@ -86,10 +84,18 @@ THD *Gtid_table_access_context::create_thd()
86
84
}
87
85
88
86
89
- void Gtid_table_access_context::drop_thd (THD * thd)
87
+ void Gtid_table_access_context::before_open (THD* thd)
90
88
{
91
- DBUG_ENTER (" Gtid_table_access_context::drop_thd" );
92
- deinit_thd (thd);
89
+ DBUG_ENTER (" Gtid_table_access_context::before_open" );
90
+ /*
91
+ Allow to operate the gtid_executed table
92
+ while disconnecting the session.
93
+ */
94
+ m_flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |
95
+ MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
96
+ MYSQL_OPEN_IGNORE_FLUSH |
97
+ MYSQL_LOCK_IGNORE_TIMEOUT |
98
+ MYSQL_OPEN_IGNORE_KILLED);
93
99
DBUG_VOID_RETURN;
94
100
}
95
101
@@ -107,7 +113,11 @@ bool Gtid_table_access_context::init(THD **thd, TABLE **table, bool is_write)
107
113
m_tmp_disable_binlog__save_options= (*thd)->variables .option_bits ;
108
114
(*thd)->variables .option_bits &= ~OPTION_BIN_LOG;
109
115
}
110
- bool ret= this ->open_table (*thd, m_is_write ? TL_WRITE : TL_READ, table);
116
+ (*thd)->is_operating_gtid_table = true ;
117
+ bool ret= this ->open_table (*thd, DB_NAME, TABLE_NAME,
118
+ Gtid_table_persistor::number_fields,
119
+ m_is_write ? TL_WRITE : TL_READ,
120
+ table, &m_backup);
111
121
112
122
DBUG_RETURN (ret);
113
123
}
@@ -118,7 +128,8 @@ void Gtid_table_access_context::deinit(THD *thd, TABLE *table,
118
128
{
119
129
DBUG_ENTER (" Gtid_table_access_context::deinit" );
120
130
121
- this ->close_table (thd, table, 0 != error, need_commit);
131
+ this ->close_table (thd, table, &m_backup, 0 != error, need_commit);
132
+ thd->is_operating_gtid_table = false ;
122
133
/* Reenable binlog */
123
134
if (m_is_write)
124
135
thd->variables .option_bits = m_tmp_disable_binlog__save_options;
@@ -129,130 +140,6 @@ void Gtid_table_access_context::deinit(THD *thd, TABLE *table,
129
140
}
130
141
131
142
132
- void Gtid_table_access_context::close_table (THD *thd, TABLE *table,
133
- bool error, bool need_commit)
134
- {
135
- Query_tables_list query_tables_list_backup;
136
-
137
- DBUG_ENTER (" Gtid_table_access_context::close_table" );
138
-
139
- if (table)
140
- {
141
- if (error)
142
- ha_rollback_trans (thd, false );
143
- else
144
- {
145
- /*
146
- To make the commit not to block with global read lock set
147
- "ignore_global_read_lock" flag to true.
148
- */
149
- ha_commit_trans (thd, false , true );
150
- }
151
-
152
- if (need_commit)
153
- {
154
- if (error)
155
- ha_rollback_trans (thd, true );
156
- else
157
- {
158
- ha_commit_trans (thd, true , true );
159
- }
160
- }
161
-
162
- /*
163
- In order not to break execution of current statement we have to
164
- backup/reset/restore Query_tables_list part of LEX, which is
165
- accessed and updated in the process of closing tables.
166
- */
167
- thd->lex ->reset_n_backup_query_tables_list (&query_tables_list_backup);
168
- close_thread_tables (thd);
169
- thd->lex ->restore_backup_query_tables_list (&query_tables_list_backup);
170
- thd->restore_backup_open_tables_state (&m_backup);
171
- }
172
- thd->is_operating_gtid_table = false ;
173
-
174
- DBUG_VOID_RETURN;
175
- }
176
-
177
-
178
- bool Gtid_table_access_context::open_table (THD *thd,
179
- enum thr_lock_type lock_type,
180
- TABLE **table)
181
- {
182
- DBUG_ENTER (" Gtid_table_access_context::open_table" );
183
-
184
- TABLE_LIST tables;
185
- Query_tables_list query_tables_list_backup;
186
-
187
- /*
188
- Allow to operate the gtid_executed table
189
- when disconnecting the session.
190
- */
191
- uint flags= (MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |
192
- MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
193
- MYSQL_OPEN_IGNORE_FLUSH |
194
- MYSQL_LOCK_IGNORE_TIMEOUT |
195
- MYSQL_OPEN_IGNORE_KILLED);
196
-
197
- /*
198
- We need to use new Open_tables_state in order not to be affected
199
- by LOCK TABLES/prelocked mode.
200
- Also in order not to break execution of current statement we also
201
- have to backup/reset/restore Query_tables_list part of LEX, which
202
- is accessed and updated in the process of opening and locking
203
- tables.
204
- */
205
- thd->lex ->reset_n_backup_query_tables_list (&query_tables_list_backup);
206
- thd->reset_n_backup_open_tables_state (&m_backup);
207
-
208
- thd->is_operating_gtid_table = true ;
209
- tables.init_one_table (
210
- DB_NAME.str , DB_NAME.length ,
211
- TABLE_NAME.str , TABLE_NAME.length ,
212
- TABLE_NAME.str , lock_type);
213
-
214
- tables.open_strategy = TABLE_LIST::OPEN_IF_EXISTS;
215
- /* Save value that is changed in mysql_lock_tables() */
216
- ulonglong save_utime_after_lock= thd->utime_after_lock ;
217
- if (!open_n_lock_single_table (thd, &tables, tables.lock_type , flags))
218
- {
219
- close_thread_tables (thd);
220
- thd->restore_backup_open_tables_state (&m_backup);
221
- thd->lex ->restore_backup_query_tables_list (&query_tables_list_backup);
222
- thd->utime_after_lock = save_utime_after_lock;
223
- sql_print_warning (" Gtid table is not ready to be used. Table "
224
- " '%s.%s' cannot be opened." , DB_NAME.str ,
225
- TABLE_NAME.str );
226
- DBUG_RETURN (true );
227
- }
228
- thd->utime_after_lock = save_utime_after_lock;
229
-
230
- DBUG_ASSERT (tables.table ->s ->table_category == TABLE_CATEGORY_GTID);
231
-
232
- if (tables.table ->s ->fields < Gtid_table_persistor::number_fields)
233
- {
234
- /*
235
- Safety: this can only happen if someone started the server and then
236
- altered the table.
237
- */
238
- ha_rollback_trans (thd, false );
239
- close_thread_tables (thd);
240
- thd->restore_backup_open_tables_state (&m_backup);
241
- thd->lex ->restore_backup_query_tables_list (&query_tables_list_backup);
242
- my_error (ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2, MYF (0 ),
243
- tables.table ->s ->db .str , tables.table ->s ->table_name .str ,
244
- Gtid_table_persistor::number_fields, tables.table ->s ->fields );
245
- DBUG_RETURN (true );
246
- }
247
-
248
- thd->lex ->restore_backup_query_tables_list (&query_tables_list_backup);
249
-
250
- *table= tables.table ;
251
- tables.table ->use_all_columns ();
252
- DBUG_RETURN (false );
253
- }
254
-
255
-
256
143
int Gtid_table_persistor::fill_fields (Field **fields, const char *sid,
257
144
rpl_gno gno_start, rpl_gno gno_end)
258
145
{
0 commit comments