| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2019, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/**************************************************/ /** |
| 29 |
@file include/log0files_governor.h |
| 30 |
|
| 31 |
Redo log management of log files. |
| 32 |
|
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#ifndef log0files_governor_h |
| 36 |
#define log0files_governor_h |
| 37 |
|
| 38 |
/* Log_files_dict */ |
| 39 |
#include "log0files_dict.h" |
| 40 |
|
| 41 |
/* Log_files_find_result */ |
| 42 |
#include "log0files_finder.h" |
| 43 |
|
| 44 |
/* log_t& */ |
| 45 |
#include "log0types.h" |
| 46 |
|
| 47 |
/* os_offset_t */ |
| 48 |
#include "os0file.h" |
| 49 |
|
| 50 |
/* srv_threads */ |
| 51 |
#include "srv0srv.h" |
| 52 |
|
| 53 |
#ifndef UNIV_HOTBACKUP |
| 54 |
|
| 55 |
/** Checks if log file governor thread is active. |
| 56 |
@return true if and only if the log checkpointer thread is active */ |
| 57 |
inline bool log_files_governor_is_active() { |
| 58 |
return srv_thread_is_active(srv_threads.m_log_files_governor); |
| 59 |
} |
| 60 |
|
| 61 |
#define log_files_mutex_enter(log) mutex_enter(&((log).m_files_mutex)) |
| 62 |
|
| 63 |
#define log_files_mutex_exit(log) mutex_exit(&((log).m_files_mutex)) |
| 64 |
|
| 65 |
#define log_files_mutex_own(log) mutex_own(&((log).m_files_mutex)) |
| 66 |
|
| 67 |
#endif /* !UNIV_HOTBACKUP */ |
| 68 |
|
| 69 |
/** Creates a new set of redo log files. |
| 70 |
@remarks |
| 71 |
Before creating the new log files, function asserts that there are no existing |
| 72 |
log files in the directory specified for the redo log. |
| 73 |
The flushed_lsn should be exactly at the beginning of its block body. |
| 74 |
The new set of log files starts at the beginning of this block. |
| 75 |
Checkpoint is written LOG_BLOCK_HDR_SIZE bytes after the beginning of that |
| 76 |
block, that is at flushed_lsn. |
| 77 |
The set is marked as initialized if this call succeeded and information about |
| 78 |
the initial LSN is emitted to the error log. In such case, a new value is |
| 79 |
generated and assigned to the log.m_log_uuid (identifying the new log files). |
| 80 |
@param[in,out] log redo log |
| 81 |
@param[in] flushed_lsn the new set of log files should start with log |
| 82 |
block in which flushed_lsn is located, and |
| 83 |
flushed_lsn should point right after this block |
| 84 |
header. |
| 85 |
|
| 86 |
@return DB_SUCCESS or error code */ |
| 87 |
dberr_t log_files_create(log_t &log, lsn_t flushed_lsn); |
| 88 |
|
| 89 |
/** Removes all log files. |
| 90 |
@param[in,out] log redo log */ |
| 91 |
void log_files_remove(log_t &log); |
| 92 |
|
| 93 |
/** Creates a next log file, ready for writes. Updates log.m_current_file. |
| 94 |
@param[in,out] log redo log |
| 95 |
@retval DB_SUCCESS if created successfully |
| 96 |
@retval DB_OUT_OF_DISK_SPACE if there was no free space to create next file, |
| 97 |
according to limitations we have for redo files, |
| 98 |
or according to space physically available on |
| 99 |
the disk |
| 100 |
@retval other errors are possible */ |
| 101 |
dberr_t log_files_produce_file(log_t &log); |
| 102 |
|
| 103 |
/** Persists log flags to the newest log file. Flushes header of the |
| 104 |
log file and updates log.m_log_flags if succeeded. |
| 105 |
@param[in,out] log redo log |
| 106 |
@param[in] log_flags log_flags to persist |
| 107 |
@return DB_SUCCESS or error */ |
| 108 |
dberr_t log_files_persist_flags(log_t &log, Log_flags log_flags); |
| 109 |
|
| 110 |
/** Resets creator name to the current creator and marks all files as full in |
| 111 |
their headers by setting LOG_HEADER_FLAG_FILE_FULL bit in the log_flags field. |
| 112 |
Flushes headers of all log files and updates log.m_creator_name and log.m_files |
| 113 |
accordingly if succeeded (if fails, then some files might remain updated and |
| 114 |
some not; metadata stored in log.m_files should reflect that). |
| 115 |
@param[in,out] log redo log |
| 116 |
@return DB_SUCCESS or error */ |
| 117 |
dberr_t log_files_reset_creator_and_set_full(log_t &log); |
| 118 |
|
| 119 |
/** Waits until a next log file is available and can be produced. |
| 120 |
@param[in] log redo log */ |
| 121 |
void log_files_wait_for_next_file_available(log_t &log); |
| 122 |
|
| 123 |
/** The log files governor thread routine. |
| 124 |
@param[in,out] log_ptr pointer to redo log */ |
| 125 |
void log_files_governor(log_t *log_ptr); |
| 126 |
|
| 127 |
/** Starts the log file management. |
| 128 |
@param[in] log redo log |
| 129 |
@return DB_SUCCESS or error */ |
| 130 |
dberr_t log_files_start(log_t &log); |
| 131 |
|
| 132 |
/** Computes initial capacity limits and size suggested for the next log file. |
| 133 |
Called when logically empty redo log is being initialized. |
| 134 |
@param[in,out] log redo log */ |
| 135 |
void log_files_initialize_on_empty_redo(log_t &log); |
| 136 |
|
| 137 |
/** Computes initial capacity limits and size suggested for the next log file. |
| 138 |
Called after existing redo log files have been discovered (log.m_files). |
| 139 |
@param[in,out] log redo log */ |
| 140 |
void log_files_initialize_on_existing_redo(log_t &log); |
| 141 |
|
| 142 |
/** Updates capacity limitations after srv_redo_log_capacity_used has been |
| 143 |
changed. It is called when user requests to change innodb_redo_log_capacity |
| 144 |
in runtime. |
| 145 |
@param[in,out] log redo log */ |
| 146 |
void log_files_resize_requested(log_t &log); |
| 147 |
|
| 148 |
/** Updates capacity limitations after srv_thread_concurrency has been changed. |
| 149 |
It is called when user requests to change innodb_thread_concurrency in runtime. |
| 150 |
@param[in,out] log redo log */ |
| 151 |
void log_files_thread_concurrency_updated(log_t &log); |
| 152 |
|
| 153 |
/** Disallows to generate dummy redo records and waits until |
| 154 |
the log_files_governor thread promised not to generate them. |
| 155 |
@param[in,out] log redo log */ |
| 156 |
void log_files_dummy_records_disable(log_t &log); |
| 157 |
|
| 158 |
/** Disallows to generate dummy redo records but does not wait until |
| 159 |
the log_files_governor promised not to generate them anymore. |
| 160 |
@param[in,out] log redo log */ |
| 161 |
void log_files_dummy_records_request_disable(log_t &log); |
| 162 |
|
| 163 |
/** Updates the encryption metadata stored in-memory for all redo log files. |
| 164 |
Caller needs to have the log.m_files_mutex acquired before calling this. |
| 165 |
@param[in,out] log redo log |
| 166 |
@param[in] encryption_metadata encryption metadata */ |
| 167 |
void log_files_update_encryption( |
| 168 |
log_t &log, const Encryption_metadata &encryption_metadata); |
| 169 |
|
| 170 |
#endif /* !log0files_governor_h */ |