mariadb/storage/xtradb/include/read0read.ic

132 lines
3.3 KiB
Text
Raw Normal View History

2009-03-25 23:11:11 -07:00
/*****************************************************************************
2013-12-16 15:38:05 +01:00
Copyright (c) 1997, 2012, Oracle and/or its affiliates. All Rights Reserved.
2009-03-25 23:11:11 -07:00
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
2013-12-16 15:38:05 +01:00
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
2009-03-25 23:11:11 -07:00
*****************************************************************************/
2009-09-07 10:22:53 +00:00
/**************************************************//**
@file include/read0read.ic
Cursor read
Created 2/16/1997 Heikki Tuuri
*******************************************************/
2013-12-16 15:38:05 +01:00
#include "trx0sys.h"
#ifdef UNIV_DEBUG
2009-09-07 10:22:53 +00:00
/*********************************************************************//**
2013-12-16 15:38:05 +01:00
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));
ut_ad(view->max_descr >= view->n_descr);
ut_ad(view->descriptors == NULL || view->max_descr > 0);
2013-05-08 09:52:54 +02:00
2013-12-16 15:38:05 +01:00
/* Check that the view->descriptors array is in ascending order. */
for (ulint i = 1; i < view->n_descr; ++i) {
2013-05-08 09:52:54 +02:00
2013-12-16 15:38:05 +01:00
ut_a(view->descriptors[i] > view->descriptors[i - 1]);
}
2013-12-16 15:38:05 +01:00
return(true);
}
2013-12-16 15:38:05 +01:00
/** Functor to validate the view list. */
struct ViewCheck {
2013-05-08 09:52:54 +02:00
2013-12-16 15:38:05 +01:00
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)
/*=========================*/
{
2013-12-16 15:38:05 +01:00
ut_ad(mutex_own(&trx_sys->mutex));
2013-12-16 15:38:05 +01:00
ut_list_map(trx_sys->view_list, &read_view_t::view_list, ViewCheck());
return(true);
}
2013-12-16 15:38:05 +01:00
#endif /* UNIV_DEBUG */
2009-09-07 10:22:53 +00:00
/*********************************************************************//**
Checks if a read view sees the specified transaction.
2013-12-16 15:38:05 +01:00
@return true if sees */
UNIV_INLINE
2013-12-16 15:38:05 +01:00
bool
read_view_sees_trx_id(
/*==================*/
2009-09-07 10:22:53 +00:00
const read_view_t* view, /*!< in: read view */
trx_id_t trx_id) /*!< in: trx id */
{
2011-07-14 21:22:41 +02:00
if (trx_id < view->up_limit_id) {
2013-12-16 15:38:05 +01:00
return(true);
} else if (trx_id >= view->low_limit_id) {
2013-12-16 15:38:05 +01:00
return(false);
}
2013-05-08 09:52:54 +02:00
/* Do a binary search over this view's descriptors array */
2013-05-08 09:52:54 +02:00
return(trx_find_descriptor(view->descriptors, view->n_descr,
trx_id) == NULL);
}
2013-12-16 15:38:05 +01:00
/*********************************************************************//**
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);
}
}
}