1/*****************************************************************************
2
3Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/**************************************************//**
20@file include/buf0flu.ic
21The database buffer pool flush algorithm
22
23Created 11/5/1995 Heikki Tuuri
24*******************************************************/
25
26#include "buf0buf.h"
27#include "mtr0mtr.h"
28#include "srv0srv.h"
29#include "fsp0types.h"
30
31/********************************************************************//**
32Inserts a modified block into the flush list. */
33void
34buf_flush_insert_into_flush_list(
35/*=============================*/
36	buf_pool_t*	buf_pool,	/*!< buffer pool instance */
37	buf_block_t*	block,		/*!< in/out: block which is modified */
38	lsn_t		lsn);		/*!< in: oldest modification */
39
40/********************************************************************//**
41This function should be called at a mini-transaction commit, if a page was
42modified in it. Puts the block to the list of modified blocks, if it is not
43already in it. */
44UNIV_INLINE
45void
46buf_flush_note_modification(
47/*========================*/
48	buf_block_t*	block,		/*!< in: block which is modified */
49	lsn_t		start_lsn,	/*!< in: start lsn of the mtr that
50					modified this block */
51	lsn_t		end_lsn,	/*!< in: end lsn of the mtr that
52					modified this block */
53	FlushObserver*	observer)	/*!< in: flush observer */
54{
55	mutex_enter(&block->mutex);
56	ut_ad(!srv_read_only_mode
57	      || fsp_is_system_temporary(block->page.id.space()));
58	ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
59	ut_ad(block->page.buf_fix_count > 0);
60	ut_ad(block->page.newest_modification <= end_lsn);
61	block->page.newest_modification = end_lsn;
62
63	/* Don't allow to set flush observer from non-null to null,
64	or from one observer to another. */
65	ut_ad(block->page.flush_observer == NULL
66	      || block->page.flush_observer == observer);
67	block->page.flush_observer = observer;
68
69	if (block->page.oldest_modification == 0) {
70		buf_pool_t*	buf_pool = buf_pool_from_block(block);
71
72		buf_flush_insert_into_flush_list(buf_pool, block, start_lsn);
73	} else {
74		ut_ad(block->page.oldest_modification <= start_lsn);
75	}
76
77	mutex_exit(&block->mutex);
78
79	srv_stats.buf_pool_write_requests.inc();
80}
81