MySQL 9.1.0
Source Code Documentation
buf0dblwr.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 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/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 */
80 ~Buffer() noexcept {
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. */
119 void clear() noexcept { m_next = m_ptr; }
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(const 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. */
179void force_flush(buf_flush_t flush_type, uint32_t buf_pool_index) noexcept;
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 */
183void force_flush_all() noexcept;
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,
199 IORequest &type) noexcept;
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. */
204void write_complete(buf_page_t *bpage, buf_flush_t flush_type) noexcept;
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 */
231extern ulong n_pages;
232
233const uint32_t REDUCED_BATCH_PAGE_SIZE = 8192;
234
235/* 20-byte header.
236Fields : [batch id][checksum][data len][batch type][unused ]
237Field Width : [4 bytes ][4 bytes ][2 bytes ][ 1 byte ][ 9 bytes]
238Field Offsets : [ 0 ][ 4 ][ 8 ][ 10 ][ 11 ] */
239const uint32_t RB_BATCH_ID_SIZE = 4;
240const uint32_t RB_CHECKSUM_SIZE = 4;
241const uint32_t RB_DATA_LEN_SIZE = 2;
242const uint32_t RB_BATCH_TYPE_SIZE = 1;
243const uint32_t RB_UNUSED_BYTES_SIZE = 9;
244
245/* Offsets of the header fields. */
246constexpr const uint32_t RB_OFF_BATCH_ID = 0;
251
252constexpr const uint32_t REDUCED_HEADER_SIZE =
253 RB_BATCH_ID_SIZE /* BATCH_ID */
254 + RB_CHECKSUM_SIZE /* CHECKSUM */
255 + RB_DATA_LEN_SIZE /* DATA_LEN */
256 + RB_BATCH_TYPE_SIZE /* BATCH_TYPE */
257 + 9 /* UNUSED BYTES */;
258
259constexpr const uint32_t REDUCED_ENTRY_SIZE =
260 sizeof(space_id_t) + sizeof(page_no_t) + sizeof(lsn_t);
261
262constexpr const uint32_t REDUCED_DATA_SIZE =
264
265constexpr const uint32_t REDUCED_MAX_ENTRIES =
267
268/** When --innodb-doublewrite=DETECT_ONLY, page contents are not written to the
269dblwr buffer. Only the following Reduced_entry information is stored in the
270dblwr buffer. */
275
277
279 : m_space_id(space_id), m_page_no(page_no), m_lsn(lsn) {}
280
281 byte *write(byte *ptr) {
282 uint16_t offset = 0;
283 mach_write_to_4(ptr + offset, m_space_id);
284 offset += sizeof(m_space_id);
285
286 mach_write_to_4(ptr + offset, m_page_no);
287 offset += sizeof(m_page_no);
288
289 mach_write_to_8(ptr + offset, m_lsn);
290 offset += sizeof(m_lsn);
291
292 return ptr + offset;
293 }
294};
295
296struct Mode {
297 /** The operating mode of doublewrite. The modes ON, TRUEE and
298 DETECT_AND_RECOVER are equal to one another. The modes OFF and FALSEE are
299 equal to one another.
300
301 @note If you change order or add new values, please update
302 innodb_doublewrite_names enum in handler/ha_innodb.cc */
303 enum mode_t {
304 /** Equal to FALSEE. In this mode, dblwr is disabled. */
306
307 /** Equal to TRUEE and DETECT_AND_RECOVER modes. */
309
310 /** In this mode, dblwr is used only to detect torn writes. At code level,
311 this mode is also called as reduced mode. It is called reduced because the
312 number of bytes written to the dblwr file is reduced in this mode. */
314
315 /** This mode is synonymous with ON, TRUEE. */
317
318 /** Equal to OFF mode. Intentionally wrong spelling because of compilation
319 issues on Windows. */
321
322 /** Equal to ON, DETECT_AND_RECOVER mode. Intentionally wrong spelling
323 because of compilation issues on Windows platform. */
324 TRUEE
325 };
326
327 /** Check if doublewrite is enabled.
328 @param[in] mode dblwr ENUM
329 @return true if dblwr is enabled. */
330 static inline bool is_enabled_low(ulong mode);
331
332 /** Check if the doublewrite mode is disabled.
333 @param[in] mode dblwr ENUM
334 @return true if dblwr mode is OFF. */
335 static inline bool is_disabled_low(ulong mode);
336
337 /** Check if the doublewrite mode is detect-only (aka reduced).
338 @param[in] mode dblwr ENUM
339 @return true if dblwr mode is DETECT_ONLY. */
340 static inline bool is_reduced_low(ulong mode);
341
342 /** Check if the dblwr mode provides atomic writes.
343 @return true if mode is ON, TRUEE or DETECT_AND_RECOVER.
344 @return false if mode is OFF, FALSE or DETECT_ONLY. */
345 static inline bool is_atomic(ulong mode);
346
347 /** Convert the dblwr mode into a string representation.
348 @param[in] mode the dblwr mode.
349 @return string representation of the dblwr mode. */
350 static const char *to_string(ulong mode);
351
352 /** Check if the mode transition is from enabled to disabled.
353 @param[in] new_value the new value of dblwr mode.
354 @return true if mode transition is from enabled to disabled. */
355 static inline bool is_enabled_to_disabled(ulong new_value);
356
357 /** Check if the mode transition is from disabled to enabled.
358 @param[in] new_value the new value of dblwr mode.
359 @return true if mode transition is from disabled to enabled. */
360 static inline bool is_disabled_to_enabled(ulong new_value);
361
362 /** Check if the mode transition is equivalent.
363 @param[in] new_value the new value of dblwr mode.
364 @return true if mode transition is equivalent. */
365 static bool is_same(ulong new_value);
366};
367
369 return mode == ON || mode == TRUEE || mode == DETECT_AND_RECOVER;
370}
371
373 return mode == ON || mode == TRUEE || mode == DETECT_AND_RECOVER ||
374 mode == DETECT_ONLY;
375}
376
377bool Mode::is_disabled_low(ulong mode) { return mode == OFF || mode == FALSEE; }
378
379bool Mode::is_reduced_low(ulong mode) { return mode == DETECT_ONLY; }
380
381/** DBLWR mode. */
382extern ulong g_mode;
383
384/** true if DETECT_ONLY (aka reduced) mode is inited */
385extern bool is_reduced_inited;
386
387/** Check if doublewrite is enabled.
388@return true if dblwr mode is ON, DETECT_ONLY, DETECT_AND_RECOVER
389@return false if dblwr mode is OFF. */
390inline bool is_enabled() { return Mode::is_enabled_low(g_mode); }
391
392/** Check if the doublewrite mode is detect-only (aka reduced).
393@return true if dblwr mode is DETECT_ONLY. */
394inline bool is_reduced() { return Mode::is_reduced_low(g_mode); }
395
396/** Check if the doublewrite mode is disabled.
397@return true if dblwr mode is OFF. */
398inline bool is_disabled() { return Mode::is_disabled_low(g_mode); }
399
400bool Mode::is_enabled_to_disabled(ulong new_value) {
401 return is_enabled() && Mode::is_disabled_low(new_value);
402}
403
404bool Mode::is_disabled_to_enabled(ulong new_value) {
405 return is_disabled() && Mode::is_enabled_low(new_value);
406}
407
408/** @return string version of dblwr numeric values
409@param[in] mode dblwr ENUM */
410const char *to_string(ulong mode);
411
412/** Number of files to use for the double write buffer. It must be <= than
413the number of buffer pool instances. */
414extern ulong n_files;
415
416/** Maximum number of pages to write in one batch. */
417extern ulong batch_size;
418
419/** Toggle the doublewrite buffer. */
420void set();
421
422namespace recv {
423
424class Pages;
425
426/** Create the recovery dblwr data structures
427@param[out] pages Pointer to newly created instance */
428void create(Pages *&pages) noexcept;
429
430/** Load the doublewrite buffer pages.
431@param[in,out] pages For storing the doublewrite pages read
432 from the double write buffer
433@return DB_SUCCESS or error code */
434[[nodiscard]] dberr_t load(Pages *pages) noexcept;
435
436/** Load the doublewrite buffer pages.
437@param[in,out] pages For storing the doublewrite pages read
438 from the double write buffer
439@return DB_SUCCESS or error code */
440[[nodiscard]] dberr_t reduced_load(Pages *pages) noexcept;
441
442/** Restore pages from the double write buffer to the tablespace.
443@param[in,out] pages Pages from the doublewrite buffer
444@param[in] space Tablespace pages to restore, if set to nullptr then try and
445 restore all. */
446void recover(Pages *pages, fil_space_t *space) noexcept;
447
448/** Find a doublewrite copy of a page.
449@param[in] pages Pages read from the doublewrite buffer
450@param[in] page_id Page number to lookup
451@return page frame
452@retval NULL if no page was found */
453[[nodiscard]] const byte *find(const Pages *pages,
454 const page_id_t &page_id) noexcept;
455
456/** Find the LSN of the given page id in the dblwr.
457@param[in] pages Pages read from the doublewrite buffer
458@param[in] page_id Page number to lookup
459@return 0th element is true if page_id found in double write buffer.
460@return 1st element is valid only if 0th element is true.
461@return 1st element contains the LSN of the page in dblwr. */
462[[nodiscard]] std::tuple<bool, lsn_t> find_entry(
463 const Pages *pages, const page_id_t &page_id) noexcept;
464
465/** Check if some pages from the double write buffer could not be
466restored because of the missing tablespace IDs.
467@param[in] pages Pages to check */
468void check_missing_tablespaces(const Pages *pages) noexcept;
469
470/** Free the recovery dblwr data structures
471@param[out] pages Free the instance */
472void destroy(Pages *&pages) noexcept;
473
474/** Redo recovery configuration. */
475class DBLWR {
476 public:
477 /** Constructor. */
478 explicit DBLWR() noexcept { create(m_pages); }
479
480 /** Destructor */
481 ~DBLWR() noexcept { destroy(m_pages); }
482
483 /** @return true if empty. */
484 bool empty() const noexcept { return (m_pages == nullptr); }
485
486 /** Load the doublewrite buffer pages. Doesn't create the doublewrite
487 @return DB_SUCCESS or error code */
488 [[nodiscard]] dberr_t load() noexcept { return (dblwr::recv::load(m_pages)); }
489
490 /** Load the doublewrite buffer pages. Doesn't create the doublewrite
491 @return DB_SUCCESS or error code */
492 [[nodiscard]] dberr_t reduced_load() noexcept {
494 }
495
496 /** Restore pages from the double write buffer to the tablespace.
497 @param[in] space Tablespace pages to restore,
498 if set to nullptr then try
499 and restore all. */
500 void recover(fil_space_t *space = nullptr) noexcept {
502 }
503
504 /** Find a doublewrite copy of a page.
505 @param[in] page_id Page number to lookup
506 @return page frame
507 @retval nullptr if no page was found */
508 [[nodiscard]] const byte *find(const page_id_t &page_id) noexcept {
509 return (dblwr::recv::find(m_pages, page_id));
510 }
511
512 /** Find the LSN of the given page id in the dblwr.
513 @param[in] page_id Page number to lookup
514 @return 0th element is true if page_id found in double write buffer.
515 @return 1st element is valid only if 0th element is true.
516 @return 1st element contains the LSN of the page in dblwr. */
517 [[nodiscard]] std::tuple<bool, lsn_t> find_entry(
518 const page_id_t &page_id) noexcept {
519 return (dblwr::recv::find_entry(m_pages, page_id));
520 }
521
522 /** Check if some pages from the double write buffer
523 could not be restored because of the missing tablespace IDs. */
526 }
527
528#ifndef UNIV_HOTBACKUP
529 /** Note that recovery is complete. Adjust the file sizes if necessary. */
530 void recovered() noexcept { dblwr::reset_files(); }
531#endif /* !UNIV_HOTBACKUP */
532
533 /** Disably copying. */
534 DBLWR(const DBLWR &) = delete;
535 DBLWR(const DBLWR &&) = delete;
536 DBLWR &operator=(DBLWR &&) = delete;
537 DBLWR &operator=(const DBLWR &) = delete;
538
539 private:
540 /** Pages read from the double write file. */
542};
543} // namespace recv
544
545#ifdef UNIV_DEBUG
546/** Check if the dblwr files contain encrypted pages.
547@return true if dblwr file contains any encrypted pages,
548 false if dblwr file contains no encrypted pages. */
549[[nodiscard]] bool has_encrypted_pages() noexcept;
550#endif /* UNIV_DEBUG */
551} // namespace dblwr
552
553#endif /* buf0dblwr_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:48
uint32_t page_no_t
Page number.
Definition: api0api.h:46
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:430
The IO Context that is passed down to the low level IO code.
Definition: os0file.h:265
Definition: buf0buf.h:1153
Redo recovery configuration.
Definition: buf0dblwr.h:475
const byte * find(const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.h:508
void recovered() noexcept
Note that recovery is complete.
Definition: buf0dblwr.h:530
DBLWR() noexcept
Constructor.
Definition: buf0dblwr.h:478
DBLWR(const DBLWR &&)=delete
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:524
Pages * m_pages
Pages read from the double write file.
Definition: buf0dblwr.h:541
void recover(fil_space_t *space=nullptr) noexcept
Restore pages from the double write buffer to the tablespace.
Definition: buf0dblwr.h:500
DBLWR & operator=(const DBLWR &)=delete
~DBLWR() noexcept
Destructor.
Definition: buf0dblwr.h:481
DBLWR(const DBLWR &)=delete
Disably copying.
DBLWR & operator=(DBLWR &&)=delete
std::tuple< bool, lsn_t > find_entry(const page_id_t &page_id) noexcept
Find the LSN of the given page id in the dblwr.
Definition: buf0dblwr.h:517
bool empty() const noexcept
Definition: buf0dblwr.h:484
dberr_t reduced_load() noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.h:492
dberr_t load() noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.h:488
Pages recovered from the doublewrite buffer.
Definition: buf0dblwr.cc:249
Page identifier.
Definition: buf0types.h:207
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:121
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:293
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 pages from the double write buffer to the tablespace.
Definition: buf0dblwr.cc:2618
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:3563
dberr_t load(Pages *pages) noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.cc:3351
void destroy(Pages *&pages) noexcept
Free the recovery dblwr data structures.
Definition: buf0dblwr.cc:3578
std::tuple< bool, lsn_t > find_entry(const Pages *pages, const page_id_t &page_id) noexcept
Find the LSN of the given page id in the dblwr.
Definition: buf0dblwr.cc:3568
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:3585
dberr_t reduced_load(Pages *pages) noexcept
Load the doublewrite buffer pages.
Definition: buf0dblwr.cc:3463
void create(Pages *&pages) noexcept
Create the recovery dblwr data structures.
Definition: buf0dblwr.cc:3573
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:2902
dberr_t init() noexcept
Read the boundaries of the legacy dblwr buffer extents.
Definition: buf0dblwr.cc:2886
Definition: buf0dblwr.cc:75
ulong n_files
Number of files to use for the double write buffer.
Definition: buf0dblwr.cc:79
constexpr const uint32_t RB_OFF_UNUSED
Definition: buf0dblwr.h:250
dberr_t reduced_open() noexcept
Check and open the reduced doublewrite files if necessary.
Definition: buf0dblwr.cc:2713
dberr_t open() noexcept
Startup the background thread(s) and create the instance.
Definition: buf0dblwr.cc:2752
constexpr const uint32_t REDUCED_MAX_ENTRIES
Definition: buf0dblwr.h:265
void set()
Toggle the doublewrite buffer.
Definition: buf0dblwr.cc:2878
dberr_t enable_reduced() noexcept
Enable the doublewrite reduced mode by creating the necessary dblwr files and in-memory structures.
Definition: buf0dblwr.cc:2853
void close() noexcept
Shutdown the background thread and destroy the instance.
Definition: buf0dblwr.cc:2876
const uint32_t REDUCED_BATCH_PAGE_SIZE
Definition: buf0dblwr.h:233
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:3134
ulong n_pages
Number of pages per doublewrite thread/segment.
Definition: buf0dblwr.cc:83
constexpr const uint32_t REDUCED_HEADER_SIZE
Definition: buf0dblwr.h:252
ulong g_mode
DBLWR mode.
Definition: buf0dblwr.cc:85
page_id_t Force_crash
Crash the server after writing this page to the data file.
Definition: buf0dblwr.cc:198
constexpr const uint32_t RB_OFF_CHECKSUM
Definition: buf0dblwr.h:247
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:2416
const uint32_t RB_BATCH_TYPE_SIZE
Definition: buf0dblwr.h:242
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:3139
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
constexpr const uint32_t RB_OFF_BATCH_TYPE
Definition: buf0dblwr.h:249
ulong batch_size
Maximum number of pages to write in one batch.
Definition: buf0dblwr.cc:81
const uint32_t RB_BATCH_ID_SIZE
Definition: buf0dblwr.h:239
bool has_encrypted_pages() noexcept
Check if the dblwr files contain encrypted pages.
Definition: buf0dblwr.cc:3601
constexpr const uint32_t REDUCED_DATA_SIZE
Definition: buf0dblwr.h:262
bool is_enabled()
Check if doublewrite is enabled.
Definition: buf0dblwr.h:390
const char * to_string(ulong mode)
constexpr const uint32_t REDUCED_ENTRY_SIZE
Definition: buf0dblwr.h:259
void reset_files() noexcept
Delete or adjust the dblwr file size if required.
Definition: buf0dblwr.cc:2884
const uint32_t RB_DATA_LEN_SIZE
Definition: buf0dblwr.h:241
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:2481
bool is_disabled()
Check if the doublewrite mode is disabled.
Definition: buf0dblwr.h:398
bool is_reduced()
Check if the doublewrite mode is detect-only (aka reduced).
Definition: buf0dblwr.h:394
constexpr const uint32_t RB_OFF_DATA_LEN
Definition: buf0dblwr.h:248
bool is_reduced_inited
true if DETECT_ONLY (aka reduced) mode is inited
Definition: buf0dblwr.cc:87
const uint32_t RB_CHECKSUM_SIZE
Definition: buf0dblwr.h:240
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:2614
constexpr const uint32_t RB_OFF_BATCH_ID
Definition: buf0dblwr.h:246
const uint32_t RB_UNUSED_BYTES_SIZE
Definition: buf0dblwr.h:243
Definition: os0file.h:89
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:1551
void aligned_free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the aligned_alloc_*() or aligned...
Definition: ut0new.h:1565
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
Buffer(const Buffer &&)=delete
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
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:296
static bool is_disabled_low(ulong mode)
Check if the doublewrite mode is disabled.
Definition: buf0dblwr.h:377
static bool is_same(ulong new_value)
Check if the mode transition is equivalent.
Definition: buf0dblwr.cc:108
static bool is_enabled_to_disabled(ulong new_value)
Check if the mode transition is from enabled to disabled.
Definition: buf0dblwr.h:400
static bool is_atomic(ulong mode)
Check if the dblwr mode provides atomic writes.
Definition: buf0dblwr.h:368
static const char * to_string(ulong mode)
Convert the dblwr mode into a string representation.
Definition: buf0dblwr.cc:89
static bool is_disabled_to_enabled(ulong new_value)
Check if the mode transition is from disabled to enabled.
Definition: buf0dblwr.h:404
static bool is_enabled_low(ulong mode)
Check if doublewrite is enabled.
Definition: buf0dblwr.h:372
static bool is_reduced_low(ulong mode)
Check if the doublewrite mode is detect-only (aka reduced).
Definition: buf0dblwr.h:379
mode_t
The operating mode of doublewrite.
Definition: buf0dblwr.h:303
@ DETECT_ONLY
In this mode, dblwr is used only to detect torn writes.
Definition: buf0dblwr.h:313
@ FALSEE
Equal to OFF mode.
Definition: buf0dblwr.h:320
@ TRUEE
Equal to ON, DETECT_AND_RECOVER mode.
Definition: buf0dblwr.h:324
@ DETECT_AND_RECOVER
This mode is synonymous with ON, TRUEE.
Definition: buf0dblwr.h:316
@ ON
Equal to TRUEE and DETECT_AND_RECOVER modes.
Definition: buf0dblwr.h:308
@ OFF
Equal to FALSEE.
Definition: buf0dblwr.h:305
When –innodb-doublewrite=DETECT_ONLY, page contents are not written to the dblwr buffer.
Definition: buf0dblwr.h:271
lsn_t m_lsn
Definition: buf0dblwr.h:274
page_no_t m_page_no
Definition: buf0dblwr.h:273
space_id_t m_space_id
Definition: buf0dblwr.h:272
Reduced_entry(space_id_t space_id, page_no_t page_no, lsn_t lsn)
Definition: buf0dblwr.h:278
Reduced_entry(buf_page_t *bpage)
Definition: buf0dblwr.cc:3633
byte * write(byte *ptr)
Definition: buf0dblwr.h:281
Tablespace or log data space.
Definition: fil0fil.h:235
unsigned long int ulint
Definition: univ.i:406
Utilities for byte operations.
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93
static uint64_t lsn
Definition: xcom_base.cc:446