Skip to content

Commit 6aae11f

Browse files
Bill QuBill Qu
Bill Qu
authored and
Bill Qu
committed
Bug#18410442 CREATE A BASE CLASS FOR GTID_TABLE_ACCESS_CONTEXT AND RPL_INFO_TABLE_ACCESS
Create a base class for Gtid_table_access_context and Rpl_info_table_access clases. ~
1 parent a613b5d commit 6aae11f

6 files changed

+295
-341
lines changed

sql/rpl_gtid_persist.cc

+20-133
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "log.h"
1919
#include "key.h"
20-
#include "sql_base.h"
2120
#include "sql_parse.h"
2221
#include "replication.h"
2322
#include "rpl_gtid_persist.h"
@@ -72,9 +71,8 @@ static void deinit_thd(THD *thd)
7271

7372
THD *Gtid_table_access_context::create_thd()
7473
{
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;
7876
/*
7977
This is equivalent to a new "statement". For that reason, we call
8078
both lex_start() and mysql_reset_thd_for_next_command.
@@ -86,10 +84,18 @@ THD *Gtid_table_access_context::create_thd()
8684
}
8785

8886

89-
void Gtid_table_access_context::drop_thd(THD *thd)
87+
void Gtid_table_access_context::before_open(THD* thd)
9088
{
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);
9399
DBUG_VOID_RETURN;
94100
}
95101

@@ -107,7 +113,11 @@ bool Gtid_table_access_context::init(THD **thd, TABLE **table, bool is_write)
107113
m_tmp_disable_binlog__save_options= (*thd)->variables.option_bits;
108114
(*thd)->variables.option_bits&= ~OPTION_BIN_LOG;
109115
}
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);
111121

112122
DBUG_RETURN(ret);
113123
}
@@ -118,7 +128,8 @@ void Gtid_table_access_context::deinit(THD *thd, TABLE *table,
118128
{
119129
DBUG_ENTER("Gtid_table_access_context::deinit");
120130

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;
122133
/* Reenable binlog */
123134
if (m_is_write)
124135
thd->variables.option_bits= m_tmp_disable_binlog__save_options;
@@ -129,130 +140,6 @@ void Gtid_table_access_context::deinit(THD *thd, TABLE *table,
129140
}
130141

131142

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-
256143
int Gtid_table_persistor::fill_fields(Field **fields, const char *sid,
257144
rpl_gno gno_start, rpl_gno gno_end)
258145
{

sql/rpl_gtid_persist.h

+18-59
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
#define RPL_GTID_PERSIST_H_
2020

2121
#include <string>
22+
#include "sql_base.h"
2223
using std::string;
2324

2425
class Open_tables_backup;
2526

2627

27-
class Gtid_table_access_context
28+
class Gtid_table_access_context : public Table_access
2829
{
2930

3031
public:
@@ -61,6 +62,22 @@ class Gtid_table_access_context
6162
@param need_commit Need to commit current transaction if it is true
6263
*/
6364
void deinit(THD *thd, TABLE *table, bool error, bool need_commit);
65+
/**
66+
Prepares before opening table.
67+
- set flags
68+
69+
@param[in] thd Thread requesting to open the table
70+
*/
71+
void before_open(THD* thd);
72+
/**
73+
Creates a new thread in the bootstrap process or in the mysqld startup,
74+
a thread is created in order to be able to access a table. And reset a
75+
new "statement".
76+
77+
@return
78+
@retval THD* Pointer to thread structure
79+
*/
80+
THD *create_thd();
6481
private:
6582
/* Pointer to new created THD. */
6683
THD *m_drop_thd_object;
@@ -70,65 +87,7 @@ class Gtid_table_access_context
7087
Open_tables_backup m_backup;
7188
/* Save binlog options. */
7289
ulonglong m_tmp_disable_binlog__save_options;
73-
/**
74-
Creates a new thread in the bootstrap process or in the mysqld startup,
75-
a thread is created in order to be able to access a table.
76-
77-
@return
78-
@retval THD* Pointer to thread structure
79-
*/
80-
THD *create_thd();
81-
/**
82-
Destroys the created thread and restores the
83-
system_thread information.
84-
85-
@param thd Thread requesting to be destroyed
86-
*/
87-
void drop_thd(THD *thd);
88-
/**
89-
Opens and locks a table.
90-
91-
It's assumed that the caller knows what they are doing:
92-
- whether it was necessary to reset-and-backup the open tables state
93-
- whether the requested lock does not lead to a deadlock
94-
- whether this open mode would work under LOCK TABLES, or inside a
95-
stored function or trigger.
96-
97-
Note that if the table can't be locked successfully this operation will
98-
close it. Therefore it provides guarantee that it either opens and locks
99-
table or fails without leaving any tables open.
10090

101-
@param thd Thread requesting to open the table
102-
@param lock_type How to lock the table
103-
@param[out] table We will store the open table here
104-
105-
@return
106-
@retval TRUE open and lock failed - an error message is pushed into the
107-
stack
108-
@retval FALSE success
109-
*/
110-
bool open_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
111-
/**
112-
Commits the changes, unlocks the table and closes it. This method
113-
needs to be called even if the open_table fails, in order to ensure
114-
the lock info is properly restored.
115-
116-
@param thd Thread requesting to close the table
117-
@param table Table to be closed
118-
@param error If there was an error while updating
119-
the table
120-
@param need_commit Need to commit current transaction if
121-
it is true.
122-
123-
If there is an error, rolls back the current statement. Otherwise,
124-
commits it. However, if a new thread was created and there is an
125-
error, the transaction must be rolled back. Otherwise, it must be
126-
committed. In this case, the changes were not done on behalf of
127-
any user transaction and if not finished, there would be pending
128-
changes.
129-
130-
*/
131-
void close_table(THD *thd, TABLE *table, bool error, bool need_commit);
13291
/* Prevent user from invoking default assignment function. */
13392
Gtid_table_access_context &operator=(const Gtid_table_access_context &info);
13493
/* Prevent user from invoking default constructor function. */

0 commit comments

Comments
 (0)