16 #include "sql_reload.h"
19 #include "sql_class.h"
21 #include "sql_servers.h"
22 #include "sql_connect.h"
26 #include "rpl_master.h"
56 bool reload_acl_and_cache(THD *thd,
unsigned long options,
61 int tmp_write_to_binlog= *write_to_binlog= 1;
63 DBUG_ASSERT(!thd || !thd->in_sub_stmt);
65 #ifndef NO_EMBEDDED_ACCESS_CHECKS
66 if (options & REFRESH_GRANT)
73 if (!thd && (thd= (tmp_thd=
new THD)))
75 thd->thread_stack= (
char*) &tmp_thd;
81 bool reload_acl_failed= acl_reload(thd);
82 bool reload_grants_failed= grant_reload(thd);
83 bool reload_servers_failed= servers_reload(thd);
85 if (reload_acl_failed || reload_grants_failed || reload_servers_failed)
92 my_error(ER_UNKNOWN_ERROR, MYF(0));
100 my_pthread_setspecific_ptr(THR_THD, 0);
106 if (options & REFRESH_LOG)
114 options|= REFRESH_BINARY_LOG;
115 options|= REFRESH_RELAY_LOG;
116 options|= REFRESH_SLOW_LOG;
117 options|= REFRESH_GENERAL_LOG;
118 options|= REFRESH_ENGINE_LOG;
119 options|= REFRESH_ERROR_LOG;
122 if (options & REFRESH_ERROR_LOG)
123 if (flush_error_log())
129 my_error(ER_UNKNOWN_ERROR, MYF(0));
133 if ((options & REFRESH_SLOW_LOG) && opt_slow_log)
136 if ((options & REFRESH_GENERAL_LOG) && opt_log)
139 if (options & REFRESH_ENGINE_LOG)
140 if (ha_flush_logs(NULL))
143 if (options & REFRESH_BINARY_LOG)
151 tmp_write_to_binlog= 0;
152 if (mysql_bin_log.is_open())
155 *write_to_binlog= -1;
158 if (options & REFRESH_RELAY_LOG)
160 #ifdef HAVE_REPLICATION
162 if (active_mi != NULL)
165 if (rotate_relay_log(active_mi))
166 *write_to_binlog= -1;
172 #ifdef HAVE_QUERY_CACHE
173 if (options & REFRESH_QUERY_CACHE_FREE)
176 options &= ~REFRESH_QUERY_CACHE;
178 if (options & (REFRESH_TABLES | REFRESH_QUERY_CACHE))
184 DBUG_ASSERT(!thd || thd->locked_tables_mode ||
185 !thd->mdl_context.has_locks() ||
186 thd->handler_tables_hash.records ||
187 thd->global_read_lock.is_acquired());
193 if (options & (REFRESH_TABLES | REFRESH_READ_LOCK))
195 if ((options & REFRESH_READ_LOCK) && thd)
203 if (thd->locked_tables_mode)
205 my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
212 tmp_write_to_binlog= 0;
213 if (thd->global_read_lock.lock_global_read_lock(thd))
215 if (close_cached_tables(thd, tables,
216 ((options & REFRESH_FAST) ? FALSE : TRUE),
217 thd->variables.lock_wait_timeout))
226 if (thd->global_read_lock.make_global_read_lock_block_commit(thd))
229 thd->global_read_lock.unlock_global_read_lock(thd);
235 if (thd && thd->locked_tables_mode)
243 for (
TABLE_LIST *t= tables; t; t= t->next_local)
255 if (thd->open_tables &&
256 !thd->mdl_context.is_lock_owner(MDL_key::GLOBAL,
"",
"",
257 MDL_INTENTION_EXCLUSIVE))
259 my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),
260 thd->open_tables->s->table_name.str);
264 for (
TABLE *tab= thd->open_tables; tab; tab= tab->next)
266 if (! tab->mdl_ticket->is_upgradable_or_exclusive())
268 my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),
269 tab->s->table_name.str);
276 if (close_cached_tables(thd, tables,
277 ((options & REFRESH_FAST) ? FALSE : TRUE),
278 (thd ? thd->variables.lock_wait_timeout :
290 if (options & REFRESH_HOSTS)
291 hostname_cache_refresh();
292 if (thd && (options & REFRESH_STATUS))
294 if (options & REFRESH_THREADS)
295 kill_blocked_pthreads();
296 #ifdef HAVE_REPLICATION
297 if (options & REFRESH_MASTER)
300 tmp_write_to_binlog= 0;
301 if (reset_master(thd))
309 if (options & REFRESH_DES_KEY_FILE)
311 if (des_key_file && load_des_key_file(des_key_file))
318 #ifdef HAVE_REPLICATION
319 if (options & REFRESH_SLAVE)
321 tmp_write_to_binlog= 0;
323 if (active_mi != NULL && reset_slave(thd, active_mi))
328 else if (active_mi == NULL)
331 my_error(ER_SLAVE_CONFIGURATION, MYF(0));
336 if (options & REFRESH_USER_RESOURCES)
338 if (*write_to_binlog != -1)
339 *write_to_binlog= tmp_write_to_binlog;
343 return result || (thd ? thd->killed : 0);
421 bool flush_tables_with_read_lock(THD *thd,
TABLE_LIST *all_tables)
431 if (thd->locked_tables_mode)
433 my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
443 thd->variables.lock_wait_timeout,
444 MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK))
447 DEBUG_SYNC(thd,
"flush_tables_with_read_lock_after_acquire_locks");
449 for (table_list= all_tables; table_list;
450 table_list= table_list->next_global)
455 table_list->table_name, FALSE);
457 table_list->mdl_request.
ticket= NULL;
471 MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK,
472 &lock_tables_prelocking_strategy) ||
473 thd->locked_tables_list.init_locked_tables(thd))
477 thd->variables.option_bits|= OPTION_TABLE_LOCK;
511 bool flush_tables_for_export(THD *thd,
TABLE_LIST *all_tables)
520 if (thd->locked_tables_mode)
522 my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
532 MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK,
533 &lock_tables_prelocking_strategy))
539 for (
TABLE_LIST *table_list= all_tables; table_list;
540 table_list= table_list->next_global)
544 my_error(ER_ILLEGAL_HA, MYF(0), table_list->table_name);
550 for (
TABLE_LIST *table_list= all_tables; table_list;
551 table_list= table_list->next_global)
553 handler *handler_file= table_list->table->file;
554 int error= handler_file->extra(HA_EXTRA_EXPORT);
563 if (thd->locked_tables_list.init_locked_tables(thd))
565 thd->variables.option_bits|= OPTION_TABLE_LOCK;