mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
Bug#16138582 MTR_MEMO_RELEASE AND DYN_ARRAY TOGETHER ARE VERY INEFFICIENT
Get rid of O(n^2) scan in dyn array (mtr->memo) operations, accessing the dyn array blocks directly. dyn_array_get_last_block(), dyn_array_get_next_block(), dyn_array_get_prev_block(): Define as a constness-preserving macro. Add const qualifiers to many dyn_array functions. mtr_memo_slot_release_func(): Renamed from mtr_memo_slot_release(): Make mtr_t* a debug-only parameter. Assume that slot->object != NULL. mtr_memo_pop_all(): Access the dyn_array blocks directly, replacing O(n^2) operation with O(n). mtr_memo_release(): Access the dyn_array blocks directly, replacing O(n^2) operation with O(n). This caused the performance problem. rb#1540 approved by Jimmy Yang
This commit is contained in:
parent
4ccfba724f
commit
49adfa3d19
5 changed files with 173 additions and 215 deletions
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
|
||||
Copyright (c) 1996, 2013, 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
|
||||
|
@ -11,8 +11,8 @@ 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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
@ -35,7 +35,7 @@ UNIV_INTERN
|
|||
dyn_block_t*
|
||||
dyn_array_add_block(
|
||||
/*================*/
|
||||
dyn_array_t* arr) /*!< in: dyn array */
|
||||
dyn_array_t* arr) /*!< in/out: dyn array */
|
||||
{
|
||||
mem_heap_t* heap;
|
||||
dyn_block_t* block;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
|
||||
Copyright (c) 1996, 2013, 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
|
||||
|
@ -11,8 +11,8 @@ 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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
@ -47,15 +47,17 @@ UNIV_INLINE
|
|||
dyn_array_t*
|
||||
dyn_array_create(
|
||||
/*=============*/
|
||||
dyn_array_t* arr); /*!< in: pointer to a memory buffer of
|
||||
dyn_array_t* arr) /*!< in/out memory buffer of
|
||||
size sizeof(dyn_array_t) */
|
||||
__attribute__((nonnull));
|
||||
/************************************************************//**
|
||||
Frees a dynamic array. */
|
||||
UNIV_INLINE
|
||||
void
|
||||
dyn_array_free(
|
||||
/*===========*/
|
||||
dyn_array_t* arr); /*!< in: dyn array */
|
||||
dyn_array_t* arr) /*!< in,own: dyn array */
|
||||
__attribute__((nonnull));
|
||||
/*********************************************************************//**
|
||||
Makes room on top of a dyn array and returns a pointer to a buffer in it.
|
||||
After copying the elements, the caller must close the buffer using
|
||||
|
@ -66,8 +68,9 @@ byte*
|
|||
dyn_array_open(
|
||||
/*===========*/
|
||||
dyn_array_t* arr, /*!< in: dynamic array */
|
||||
ulint size); /*!< in: size in bytes of the buffer; MUST be
|
||||
ulint size) /*!< in: size in bytes of the buffer; MUST be
|
||||
smaller than DYN_ARRAY_DATA_SIZE! */
|
||||
__attribute__((nonnull, warn_unused_result));
|
||||
/*********************************************************************//**
|
||||
Closes the buffer returned by dyn_array_open. */
|
||||
UNIV_INLINE
|
||||
|
@ -75,7 +78,8 @@ void
|
|||
dyn_array_close(
|
||||
/*============*/
|
||||
dyn_array_t* arr, /*!< in: dynamic array */
|
||||
byte* ptr); /*!< in: buffer space from ptr up was not used */
|
||||
const byte* ptr) /*!< in: end of used space */
|
||||
__attribute__((nonnull));
|
||||
/*********************************************************************//**
|
||||
Makes room on top of a dyn array and returns a pointer to
|
||||
the added element. The caller must copy the element to
|
||||
|
@ -85,8 +89,9 @@ UNIV_INLINE
|
|||
void*
|
||||
dyn_array_push(
|
||||
/*===========*/
|
||||
dyn_array_t* arr, /*!< in: dynamic array */
|
||||
ulint size); /*!< in: size in bytes of the element */
|
||||
dyn_array_t* arr, /*!< in/out: dynamic array */
|
||||
ulint size) /*!< in: size in bytes of the element */
|
||||
__attribute__((nonnull, warn_unused_result));
|
||||
/************************************************************//**
|
||||
Returns pointer to an element in dyn array.
|
||||
@return pointer to element */
|
||||
|
@ -94,9 +99,10 @@ UNIV_INLINE
|
|||
void*
|
||||
dyn_array_get_element(
|
||||
/*==================*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
ulint pos); /*!< in: position of element as bytes
|
||||
from array start */
|
||||
const dyn_array_t* arr, /*!< in: dyn array */
|
||||
ulint pos) /*!< in: position of element
|
||||
in bytes from array start */
|
||||
__attribute__((nonnull, warn_unused_result));
|
||||
/************************************************************//**
|
||||
Returns the size of stored data in a dyn array.
|
||||
@return data size in bytes */
|
||||
|
@ -104,30 +110,33 @@ UNIV_INLINE
|
|||
ulint
|
||||
dyn_array_get_data_size(
|
||||
/*====================*/
|
||||
dyn_array_t* arr); /*!< in: dyn array */
|
||||
const dyn_array_t* arr) /*!< in: dyn array */
|
||||
__attribute__((nonnull, warn_unused_result, pure));
|
||||
/************************************************************//**
|
||||
Gets the first block in a dyn array. */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_first_block(
|
||||
/*======================*/
|
||||
dyn_array_t* arr); /*!< in: dyn array */
|
||||
Gets the first block in a dyn array.
|
||||
@param arr dyn array
|
||||
@return first block */
|
||||
#define dyn_array_get_first_block(arr) (arr)
|
||||
/************************************************************//**
|
||||
Gets the last block in a dyn array. */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_last_block(
|
||||
/*=====================*/
|
||||
dyn_array_t* arr); /*!< in: dyn array */
|
||||
Gets the last block in a dyn array.
|
||||
@param arr dyn array
|
||||
@return last block */
|
||||
#define dyn_array_get_last_block(arr) \
|
||||
((arr)->heap ? UT_LIST_GET_LAST((arr)->base) : (arr))
|
||||
/********************************************************************//**
|
||||
Gets the next block in a dyn array.
|
||||
@return pointer to next, NULL if end of list */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_next_block(
|
||||
/*=====================*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
dyn_block_t* block); /*!< in: dyn array block */
|
||||
@param arr dyn array
|
||||
@param block dyn array block
|
||||
@return pointer to next, NULL if end of list */
|
||||
#define dyn_array_get_next_block(arr, block) \
|
||||
((arr)->heap ? UT_LIST_GET_NEXT(list, block) : NULL)
|
||||
/********************************************************************//**
|
||||
Gets the previous block in a dyn array.
|
||||
@param arr dyn array
|
||||
@param block dyn array block
|
||||
@return pointer to previous, NULL if end of list */
|
||||
#define dyn_array_get_prev_block(arr, block) \
|
||||
((arr)->heap ? UT_LIST_GET_PREV(list, block) : NULL)
|
||||
/********************************************************************//**
|
||||
Gets the number of used bytes in a dyn array block.
|
||||
@return number of bytes used */
|
||||
|
@ -135,7 +144,8 @@ UNIV_INLINE
|
|||
ulint
|
||||
dyn_block_get_used(
|
||||
/*===============*/
|
||||
dyn_block_t* block); /*!< in: dyn array block */
|
||||
const dyn_block_t* block) /*!< in: dyn array block */
|
||||
__attribute__((nonnull, warn_unused_result, pure));
|
||||
/********************************************************************//**
|
||||
Gets pointer to the start of data in a dyn array block.
|
||||
@return pointer to data */
|
||||
|
@ -143,16 +153,18 @@ UNIV_INLINE
|
|||
byte*
|
||||
dyn_block_get_data(
|
||||
/*===============*/
|
||||
dyn_block_t* block); /*!< in: dyn array block */
|
||||
const dyn_block_t* block) /*!< in: dyn array block */
|
||||
__attribute__((nonnull, warn_unused_result, pure));
|
||||
/********************************************************//**
|
||||
Pushes n bytes to a dyn array. */
|
||||
UNIV_INLINE
|
||||
void
|
||||
dyn_push_string(
|
||||
/*============*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
dyn_array_t* arr, /*!< in/out: dyn array */
|
||||
const byte* str, /*!< in: string to write */
|
||||
ulint len); /*!< in: string length */
|
||||
ulint len) /*!< in: string length */
|
||||
__attribute__((nonnull));
|
||||
|
||||
/*#################################################################*/
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
|
||||
Copyright (c) 1996, 2013, 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
|
||||
|
@ -11,8 +11,8 @@ 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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
|
@ -35,56 +35,8 @@ UNIV_INTERN
|
|||
dyn_block_t*
|
||||
dyn_array_add_block(
|
||||
/*================*/
|
||||
dyn_array_t* arr); /*!< in: dyn array */
|
||||
|
||||
|
||||
/************************************************************//**
|
||||
Gets the first block in a dyn array. */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_first_block(
|
||||
/*======================*/
|
||||
dyn_array_t* arr) /*!< in: dyn array */
|
||||
{
|
||||
return(arr);
|
||||
}
|
||||
|
||||
/************************************************************//**
|
||||
Gets the last block in a dyn array. */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_last_block(
|
||||
/*=====================*/
|
||||
dyn_array_t* arr) /*!< in: dyn array */
|
||||
{
|
||||
if (arr->heap == NULL) {
|
||||
|
||||
return(arr);
|
||||
}
|
||||
|
||||
return(UT_LIST_GET_LAST(arr->base));
|
||||
}
|
||||
|
||||
/********************************************************************//**
|
||||
Gets the next block in a dyn array.
|
||||
@return pointer to next, NULL if end of list */
|
||||
UNIV_INLINE
|
||||
dyn_block_t*
|
||||
dyn_array_get_next_block(
|
||||
/*=====================*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
dyn_block_t* block) /*!< in: dyn array block */
|
||||
{
|
||||
ut_ad(arr && block);
|
||||
|
||||
if (arr->heap == NULL) {
|
||||
ut_ad(arr == block);
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(UT_LIST_GET_NEXT(list, block));
|
||||
}
|
||||
dyn_array_t* arr) /*!< in/out: dyn array */
|
||||
__attribute__((nonnull, warn_unused_result));
|
||||
|
||||
/********************************************************************//**
|
||||
Gets the number of used bytes in a dyn array block.
|
||||
|
@ -93,7 +45,7 @@ UNIV_INLINE
|
|||
ulint
|
||||
dyn_block_get_used(
|
||||
/*===============*/
|
||||
dyn_block_t* block) /*!< in: dyn array block */
|
||||
const dyn_block_t* block) /*!< in: dyn array block */
|
||||
{
|
||||
ut_ad(block);
|
||||
|
||||
|
@ -107,11 +59,11 @@ UNIV_INLINE
|
|||
byte*
|
||||
dyn_block_get_data(
|
||||
/*===============*/
|
||||
dyn_block_t* block) /*!< in: dyn array block */
|
||||
const dyn_block_t* block) /*!< in: dyn array block */
|
||||
{
|
||||
ut_ad(block);
|
||||
|
||||
return(block->data);
|
||||
return((byte*) block->data);
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
|
@ -121,7 +73,7 @@ UNIV_INLINE
|
|||
dyn_array_t*
|
||||
dyn_array_create(
|
||||
/*=============*/
|
||||
dyn_array_t* arr) /*!< in: pointer to a memory buffer of
|
||||
dyn_array_t* arr) /*!< in/out: memory buffer of
|
||||
size sizeof(dyn_array_t) */
|
||||
{
|
||||
ut_ad(arr);
|
||||
|
@ -132,10 +84,9 @@ dyn_array_create(
|
|||
arr->heap = NULL;
|
||||
arr->used = 0;
|
||||
|
||||
#ifdef UNIV_DEBUG
|
||||
arr->buf_end = 0;
|
||||
arr->magic_n = DYN_BLOCK_MAGIC_N;
|
||||
#endif
|
||||
ut_d(arr->buf_end = 0);
|
||||
ut_d(arr->magic_n = DYN_BLOCK_MAGIC_N);
|
||||
|
||||
return(arr);
|
||||
}
|
||||
|
||||
|
@ -151,9 +102,7 @@ dyn_array_free(
|
|||
mem_heap_free(arr->heap);
|
||||
}
|
||||
|
||||
#ifdef UNIV_DEBUG
|
||||
arr->magic_n = 0;
|
||||
#endif
|
||||
ut_d(arr->magic_n = 0);
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
|
@ -164,7 +113,7 @@ UNIV_INLINE
|
|||
void*
|
||||
dyn_array_push(
|
||||
/*===========*/
|
||||
dyn_array_t* arr, /*!< in: dynamic array */
|
||||
dyn_array_t* arr, /*!< in/out: dynamic array */
|
||||
ulint size) /*!< in: size in bytes of the element */
|
||||
{
|
||||
dyn_block_t* block;
|
||||
|
@ -176,24 +125,23 @@ dyn_array_push(
|
|||
ut_ad(size);
|
||||
|
||||
block = arr;
|
||||
used = block->used;
|
||||
|
||||
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
if (block->used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
/* Get the last array block */
|
||||
|
||||
block = dyn_array_get_last_block(arr);
|
||||
used = block->used;
|
||||
|
||||
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
if (block->used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
block = dyn_array_add_block(arr);
|
||||
used = block->used;
|
||||
}
|
||||
}
|
||||
|
||||
used = block->used;
|
||||
|
||||
block->used = used + size;
|
||||
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
||||
|
||||
return((block->data) + used);
|
||||
return(block->data + used);
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
|
@ -210,7 +158,6 @@ dyn_array_open(
|
|||
smaller than DYN_ARRAY_DATA_SIZE! */
|
||||
{
|
||||
dyn_block_t* block;
|
||||
ulint used;
|
||||
|
||||
ut_ad(arr);
|
||||
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
||||
|
@ -218,28 +165,23 @@ dyn_array_open(
|
|||
ut_ad(size);
|
||||
|
||||
block = arr;
|
||||
used = block->used;
|
||||
|
||||
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
if (block->used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
/* Get the last array block */
|
||||
|
||||
block = dyn_array_get_last_block(arr);
|
||||
used = block->used;
|
||||
|
||||
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
if (block->used + size > DYN_ARRAY_DATA_SIZE) {
|
||||
block = dyn_array_add_block(arr);
|
||||
used = block->used;
|
||||
ut_a(size <= DYN_ARRAY_DATA_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
||||
#ifdef UNIV_DEBUG
|
||||
ut_ad(arr->buf_end == 0);
|
||||
ut_d(arr->buf_end = block->used + size);
|
||||
|
||||
arr->buf_end = used + size;
|
||||
#endif
|
||||
return((block->data) + used);
|
||||
return(block->data + block->used);
|
||||
}
|
||||
|
||||
/*********************************************************************//**
|
||||
|
@ -248,8 +190,8 @@ UNIV_INLINE
|
|||
void
|
||||
dyn_array_close(
|
||||
/*============*/
|
||||
dyn_array_t* arr, /*!< in: dynamic array */
|
||||
byte* ptr) /*!< in: buffer space from ptr up was not used */
|
||||
dyn_array_t* arr, /*!< in/out: dynamic array */
|
||||
const byte* ptr) /*!< in: end of used space */
|
||||
{
|
||||
dyn_block_t* block;
|
||||
|
||||
|
@ -264,9 +206,7 @@ dyn_array_close(
|
|||
|
||||
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
||||
|
||||
#ifdef UNIV_DEBUG
|
||||
arr->buf_end = 0;
|
||||
#endif
|
||||
ut_d(arr->buf_end = 0);
|
||||
}
|
||||
|
||||
/************************************************************//**
|
||||
|
@ -276,12 +216,11 @@ UNIV_INLINE
|
|||
void*
|
||||
dyn_array_get_element(
|
||||
/*==================*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
ulint pos) /*!< in: position of element as bytes
|
||||
from array start */
|
||||
const dyn_array_t* arr, /*!< in: dyn array */
|
||||
ulint pos) /*!< in: position of element
|
||||
in bytes from array start */
|
||||
{
|
||||
dyn_block_t* block;
|
||||
ulint used;
|
||||
const dyn_block_t* block;
|
||||
|
||||
ut_ad(arr);
|
||||
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
||||
|
@ -290,21 +229,23 @@ dyn_array_get_element(
|
|||
block = dyn_array_get_first_block(arr);
|
||||
|
||||
if (arr->heap != NULL) {
|
||||
used = dyn_block_get_used(block);
|
||||
for (;;) {
|
||||
ulint used = dyn_block_get_used(block);
|
||||
|
||||
if (pos < used) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (pos >= used) {
|
||||
pos -= used;
|
||||
block = UT_LIST_GET_NEXT(list, block);
|
||||
ut_ad(block);
|
||||
|
||||
used = dyn_block_get_used(block);
|
||||
}
|
||||
}
|
||||
|
||||
ut_ad(block);
|
||||
ut_ad(dyn_block_get_used(block) >= pos);
|
||||
|
||||
return(block->data + pos);
|
||||
return((byte*) block->data + pos);
|
||||
}
|
||||
|
||||
/************************************************************//**
|
||||
|
@ -314,10 +255,10 @@ UNIV_INLINE
|
|||
ulint
|
||||
dyn_array_get_data_size(
|
||||
/*====================*/
|
||||
dyn_array_t* arr) /*!< in: dyn array */
|
||||
const dyn_array_t* arr) /*!< in: dyn array */
|
||||
{
|
||||
dyn_block_t* block;
|
||||
ulint sum = 0;
|
||||
const dyn_block_t* block;
|
||||
ulint sum = 0;
|
||||
|
||||
ut_ad(arr);
|
||||
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
||||
|
@ -344,7 +285,7 @@ UNIV_INLINE
|
|||
void
|
||||
dyn_push_string(
|
||||
/*============*/
|
||||
dyn_array_t* arr, /*!< in: dyn array */
|
||||
dyn_array_t* arr, /*!< in/out: dyn array */
|
||||
const byte* str, /*!< in: string to write */
|
||||
ulint len) /*!< in: string length */
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved.
|
||||
Copyright (c) 1995, 2013, 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
|
||||
|
@ -295,9 +295,10 @@ UNIV_INTERN
|
|||
void
|
||||
mtr_memo_release(
|
||||
/*=============*/
|
||||
mtr_t* mtr, /*!< in: mtr */
|
||||
mtr_t* mtr, /*!< in/out: mini-transaction */
|
||||
void* object, /*!< in: object */
|
||||
ulint type); /*!< in: object type: MTR_MEMO_S_LOCK, ... */
|
||||
ulint type) /*!< in: object type: MTR_MEMO_S_LOCK, ... */
|
||||
__attribute__((nonnull));
|
||||
#ifdef UNIV_DEBUG
|
||||
# ifndef UNIV_HOTBACKUP
|
||||
/**********************************************************//**
|
||||
|
@ -309,7 +310,8 @@ mtr_memo_contains(
|
|||
/*==============*/
|
||||
mtr_t* mtr, /*!< in: mtr */
|
||||
const void* object, /*!< in: object to search */
|
||||
ulint type); /*!< in: type of object */
|
||||
ulint type) /*!< in: type of object */
|
||||
__attribute__((warn_unused_result, nonnull));
|
||||
|
||||
/**********************************************************//**
|
||||
Checks if memo contains the given page.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*****************************************************************************
|
||||
|
||||
Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved.
|
||||
Copyright (c) 1995, 2013, 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
|
||||
|
@ -39,72 +39,81 @@ Created 11/26/1995 Heikki Tuuri
|
|||
# include "log0recv.h"
|
||||
/*****************************************************************//**
|
||||
Releases the item in the slot given. */
|
||||
static
|
||||
static __attribute__((nonnull))
|
||||
void
|
||||
mtr_memo_slot_release(
|
||||
/*==================*/
|
||||
mtr_t* mtr, /*!< in: mtr */
|
||||
mtr_memo_slot_release_func(
|
||||
/*=======================*/
|
||||
#ifdef UNIV_DEBUG
|
||||
mtr_t* mtr, /*!< in/out: mini-transaction */
|
||||
#endif /* UNIV_DEBUG */
|
||||
mtr_memo_slot_t* slot) /*!< in: memo slot */
|
||||
{
|
||||
void* object;
|
||||
ulint type;
|
||||
|
||||
ut_ad(mtr);
|
||||
ut_ad(slot);
|
||||
|
||||
#ifndef UNIV_DEBUG
|
||||
UT_NOT_USED(mtr);
|
||||
#endif /* UNIV_DEBUG */
|
||||
|
||||
object = slot->object;
|
||||
type = slot->type;
|
||||
|
||||
if (UNIV_LIKELY(object != NULL)) {
|
||||
if (type <= MTR_MEMO_BUF_FIX) {
|
||||
buf_page_release((buf_block_t*)object, type);
|
||||
} else if (type == MTR_MEMO_S_LOCK) {
|
||||
rw_lock_s_unlock((rw_lock_t*)object);
|
||||
#ifdef UNIV_DEBUG
|
||||
} else if (type != MTR_MEMO_X_LOCK) {
|
||||
ut_ad(type == MTR_MEMO_MODIFY);
|
||||
ut_ad(mtr_memo_contains(mtr, object,
|
||||
MTR_MEMO_PAGE_X_FIX));
|
||||
#endif /* UNIV_DEBUG */
|
||||
} else {
|
||||
rw_lock_x_unlock((rw_lock_t*)object);
|
||||
}
|
||||
}
|
||||
|
||||
void* object = slot->object;
|
||||
slot->object = NULL;
|
||||
|
||||
/* slot release is a local operation for the current mtr.
|
||||
We must not be holding the flush_order mutex while
|
||||
doing this. */
|
||||
ut_ad(!log_flush_order_mutex_own());
|
||||
|
||||
switch (slot->type) {
|
||||
case MTR_MEMO_PAGE_S_FIX:
|
||||
case MTR_MEMO_PAGE_X_FIX:
|
||||
case MTR_MEMO_BUF_FIX:
|
||||
buf_page_release((buf_block_t*) object, slot->type);
|
||||
break;
|
||||
case MTR_MEMO_S_LOCK:
|
||||
rw_lock_s_unlock((rw_lock_t*) object);
|
||||
break;
|
||||
case MTR_MEMO_X_LOCK:
|
||||
rw_lock_x_unlock((rw_lock_t*) object);
|
||||
break;
|
||||
#ifdef UNIV_DEBUG
|
||||
default:
|
||||
ut_ad(slot->type == MTR_MEMO_MODIFY);
|
||||
ut_ad(mtr_memo_contains(mtr, object, MTR_MEMO_PAGE_X_FIX));
|
||||
#endif /* UNIV_DEBUG */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UNIV_DEBUG
|
||||
# define mtr_memo_slot_release(mtr, slot) mtr_memo_slot_release_func(mtr, slot)
|
||||
#else /* UNIV_DEBUG */
|
||||
# define mtr_memo_slot_release(mtr, slot) mtr_memo_slot_release_func(slot)
|
||||
#endif /* UNIV_DEBUG */
|
||||
|
||||
/**********************************************************//**
|
||||
Releases the mlocks and other objects stored in an mtr memo.
|
||||
They are released in the order opposite to which they were pushed
|
||||
to the memo. */
|
||||
static
|
||||
static __attribute__((nonnull))
|
||||
void
|
||||
mtr_memo_pop_all(
|
||||
/*=============*/
|
||||
mtr_t* mtr) /*!< in: mtr */
|
||||
mtr_t* mtr) /*!< in/out: mini-transaction */
|
||||
{
|
||||
mtr_memo_slot_t* slot;
|
||||
dyn_array_t* memo;
|
||||
ulint offset;
|
||||
const dyn_block_t* block;
|
||||
|
||||
ut_ad(mtr);
|
||||
ut_ad(mtr->magic_n == MTR_MAGIC_N);
|
||||
ut_ad(mtr->state == MTR_COMMITTING); /* Currently only used in
|
||||
commit */
|
||||
memo = &(mtr->memo);
|
||||
|
||||
offset = dyn_array_get_data_size(memo);
|
||||
for (block = dyn_array_get_last_block(&mtr->memo);
|
||||
block;
|
||||
block = dyn_array_get_prev_block(&mtr->memo, block)) {
|
||||
const mtr_memo_slot_t* start
|
||||
= (mtr_memo_slot_t*) dyn_block_get_data(block);
|
||||
mtr_memo_slot_t* slot
|
||||
= (mtr_memo_slot_t*) (dyn_block_get_data(block)
|
||||
+ dyn_block_get_used(block));
|
||||
|
||||
while (offset > 0) {
|
||||
offset -= sizeof(mtr_memo_slot_t);
|
||||
slot = dyn_array_get_element(memo, offset);
|
||||
ut_ad(!(dyn_block_get_used(block) % sizeof(mtr_memo_slot_t)));
|
||||
|
||||
mtr_memo_slot_release(mtr, slot);
|
||||
while (slot-- != start) {
|
||||
if (slot->object != NULL) {
|
||||
mtr_memo_slot_release(mtr, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,42 +297,36 @@ UNIV_INTERN
|
|||
void
|
||||
mtr_memo_release(
|
||||
/*=============*/
|
||||
mtr_t* mtr, /*!< in: mtr */
|
||||
mtr_t* mtr, /*!< in/out: mini-transaction */
|
||||
void* object, /*!< in: object */
|
||||
ulint type) /*!< in: object type: MTR_MEMO_S_LOCK, ... */
|
||||
{
|
||||
mtr_memo_slot_t* slot;
|
||||
dyn_array_t* memo;
|
||||
ulint offset;
|
||||
const dyn_block_t* block;
|
||||
|
||||
ut_ad(mtr);
|
||||
ut_ad(mtr->magic_n == MTR_MAGIC_N);
|
||||
ut_ad(mtr->state == MTR_ACTIVE);
|
||||
/* We cannot release a page that has been written to in the
|
||||
middle of a mini-transaction. */
|
||||
ut_ad(!mtr->modifications || type != MTR_MEMO_PAGE_X_FIX);
|
||||
|
||||
memo = &(mtr->memo);
|
||||
for (block = dyn_array_get_last_block(&mtr->memo);
|
||||
block;
|
||||
block = dyn_array_get_prev_block(&mtr->memo, block)) {
|
||||
const mtr_memo_slot_t* start
|
||||
= (mtr_memo_slot_t*) dyn_block_get_data(block);
|
||||
mtr_memo_slot_t* slot
|
||||
= (mtr_memo_slot_t*) (dyn_block_get_data(block)
|
||||
+ dyn_block_get_used(block));
|
||||
|
||||
offset = dyn_array_get_data_size(memo);
|
||||
ut_ad(!(dyn_block_get_used(block) % sizeof(mtr_memo_slot_t)));
|
||||
|
||||
log_flush_order_mutex_enter();
|
||||
while (offset > 0) {
|
||||
offset -= sizeof(mtr_memo_slot_t);
|
||||
|
||||
slot = dyn_array_get_element(memo, offset);
|
||||
|
||||
if (object == slot->object && type == slot->type) {
|
||||
|
||||
/* We cannot release a page that has been written
|
||||
to in the middle of a mini-transaction. */
|
||||
|
||||
ut_ad(!(mtr->modifications
|
||||
&& slot->type == MTR_MEMO_PAGE_X_FIX));
|
||||
|
||||
mtr_memo_slot_release(mtr, slot);
|
||||
|
||||
break;
|
||||
while (slot-- != start) {
|
||||
if (object == slot->object && type == slot->type) {
|
||||
mtr_memo_slot_release(mtr, slot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
log_flush_order_mutex_exit();
|
||||
}
|
||||
#endif /* !UNIV_HOTBACKUP */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue