MySQL 8.0.39
Source Code Documentation
arch0page.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/arch0page.h
29 Innodb interface for modified page archive
30
31 *******************************************************/
32
33#ifndef ARCH_PAGE_INCLUDE
34#define ARCH_PAGE_INCLUDE
35
36#include "arch0arch.h"
37#include "buf0buf.h"
38
39/** Archived page header file size (RESET Page) in number of blocks. */
41
42/** Archived file header size. No file header for this version. */
45
46/** @name Page Archive doublewrite buffer file name prefix and constant length
47parameters. @{ */
48
49/** Archive doublewrite buffer directory prefix */
50constexpr char ARCH_DBLWR_DIR[] = "ib_dblwr";
51
52/** Archive doublewrite buffer file prefix */
53constexpr char ARCH_DBLWR_FILE[] = "dblwr_";
54
55/** File name for the active file which indicates whether a group is active or
56not. */
57constexpr char ARCH_PAGE_GROUP_ACTIVE_FILE_NAME[] = "active";
58
59/** Archive doublewrite buffer number of files */
61
62/** Archive doublewrite buffer file capacity in no. of blocks */
64
65/** @} */
66
67/** @name Archive block header elements
68@{ */
69
70/** Block Header: Version is in first 1 byte. */
72
73/** Block Header: Block Type is in next 1 byte. */
75
76/** Block Header: Checksum is in next 4 bytes. */
78
79/** Block Header: Data length is in next 2 bytes. */
81
82/** Block Header: Stop LSN is in next 8 bytes */
84
85/** Block Header: Reset LSN is in next 8 bytes */
87
88/** Block Header: Block number is in next 8 bytes */
90
91/** Block Header: Total length.
92Keep header length in multiple of #ARCH_BLK_PAGE_ID_SIZE */
94
95/** @} */
96
97/** @name Page Archive reset block elements size.
98@{ */
99
100/** Serialized Reset ID: Reset LSN total size */
102
103/** Serialized Reset ID: Reset block number size */
105
106/** Serialized Reset ID: Reset block offset size */
108
109/** Serialized Reset ID: Reset position total size */
113
114/** @} */
115
116/** @name Page Archive data block elements
117@{ */
118
119/** Serialized page ID: tablespace ID in First 4 bytes */
121
122/** Serialized page ID: Page number in next 4 bytes */
124
125/** Serialized page ID: Total length */
127
128/** @} */
129
130/** Number of memory blocks */
132
133/** Archived file format version */
135
136#ifdef UNIV_DEBUG
137/** Archived page file default size in number of blocks. */
139
140/** Archived page data file size (without header) in number of blocks. */
142#else
143/** Archived page file default size in number of blocks. */
146
147/** Archived page data file size (without header) in number of blocks. */
150#endif
151
152/** Threshold for page archive reset. Attach to current reset if the number of
153tracked pages between the reset request and the current reset is less than this
154threshold as we allow only one reset per data block. */
157
158/** Callback for retrieving archived page IDs
159@param[in] ctx context passed by caller
160@param[in] buff buffer with page IDs
161@param[in] num_pages number of page IDs in buffer
162@return error code */
163using Page_Arch_Cbk = int(void *ctx, byte *buff, uint num_pages);
164
165/** Callback function to check if we need to wait for flush archiver to flush
166more blocks */
167using Page_Wait_Flush_Archiver_Cbk = std::function<bool(void)>;
168
169/** Dirty page archiver client context */
171 public:
172 /** Constructor: Initialize elements
173 @param[in] is_durable true if the client requires durability, else
174 false */
175 Page_Arch_Client_Ctx(bool is_durable) : m_is_durable(is_durable) {
179 }
180
181 /** Destructor. */
183
184 /** Start dirty page tracking and archiving
185 @param[in] recovery true if the tracking is being started as part of
186 recovery process
187 @param[out] start_id fill the start lsn
188 @return error code. */
189 int start(bool recovery, uint64_t *start_id);
190
191 /** Stop dirty page tracking and archiving
192 @param[out] stop_id fill the stop lsn
193 @return error code. */
194 int stop(uint64_t *stop_id);
195
196 /** Release archived data so that system can purge it */
197 void release();
198
199 /** Initialize context during recovery.
200 @param[in] group Group which needs to be attached to the client
201 @param[in] last_lsn last reset lsn
202 @return error code. */
203 int init_during_recovery(Arch_Group *group, lsn_t last_lsn);
204
205 /** Check if this client context is active.
206 @return true if active, else false */
207 bool is_active() const { return (m_state == ARCH_CLIENT_STATE_STARTED); }
208
209 /** Get archived page Ids.
210 Attempt to read blocks directly from in memory buffer. If overwritten,
211 copy from archived files.
212 @param[in] cbk_func called repeatedly with page ID buffer
213 @param[in] cbk_ctx callback function context
214 @param[in,out] buff buffer to fill page IDs
215 @param[in] buf_len buffer length in bytes
216 @return error code */
217 int get_pages(Page_Arch_Cbk *cbk_func, void *cbk_ctx, byte *buff,
218 uint buf_len);
219
220#ifdef UNIV_DEBUG
221 /** Print information related to the archiver client for debugging purposes.
222 */
223 void print();
224#endif
225
226 /** Disable copy construction */
228
229 /** Disable assignment */
231
232 private:
233 /** Acquire client archiver mutex.
234 It synchronizes members on concurrent start and stop operations. */
236
237 /** Release client archiver mutex */
239
240 private:
241 /** Page archiver client state */
243
244 /** Archive group the client is attached to */
246
247 /** True if the client requires durablity */
249
250 /** Start LSN for archived data */
252
253 /** Stop LSN for archived data */
255
256 /** Reset LSN at the time of last reset. */
258
259 /** Start position for client in archived file group */
261
262 /** Stop position for client in archived file group */
264
265 /** Mutex protecting concurrent operation on data */
266 ib_mutex_t m_mutex;
267};
268
269#endif /* ARCH_PAGE_INCLUDE */
Common interface for redo log and dirty page archiver system.
constexpr uint ARCH_PAGE_BLK_SIZE
Memory block size.
Definition: arch0arch.h:91
Arch_Client_State
Archiver client state.
Definition: arch0arch.h:114
@ ARCH_CLIENT_STATE_INIT
Client is initialized.
Definition: arch0arch.h:116
@ ARCH_CLIENT_STATE_STARTED
Archiving started by client.
Definition: arch0arch.h:119
constexpr uint ARCH_PAGE_FILE_HEADER_RESET_POS_SIZE
Serialized Reset ID: Reset position total size.
Definition: arch0page.h:110
constexpr uint ARCH_DBLWR_NUM_FILES
Archive doublewrite buffer number of files.
Definition: arch0page.h:60
constexpr uint ARCH_PAGE_FILE_HEADER_RESET_BLOCK_OFFSET_SIZE
Serialized Reset ID: Reset block offset size.
Definition: arch0page.h:107
constexpr uint ARCH_PAGE_BLK_HEADER_RESET_LSN_OFFSET
Block Header: Reset LSN is in next 8 bytes.
Definition: arch0page.h:86
constexpr uint ARCH_PAGE_FILE_HDR_SIZE
Archived file header size.
Definition: arch0page.h:43
constexpr uint ARCH_BLK_SPCE_ID_OFFSET
Serialized page ID: tablespace ID in First 4 bytes.
Definition: arch0page.h:120
std::function< bool(void)> Page_Wait_Flush_Archiver_Cbk
Callback function to check if we need to wait for flush archiver to flush more blocks.
Definition: arch0page.h:167
constexpr uint ARCH_PAGE_BLK_HEADER_DATA_LEN_OFFSET
Block Header: Data length is in next 2 bytes.
Definition: arch0page.h:80
constexpr uint ARCH_PAGE_BLK_HEADER_VERSION_OFFSET
Block Header: Version is in first 1 byte.
Definition: arch0page.h:71
constexpr uint ARCH_BLK_PAGE_ID_SIZE
Serialized page ID: Total length.
Definition: arch0page.h:126
uint ARCH_PAGE_FILE_CAPACITY
Archived page file default size in number of blocks.
Definition: arch0page.cc:42
constexpr uint ARCH_PAGE_FILE_VERSION
Archived file format version.
Definition: arch0page.h:134
constexpr char ARCH_DBLWR_DIR[]
Archive doublewrite buffer directory prefix.
Definition: arch0page.h:50
constexpr uint ARCH_PAGE_BLK_HEADER_CHECKSUM_OFFSET
Block Header: Checksum is in next 4 bytes.
Definition: arch0page.h:77
constexpr uint ARCH_DBLWR_FILE_CAPACITY
Archive doublewrite buffer file capacity in no.
Definition: arch0page.h:63
int(void *ctx, byte *buff, uint num_pages) Page_Arch_Cbk
Callback for retrieving archived page IDs.
Definition: arch0page.h:163
constexpr uint ARCH_BLK_PAGE_NO_OFFSET
Serialized page ID: Page number in next 4 bytes.
Definition: arch0page.h:123
constexpr uint ARCH_PAGE_FILE_HEADER_RESET_BLOCK_NUM_SIZE
Serialized Reset ID: Reset block number size.
Definition: arch0page.h:104
constexpr char ARCH_DBLWR_FILE[]
Archive doublewrite buffer file prefix.
Definition: arch0page.h:53
constexpr uint ARCH_PAGE_FILE_HEADER_RESET_LSN_SIZE
Serialized Reset ID: Reset LSN total size.
Definition: arch0page.h:101
constexpr uint ARCH_PAGE_BLK_HEADER_TYPE_OFFSET
Block Header: Block Type is in next 1 byte.
Definition: arch0page.h:74
constexpr uint ARCH_PAGE_FILE_NUM_RESET_PAGE
Archived page header file size (RESET Page) in number of blocks.
Definition: arch0page.h:40
constexpr uint ARCH_PAGE_NUM_BLKS
Number of memory blocks.
Definition: arch0page.h:131
constexpr uint ARCH_PAGE_BLK_HEADER_STOP_LSN_OFFSET
Block Header: Stop LSN is in next 8 bytes.
Definition: arch0page.h:83
constexpr char ARCH_PAGE_GROUP_ACTIVE_FILE_NAME[]
File name for the active file which indicates whether a group is active or not.
Definition: arch0page.h:57
constexpr uint ARCH_PAGE_BLK_HEADER_NUMBER_OFFSET
Block Header: Block number is in next 8 bytes.
Definition: arch0page.h:89
uint ARCH_PAGE_FILE_DATA_CAPACITY
Archived page data file size (without header) in number of blocks.
Definition: arch0page.cc:46
constexpr uint ARCH_PAGE_RESET_THRESHOLD
Threshold for page archive reset.
Definition: arch0page.h:155
constexpr uint ARCH_PAGE_BLK_HEADER_LENGTH
Block Header: Total length.
Definition: arch0page.h:93
The database buffer pool high-level routines.
Contiguous archived data for redo log or page tracking.
Definition: arch0arch.h:843
Dirty page archiver client context.
Definition: arch0page.h:170
lsn_t m_start_lsn
Start LSN for archived data.
Definition: arch0page.h:251
Page_Arch_Client_Ctx(bool is_durable)
Constructor: Initialize elements.
Definition: arch0page.h:175
~Page_Arch_Client_Ctx()
Destructor.
Definition: arch0page.h:182
bool is_active() const
Check if this client context is active.
Definition: arch0page.h:207
void arch_client_mutex_exit()
Release client archiver mutex.
Definition: arch0page.h:238
Page_Arch_Client_Ctx(Page_Arch_Client_Ctx const &)=delete
Disable copy construction.
lsn_t m_stop_lsn
Stop LSN for archived data.
Definition: arch0page.h:254
void print()
Print information related to the archiver client for debugging purposes.
Definition: arch0page.cc:879
int get_pages(Page_Arch_Cbk *cbk_func, void *cbk_ctx, byte *buff, uint buf_len)
Get archived page Ids.
Definition: arch0page.cc:1011
Page_Arch_Client_Ctx & operator=(Page_Arch_Client_Ctx const &)=delete
Disable assignment.
bool m_is_durable
True if the client requires durablity.
Definition: arch0page.h:248
Arch_Page_Pos m_stop_pos
Stop position for client in archived file group.
Definition: arch0page.h:263
void arch_client_mutex_enter()
Acquire client archiver mutex.
Definition: arch0page.h:235
void release()
Release archived data so that system can purge it.
Definition: arch0page.cc:1083
Arch_Group * m_group
Archive group the client is attached to.
Definition: arch0page.h:245
ib_mutex_t m_mutex
Mutex protecting concurrent operation on data.
Definition: arch0page.h:266
int init_during_recovery(Arch_Group *group, lsn_t last_lsn)
Initialize context during recovery.
Definition: arch0page.cc:962
Arch_Page_Pos m_start_pos
Start position for client in archived file group.
Definition: arch0page.h:260
lsn_t m_last_reset_lsn
Reset LSN at the time of last reset.
Definition: arch0page.h:257
Arch_Client_State m_state
Page archiver client state.
Definition: arch0page.h:242
int start(bool recovery, uint64_t *start_id)
Start dirty page tracking and archiving.
Definition: arch0page.cc:893
int stop(uint64_t *stop_id)
Stop dirty page tracking and archiving.
Definition: arch0page.cc:979
constexpr lsn_t LSN_MAX
Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumera...
Definition: log0constants.h:159
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
Position in page ID archiving system.
Definition: arch0arch.h:299
void init()
Initialize a position.
Definition: arch0page.cc:1443
@ LATCH_ID_PAGE_ARCH_CLIENT
Definition: sync0types.h:391
unsigned int uint
Definition: uca9-dump.cc:75
#define mutex_exit(M)
Definition: ut0mutex.h:123
#define mutex_free(M)
Definition: ut0mutex.h:125
#define mutex_enter(M)
Definition: ut0mutex.h:117
#define mutex_create(I, M)
Definition: ut0mutex.h:110