summaryrefslogtreecommitdiff
path: root/storage/innobase/include/mtr0mtr.ic
blob: 02ad88194fb04e89b963e0321b8fc2b9cce775aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*****************************************************************************

Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA

*****************************************************************************/

/**************************************************//**
@file include/mtr0mtr.ic
Mini-transaction buffer

Created 11/26/1995 Heikki Tuuri
*******************************************************/

#include "buf0buf.h"

/** Check if a mini-transaction is dirtying a clean page.
@return true if the mtr is dirtying a clean page. */
inline bool mtr_t::is_block_dirtied(const buf_block_t *block)
{
  ut_ad(block->page.in_file());
  ut_ad(block->page.frame);
  ut_ad(block->page.buf_fix_count());
  return block->page.oldest_modification() <= 1;
}

/**
Pushes an object to an mtr memo stack. */
void
mtr_t::memo_push(void* object, mtr_memo_type_t type)
{
	ut_ad(is_active());
	ut_ad(object != NULL);
	ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
	ut_ad(type <= MTR_MEMO_SPACE_S_LOCK);
	ut_ad(ut_is_2pow(type));

	/* If this mtr has x-fixed a clean page then we set
	the made_dirty flag. This tells us if we need to
	grab log_sys.flush_order_mutex at mtr_t::commit() so that we
	can insert the dirtied page into the flush list. */

	if ((type == MTR_MEMO_PAGE_X_FIX || type == MTR_MEMO_PAGE_SX_FIX)
	    && !m_made_dirty) {

		m_made_dirty = is_block_dirtied(
			reinterpret_cast<const buf_block_t*>(object));
	}

	mtr_memo_slot_t* slot = m_memo.push<mtr_memo_slot_t*>(sizeof(*slot));

	slot->type = type;
	slot->object = object;
}

/**
Releases the (index tree) s-latch stored in an mtr memo after a
savepoint. */
void
mtr_t::release_s_latch_at_savepoint(
	ulint		savepoint,
	index_lock*	lock)
{
	ut_ad(is_active());
	ut_ad(m_memo.size() > savepoint);

	mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);

	ut_ad(slot->object == lock);
	ut_ad(slot->type == MTR_MEMO_S_LOCK);

	lock->s_unlock();

	slot->object = NULL;
}

/**
SX-latches the not yet latched block after a savepoint. */

void
mtr_t::sx_latch_at_savepoint(
	ulint		savepoint,
	buf_block_t*	block)
{
	ut_ad(is_active());
	ut_ad(m_memo.size() > savepoint);

	ut_ad(!memo_contains_flagged(
			block,
			MTR_MEMO_PAGE_S_FIX
			| MTR_MEMO_PAGE_X_FIX
			| MTR_MEMO_PAGE_SX_FIX));

	mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);

	ut_ad(slot->object == block);

	/* == RW_NO_LATCH */
	ut_a(slot->type == MTR_MEMO_BUF_FIX);

	block->page.lock.u_lock();
	ut_ad(!block->page.is_io_fixed());

	if (!m_made_dirty) {
		m_made_dirty = is_block_dirtied(block);
	}

	slot->type = MTR_MEMO_PAGE_SX_FIX;
}

/**
X-latches the not yet latched block after a savepoint. */

void
mtr_t::x_latch_at_savepoint(
	ulint		savepoint,
	buf_block_t*	block)
{
	ut_ad(is_active());
	ut_ad(m_memo.size() > savepoint);

	ut_ad(!memo_contains_flagged(
			block,
			MTR_MEMO_PAGE_S_FIX
			| MTR_MEMO_PAGE_X_FIX
			| MTR_MEMO_PAGE_SX_FIX));

	mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);

	ut_ad(slot->object == block);

	/* == RW_NO_LATCH */
	ut_a(slot->type == MTR_MEMO_BUF_FIX);

	block->page.lock.x_lock();
	ut_ad(!block->page.is_io_fixed());

	if (!m_made_dirty) {
		m_made_dirty = is_block_dirtied(block);
	}

	slot->type = MTR_MEMO_PAGE_X_FIX;
}

/**
Releases the block in an mtr memo after a savepoint. */

void
mtr_t::release_block_at_savepoint(
	ulint		savepoint,
	buf_block_t*	block)
{
  ut_ad(is_active());

  mtr_memo_slot_t *slot = m_memo.at<mtr_memo_slot_t*>(savepoint);

  ut_a(slot->object == block);
  slot->object= nullptr;
  block->page.unfix();

  switch (slot->type) {
  case MTR_MEMO_PAGE_S_FIX:
    block->page.lock.s_unlock();
    break;
  case MTR_MEMO_PAGE_SX_FIX:
  case MTR_MEMO_PAGE_X_FIX:
    block->page.lock.u_or_x_unlock(slot->type == MTR_MEMO_PAGE_SX_FIX);
    break;
  default:
    break;
  }
}