MySQL 8.4.0
Source Code Documentation
srv0shutdown.h File Reference

Shutdowns the Innobase database server. More...

#include "my_compiler.h"
#include "univ.i"

Go to the source code of this file.

Enumerations

enum  srv_shutdown_t {
  SRV_SHUTDOWN_NONE = 0 , SRV_SHUTDOWN_RECOVERY_ROLLBACK , SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS , SRV_SHUTDOWN_PURGE ,
  SRV_SHUTDOWN_DD , SRV_SHUTDOWN_CLEANUP , SRV_SHUTDOWN_MASTER_STOP , SRV_SHUTDOWN_FLUSH_PHASE ,
  SRV_SHUTDOWN_LAST_PHASE , SRV_SHUTDOWN_EXIT_THREADS
}
 Shutdown state. More...
 

Functions

void srv_pre_dd_shutdown ()
 Shut down all InnoDB background tasks that may look up objects in the data dictionary. More...
 
void srv_shutdown ()
 Shut down the InnoDB database. More...
 
void srv_fatal_error ()
 Call std::quick_exit(3) More...
 
void srv_shutdown_exit_threads ()
 Attempt to shutdown all background threads created by InnoDB. More...
 
bool srv_shutdown_waits_for_rollback_of_recovered_transactions ()
 Checks if all recovered transactions are supposed to be rolled back before shutdown is ended. More...
 
template<typename F >
bool srv_shutdown_state_matches (F &&f)
 Allows to safely check value of the current shutdown state. More...
 

Variables

std::atomic< enum srv_shutdown_tsrv_shutdown_state
 At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_EXIT_THREADS. More...
 

Detailed Description

Shutdowns the Innobase database server.

Enumeration Type Documentation

◆ srv_shutdown_t

Shutdown state.

Enumerator
SRV_SHUTDOWN_NONE 

Database running normally.

SRV_SHUTDOWN_RECOVERY_ROLLBACK 

Shutdown has started.

Stopping the thread responsible for rollback of recovered transactions. In case of slow shutdown, this implies waiting for completed rollback of all recovered transactions.

Remarks
Note that user transactions are stopped earlier, when the shutdown state is still equal to SRV_SHUTDOWN_NONE (user transactions are closed when related connections are closed in close_connections()).
SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS 

Stopping threads that might use system transactions or DD objects.

This is important because we need to ensure that in the next phase no undo records could be produced (we will be stopping purge threads). After next phase DD is shut down, so also no accesses to DD objects are allowed then. List of threads being stopped within this phase:

  • dict_stats thread,
  • fts_optimize thread,
  • ts_alter_encrypt thread. The master thread exits its main loop and finishes its first phase of shutdown (in which it was allowed to touch DD objects).
SRV_SHUTDOWN_PURGE 

Stopping the purge threads.

Before we enter this phase, we have the guarantee that no new undo records could be produced.

SRV_SHUTDOWN_DD 

Shutting down the DD.

SRV_SHUTDOWN_CLEANUP 

Stopping remaining InnoDB background threads except:

  • the master thread,
  • redo log threads,
  • page cleaner threads,
  • archiver threads. List of threads being stopped within this phase:
  • lock_wait_timeout thread,
  • error_monitor thread,
  • monitor thread,
  • buf_dump thread,
  • buf_resize thread.
    Remarks
    If your thread might touch DD objects or use system transactions it must be stopped within SRV_SHUTDOWN_PRE_DD_AND_SYSTEM_TRANSACTIONS phase.
SRV_SHUTDOWN_MASTER_STOP 

Stopping the master thread.

SRV_SHUTDOWN_FLUSH_PHASE 

Once we enter this phase, the page cleaners can clean up the buffer pool and exit.

The redo log threads write and flush the log buffer and exit after the page cleaners (and within this phase).

SRV_SHUTDOWN_LAST_PHASE 

Last phase after ensuring that all data have been flushed to disk and the flushed_lsn has been updated in the header of system tablespace.

During this phase we close all files and ensure archiver has archived all.

SRV_SHUTDOWN_EXIT_THREADS 

Exit all threads and free resources.

We might reach this phase in one of two different ways:

  • after visiting all previous states (usual shutdown),
  • or during startup when we failed and we abort the startup.

Function Documentation

◆ srv_fatal_error()

void srv_fatal_error ( )

Call std::quick_exit(3)

Call std::quick_exit(3)

◆ srv_pre_dd_shutdown()

void srv_pre_dd_shutdown ( )

Shut down all InnoDB background tasks that may look up objects in the data dictionary.

◆ srv_shutdown()

void srv_shutdown ( )

Shut down the InnoDB database.

◆ srv_shutdown_exit_threads()

void srv_shutdown_exit_threads ( )

Attempt to shutdown all background threads created by InnoDB.

NOTE: Does not guarantee they are actually shut down, only does the best effort. Changes state of shutdown to SHUTDOWN_EXIT_THREADS, wakes up the background threads and waits a little bit. It might be used within startup phase or when fatal error is discovered during some IO operation. Therefore you must not assume anything related to the state in which it might be used.

◆ srv_shutdown_state_matches()

template<typename F >
bool srv_shutdown_state_matches ( F &&  f)

Allows to safely check value of the current shutdown state.

Note that the current shutdown state might be changed while the check is being executed, but the check is based on a single load of the srv_shutdown_state (atomic global variable).

◆ srv_shutdown_waits_for_rollback_of_recovered_transactions()

bool srv_shutdown_waits_for_rollback_of_recovered_transactions ( )

Checks if all recovered transactions are supposed to be rolled back before shutdown is ended.

Returns
value of the check

Variable Documentation

◆ srv_shutdown_state

std::atomic<enum srv_shutdown_t> srv_shutdown_state
extern

At a shutdown this value climbs from SRV_SHUTDOWN_NONE to SRV_SHUTDOWN_EXIT_THREADS.