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