summaryrefslogtreecommitdiff
path: root/storage/innobase/include/read0read.ic
blob: 82c1028f12ee806fa7f31f7bd9269148972aa6c7 (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
/*****************************************************************************

Copyright (c) 1997, 2012, Oracle and/or its affiliates. All Rights Reserved.

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, Suite 500, Boston, MA 02110-1335 USA

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

/**************************************************//**
@file include/read0read.ic
Cursor read

Created 2/16/1997 Heikki Tuuri
*******************************************************/

#include "trx0sys.h"

#ifdef UNIV_DEBUG
/*********************************************************************//**
Validates a read view object. */
static
bool
read_view_validate(
/*===============*/
	const read_view_t*	view)	/*!< in: view to validate */
{
	ut_ad(mutex_own(&trx_sys->mutex));

	/* Check that the view->trx_ids array is in descending order. */
	for (ulint i = 1; i < view->n_trx_ids; ++i) {

		ut_a(view->trx_ids[i] < view->trx_ids[i - 1]);
	}

	return(true);
}

/** Functor to validate the view list. */
struct	ViewCheck {

	ViewCheck() : m_prev_view(0) { }

	void	operator()(const read_view_t* view)
	{
		ut_a(m_prev_view == NULL
		     || m_prev_view->low_limit_no >= view->low_limit_no);

		m_prev_view = view;
	}

	const read_view_t*	m_prev_view;
};

/*********************************************************************//**
Validates a read view list. */
static
bool
read_view_list_validate(void)
/*=========================*/
{
	ut_ad(mutex_own(&trx_sys->mutex));

	ut_list_map(trx_sys->view_list, &read_view_t::view_list, ViewCheck());

	return(true);
}
#endif /* UNIV_DEBUG */

/*********************************************************************//**
Checks if a read view sees the specified transaction.
@return	true if sees */
UNIV_INLINE
bool
read_view_sees_trx_id(
/*==================*/
	const read_view_t*	view,	/*!< in: read view */
	trx_id_t		trx_id)	/*!< in: trx id */
{
	if (trx_id < view->up_limit_id) {

		return(true);
	} else if (trx_id >= view->low_limit_id) {

		return(false);
	} else {
		ulint	lower = 0;
		ulint	upper = view->n_trx_ids - 1;

		ut_a(view->n_trx_ids > 0);

		do {
			ulint		mid	= (lower + upper) >> 1;
			trx_id_t	mid_id	= view->trx_ids[mid];

			if (mid_id == trx_id) {
				return(FALSE);
			} else if (mid_id < trx_id) {
				if (mid > 0) {
					upper = mid - 1;
				} else {
					break;
				}
			} else {
				lower = mid + 1;
			}
		} while (lower <= upper);
	}

	return(true);
}

/*********************************************************************//**
Remove a read view from the trx_sys->view_list. */
UNIV_INLINE
void
read_view_remove(
/*=============*/
	read_view_t*	view,		/*!< in: read view, can be 0 */
	bool		own_mutex)	/*!< in: true if caller owns the
					trx_sys_t::mutex */
{
	if (view != 0) {
		if (!own_mutex) {
			mutex_enter(&trx_sys->mutex);
		}

		ut_ad(read_view_validate(view));

		UT_LIST_REMOVE(view_list, trx_sys->view_list, view);

		ut_ad(read_view_list_validate());

		if (!own_mutex) {
			mutex_exit(&trx_sys->mutex);
		}
	}
}