| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1995, 2026, Oracle and/or its affiliates. |
| 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 designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/buf0flu.ic |
| 29 |
The database buffer pool flush algorithm |
| 30 |
|
| 31 |
Created 11/5/1995 Heikki Tuuri |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#include "buf0buf.h" |
| 35 |
#include "fsp0types.h" |
| 36 |
#include "mtr0mtr.h" |
| 37 |
#include "srv0srv.h" |
| 38 |
|
| 39 |
#ifndef UNIV_HOTBACKUP |
| 40 |
/** Inserts a modified block into the flush list. */ |
| 41 |
void buf_flush_insert_into_flush_list( |
| 42 |
buf_pool_t *buf_pool, /*!< buffer pool instance */ |
| 43 |
buf_block_t *block, /*!< in/out: block which is modified */ |
| 44 |
lsn_t lsn); /*!< in: oldest modification */ |
| 45 |
|
| 46 |
/** Inserts a modified block into the flush list in the right sorted position. |
| 47 |
This function is used by recovery, because there the modifications do not |
| 48 |
necessarily come in the order of lsn's. */ |
| 49 |
void buf_flush_insert_sorted_into_flush_list( |
| 50 |
buf_pool_t *buf_pool, /*!< buffer pool instance */ |
| 51 |
buf_block_t *block, /*!< in/out: block which is modified */ |
| 52 |
lsn_t lsn); /*!< in: oldest modification */ |
| 53 |
|
| 54 |
/** This function should be called at a mini-transaction commit, if a page was |
| 55 |
modified in it. Puts the block to the list of modified blocks, if it is not |
| 56 |
already in it. */ |
| 57 |
static inline void buf_flush_note_modification( |
| 58 |
buf_block_t *block, /*!< in: block which is modified */ |
| 59 |
lsn_t start_lsn, /*!< in: start lsn of the mtr that |
| 60 |
modified this block */ |
| 61 |
lsn_t end_lsn, /*!< in: end lsn of the mtr that |
| 62 |
modified this block */ |
| 63 |
Flush_observer *observer) /*!< in: flush observer */ |
| 64 |
{ |
| 65 |
#ifdef UNIV_DEBUG |
| 66 |
{ |
| 67 |
/* Allow write to proceed to shared temporary tablespace |
| 68 |
in read-only mode. */ |
| 69 |
ut_ad(!srv_read_only_mode || |
| 70 |
fsp_is_system_temporary(block->page.id.space())); |
| 71 |
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); |
| 72 |
ut_ad(block->page.buf_fix_count > 0); |
| 73 |
|
| 74 |
buf_pool_t *buf_pool = buf_pool_from_block(block); |
| 75 |
|
| 76 |
ut_ad(!buf_flush_list_mutex_own(buf_pool)); |
| 77 |
} |
| 78 |
#endif /* UNIV_DEBUG */ |
| 79 |
|
| 80 |
mutex_enter(&block->mutex); |
| 81 |
|
| 82 |
if (end_lsn != 0) { |
| 83 |
ut_ad(block->page.get_newest_lsn() <= end_lsn); |
| 84 |
block->page.set_newest_lsn(end_lsn); |
| 85 |
} else { |
| 86 |
/* Do nothing. This is the case with no-redo mtr and it |
| 87 |
possibly could re-modify some earlier dirtied page, in |
| 88 |
which case we don't want to change oldest/newest lsns. |
| 89 |
If that's not the case, we will set newest_modification |
| 90 |
within buf_flush_insert_into_flush_list call. That's |
| 91 |
because we can't read the value now, because we don't |
| 92 |
hold the flush list mutex yet. */ |
| 93 |
} |
| 94 |
|
| 95 |
if (observer != nullptr) { |
| 96 |
block->page.set_flush_observer(observer); |
| 97 |
} else { |
| 98 |
block->page.reset_flush_observer(); |
| 99 |
} |
| 100 |
|
| 101 |
if (!block->page.is_dirty()) { |
| 102 |
auto buf_pool = buf_pool_from_block(block); |
| 103 |
|
| 104 |
buf_flush_insert_into_flush_list(buf_pool, block, start_lsn); |
| 105 |
} else if (start_lsn != 0) { |
| 106 |
ut_ad(block->page.get_oldest_lsn() <= start_lsn); |
| 107 |
} |
| 108 |
|
| 109 |
buf_page_mutex_exit(block); |
| 110 |
|
| 111 |
srv_stats.buf_pool_write_requests.inc(); |
| 112 |
} |
| 113 |
|
| 114 |
/** This function should be called when recovery has modified a buffer page. */ |
| 115 |
static inline void buf_flush_recv_note_modification( |
| 116 |
buf_block_t *block, /*!< in: block which is modified */ |
| 117 |
lsn_t start_lsn, /*!< in: start lsn of the first mtr in a |
| 118 |
set of mtr's */ |
| 119 |
lsn_t end_lsn) /*!< in: end lsn of the last mtr in the |
| 120 |
set of mtr's */ |
| 121 |
{ |
| 122 |
#ifdef UNIV_DEBUG |
| 123 |
{ |
| 124 |
ut_ad(!srv_read_only_mode); |
| 125 |
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); |
| 126 |
ut_ad(block->page.buf_fix_count > 0); |
| 127 |
|
| 128 |
buf_pool_t *buf_pool = buf_pool_from_block(block); |
| 129 |
|
| 130 |
ut_ad(!buf_flush_list_mutex_own(buf_pool)); |
| 131 |
|
| 132 |
ut_ad(start_lsn != 0); |
| 133 |
ut_ad(block->page.get_newest_lsn() <= end_lsn); |
| 134 |
} |
| 135 |
#endif /* UNIV_DEBUG */ |
| 136 |
|
| 137 |
buf_page_mutex_enter(block); |
| 138 |
|
| 139 |
block->page.set_newest_lsn(end_lsn); |
| 140 |
|
| 141 |
if (!block->page.is_dirty()) { |
| 142 |
buf_pool_t *buf_pool = buf_pool_from_block(block); |
| 143 |
|
| 144 |
buf_flush_insert_sorted_into_flush_list(buf_pool, block, start_lsn); |
| 145 |
} else { |
| 146 |
ut_ad(block->page.get_oldest_lsn() <= start_lsn); |
| 147 |
} |
| 148 |
|
| 149 |
buf_page_mutex_exit(block); |
| 150 |
} |
| 151 |
#endif /* !UNIV_HOTBACKUP */ |