MySQL  8.0.19
Source Code Documentation
buf0dblwr.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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 "log0log.h"
38 #include "log0recv.h"
39 #include "univ.i"
40 #include "ut0byte.h"
41 
42 /** Doublewrite system */
43 extern buf_dblwr_t *buf_dblwr;
44 /** Set to TRUE when the doublewrite buffer is being created */
45 extern ibool buf_dblwr_being_created;
46 
47 /** Creates the doublewrite buffer to a new InnoDB installation. The header of
48  the doublewrite buffer is placed on the trx system header page.
49  @return true if successful, false if not. */
50 MY_ATTRIBUTE((warn_unused_result))
51 bool buf_dblwr_create(void);
52 
53 /** At a database startup initializes the doublewrite buffer memory structure if
54  we already have a doublewrite buffer created in the data files. If we are
55  upgrading to an InnoDB version which supports multiple tablespaces, then this
56  function performs the necessary update operations. If we are in a crash
57  recovery, this function loads the pages from double write buffer into memory.
58  @return DB_SUCCESS or error code */
60 
61 /** Process and remove the double write buffer pages for all tablespaces. */
62 void buf_dblwr_process(void);
63 
64 /** frees doublewrite buffer. */
65 void buf_dblwr_free(void);
66 /** Updates the doublewrite buffer when an IO request is completed. */
67 void buf_dblwr_update(
68  const buf_page_t *bpage, /*!< in: buffer block descriptor */
69  buf_flush_t flush_type); /*!< in: flush type */
70 /** Determines if a page number is located inside the doublewrite buffer.
71  @return true if the location is inside the two blocks of the
72  doublewrite buffer */
73 ibool buf_dblwr_page_inside(page_no_t page_no); /*!< in: page number */
74 
75 /** Posts a buffer page for writing. If the doublewrite memory buffer
76 is full, calls buf_dblwr_flush_buffered_writes and waits for for free
77 space to appear.
78 @param[in] bpage buffer block to write */
80 
81 /** Flush a batch of writes to the datafiles that have already been
82  written to the dblwr buffer on disk. */
84 
85 /** Flushes possible buffered writes from the doublewrite memory buffer to disk,
86  and also wakes up the aio thread if simulated aio is used. It is very
87  important to call this function after a batch of writes has been posted,
88  and also when we may have to wait for a page latch! Otherwise a deadlock
89  of threads can occur. */
91 /** Writes a page to the doublewrite buffer on disk, sync it, then write
92  the page to the datafile and sync the datafile. This function is used
93  for single page flushes. If all the buffers allocated for single page
94  flushes in the doublewrite buffer are in use we wait here for one to
95  become free. We are guaranteed that a slot will become free because any
96  thread that is using a slot must also release the slot before leaving
97  this function. */
99  buf_page_t *bpage, /*!< in: buffer block to write */
100  bool sync); /*!< in: true if sync IO requested */
101 
102 /** Recover pages from the double write buffer for a specific tablespace.
103 The pages that were read from the doublewrite buffer are written to the
104 tablespace they belong to.
105 @param[in] space Tablespace instance */
107 
108 /** Doublewrite control struct */
109 struct buf_dblwr_t {
110  ib_mutex_t mutex; /*!< mutex protecting the first_free
111  field and write_buf */
112  page_no_t block1; /*!< the page number of the first
113  doublewrite block (64 pages) */
114  page_no_t block2; /*!< page number of the second block */
115  page_no_t first_free; /*!< first free position in write_buf
116  measured in units of UNIV_PAGE_SIZE */
117  ulint b_reserved; /*!< number of slots currently reserved
118  for batch flush. */
119  os_event_t b_event; /*!< event where threads wait for a
120  batch flush to end. */
121  ulint s_reserved; /*!< number of slots currently
122  reserved for single page flushes. */
123  os_event_t s_event; /*!< event where threads wait for a
124  single page flush slot. */
125  bool *in_use; /*!< flag used to indicate if a slot is
126  in use. Only used for single page
127  flushes. */
128  bool batch_running; /*!< set to TRUE if currently a batch
129  is being written from the doublewrite
130  buffer. */
131  byte *write_buf; /*!< write buffer used in writing to the
132  doublewrite buffer, aligned to an
133  address divisible by UNIV_PAGE_SIZE
134  (which is required by Windows aio) */
135  byte *write_buf_unaligned; /*!< pointer to write_buf,
136  but unaligned */
137  buf_page_t **buf_block_arr; /*!< array to store pointers to
138  the buffer blocks which have been
139  cached to write_buf */
140 };
141 
142 #endif
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
buf_dblwr_t::write_buf
byte * write_buf
write buffer used in writing to the doublewrite buffer, aligned to an address divisible by UNIV_PAGE_...
Definition: buf0dblwr.h:131
buf_dblwr_t::buf_block_arr
buf_page_t ** buf_block_arr
array to store pointers to the buffer blocks which have been cached to write_buf
Definition: buf0dblwr.h:137
buf_dblwr_t::s_event
os_event_t s_event
event where threads wait for a single page flush slot.
Definition: buf0dblwr.h:123
buf_dblwr_t::mutex
ib_mutex_t mutex
mutex protecting the first_free field and write_buf
Definition: buf0dblwr.h:110
buf_dblwr_t::in_use
bool * in_use
flag used to indicate if a slot is in use.
Definition: buf0dblwr.h:125
os_event
InnoDB condition variable.
Definition: os0event.cc:66
buf_dblwr_t::write_buf_unaligned
byte * write_buf_unaligned
pointer to write_buf, but unaligned
Definition: buf0dblwr.h:135
dberr_t
dberr_t
Definition: db0err.h:38
buf_dblwr_process
void buf_dblwr_process(void)
Process and remove the double write buffer pages for all tablespaces.
Definition: buf0dblwr.cc:591
fil_space_t
Tablespace or log data space.
Definition: fil0fil.h:218
buf_page_t
Definition: buf0buf.h:1161
buf_dblwr_flush_buffered_writes
void buf_dblwr_flush_buffered_writes(void)
Flushes possible buffered writes from the doublewrite memory buffer to disk, and also wakes up the ai...
Definition: buf0dblwr.cc:885
buf_dblwr_page_inside
ibool buf_dblwr_page_inside(page_no_t page_no)
Determines if a page number is located inside the doublewrite buffer.
Definition: buf0dblwr.cc:55
buf_dblwr_t::s_reserved
ulint s_reserved
number of slots currently reserved for single page flushes.
Definition: buf0dblwr.h:121
buf_dblwr_init_or_load_pages
dberr_t buf_dblwr_init_or_load_pages(pfs_os_file_t file, const char *path)
At a database startup initializes the doublewrite buffer memory structure if we already have a double...
Definition: buf0dblwr.cc:319
buf_dblwr_t::block2
page_no_t block2
page number of the second block
Definition: buf0dblwr.h:114
buf_dblwr_write_single_page
void buf_dblwr_write_single_page(buf_page_t *bpage, bool sync)
Writes a page to the doublewrite buffer on disk, sync it, then write the page to the datafile and syn...
Definition: buf0dblwr.cc:1110
buf_dblwr_add_to_batch
void buf_dblwr_add_to_batch(buf_page_t *bpage)
Posts a buffer page for writing.
Definition: buf0dblwr.cc:1033
buf_dblwr_t::first_free
page_no_t first_free
first free position in write_buf measured in units of UNIV_PAGE_SIZE
Definition: buf0dblwr.h:115
buf_flush_t
buf_flush_t
Flags for flush types.
Definition: buf0types.h:65
buf_dblwr_t::batch_running
bool batch_running
set to TRUE if currently a batch is being written from the doublewrite buffer.
Definition: buf0dblwr.h:128
buf_dblwr_being_created
ibool buf_dblwr_being_created
Set to TRUE when the doublewrite buffer is being created.
Definition: buf0dblwr.cc:50
log0log.h
pfs_os_file_t
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:136
buf_dblwr_free
void buf_dblwr_free(void)
frees doublewrite buffer.
Definition: buf0dblwr.cc:659
buf_dblwr
buf_dblwr_t * buf_dblwr
Doublewrite system.
Definition: buf0dblwr.cc:47
flush_type
flush_type
Definition: my_sys.h:289
buf0types.h
path
static char * path
Definition: mysqldump.cc:130
buf_dblwr_sync_datafiles
void buf_dblwr_sync_datafiles()
Flush a batch of writes to the datafiles that have already been written to the dblwr buffer on disk.
Definition: buf0dblwr.cc:93
buf_dblwr_t::block1
page_no_t block1
the page number of the first doublewrite block (64 pages)
Definition: buf0dblwr.h:112
buf_dblwr_t::b_event
os_event_t b_event
event where threads wait for a batch flush to end.
Definition: buf0dblwr.h:119
buf_dblwr_update
void buf_dblwr_update(const buf_page_t *bpage, buf_flush_t flush_type)
Updates the doublewrite buffer when an IO request is completed.
Definition: buf0dblwr.cc:681
buf_dblwr_t
Doublewrite control struct.
Definition: buf0dblwr.h:109
buf_dblwr_recover_pages
void buf_dblwr_recover_pages(fil_space_t *space)
Recover pages from the double write buffer for a specific tablespace.
Definition: buf0dblwr.cc:630
buf_dblwr_t::b_reserved
ulint b_reserved
number of slots currently reserved for batch flush.
Definition: buf0dblwr.h:117
buf_dblwr_create
bool buf_dblwr_create(void)
Creates the doublewrite buffer to a new InnoDB installation.
Definition: buf0dblwr.cc:153
log0recv.h
ut0byte.h