MySQL  8.0.27
Source Code Documentation
sql_reload.h File Reference

Go to the source code of this file.

Functions

bool handle_reload_request (THD *thd, unsigned long options, TABLE_LIST *tables, int *write_to_binlog)
 Reload/resets privileges and the different caches. More...
 
bool is_reload_request_denied (THD *thd, unsigned long op_type)
 Check the privileges required to execute a FLUSH command. More...
 
bool flush_tables_with_read_lock (THD *thd, TABLE_LIST *all_tables)
 Implementation of FLUSH TABLES <table_list> WITH READ LOCK. More...
 
bool flush_tables_for_export (THD *thd, TABLE_LIST *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_LIST 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_LIST for tables to be exported
Return values
falseOk
trueError

◆ flush_tables_with_read_lock()

bool flush_tables_with_read_lock ( THD thd,
TABLE_LIST 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_LIST 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