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