MySQL 26.7.0
Source Code Documentation
buf0dblwr.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2026, 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/buf0dblwr.h
29 Doublewrite buffer module
30
31 Created 2011/12/19 Inaam Rana
32 *******************************************************/
33
34#ifndef buf0dblwr_h
35#define buf0dblwr_h
36
37#include "buf0types.h"
38#include "fil0fil.h"
39#include "log0recv.h"
40#include "ut0byte.h"
41
42/** Size of the doublewrite block in pages. */
43#define DBLWR_V1_EXTENT_SIZE FSP_EXTENT_SIZE
44
45/** Offset of the doublewrite buffer header on the trx system header page. */
46#define TRX_SYS_DBLWR_V1 (UNIV_PAGE_SIZE - 200)
47
48/** 4-byte ver number which shows if we have created the doublewrite buffer. */
50
51/** Page number of the first page in the first sequence of 64 (=
52FSP_EXTENT_SIZE) consecutive pages in the doublewrite buffer. */
54
55/** Page number of the first page in the second sequence of 64 consecutive
56pages in the doublewrite buffer. */
58
59namespace dblwr {
60
61/** IO buffer in UNIV_PAGE_SIZE units and aligned on UNIV_PAGE_SIZE */
62struct Buffer {
63 /** Constructor
64 @param[in] n_pages Number of pages to create */
65 explicit Buffer(size_t n_pages) noexcept
67
68 /** Constructor
69 @param[in] n_pages Number of pages to create
70 @param[in] phy_size physical page size. */
71 explicit Buffer(size_t n_pages, uint32_t phy_size) noexcept
72 : m_phy_size(phy_size), m_n_bytes(n_pages * phy_size) {
73 ut_a(n_pages > 0);
74 m_ptr = static_cast<byte *>(ut::aligned_zalloc(m_n_bytes, phy_size));
75
76 m_next = m_ptr;
77 }
78
79 /** Destructor */
82 m_ptr = nullptr;
83 }
84
85 /** Add the contents of ptr up to n_bytes to the buffer.
86 @return false if it won't fit. Nothing is copied if it won't fit. */
87 bool append(const void *ptr, size_t n_bytes) noexcept {
89
90 if (m_next + m_phy_size > m_ptr + m_n_bytes) {
91 return false;
92 }
93
94 memcpy(m_next, ptr, n_bytes);
96
97 return true;
98 }
99
100 /** @return the start of the buffer to write from. */
101 byte *begin() noexcept { return m_ptr; }
102
103 /** @return the start of the buffer to write from. */
104 const byte *begin() const noexcept { return m_ptr; }
105
106 /** @return the size of of the buffer to write. */
107 size_t size() const noexcept {
108 ut_a(m_next >= m_ptr);
109 return std::ptrdiff_t(m_next - m_ptr);
110 }
111
112 /** @return the capacity of the buffer in bytes. */
113 size_t capacity() const noexcept { return m_n_bytes; }
114
115 /** @return true if the buffer is empty. */
116 bool empty() const noexcept { return size() == 0; }
117
118 /** Empty the buffer. */
120
121 /** Page size on disk (aka physical page size). */
122 uint32_t m_phy_size;
123
124 /** Write buffer used in writing to the doublewrite buffer,
125 aligned to an address divisible by UNIV_PAGE_SIZE (which is
126 required by Windows AIO) */
127 byte *m_ptr{};
128
129 /** Start of next write to the buffer. */
130 byte *m_next{};
131
132 /** Size of the unaligned (raw) buffer. */
133 const size_t m_n_bytes{};
134
135 // Disable copying
136 Buffer(const Buffer &) = delete;
137 Buffer(Buffer &&) = delete;
138 Buffer &operator=(Buffer &&) = delete;
139 Buffer &operator=(const Buffer &) = delete;
140};
141
142} // namespace dblwr
143
144#ifndef UNIV_HOTBACKUP
145
146// Forward declaration
147class buf_page_t;
148class Double_write;
149
150namespace dblwr {
151
152/** Double write files location. */
153extern std::string dir;
154
155#ifdef UNIV_DEBUG
156/** Crash the server after writing this page to the data file. */
158#endif /* UNIV_DEBUG */
159
160/** Startup the background thread(s) and create the instance.
161@return DB_SUCCESS or error code */
162[[nodiscard]] dberr_t open() noexcept;
163
164/** Enable the doublewrite reduced mode by creating the necessary dblwr files
165and in-memory structures
166@return DB_SUCCESS or error code */
167[[nodiscard]] dberr_t enable_reduced() noexcept;
168
169/** Check and open the reduced doublewrite files if necessary
170@return DB_SUCCESS or error code */
171[[nodiscard]] dberr_t reduced_open() noexcept;
172
173/** Shutdown the background thread and destroy the instance */
174void close() noexcept;
175
176/** Force a write of all pages in the queue.
177@param[in] flush_type FLUSH LIST or LRU_LIST flush request.
178@param[in] buf_pool_index Buffer pool instance for which called. */
180
181/** Force a write of all pages in all dblwr segments (reduced or regular)
182This is used only when switching the doublewrite mode dynamically */
184
185/** Writes a page to the doublewrite buffer on disk, syncs it,
186then writes the page to the datafile.
187@param[in] flush_type Flush type
188@param[in] bpage Buffer block to write
189@param[in] sync True if sync IO requested
190@return DB_SUCCESS or error code */
191[[nodiscard]] dberr_t write(buf_flush_t flush_type, buf_page_t *bpage,
192 bool sync) noexcept;
193
194/** Obtain the encrypted frame and store it in bpage->m_io_frame
195@param[in,out] bpage the buffer page containing the unencrypted frame.
196@param[in,out] type i/o operation type.
197@return the memory block containing the compressed + encrypted frame. */
198[[nodiscard]] file::Block *get_encrypted_frame(buf_page_t *bpage,
200
201/** Updates the double write buffer when a write request is completed.
202@param[in] bpage Block that has just been writtent to disk.
203@param[in] flush_type Flush type that triggered the write. */
205
206/** Delete or adjust the dblwr file size if required. */
207void reset_files() noexcept;
208
209namespace v1 {
210/** Read the boundaries of the legacy dblwr buffer extents.
211@return DB_SUCCESS or error code. */
212[[nodiscard]] dberr_t init() noexcept;
213
214/** Create the dblwr data structures in the system tablespace.
215@return DB_SUCCESS or error code. */
216[[nodiscard]] dberr_t create() noexcept;
217
218/** Check if the read is of a page inside the legacy dblwr buffer.
219@param[in] page_no Page number to check.
220@return true if offset inside legacy dblwr buffer. */
221[[nodiscard]] bool is_inside(page_no_t page_no) noexcept;
222
223} // namespace v1
224} // namespace dblwr
225
226#endif /* !UNIV_HOTBACKUP */
227
228namespace dblwr {
229
230/** Number of pages per doublewrite thread/segment of the dblwr file. Refer
231to the system variable --innodb-doublewrite-pages for more details. */
232extern ulong n_pages;
233
234const uint32_t REDUCED_BATCH_PAGE_SIZE = 8192;
235
236/* 20-byte header.
237Fields : [batch id][checksum][data len][batch type][unused ]
238Field Width : [4 bytes ][4 bytes ][2 bytes ][ 1 byte ][ 9 bytes]
239Field Offsets : [ 0 ][ 4 ][ 8 ][ 10 ][ 11 ] */
240const uint32_t RB_BATCH_ID_SIZE = 4;
241const uint32_t RB_CHECKSUM_SIZE = 4;
242const uint32_t RB_DATA_LEN_SIZE = 2;
243const uint32_t RB_BATCH_TYPE_SIZE = 1;
244const uint32_t RB_UNUSED_BYTES_SIZE = 9;
245
246/* Offsets of the header fields. */
247constexpr const uint32_t RB_OFF_BATCH_ID = 0;
252
253constexpr const uint32_t REDUCED_HEADER_SIZE =
254 RB_BATCH_ID_SIZE /* BATCH_ID */
255 + RB_CHECKSUM_SIZE /* CHECKSUM */
256 + RB_DATA_LEN_SIZE /* DATA_LEN */
257 + RB_BATCH_TYPE_SIZE /* BATCH_TYPE */
258 + 9 /* UNUSED BYTES */;
259
260constexpr const uint32_t REDUCED_ENTRY_SIZE =
261 sizeof(space_id_t) + sizeof(page_no_t) + sizeof(lsn_t);
262
263constexpr const uint32_t REDUCED_DATA_SIZE =
265
266constexpr const uint32_t REDUCED_MAX_ENTRIES =
268
269/** When --innodb-doublewrite=DETECT_ONLY, page contents are not written to the
270dblwr buffer. Only the following Reduced_entry information is stored in the
271dblwr buffer. */
276
278
280 : m_space_id(space_id), m_page_no(page_no), m_lsn(lsn) {}
281
282 byte *write(byte *ptr) {
283 uint16_t offset = 0;
284 mach_write_to_4(ptr + offset, m_space_id);
285 offset += sizeof(m_space_id);
286
287 mach_write_to_4(ptr + offset, m_page_no);
288 offset += sizeof(m_page_no);
289
290 mach_write_to_8(ptr + offset, m_lsn);
291 offset += sizeof(m_lsn);
292
293 return ptr + offset;
294 }
295};
296
297struct Mode {
298 /** The operating mode of doublewrite. The modes ON, TRUEE and
299 DETECT_AND_RECOVER are equal to one another. The modes OFF and FALSEE are
300 equal to one another.
301
302 @note If you change order or add new values, please update
303 innodb_doublewrite_names enum in handler/ha_innodb.cc */
304 enum mode_t {
305 /** Equal to FALSEE. In this mode, dblwr is disabled. */
307
308 /** Equal to TRUEE and DETECT_AND_RECOVER modes. */
310
311 /** In this mode, dblwr is used only to detect torn writes. At code level,
312 this mode is also called as reduced mode. It is called reduced because the
313 number of bytes written to the dblwr file is reduced in this mode. */
315
316 /** This mode is synonymous with ON, TRUEE. */
318
319 /** Equal to OFF mode. Intentionally wrong spelling because of compilation
320 issues on Windows. */
322
323 /** Equal to ON, DETECT_AND_RECOVER mode. Intentionally wrong spelling
324 because of compilation issues on Windows platform. */
325 TRUEE
326 };
327
328 /** Check if doublewrite is enabled.
329 @param[in] mode dblwr ENUM
330 @return true if dblwr is enabled. */
331 static inline bool is_enabled_low(ulong mode);
332
333 /** Check if the doublewrite mode is disabled.
334 @param[in] mode dblwr ENUM
335 @return true if dblwr mode is OFF. */
336 static inline bool is_disabled_low(ulong mode);
337
338 /** Check if the doublewrite mode is detect-only (aka reduced).
339 @param[in] mode dblwr ENUM
340 @return true if dblwr mode is DETECT_ONLY. */
341 static inline bool is_reduced_low(ulong mode);
342
343 /** Check if the dblwr mode provides atomic writes.
344 @return true if mode is ON, TRUEE or DETECT_AND_RECOVER.
345 @return false if mode is OFF, FALSE or DETECT_ONLY. */
346 static inline bool is_atomic(ulong mode);
347
348 /** Convert the dblwr mode into a string representation.
349 @param[in] mode the dblwr mode.
350 @return string representation of the dblwr mode. */
351 static const char *to_string(ulong mode);
352
353 /** Check if the mode transition is from enabled to disabled.
354 @param[in] new_value the new value of dblwr mode.
355 @return true if mode transition is from enabled to disabled. */
356 static inline bool is_enabled_to_disabled(ulong new_value);
357
358 /** Check if the mode transition is from disabled to enabled.
359 @param[in] new_value the new value of dblwr mode.
360 @return true if mode transition is from disabled to enabled. */
361 static inline bool is_disabled_to_enabled(ulong new_value);
362
363 /** Check if the mode transition is equivalent.
364 @param[in] new_value the new value of dblwr mode.
365 @return true if mode transition is equivalent. */
366 static bool is_same(ulong new_value);
367};
368
370 return mode == ON || mode == TRUEE || mode == DETECT_AND_RECOVER;
371}
372
374 return mode == ON || mode == TRUEE || mode == DETECT_AND_RECOVER ||
375 mode == DETECT_ONLY;
376}
377
378bool Mode::is_disabled_low(ulong mode) { return mode == OFF || mode == FALSEE; }
379
380bool Mode::is_reduced_low(ulong mode) { return mode == DETECT_ONLY; }
381
382/** DBLWR mode. */
383extern ulong g_mode;
384
385/** true if DETECT_ONLY (aka reduced) mode is inited */
386extern bool is_reduced_inited;
387
388/** Check if doublewrite is enabled.
389@return true if dblwr mode is ON, DETECT_ONLY, DETECT_AND_RECOVER
390@return false if dblwr mode is OFF. */
391inline bool is_enabled() { return Mode::is_enabled_low(g_mode); }
392
393/** Check if the doublewrite mode is detect-only (aka reduced).
394@return true if dblwr mode is DETECT_ONLY. */
395inline bool is_reduced() { return Mode::is_reduced_low(g_mode); }
396
397/** Check if the doublewrite mode is disabled.
398@return true if dblwr mode is OFF. */
399inline bool is_disabled() { return Mode::is_disabled_low(g_mode); }
400
401bool Mode::is_enabled_to_disabled(ulong new_value) {
402 return is_enabled() && Mode::is_disabled_low(new_value);
403}
404
405bool Mode::is_disabled_to_enabled(ulong new_value) {
406 return is_disabled() && Mode::is_enabled_low(new_value);
407}
408
409/** @return string version of dblwr numeric values
410@param[in] mode dblwr ENUM */
411const char *to_string(ulong mode);
412
413/** Number of files to use for the double write buffer. Refer to the system
414variable --innodb-doublewrite-files for more details. */
415extern ulong n_files;
416
417/** Maximum number of pages to write in one batch. */
418extern ulong batch_size;
419
420/** Toggle the doublewrite buffer. */
421void set();
422
423namespace recv {
424
425class Pages;
426
427/** Create the recovery dblwr data structures
428@param[out] pages Pointer to newly created instance */
429void create(Pages *&pages) noexcept;
430
431/** Load the doublewrite buffer pages.
432@param[in,out] pages For storing the doublewrite pages read
433 from the double write buffer
434@return DB_SUCCESS or error code */
435[[nodiscard]] dberr_t load(Pages *pages) noexcept;
436
437/** Restore corrupted pages of the tablespace from the double write buffer.
438Iterates over the supplied double write buffer pages, but only ones that are not
439corrupted, searching for mentions of pages from the specified space, and for
440each such page checks if tablespace file contains a corrupted version of it and
441if so, restores it from the backup in image found in double write buffer page,
442unless this is impossible because the double write buffer page does not contain
443the body (in reduced, detect-only mode). In case of any errors (IO errors, out
444of bounds space access) we crash the server.
445@param[in,out] pages Pages from the doublewrite buffer
446@param[in] space Tablespace to restore pages in. */
447void recover(Pages &pages, fil_space_t &space) noexcept;
448
449/** Checks if content of the first page provided from the specified space
450requires recovery from the Double-write Buffer. If the supplied @p page_content
451has a valid not corrupted page, no action is taken. If it is not, then we try to
452get a non-corrupted copy from the Double-write Buffer. If there are any entries
453in the Reduced Double-write pages list, we may crash.
454@param[in] pages The Double-write pages read from the Double-write
455 Buffer.
456@param[in] space_id ID of the space to be checked.
457@param[in] page_size Page size structure to use for the tablespace page
458 manipulation.
459@param[in] file_path Path of a file to be used for error reporting.
460@param[in] page_content Content of the first page of the specified tablespace
461 read from the disk. The buffer must hold at least
462 `page_size.physical()` bytes.
463@return pointer to @p page_content if the page does not require recovery,
464pointer to page contents from the Double-write Buffer or nullptr if
465page_content is corrupted, but there's no valid image of it in the
466Double-write Buffer to restore it from */
467[[nodiscard]] const byte *get_first_page_content_for_recovery(
468 const recv::Pages &pages, space_id_t space_id, page_size_t page_size,
469 const std::string &file_path, const byte *page_content);
470
471/** Check if some pages from the double write buffer could not be
472restored because of the missing tablespace IDs.
473@param[in] pages Pages to check */
474void check_missing_tablespaces(const Pages *pages) noexcept;
475
476/** Free the recovery dblwr data structures
477@param[out] pages Instance of the Pages to free. */
478void destroy(Pages *&pages) noexcept;
479
480/** Redo recovery configuration. */
481class DBLWR {
482 public:
483 /** Constructor. */
484 explicit DBLWR() noexcept { create(m_pages); }
485
486 /** Destructor */
488
489 /** @return true if empty. */
490 bool empty() const noexcept { return (m_pages == nullptr); }
491
492 /** Load the doublewrite buffer pages. Doesn't create the doublewrite
493 @return DB_SUCCESS or error code */
494 [[nodiscard]] dberr_t load() noexcept { return (dblwr::recv::load(m_pages)); }
495
496#ifndef UNIV_HOTBACKUP
497 /** Restore corrupted pages of the tablespace from the double write buffer.
498 Iterates over the previously loaded double write buffer pages, but only ones
499 that are not corrupted, searching for mentions of pages from the specified
500 space, and for each such page checks if tablespace file contains a corrupted
501 version of it and if so, restores it from the backup in image found in double
502 write buffer page, unless this is impossible because the double write buffer
503 page does not contain the body (in reduced, detect-only mode). In case of any
504 errors (IO errors, out of bounds space access) we crash the server.
505 @param[in] space Tablespace to restore pages in. */
506 void recover(fil_space_t &space) noexcept {
508 }
509
510 /** Checks if content of the first page provided from the specified space
511 requires recovery from the Double-write Buffer. If the supplied @p
512 page_content has a valid not corrupted page, no action is taken. If it is not,
513 then we try to get a non-corrupted copy from the Double-write Buffer. If there
514 are any entries in the Reduced Double-write pages list, we may crash.
515 @param[in] space_id ID of the space to be checked.
516 @param[in] page_size Page size structure to use for the tablespace page
517 manipulation.
518 @param[in] file_path Path of a file to be used for error reporting.
519 @param[in] page_content Content of the first page of the specified tablespace
520 read from the disk. The buffer must hold at least
521 `page_size.physical()` bytes.
522 @return pointer to @p page_content if the page does not require recovery, a
523 pointer to page contents from the Double-write Buffer or nullptr if
524 page_content is corrupted, but there's no valid image of it in the
525 Double-write Buffer to restore it from */
527 space_id_t space_id, page_size_t page_size, const std::string &file_path,
528 const byte *page_content) noexcept {
530 *m_pages, space_id, page_size, file_path, page_content);
531 }
532
533 /** Check if some pages from the double write buffer
534 could not be restored because of the missing tablespace IDs. */
537 }
538
539 /** Note that recovery is complete. Adjust the file sizes if necessary. */
541#endif /* !UNIV_HOTBACKUP */
542
543 /** Disable copying. */
544 DBLWR(const DBLWR &) = delete;
545 DBLWR(DBLWR &&) = delete;
546 DBLWR &operator=(DBLWR &&) = delete;
547 DBLWR &operator=(const DBLWR &) = delete;
548
549 private:
550 /** Pages read from the double write file. */
552};
553} // namespace recv
554
555#ifdef UNIV_DEBUG
556/** Check if the dblwr files contain encrypted pages.
557@return true if dblwr file contains any encrypted pages,
558 false if dblwr file contains no encrypted pages. */
559[[nodiscard]] bool has_encrypted_pages() noexcept;
560#endif /* UNIV_DEBUG */
561} // namespace dblwr
562
563#endif /* buf0dblwr_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
static ulint buf_pool_index(const buf_pool_t *buf_pool)
Calculates the index of a buffer pool to the buf_pool[] array.
constexpr ulint DBLWR_VER
4-byte ver number which shows if we have created the doublewrite buffer.
Definition: buf0dblwr.h:49
constexpr ulint DBLWR_V1_BLOCK1
Page number of the first page in the first sequence of 64 (= FSP_EXTENT_SIZE) consecutive pages in th...
Definition: buf0dblwr.h:53
constexpr ulint DBLWR_V1_BLOCK2
Page number of the first page in the second sequence of 64 consecutive pages in the doublewrite buffe...
Definition: buf0dblwr.h:57
The database buffer pool global types for the directory.
buf_flush_t
Flags for flush types.
Definition: buf0types.h:68
Doublewrite implementation.
Definition: buf0dblwr.cc:491
Types for AIO operations.
Definition: os0file.h:262
Definition: buf0buf.h:1156
Redo recovery configuration.
Definition: buf0dblwr.h:481
void recovered() noexcept
Note that recovery is complete.
Definition: buf0dblwr.h:540
DBLWR(DBLWR &&)=delete
DBLWR() noexcept
Constructor.
Definition: buf0dblwr.h:484
void check_missing_tablespaces() noexcept
Check if some pages from the double write buffer could not be restored because of the missing tablesp...
Definition: buf0dblwr.h:535
Pages * m_pages
Pages read from the double write file.
Definition: buf0dblwr.h:551
DBLWR & operator=(const DBLWR &)=delete
const byte * get_first_page_content_for_recovery(space_id_t space_id, page_size_t page_size, const std::string &file_path, const byte *page_content) noexcept
Checks if content of the first page provided from the specified space requires recovery from the Doub...
Definition: buf0dblwr.h:526
~DBLWR() noexcept
Destructor.
Definition: buf0dblwr.h:487
DBLWR(const DBLWR &)=delete
Disable copying.
DBLWR & operator=(DBLWR &&)=delete
void recover(fil_space_t &space) noexcept
Restore corrupted pages of the tablespace from the double write buffer.
Definition: buf0dblwr.h:506
bool empty() const noexcept
Definition: buf0dblwr.h:490
dberr_t load() noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.h:494
Pages recovered from the doublewrite buffer.
Definition: buf0dblwr.cc:277
Tablespace or log data space.
Definition: fil0fil.h:506
Page identifier.
Definition: buf0types.h:191
Page size descriptor.
Definition: page0size.h:50
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:129
dberr_t
Definition: db0err.h:39
The low-level file system.
constexpr uint32_t FSEG_HEADER_SIZE
Length of the file system header, in bytes.
Definition: fsp0types.h:94
mysql_service_status_t recv(const char *tag, const unsigned char *data, size_t data_length) noexcept
Definition: gr_message_service_example.cc:39
flush_type
Definition: my_sys.h:300
Recovery.
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
static void mach_write_to_8(void *b, uint64_t n)
The following function is used to store data in 8 consecutive bytes.
static void mach_write_to_4(byte *b, ulint n)
The following function is used to store data in 4 consecutive bytes.
void recover(Pages &pages, fil_space_t &space) noexcept
Restore corrupted pages of the tablespace from the double write buffer.
Definition: buf0dblwr.cc:2722
dberr_t load(Pages *pages) noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.cc:3402
void destroy(Pages *&pages) noexcept
Free the recovery dblwr data structures.
Definition: buf0dblwr.cc:3612
void check_missing_tablespaces(const Pages *pages) noexcept
Check if some pages from the double write buffer could not be restored because of the missing tablesp...
Definition: buf0dblwr.cc:3620
void create(Pages *&pages) noexcept
Create the recovery dblwr data structures.
Definition: buf0dblwr.cc:3607
const byte * get_first_page_content_for_recovery(const recv::Pages &pages, space_id_t space_id, page_size_t page_size, const std::string &file_path, const byte *page_content)
Checks if content of the first page provided from the specified space requires recovery from the Doub...
Definition: buf0dblwr.cc:2726
bool is_inside(page_no_t page_no) noexcept
Check if the read is of a page inside the legacy dblwr buffer.
Definition: buf0dblwr.cc:3023
dberr_t init() noexcept
Read the boundaries of the legacy dblwr buffer extents.
Definition: buf0dblwr.cc:3007
Definition: buf0dblwr.cc:79
ulong n_files
Number of files to use for the double write buffer.
Definition: buf0dblwr.cc:83
constexpr const uint32_t RB_OFF_UNUSED
Definition: buf0dblwr.h:251
dberr_t reduced_open() noexcept
Check and open the reduced doublewrite files if necessary.
Definition: buf0dblwr.cc:2820
dberr_t open() noexcept
Startup the background thread(s) and create the instance.
Definition: buf0dblwr.cc:2859
constexpr const uint32_t REDUCED_MAX_ENTRIES
Definition: buf0dblwr.h:266
void set()
Toggle the doublewrite buffer.
Definition: buf0dblwr.cc:2999
dberr_t enable_reduced() noexcept
Enable the doublewrite reduced mode by creating the necessary dblwr files and in-memory structures.
Definition: buf0dblwr.cc:2974
void close() noexcept
Shutdown the background thread and destroy the instance.
Definition: buf0dblwr.cc:2997
const uint32_t REDUCED_BATCH_PAGE_SIZE
Definition: buf0dblwr.h:234
void force_flush(buf_flush_t flush_type, uint32_t buf_pool_index) noexcept
Force a write of all pages in the queue.
Definition: buf0dblwr.cc:3176
ulong n_pages
Number of pages per doublewrite thread/segment of the dblwr file.
Definition: buf0dblwr.cc:87
constexpr const uint32_t REDUCED_HEADER_SIZE
Definition: buf0dblwr.h:253
ulong g_mode
DBLWR mode.
Definition: buf0dblwr.cc:89
page_id_t Force_crash
Crash the server after writing this page to the data file.
Definition: buf0dblwr.cc:206
constexpr const uint32_t RB_OFF_CHECKSUM
Definition: buf0dblwr.h:248
file::Block * get_encrypted_frame(buf_page_t *bpage, IORequest &type) noexcept
Obtain the encrypted frame and store it in bpage->m_io_frame.
Definition: buf0dblwr.cc:2525
const uint32_t RB_BATCH_TYPE_SIZE
Definition: buf0dblwr.h:243
void force_flush_all() noexcept
Force a write of all pages in all dblwr segments (reduced or regular) This is used only when switchin...
Definition: buf0dblwr.cc:3181
std::string dir
Double write files location.
Definition: buf0dblwr.cc:81
constexpr const uint32_t RB_OFF_BATCH_TYPE
Definition: buf0dblwr.h:250
ulong batch_size
Maximum number of pages to write in one batch.
Definition: buf0dblwr.cc:85
const uint32_t RB_BATCH_ID_SIZE
Definition: buf0dblwr.h:240
bool has_encrypted_pages() noexcept
Check if the dblwr files contain encrypted pages.
Definition: buf0dblwr.cc:3637
constexpr const uint32_t REDUCED_DATA_SIZE
Definition: buf0dblwr.h:263
bool is_enabled()
Check if doublewrite is enabled.
Definition: buf0dblwr.h:391
const char * to_string(ulong mode)
constexpr const uint32_t REDUCED_ENTRY_SIZE
Definition: buf0dblwr.h:260
void reset_files() noexcept
Delete or adjust the dblwr file size if required.
Definition: buf0dblwr.cc:3005
const uint32_t RB_DATA_LEN_SIZE
Definition: buf0dblwr.h:242
dberr_t write(buf_flush_t flush_type, buf_page_t *bpage, bool sync) noexcept
Writes a page to the doublewrite buffer on disk, syncs it, then writes the page to the datafile.
Definition: buf0dblwr.cc:2590
bool is_disabled()
Check if the doublewrite mode is disabled.
Definition: buf0dblwr.h:399
bool is_reduced()
Check if the doublewrite mode is detect-only (aka reduced).
Definition: buf0dblwr.h:395
constexpr const uint32_t RB_OFF_DATA_LEN
Definition: buf0dblwr.h:249
bool is_reduced_inited
true if DETECT_ONLY (aka reduced) mode is inited
Definition: buf0dblwr.cc:91
const uint32_t RB_CHECKSUM_SIZE
Definition: buf0dblwr.h:241
void write_complete(buf_page_t *bpage, buf_flush_t flush_type) noexcept
Updates the double write buffer when a write request is completed.
Definition: buf0dblwr.cc:2718
constexpr const uint32_t RB_OFF_BATCH_ID
Definition: buf0dblwr.h:247
const uint32_t RB_UNUSED_BYTES_SIZE
Definition: buf0dblwr.h:244
Definition: os0file.h:89
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
mode
Definition: file_handle.h:61
void * aligned_zalloc(std::size_t size, std::size_t alignment) noexcept
Dynamically allocates zero-initialized storage of given size and at the address aligned to the reques...
Definition: ut0new.h:1391
void aligned_free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the aligned_alloc_*() or aligned...
Definition: ut0new.h:1405
page_size_t univ_page_size
required string type
Definition: replication_group_member_actions.proto:34
IO buffer in UNIV_PAGE_SIZE units and aligned on UNIV_PAGE_SIZE.
Definition: buf0dblwr.h:62
Buffer & operator=(const Buffer &)=delete
Buffer(size_t n_pages) noexcept
Constructor.
Definition: buf0dblwr.h:65
size_t capacity() const noexcept
Definition: buf0dblwr.h:113
uint32_t m_phy_size
Page size on disk (aka physical page size).
Definition: buf0dblwr.h:122
Buffer(const Buffer &)=delete
~Buffer() noexcept
Destructor.
Definition: buf0dblwr.h:80
bool append(const void *ptr, size_t n_bytes) noexcept
Add the contents of ptr up to n_bytes to the buffer.
Definition: buf0dblwr.h:87
const byte * begin() const noexcept
Definition: buf0dblwr.h:104
byte * m_next
Start of next write to the buffer.
Definition: buf0dblwr.h:130
byte * m_ptr
Write buffer used in writing to the doublewrite buffer, aligned to an address divisible by UNIV_PAGE_...
Definition: buf0dblwr.h:127
Buffer(Buffer &&)=delete
void clear() noexcept
Empty the buffer.
Definition: buf0dblwr.h:119
bool empty() const noexcept
Definition: buf0dblwr.h:116
size_t size() const noexcept
Definition: buf0dblwr.h:107
byte * begin() noexcept
Definition: buf0dblwr.h:101
const size_t m_n_bytes
Size of the unaligned (raw) buffer.
Definition: buf0dblwr.h:133
Buffer & operator=(Buffer &&)=delete
Buffer(size_t n_pages, uint32_t phy_size) noexcept
Constructor.
Definition: buf0dblwr.h:71
Definition: buf0dblwr.h:297
static bool is_disabled_low(ulong mode)
Check if the doublewrite mode is disabled.
Definition: buf0dblwr.h:378
static bool is_same(ulong new_value)
Check if the mode transition is equivalent.
Definition: buf0dblwr.cc:112
static bool is_enabled_to_disabled(ulong new_value)
Check if the mode transition is from enabled to disabled.
Definition: buf0dblwr.h:401
static bool is_atomic(ulong mode)
Check if the dblwr mode provides atomic writes.
Definition: buf0dblwr.h:369
static const char * to_string(ulong mode)
Convert the dblwr mode into a string representation.
Definition: buf0dblwr.cc:93
static bool is_disabled_to_enabled(ulong new_value)
Check if the mode transition is from disabled to enabled.
Definition: buf0dblwr.h:405
static bool is_enabled_low(ulong mode)
Check if doublewrite is enabled.
Definition: buf0dblwr.h:373
static bool is_reduced_low(ulong mode)
Check if the doublewrite mode is detect-only (aka reduced).
Definition: buf0dblwr.h:380
mode_t
The operating mode of doublewrite.
Definition: buf0dblwr.h:304
@ DETECT_ONLY
In this mode, dblwr is used only to detect torn writes.
Definition: buf0dblwr.h:314
@ FALSEE
Equal to OFF mode.
Definition: buf0dblwr.h:321
@ TRUEE
Equal to ON, DETECT_AND_RECOVER mode.
Definition: buf0dblwr.h:325
@ DETECT_AND_RECOVER
This mode is synonymous with ON, TRUEE.
Definition: buf0dblwr.h:317
@ ON
Equal to TRUEE and DETECT_AND_RECOVER modes.
Definition: buf0dblwr.h:309
@ OFF
Equal to FALSEE.
Definition: buf0dblwr.h:306
When –innodb-doublewrite=DETECT_ONLY, page contents are not written to the dblwr buffer.
Definition: buf0dblwr.h:272
lsn_t m_lsn
Definition: buf0dblwr.h:275
page_no_t m_page_no
Definition: buf0dblwr.h:274
space_id_t m_space_id
Definition: buf0dblwr.h:273
Reduced_entry(space_id_t space_id, page_no_t page_no, lsn_t lsn)
Definition: buf0dblwr.h:279
Reduced_entry(buf_page_t *bpage)
Definition: buf0dblwr.cc:3669
byte * write(byte *ptr)
Definition: buf0dblwr.h:282
unsigned long int ulint
Definition: univ.i:403
Utilities for byte operations.
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
static uint64_t lsn
Definition: xcom_base.cc:446