MySQL 9.0.0
Source Code Documentation
sql_reload.cc File Reference
#include "sql/sql_reload.h"
#include <stddef.h>
#include <atomic>
#include "lex_string.h"
#include "map_helpers.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/binlog.h"
#include "sql/conn_handler/connection_handler_impl.h"
#include "sql/current_thd.h"
#include "sql/debug_sync.h"
#include "sql/handler.h"
#include "sql/hostname_cache.h"
#include "sql/log.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/opt_costconstantcache.h"
#include "sql/query_options.h"
#include "sql/rpl_replica.h"
#include "sql/rpl_source.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_connect.h"
#include "sql/sql_const.h"
#include "sql/sql_servers.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "string_with_len.h"

Functions

bool is_reload_request_denied (THD *thd, unsigned long op_type)
 Check the privileges required to execute a FLUSH command. More...
 
bool handle_reload_request (THD *thd, unsigned long options, Table_ref *tables, int *write_to_binlog)
 Reload/resets privileges and the different caches. More...
 
bool flush_tables_with_read_lock (THD *thd, Table_ref *all_tables)
 Implementation of FLUSH TABLES <table_list> WITH READ LOCK. More...
 
bool flush_tables_for_export (THD *thd, Table_ref *all_tables)
 Prepare tables for export (transportable tablespaces) by a) waiting until write transactions/DDL operations using these tables have completed. More...
 

Function Documentation

◆ flush_tables_for_export()

bool flush_tables_for_export ( THD thd,
Table_ref all_tables 
)

Prepare tables for export (transportable tablespaces) by a) waiting until write transactions/DDL operations using these tables have completed.

b) block new write operations/DDL operations on these tables.

Once this is done, notify the storage engines using handler::extra().

Finally, enter LOCK TABLES mode, so that locks are held until UNLOCK TABLES is executed.

Parameters
thdThread handler
all_tablesTable_ref for tables to be exported
Return values
falseOk
trueError

◆ flush_tables_with_read_lock()

bool flush_tables_with_read_lock ( THD thd,
Table_ref all_tables 
)

Implementation of FLUSH TABLES <table_list> WITH READ LOCK.

In brief: take exclusive locks, expel tables from the table cache, reopen the tables, enter the 'LOCKED TABLES' mode, downgrade the locks. Note: the function is written to be called from mysql_execute_command(), it is not reusable in arbitrary execution context.

Required privileges

Since the statement implicitly enters LOCK TABLES mode, it requires LOCK TABLES privilege on every table. But since the rest of FLUSH commands require the global RELOAD_ACL, it also requires RELOAD_ACL.

Compatibility with the global read lock

We don't wait for the GRL, since neither the 5.1 combination that this new statement is intended to replace (LOCK TABLE <list> WRITE; FLUSH TABLES;), nor FLUSH TABLES WITH READ LOCK do.

Behaviour under LOCK TABLES

Bail out: i.e. don't perform an implicit UNLOCK TABLES. This is not consistent with LOCK TABLES statement, but is in line with behaviour of FLUSH TABLES WITH READ LOCK, and we try to not introduce any new statements with implicit semantics.

Compatibility with parallel updates

As a result, we will wait for all open transactions against the tables to complete. After the lock downgrade, new transactions will be able to read the tables, but not write to them.

Differences from FLUSH TABLES <list>

  • you can't flush WITH READ LOCK a non-existent table
  • you can't flush WITH READ LOCK under LOCK TABLES

Effect on views and temporary tables.

You can only apply this command to existing base tables. If a view with such name exists, ER_WRONG_OBJECT is returned. If a temporary table with such name exists, it's ignored: if there is a base table, it's used, otherwise ER_NO_SUCH_TABLE is returned.

Handling of MERGE tables

For MERGE table this statement will open and lock child tables for read (it is impossible to lock parent table without it). Child tables won't be flushed unless they are explicitly present in the statement's table list.

Implicit commit

This statement causes an implicit commit before and after it.

HANDLER SQL

If this connection has HANDLERs open against some of the tables being FLUSHed, these handlers are implicitly flushed (lose their position).

◆ handle_reload_request()

bool handle_reload_request ( THD thd,
unsigned long  options,
Table_ref tables,
int *  write_to_binlog 
)

Reload/resets privileges and the different caches.

Parameters
thdThread handler (can be NULL!)
optionsWhat should be reset/reloaded (tables, privileges, slave...)
tablesTables to flush (if any)
write_to_binlog< 0 if there was an error while interacting with the binary log inside handle_reload_request, 0 if we should not write to the binary log, > 0 if we can write to the binlog.
Note
Depending on 'options', it may be very bad to write the query to the binlog (e.g. FLUSH SLAVE); this is a pointer where handle_reload_request() will put 0 if it thinks we really should not write to the binlog. Otherwise it will put 1.
Returns
Error status code
Return values
0Ok
!=0Error; thd->killed is set or thd->is_error() is true

◆ is_reload_request_denied()

bool is_reload_request_denied ( THD thd,
unsigned long  op_type 
)

Check the privileges required to execute a FLUSH command.

Generally checks for RELOAD_ACL. But for some sub-commands it does accept alternative privs too. Or warns about deprecated commands.

Parameters
thdthe current thread
op_typea bitmask of COM_REFRESH Flags
Return values
falseif granted
trueif denied