MySQL 8.4.2
Source Code Documentation
|
Purge old versions. More...
#include <sys/types.h>
#include <new>
#include <unordered_map>
#include "clone0api.h"
#include "clone0clone.h"
#include "dict0dd.h"
#include "fil0fil.h"
#include "fsp0fsp.h"
#include "fsp0sysspace.h"
#include "fsp0types.h"
#include "fut0fut.h"
#include "ha_prototypes.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "mach0data.h"
#include "mtr0log.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "os0thread.h"
#include "que0que.h"
#include "read0read.h"
#include "row0purge.h"
#include "row0upd.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "sync0sync.h"
#include "trx0purge.h"
#include "trx0rec.h"
#include "trx0roll.h"
#include "trx0rseg.h"
#include "trx0trx.h"
Classes | |
struct | Purge_groups_t |
Namespaces | |
namespace | undo |
Functions | |
static que_t * | trx_purge_graph_build (trx_t *trx, ulint n_purge_threads) |
Builds a purge 'query' graph. More... | |
void | trx_purge_sys_mem_create () |
Initialize in-memory purge structures. More... | |
void | trx_purge_sys_initialize (uint32_t n_purge_threads, purge_pq_t *purge_queue) |
Creates the global purge system control structure and inits the history mutex. More... | |
void | trx_purge_sys_close () |
Frees the global purge system control structure. More... | |
void | trx_purge_add_update_undo_to_history (trx_t *trx, trx_undo_ptr_t *undo_ptr, page_t *undo_page, bool update_rseg_history_len, ulint n_added_logs, mtr_t *mtr) |
Adds the update undo log as the first log in the history list. More... | |
static void | trx_purge_remove_log_hdr (trx_rsegf_t *rseg_hdr, trx_ulogf_t *log_hdr, mtr_t *mtr) |
Remove an rseg header from the history list. More... | |
static void | trx_purge_free_segment (trx_rseg_t *rseg, fil_addr_t hdr_addr, bool noredo) |
Frees a rollback segment which is in the history list. More... | |
static void | trx_purge_truncate_rseg_history (trx_rseg_t *rseg, const purge_iter_t *limit) |
Removes unnecessary history data from a rollback segment. More... | |
void | undo::init_space_id_bank () |
Initialize the undo tablespace space_id bank which is a lock free repository for information about the space IDs used for undo tablespaces. More... | |
void | undo::use_space_id (space_id_t space_id) |
Note that the undo space number for a space ID is being used. More... | |
void | undo::unuse_space_id (space_id_t space_id) |
Mark an undo number associated with a given space_id as unused and available to be reused. More... | |
space_id_t | undo::next_space_id (space_id_t space_id, space_id_t space_num) |
Given a valid undo space_id or SPACE_UNKNOWN, return the next space_id for the given space number. More... | |
space_id_t | undo::next_space_id (space_id_t space_id) |
Given a valid undo space_id, return the next space_id for that space number. More... | |
space_id_t | undo::use_next_space_id (space_id_t space_num) |
Mark that the given undo space number is being used and return the next available space_id for that space number. More... | |
space_id_t | undo::get_next_available_space_num () |
Return the next available undo space ID to be used for a new explicit undo tablespaces. More... | |
char * | undo::make_space_name (space_id_t space_id) |
Build a standard undo tablespace name from a space_id. More... | |
char * | undo::make_file_name (space_id_t space_id) |
Build a standard undo tablespace file name from a space_id. More... | |
void | undo::inject_crash (const char *injection_point_name) |
Inject a crash if a certain SET GLOBAL DEBUG has been set. More... | |
dberr_t | undo::start_logging (Tablespace *undo_space) |
Create the truncate log file. More... | |
void | undo::done_logging (space_id_t space_num) |
Mark completion of undo truncate action by writing magic number to the log file and then removing it from the disk. More... | |
bool | undo::is_active_truncate_log_present (space_id_t space_num) |
Check if TRUNCATE_DDL_LOG file exist. More... | |
void | undo::add_space_to_construction_list (space_id_t space_id) |
Add undo tablespace to s_under_construction vector. More... | |
void | undo::clear_construction_list () |
Clear the s_under_construction vector. More... | |
bool | undo::is_under_construction (space_id_t space_id) |
Is an undo tablespace under construction at the moment. More... | |
void | undo::set_active (space_id_t space_id) |
Set an undo tablespace active. More... | |
bool | undo::is_active (space_id_t space_id, bool get_latch=true) |
static bool | trx_purge_mark_undo_for_truncate (size_t truncate_count) |
Decide if an undo truncation needs to be done at this time. More... | |
static bool | trx_purge_check_if_marked_undo_is_empty () |
Iterate over selected UNDO tablespace and check if all the rsegs that resides in the tablespace have been freed. More... | |
static bool | trx_purge_truncate_marked_undo_low (space_id_t space_num, std::string space_name) |
Truncate the marked undo tablespace. More... | |
static bool | trx_purge_truncate_marked_undo () |
Truncate the marked undo tablespace. More... | |
static void | trx_purge_truncate_history (purge_iter_t *limit, const ReadView *view) |
Removes unnecessary history data from rollback segments. More... | |
static void | trx_purge_truncate_undo_spaces () |
Select an undo tablespace to truncate, make sure it is empty of undo logs, then finally truncate it. More... | |
static void | trx_purge_rseg_get_next_history_log (trx_rseg_t *rseg, ulint *n_pages_handled) |
Updates the last not yet purged history log info in rseg when we have purged a whole undo log. More... | |
static void | trx_purge_read_undo_rec (trx_purge_t *purge_sys, const page_size_t &page_size) |
Position the purge sys "iterator" on the undo record to use for purging. More... | |
static void | trx_purge_choose_next_log (void) |
Chooses the next undo log to purge and updates the info in purge_sys. More... | |
static trx_undo_rec_t * | trx_purge_get_next_rec (ulint *n_pages_handled, mem_heap_t *heap) |
Gets the next record to purge and updates the info in the purge system. More... | |
static trx_undo_rec_t * | trx_purge_fetch_next_rec (trx_id_t *modifier_trx_id, roll_ptr_t *roll_ptr, ulint *n_pages_handled, mem_heap_t *heap) |
Fetches the next undo log record from the history list to purge. More... | |
static ulint | trx_purge_attach_undo_recs (const ulint n_purge_threads, ulint batch_size) |
This function runs a purge batch. More... | |
static ulint | trx_purge_dml_delay (void) |
Calculate the DML delay required. More... | |
static void | trx_purge_wait_for_workers_to_complete () |
Wait for pending purge jobs to complete. More... | |
static void | trx_purge_truncate (void) |
Remove old historical changes from the rollback segments. More... | |
ulint | trx_purge (ulint n_purge_threads, ulint batch_size, bool truncate) |
This function runs a purge batch. More... | |
purge_state_t | trx_purge_state (void) |
Get the purge state. More... | |
void | trx_purge_stop (void) |
Stop purge and wait for it to stop, move to PURGE_STATE_STOP. More... | |
void | trx_purge_run (void) |
Resume purge, move to PURGE_STATE_RUN. More... | |
Variables | |
ulong | srv_max_purge_lag = 0 |
Maximum allowable purge history length. More... | |
ulong | srv_max_purge_lag_delay = 0 |
Max DML user threads delay in micro-seconds. More... | |
trx_purge_t * | purge_sys = nullptr |
The global data structure coordinating a purge. More... | |
static constexpr int64_t | PURGE_CHECK_UNDO_TRUNCATE_DELAY_IN_MS = 10 |
Wait for a short delay between checks. More... | |
bool | srv_purge_view_update_only_debug |
static trx_undo_rec_t | trx_purge_ignore_rec |
A sentinel undo record used as a return value when we have a whole undo log which can be skipped by purge. More... | |
Purge old versions.
Created 3/26/1996 Heikki Tuuri
This function runs a purge batch.
n_purge_threads | in: number of purge tasks to submit to the work queue |
batch_size | in: the maximum number of records to purge in one batch |
truncate | in: truncate history if true |
void trx_purge_add_update_undo_to_history | ( | trx_t * | trx, |
trx_undo_ptr_t * | undo_ptr, | ||
page_t * | undo_page, | ||
bool | update_rseg_history_len, | ||
ulint | n_added_logs, | ||
mtr_t * | mtr | ||
) |
Adds the update undo log as the first log in the history list.
in: mtr
Removes the update undo log segment from the rseg slot if it is too big for reuse.
trx | in: transaction |
undo_ptr | in/out: update undo log. |
undo_page | in: update undo log header page, x-latched |
update_rseg_history_len | in: if true: update rseg history len else skip updating it. |
n_added_logs | in: number of logs added |
mtr | in: mtr |
This function runs a purge batch.
[in] | n_purge_threads | number of purge threads |
[in] | batch_size | number of pages to purge |
|
static |
Iterate over selected UNDO tablespace and check if all the rsegs that resides in the tablespace have been freed.
|
static |
Chooses the next undo log to purge and updates the info in purge_sys.
This function is used to initialize purge_sys when the next record to purge is not known, and also to update the purge system info on the next record when purge has handled the whole undo log for a transaction.
|
static |
Calculate the DML delay required.
|
static |
Fetches the next undo log record from the history list to purge.
It must be released with the corresponding release function.
modifier_trx_id | out: modifier trx id. this is the trx that created the undo record. |
roll_ptr | out: roll pointer to undo record |
n_pages_handled | in/out: number of UNDO log pages handled |
heap | in: memory heap where copied |
|
static |
Frees a rollback segment which is in the history list.
Removes the rseg hdr from the history list.
[in,out] | rseg | rollback segment |
[in] | hdr_addr | file address of log_hdr |
[in] | noredo | skip redo logging. |
|
static |
Gets the next record to purge and updates the info in the purge system.
n_pages_handled | in/out: number of UNDO pages handled |
heap | in: memory heap where copied |
Builds a purge 'query' graph.
The actual purge is performed by executing this query graph.
[in] | trx | transaction |
[in] | n_purge_threads | number of purge threads |
|
static |
Decide if an undo truncation needs to be done at this time.
If an undo tablespace is already marked, return that so that this truncation will get finished. If none is marked, iterate over all the UNDO tablespaces and check if any qualify to be truncated. Normal operation; Choose the marked space. If none are marked, choose an explicitly inactive space. If none exist, check if conditions allow implicit truncation. If conditions allow, choose an implicitly inactive space. If none exist and no space has been truncated yet, look for an undo space that is too big. Fast shutdown; Do not truncate. This routine is not called. Slow shutdown; Choose the marked space. If none are marked, choose an explicitly inactive space. If none exist, check if conditions allow implicit truncation. If conditions allow, ignoring the previous truncate count, look for an undo space that is too big.
[in] | truncate_count | number of times this is called in a loop |
|
static |
Position the purge sys "iterator" on the undo record to use for purging.
[in,out] | purge_sys | purge instance |
[in] | page_size | page size |
|
static |
Remove an rseg header from the history list.
[in,out] | rseg_hdr | Rollback segment header |
[in] | log_hdr | Undo log segment header |
[in,out] | mtr | Mini-transaction. |
|
static |
Updates the last not yet purged history log info in rseg when we have purged a whole undo log.
Advances also purge_sys->purge_trx_no past the purged log.
rseg | in: rollback segment |
n_pages_handled | in/out: number of UNDO pages handled |
void trx_purge_run | ( | void | ) |
Resume purge, move to PURGE_STATE_RUN.
purge_state_t trx_purge_state | ( | void | ) |
Get the purge state.
void trx_purge_stop | ( | void | ) |
Stop purge and wait for it to stop, move to PURGE_STATE_STOP.
void trx_purge_sys_close | ( | void | ) |
Frees the global purge system control structure.
void trx_purge_sys_initialize | ( | uint32_t | n_purge_threads, |
purge_pq_t * | purge_queue | ||
) |
Creates the global purge system control structure and inits the history mutex.
[in] | n_purge_threads | number of purge threads |
[in,out] | purge_queue | UNDO log min binary heap |
void trx_purge_sys_mem_create | ( | ) |
Initialize in-memory purge structures.
|
static |
Remove old historical changes from the rollback segments.
|
static |
Removes unnecessary history data from rollback segments.
NOTE that when this function is called, the caller must not have any latches on undo log pages!
[in] | limit | Truncate limit |
[in] | view | Purge view |
|
static |
Truncate the marked undo tablespace.
This wrapper does initial preparation and handles cleanup.
|
static |
Truncate the marked undo tablespace.
This layer handles locking of marked_rsegs and undo::spaces.
|
static |
Removes unnecessary history data from a rollback segment.
rseg | in: rollback segment |
limit | in: truncate offset |
|
static |
Select an undo tablespace to truncate, make sure it is empty of undo logs, then finally truncate it.
|
static |
Wait for pending purge jobs to complete.
|
staticconstexpr |
Wait for a short delay between checks.
trx_purge_t* purge_sys = nullptr |
The global data structure coordinating a purge.
ulong srv_max_purge_lag = 0 |
Maximum allowable purge history length.
<=0 means 'infinite'.
ulong srv_max_purge_lag_delay = 0 |
Max DML user threads delay in micro-seconds.
bool srv_purge_view_update_only_debug |
|
static |
A sentinel undo record used as a return value when we have a whole undo log which can be skipped by purge.