2005-10-27 07:29:40 +00:00
|
|
|
/******************************************************
|
|
|
|
The database buffer replacement algorithm
|
|
|
|
|
|
|
|
(c) 1995 Innobase Oy
|
|
|
|
|
|
|
|
Created 11/5/1995 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "buf0lru.h"
|
|
|
|
|
|
|
|
#ifdef UNIV_NONINL
|
|
|
|
#include "buf0lru.ic"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ut0byte.h"
|
|
|
|
#include "ut0lst.h"
|
|
|
|
#include "ut0rnd.h"
|
|
|
|
#include "sync0sync.h"
|
|
|
|
#include "sync0rw.h"
|
|
|
|
#include "hash0hash.h"
|
|
|
|
#include "os0sync.h"
|
|
|
|
#include "fil0fil.h"
|
|
|
|
#include "btr0btr.h"
|
2006-12-11 14:27:43 +00:00
|
|
|
#include "buf0buddy.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "buf0buf.h"
|
|
|
|
#include "buf0flu.h"
|
|
|
|
#include "buf0rea.h"
|
|
|
|
#include "btr0sea.h"
|
2008-11-21 14:28:42 +00:00
|
|
|
#include "ibuf0ibuf.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "os0file.h"
|
2006-11-27 13:44:32 +00:00
|
|
|
#include "page0zip.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
#include "log0recv.h"
|
2006-10-25 11:03:27 +00:00
|
|
|
#include "srv0srv.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* The number of blocks from the LRU_old pointer onward, including the block
|
|
|
|
pointed to, must be 3/8 of the whole LRU list length, except that the
|
|
|
|
tolerance defined below is allowed. Note that the tolerance must be small
|
|
|
|
enough such that for even the BUF_LRU_OLD_MIN_LEN long LRU list, the
|
|
|
|
LRU_old pointer is not allowed to point to either end of the LRU list. */
|
|
|
|
|
|
|
|
#define BUF_LRU_OLD_TOLERANCE 20
|
|
|
|
|
|
|
|
/* The whole LRU list length is divided by this number to determine an
|
|
|
|
initial segment in buf_LRU_get_recent_limit */
|
|
|
|
|
|
|
|
#define BUF_LRU_INITIAL_RATIO 8
|
|
|
|
|
2008-10-11 19:37:21 +00:00
|
|
|
/* When dropping the search hash index entries before deleting an ibd
|
|
|
|
file, we build a local array of pages belonging to that tablespace
|
|
|
|
in the buffer pool. Following is the size of that array. */
|
|
|
|
#define BUF_LRU_DROP_SEARCH_HASH_SIZE 1024
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If we switch on the InnoDB monitor because there are too few available
|
|
|
|
frames in the buffer pool, we set this to TRUE */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN ibool buf_lru_switched_on_innodb_mon = FALSE;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
These statistics are not 'of' LRU but 'for' LRU. We keep count of I/O
|
|
|
|
and page_zip_decompress() operations. Based on the statistics,
|
|
|
|
buf_LRU_evict_from_unzip_LRU() decides if we want to evict from
|
|
|
|
unzip_LRU or the regular LRU. From unzip_LRU, we will only evict the
|
|
|
|
uncompressed frame (meaning we can evict dirty blocks as well). From
|
|
|
|
the regular LRU, we will evict the entire block (i.e.: both the
|
|
|
|
uncompressed and compressed data), which must be clean. */
|
|
|
|
|
|
|
|
/* Number of intervals for which we keep the history of these stats.
|
|
|
|
Each interval is 1 second, defined by the rate at which
|
|
|
|
srv_error_monitor_thread() calls buf_LRU_stat_update(). */
|
|
|
|
#define BUF_LRU_STAT_N_INTERVAL 50
|
|
|
|
|
|
|
|
/* Co-efficient with which we multiply I/O operations to equate them
|
|
|
|
with page_zip_decompress() operations. */
|
|
|
|
#define BUF_LRU_IO_TO_UNZIP_FACTOR 50
|
|
|
|
|
|
|
|
/* Sampled values buf_LRU_stat_cur.
|
|
|
|
Protected by buf_pool_mutex. Updated by buf_LRU_stat_update(). */
|
|
|
|
static buf_LRU_stat_t buf_LRU_stat_arr[BUF_LRU_STAT_N_INTERVAL];
|
|
|
|
/* Cursor to buf_LRU_stat_arr[] that is updated in a round-robin fashion. */
|
|
|
|
static ulint buf_LRU_stat_arr_ind;
|
|
|
|
|
|
|
|
/* Current operation counters. Not protected by any mutex. Cleared
|
|
|
|
by buf_LRU_stat_update(). */
|
|
|
|
UNIV_INTERN buf_LRU_stat_t buf_LRU_stat_cur;
|
|
|
|
|
|
|
|
/* Running sum of past values of buf_LRU_stat_cur.
|
|
|
|
Updated by buf_LRU_stat_update(). Protected by buf_pool_mutex. */
|
|
|
|
UNIV_INTERN buf_LRU_stat_t buf_LRU_stat_sum;
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
2007-01-03 13:10:46 +00:00
|
|
|
Takes a block out of the LRU list and page hash table.
|
|
|
|
If the block is compressed-only (BUF_BLOCK_ZIP_PAGE),
|
2008-01-10 09:37:13 +00:00
|
|
|
the object will be freed and buf_pool_zip_mutex will be released.
|
2007-01-09 15:52:08 +00:00
|
|
|
|
|
|
|
If a compressed page or a compressed-only block descriptor is freed,
|
|
|
|
other compressed pages or compressed-only block descriptors may be
|
|
|
|
relocated. */
|
2005-10-27 07:29:40 +00:00
|
|
|
static
|
2006-12-15 15:05:18 +00:00
|
|
|
enum buf_page_state
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_LRU_block_remove_hashed_page(
|
|
|
|
/*=============================*/
|
2006-12-15 15:05:18 +00:00
|
|
|
/* out: the new state of the block
|
|
|
|
(BUF_BLOCK_ZIP_FREE if the state was
|
|
|
|
BUF_BLOCK_ZIP_PAGE, or BUF_BLOCK_REMOVE_HASH
|
|
|
|
otherwise) */
|
|
|
|
buf_page_t* bpage, /* in: block, must contain a file page and
|
2005-10-27 07:29:40 +00:00
|
|
|
be in a state where it can be freed; there
|
|
|
|
may or may not be a hash index to the page */
|
2006-12-15 15:05:18 +00:00
|
|
|
ibool zip); /* in: TRUE if should remove also the
|
|
|
|
compressed page of an uncompressed page */
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Puts a file page whose has no hash index to the free list. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_LRU_block_free_hashed_page(
|
|
|
|
/*===========================*/
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_block_t* block); /* in: block, must contain a file page and
|
2005-10-27 07:29:40 +00:00
|
|
|
be in a state where it can be freed */
|
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Determines if the unzip_LRU list should be used for evicting a victim
|
|
|
|
instead of the general LRU list. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_LRU_evict_from_unzip_LRU(void)
|
|
|
|
/*==============================*/
|
|
|
|
/* out: TRUE if should use unzip_LRU */
|
|
|
|
{
|
|
|
|
ulint io_avg;
|
|
|
|
ulint unzip_avg;
|
|
|
|
|
|
|
|
ut_ad(buf_pool_mutex_own());
|
|
|
|
|
|
|
|
/* If the unzip_LRU list is empty, we can only use the LRU. */
|
|
|
|
if (UT_LIST_GET_LEN(buf_pool->unzip_LRU) == 0) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If unzip_LRU is at most 10% of the size of the LRU list,
|
|
|
|
then use the LRU. This slack allows us to keep hot
|
|
|
|
decompressed pages in the buffer pool. */
|
|
|
|
if (UT_LIST_GET_LEN(buf_pool->unzip_LRU)
|
|
|
|
<= UT_LIST_GET_LEN(buf_pool->LRU) / 10) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If eviction hasn't started yet, we assume by default
|
|
|
|
that a workload is disk bound. */
|
|
|
|
if (buf_pool->freed_page_clock == 0) {
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the average over past intervals, and add the values
|
|
|
|
of the current interval. */
|
|
|
|
io_avg = buf_LRU_stat_sum.io / BUF_LRU_STAT_N_INTERVAL
|
|
|
|
+ buf_LRU_stat_cur.io;
|
|
|
|
unzip_avg = buf_LRU_stat_sum.unzip / BUF_LRU_STAT_N_INTERVAL
|
|
|
|
+ buf_LRU_stat_cur.unzip;
|
|
|
|
|
|
|
|
/* Decide based on our formula. If the load is I/O bound
|
|
|
|
(unzip_avg is smaller than the weighted io_avg), evict an
|
|
|
|
uncompressed frame from unzip_LRU. Otherwise we assume that
|
|
|
|
the load is CPU bound and evict from the regular LRU. */
|
|
|
|
return(unzip_avg <= io_avg * BUF_LRU_IO_TO_UNZIP_FACTOR);
|
|
|
|
}
|
|
|
|
|
2008-10-11 19:37:21 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Attempts to drop page hash index on a batch of pages belonging to a
|
|
|
|
particular space id. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_LRU_drop_page_hash_batch(
|
|
|
|
/*=========================*/
|
|
|
|
ulint space_id, /* in: space id */
|
|
|
|
ulint zip_size, /* in: compressed page size in bytes
|
|
|
|
or 0 for uncompressed pages */
|
|
|
|
const ulint* arr, /* in: array of page_no */
|
|
|
|
ulint count) /* in: number of entries in array */
|
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
|
|
|
|
ut_ad(arr != NULL);
|
|
|
|
ut_ad(count <= BUF_LRU_DROP_SEARCH_HASH_SIZE);
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
btr_search_drop_page_hash_when_freed(space_id, zip_size,
|
|
|
|
arr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
When doing a DROP TABLE/DISCARD TABLESPACE we have to drop all page
|
|
|
|
hash index entries belonging to that table. This function tries to
|
|
|
|
do that in batch. Note that this is a 'best effort' attempt and does
|
|
|
|
not guarantee that ALL hash entries will be removed. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_LRU_drop_page_hash_for_tablespace(
|
|
|
|
/*==================================*/
|
|
|
|
ulint id) /* in: space id */
|
|
|
|
{
|
|
|
|
buf_page_t* bpage;
|
|
|
|
ulint* page_arr;
|
|
|
|
ulint num_entries;
|
|
|
|
ulint zip_size;
|
|
|
|
|
|
|
|
zip_size = fil_space_get_zip_size(id);
|
|
|
|
|
|
|
|
if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
|
|
|
|
/* Somehow, the tablespace does not exist. Nothing to drop. */
|
|
|
|
ut_ad(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page_arr = ut_malloc(sizeof(ulint)
|
|
|
|
* BUF_LRU_DROP_SEARCH_HASH_SIZE);
|
|
|
|
buf_pool_mutex_enter();
|
|
|
|
|
|
|
|
scan_again:
|
|
|
|
num_entries = 0;
|
|
|
|
bpage = UT_LIST_GET_LAST(buf_pool->LRU);
|
|
|
|
|
|
|
|
while (bpage != NULL) {
|
|
|
|
mutex_t* block_mutex = buf_page_get_mutex(bpage);
|
|
|
|
buf_page_t* prev_bpage;
|
|
|
|
|
|
|
|
mutex_enter(block_mutex);
|
|
|
|
prev_bpage = UT_LIST_GET_PREV(LRU, bpage);
|
|
|
|
|
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
|
|
|
|
if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE
|
|
|
|
|| bpage->space != id
|
|
|
|
|| bpage->buf_fix_count > 0
|
|
|
|
|| bpage->io_fix != BUF_IO_NONE) {
|
|
|
|
/* We leave the fixed pages as is in this scan.
|
|
|
|
To be dealt with later in the final scan. */
|
|
|
|
mutex_exit(block_mutex);
|
|
|
|
goto next_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((buf_block_t*) bpage)->is_hashed) {
|
|
|
|
|
|
|
|
/* Store the offset(i.e.: page_no) in the array
|
|
|
|
so that we can drop hash index in a batch
|
|
|
|
later. */
|
|
|
|
page_arr[num_entries] = bpage->offset;
|
|
|
|
mutex_exit(block_mutex);
|
|
|
|
ut_a(num_entries < BUF_LRU_DROP_SEARCH_HASH_SIZE);
|
|
|
|
++num_entries;
|
|
|
|
|
|
|
|
if (num_entries < BUF_LRU_DROP_SEARCH_HASH_SIZE) {
|
|
|
|
goto next_page;
|
|
|
|
}
|
branches/innodb+: Merge revisions 3602:3931 from branches/zip:
------------------------------------------------------------------------
r3607 | marko | 2008-12-30 22:33:31 +0200 (Tue, 30 Dec 2008) | 20 lines
branches/zip: Remove the dependency on the MySQL HASH table implementation.
Use the InnoDB hash table for keeping track of INNOBASE_SHARE objects.
struct st_innobase_share: Make table_name const uchar*. Add the member
table_name_hash.
innobase_open_tables: Change the type from HASH to hash_table_t*.
innobase_get_key(): Remove.
innobase_fold_name(): New function, for computing the fold value for the
InnoDB hash table.
get_share(), free_share(): Use the InnoDB hash functions.
innobase_end(): Free innobase_open_tables before shutting down InnoDB.
Shutting down InnoDB will invalidate all memory allocated via InnoDB.
rb://65 approved by Heikki Tuuri. This addresses Issue #104.
------------------------------------------------------------------------
r3608 | marko | 2008-12-30 22:45:04 +0200 (Tue, 30 Dec 2008) | 22 lines
branches/zip: When setting the PAGE_LEVEL of a compressed B-tree page
from or to 0, compress the page at the same time. This is necessary,
because the column information stored on the compressed page will
differ between leaf and non-leaf pages. Leaf pages are identified by
PAGE_LEVEL=0. This bug was reported as Issue #150.
Document the similarity between btr_page_create() and
btr_page_empty(). Make the function signature of btr_page_empty()
identical with btr_page_create(). (This will add the parameter "level".)
btr_root_raise_and_insert(): Replace some code with a call to
btr_page_empty().
btr_attach_half_pages(): Assert that the page level has already been
set on both block and new_block. Do not set it again.
btr_discard_only_page_on_level(): Document that this function is
probably never called. Make it work on any height tree. (Tested on
2-high tree by disabling btr_lift_page_up().)
rb://68
------------------------------------------------------------------------
r3612 | marko | 2009-01-02 11:02:44 +0200 (Fri, 02 Jan 2009) | 14 lines
branches/zip: Merge c2998 from branches/6.0, so that the same InnoDB Plugin
source tree will work both under 5.1 and 6.0. Do not add the test case
innodb_ctype_ldml.test, because it would not work under MySQL 5.1.
Refuse to create tables whose columns contain collation IDs above 255.
This removes an assertion failure that was introduced in WL#4164
(Two-byte collation IDs).
create_table_def(): Do not fail an assertion if a column contains a
charset-collation ID greater than 256. Instead, issue an error and
refuse to create the table.
The original change (branches/6.0 r2998) was rb://51 approved by Calvin Sun.
------------------------------------------------------------------------
r3613 | inaam | 2009-01-02 15:10:50 +0200 (Fri, 02 Jan 2009) | 6 lines
branches/zip: Implement the parameter innodb_use_sys_malloc
(false by default), for disabling InnoDB's internal memory allocator
and using system malloc/free instead.
rb://62 approved by Marko
------------------------------------------------------------------------
r3614 | marko | 2009-01-02 15:55:12 +0200 (Fri, 02 Jan 2009) | 1 line
branches/zip: ChangeLog: Document r3608 and r3613.
------------------------------------------------------------------------
r3615 | marko | 2009-01-02 15:57:51 +0200 (Fri, 02 Jan 2009) | 1 line
branches/zip: ChangeLog: Clarify the impact of r3608.
------------------------------------------------------------------------
r3616 | marko | 2009-01-03 00:23:30 +0200 (Sat, 03 Jan 2009) | 1 line
branches/zip: srv_suspend_mysql_thread(): Add some clarifying comments.
------------------------------------------------------------------------
r3618 | marko | 2009-01-05 12:54:53 +0200 (Mon, 05 Jan 2009) | 15 lines
branches/zip: Merge revisions 3598:3601 from branches/5.1:
------------------------------------------------------------------------
r3601 | marko | 2008-12-22 16:05:19 +0200 (Mon, 22 Dec 2008) | 9 lines
branches/5.1: Make
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
a true replacement of SET GLOBAL INNODB_LOCKS_UNSAFE_FOR_BINLOG=1.
This fixes an error that was introduced in r370, causing
semi-consistent read not to not unlock rows in READ COMMITTED mode.
(Bug #41671, Issue #146)
rb://67 approved by Heikki Tuuri
------------------------------------------------------------------------
------------------------------------------------------------------------
r3623 | vasil | 2009-01-06 09:56:32 +0200 (Tue, 06 Jan 2009) | 7 lines
branches/zip:
Add patch to fix the failing main.variables mysql-test. It started failing
after the variable innodb_use_sys_malloc was added because it matches
'%alloc%' and the test is badly written and expects that no new variables
like that will ever be added.
------------------------------------------------------------------------
r3795 | marko | 2009-01-07 16:17:47 +0200 (Wed, 07 Jan 2009) | 7 lines
branches/zip: row_merge_tuple_cmp(): Do not report a duplicate key value
if any of the fields are NULL. While the tuples are equal in the
sorting order, SQL NULL is defined to be logically inequal to
anything else. (Bug #41904)
rb://70 approved by Heikki Tuuri
------------------------------------------------------------------------
r3796 | marko | 2009-01-07 16:19:32 +0200 (Wed, 07 Jan 2009) | 1 line
branches/zip: Add the tests that were forgotten from r3795.
------------------------------------------------------------------------
r3797 | marko | 2009-01-07 16:22:18 +0200 (Wed, 07 Jan 2009) | 22 lines
branches/zip: Do not call trx_allocate_for_mysql() directly, but use
helper functions that initialize some members of the transaction struct.
(Bug #41680)
innobase_trx_init(): New function: initialize some fields of a
transaction struct from a MySQL THD object.
innobase_trx_allocate(): New function: allocate and initialize a
transaction struct.
check_trx_exists(): Use the above two functions.
ha_innobase::delete_table(), ha_innobase::rename_table(),
ha_innobase::add_index(), ha_innobase::final_drop_index():
Use innobase_trx_allocate().
innobase_drop_database(): In the Windows plugin, initialize the trx_t
specially, because the THD is not available. Otherwise, use
innobase_trx_allocate().
rb://69 accepted by Heikki Tuuri
------------------------------------------------------------------------
r3798 | marko | 2009-01-07 16:42:42 +0200 (Wed, 07 Jan 2009) | 8 lines
branches/zip: row_merge_drop_temp_indexes(): Do not lock the rows of
SYS_INDEXES when looking for partially created indexes. Use the
transaction isolation level READ UNCOMMITTED to avoid interfering with
locks held by incomplete transactions that will be rolled back in a
subsequent step in the recovery. (Issue #152)
Approved by Heikki Tuuri
------------------------------------------------------------------------
r3852 | vasil | 2009-01-08 22:10:10 +0200 (Thu, 08 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for r3795 r3796 r3797 r3798.
------------------------------------------------------------------------
r3866 | marko | 2009-01-09 15:09:51 +0200 (Fri, 09 Jan 2009) | 2 lines
branches/zip: buf_flush_try_page(): Move some common code from each
switch case before the switch block.
------------------------------------------------------------------------
r3867 | marko | 2009-01-09 15:13:14 +0200 (Fri, 09 Jan 2009) | 2 lines
branches/zip: buf_flush_try_page(): Introduce the variable is_compressed
for caching the result of buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE.
------------------------------------------------------------------------
r3868 | marko | 2009-01-09 15:40:11 +0200 (Fri, 09 Jan 2009) | 4 lines
branches/zip: buf_flush_insert_into_flush_list(),
buf_flush_insert_sorted_into_flush_list(): Remove unused code.
Change the parameter to buf_block_t* block and assert that
block->state == BUF_BLOCK_FILE_PAGE. This is part of Issue #155.
------------------------------------------------------------------------
r3873 | marko | 2009-01-09 22:27:40 +0200 (Fri, 09 Jan 2009) | 17 lines
branches/zip: Some non-functional changes related to Issue #155.
buf_page_struct: Note that space and offset are also protected by
buf_pool_mutex. They are only assigned to by
buf_block_set_file_page(). Thus, it suffices for buf_flush_batch() to
hold just buf_pool_mutex when checking these fields.
buf_flush_try_page(): Rename "locked" to "is_s_latched", per Heikki's request.
buf_flush_batch(): Move the common statement mutex_exit(block_mutex)
from all if-else if-else branches before the if block. Remove the
redundant test (buf_pool->init_flush[flush_type] == FALSE) that was
apparently copied from buf_flush_write_complete().
buf_flush_write_block_low(): Note why it is safe not to hold buf_pool_mutex
or block_mutex. Enumerate the assumptions in debug assertions.
------------------------------------------------------------------------
r3874 | marko | 2009-01-09 23:09:06 +0200 (Fri, 09 Jan 2009) | 4 lines
branches/zip: Add comments related to Issue #155.
buf_flush_try_page(): Note why it is safe to access bpage without
holding buf_pool_mutex or block_mutex.
------------------------------------------------------------------------
r3875 | marko | 2009-01-09 23:15:12 +0200 (Fri, 09 Jan 2009) | 11 lines
branches/zip: Non-functional change: Tighten debug assertions and
remove dead code.
buf_flush_ready_for_flush(), buf_flush_try_page(): Assert that
flush_type is one of BUF_FLUSH_LRU or BUF_FLUSH_LIST. The flush_type
comes from buf_flush_batch(), which already asserts this. The
assertion holds for all calls in the source code.
buf_flush_try_page(): Remove the dead case BUF_FLUSH_SINGLE_PAGE
of switch (flush_type).
------------------------------------------------------------------------
r3879 | marko | 2009-01-12 12:46:44 +0200 (Mon, 12 Jan 2009) | 14 lines
branches/zip: Simplify the flushing of dirty pages from the buffer pool.
buf_flush_try_page(): Rename to buf_flush_page(), and change the
return type to void. Replace the parameters space, offset with bpage,
and remove the second page hash lookup. Note and assert that both
buf_pool_mutex and block_mutex must now be held upon entering the
function. They will still be released by this function.
buf_flush_try_neighbors(): Replace buf_flush_try_page() with
buf_flush_page(). Make the logic easier to follow by not negating the
precondition of buf_flush_page().
rb://73 approved by Sunny Bains. This is related to Issue #157.
------------------------------------------------------------------------
r3880 | marko | 2009-01-12 13:24:37 +0200 (Mon, 12 Jan 2009) | 2 lines
branches/zip: buf_flush_page(): Fix a comment that should have been fixed
in r3879. Spotted by Sunny.
------------------------------------------------------------------------
r3881 | marko | 2009-01-12 14:25:22 +0200 (Mon, 12 Jan 2009) | 2 lines
branches/zip: buf_page_get_newest_modification(): Use the block mutex
instead of the buffer pool mutex. This is related to Issue #157.
------------------------------------------------------------------------
r3882 | marko | 2009-01-12 14:40:08 +0200 (Mon, 12 Jan 2009) | 3 lines
branches/zip: struct mtr_struct: Remove the unused field magic_n
unless UNIV_DEBUG is defined. mtr->magic_n is only assigned to
and checked in UNIV_DEBUG builds.
------------------------------------------------------------------------
r3883 | marko | 2009-01-12 14:48:59 +0200 (Mon, 12 Jan 2009) | 1 line
branches/zip: Non-functional change: Use ut_d when assigning to mtr->state.
------------------------------------------------------------------------
r3884 | marko | 2009-01-12 18:56:11 +0200 (Mon, 12 Jan 2009) | 16 lines
branches/zip: Non-functional change: Add some debug assertions and comments.
buf_page_t: Note that the LRU fields are protected by buf_pool_mutex
only, not block->mutex or buf_pool_zip_mutex.
buf_page_get_freed_page_clock(): Note that this is sometimes invoked
without mutex protection.
buf_pool_get_oldest_modification(): Note that the result may be out of
date.
buf_page_get_LRU_position(), buf_page_is_old(): Assert that the buffer
pool mutex is being held.
buf_page_release(): Assert that dirty blocks are in the flush list.
------------------------------------------------------------------------
r3896 | marko | 2009-01-13 09:30:26 +0200 (Tue, 13 Jan 2009) | 2 lines
branches/zip: buf_flush_try_neighbors(): Fix a bug
that was introduced in r3879 (rb://73).
------------------------------------------------------------------------
r3900 | marko | 2009-01-13 10:32:24 +0200 (Tue, 13 Jan 2009) | 1 line
branches/zip: Fix some comments to say buf_pool_mutex.
------------------------------------------------------------------------
r3907 | marko | 2009-01-13 11:54:01 +0200 (Tue, 13 Jan 2009) | 3 lines
branches/zip: row_merge_create_temporary_table(): On error,
row_create_table_for_mysql() already frees new_table.
Do not attempt to free it again.
------------------------------------------------------------------------
r3908 | marko | 2009-01-13 12:34:32 +0200 (Tue, 13 Jan 2009) | 1 line
branches/zip: Enable HASH_ASSERT_OWNED independently of UNIV_SYNC_DEBUG.
------------------------------------------------------------------------
r3914 | marko | 2009-01-13 21:46:22 +0200 (Tue, 13 Jan 2009) | 37 lines
branches/zip: In hash table lookups, assert that the traversed items
satisfy some conditions when UNIV_DEBUG is defined.
HASH_SEARCH(): New parameter: ASSERTION. All users will pass an appropriate
ut_ad() or nothing.
dict_table_add_to_columns(): Assert that the table being added to the data
dictionary cache is not already being pointed to by the name_hash and
id_hash tables.
HASH_SEARCH_ALL(): New macro, for use in dict_table_add_to_columns().
dict_mem_table_free(): Set ut_d(table->cached = FALSE), so that we can
check ut_ad(table->cached) when traversing the hash tables, as in
HASH_SEARCH(name_hash, dict_sys->table_hash, ...) and
HASH_SEARCH(id_hash, dict_sys->table_id_hash, ...).
dict_table_get_low(), dict_table_get_on_id_low(): Assert
ut_ad(!table || table->cached).
fil_space_get_by_id(): Check ut_ad(space->magic_n == FIL_SPACE_MAGIC_N)
in HASH_SEARCH(hash, fil_system->spaces, ...).
fil_space_get_by_name(): Check ut_ad(space->magic_n == FIL_SPACE_MAGIC_N)
in HASH_SEARCH(name_hash, fil_system->name_hash, ...).
buf_buddy_block_free(): Check that the blocks are in valid state in
HASH_SEARCH(hash, buf_pool->zip_hash, ...).
buf_page_hash_get(): Check that the blocks are in valid state in
HASH_SEARCH(hash, buf_pool->page_hash, ...).
get_share(), free_share(): Check ut_ad(share->use_count > 0) in
HASH_SEARCH(table_name_hash, innobase_open_tables, ...).
This was posted as rb://75 for tracking down errors similar to Issue #153.
------------------------------------------------------------------------
r3931 | marko | 2009-01-14 16:06:22 +0200 (Wed, 14 Jan 2009) | 26 lines
branches/zip: Merge revisions 3601:3930 from branches/5.1:
------------------------------------------------------------------------
r3911 | sunny | 2009-01-13 14:15:24 +0200 (Tue, 13 Jan 2009) | 13 lines
branches/5.1: Fix Bug#38187 Error 153 when creating savepoints
InnoDB previously treated savepoints as a stack e.g.,
SAVEPOINT a;
SAVEPOINT b;
SAVEPOINT c;
SAVEPOINT b; <- This would delete b and c.
This fix changes the behavior to:
SAVEPOINT a;
SAVEPOINT b;
SAVEPOINT c;
SAVEPOINT b; <- Does not delete savepoint c
------------------------------------------------------------------------
r3930 | marko | 2009-01-14 15:51:30 +0200 (Wed, 14 Jan 2009) | 4 lines
branches/5.1: dict_load_table(): If dict_load_indexes() fails,
invoke dict_table_remove_from_cache() instead of dict_mem_table_free(),
so that the data dictionary will not point to freed data.
(Bug #42075, Issue #153, rb://76 approved by Heikki Tuuri)
------------------------------------------------------------------------
------------------------------------------------------------------------
2009-01-14 14:25:45 +00:00
|
|
|
/* Array full. We release the buf_pool_mutex to
|
2008-10-11 19:37:21 +00:00
|
|
|
obey the latching order. */
|
|
|
|
buf_pool_mutex_exit();
|
|
|
|
|
|
|
|
buf_LRU_drop_page_hash_batch(id, zip_size, page_arr,
|
|
|
|
num_entries);
|
|
|
|
num_entries = 0;
|
|
|
|
buf_pool_mutex_enter();
|
|
|
|
} else {
|
|
|
|
mutex_exit(block_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
next_page:
|
|
|
|
/* Note that we may have released the buf_pool mutex
|
|
|
|
above after reading the prev_bpage during processing
|
|
|
|
of a page_hash_batch (i.e.: when the array was full).
|
|
|
|
This means that prev_bpage can change in LRU list.
|
|
|
|
This is OK because this function is a 'best effort'
|
|
|
|
to drop as many search hash entries as possible and
|
|
|
|
it does not guarantee that ALL such entries will be
|
|
|
|
dropped. */
|
|
|
|
bpage = prev_bpage;
|
|
|
|
|
|
|
|
/* If, however, bpage has been removed from LRU list
|
|
|
|
to the free list then we should restart the scan.
|
|
|
|
bpage->state is protected by buf_pool mutex. */
|
|
|
|
if (bpage && !buf_page_in_file(bpage)) {
|
|
|
|
ut_a(num_entries == 0);
|
|
|
|
goto scan_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf_pool_mutex_exit();
|
|
|
|
|
|
|
|
/* Drop any remaining batch of search hashed pages. */
|
|
|
|
buf_LRU_drop_page_hash_batch(id, zip_size, page_arr, num_entries);
|
|
|
|
ut_free(page_arr);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Invalidates all pages belonging to a given tablespace when we are deleting
|
|
|
|
the data file(s) of that tablespace. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_invalidate_tablespace(
|
|
|
|
/*==========================*/
|
|
|
|
ulint id) /* in: space id */
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint page_no;
|
|
|
|
ibool all_freed;
|
|
|
|
|
2008-10-11 19:37:21 +00:00
|
|
|
/* Before we attempt to drop pages one by one we first
|
|
|
|
attempt to drop page hash index entries in batches to make
|
|
|
|
it more efficient. The batching attempt is a best effort
|
|
|
|
attempt and does not guarantee that all pages hash entries
|
|
|
|
will be dropped. We get rid of remaining page hash entries
|
|
|
|
one by one below. */
|
|
|
|
buf_LRU_drop_page_hash_for_tablespace(id);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
scan_again:
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
all_freed = TRUE;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_LAST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
while (bpage != NULL) {
|
|
|
|
mutex_t* block_mutex = buf_page_get_mutex(bpage);
|
|
|
|
buf_page_t* prev_bpage;
|
2006-11-10 11:15:59 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_page_in_file(bpage));
|
2006-11-10 11:15:59 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
mutex_enter(block_mutex);
|
|
|
|
prev_bpage = UT_LIST_GET_PREV(LRU, bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_get_space(bpage) == id) {
|
|
|
|
if (bpage->buf_fix_count > 0
|
|
|
|
|| buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
/* We cannot remove this page during
|
|
|
|
this scan yet; maybe the system is
|
|
|
|
currently reading it in, or flushing
|
|
|
|
the modifications to the file */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
all_freed = FALSE;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
goto next_page;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (buf_debug_prints) {
|
2006-08-29 09:30:31 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Dropping space %lu page %lu\n",
|
2006-11-30 12:27:49 +00:00
|
|
|
(ulong) buf_page_get_space(bpage),
|
|
|
|
(ulong) buf_page_get_page_no(bpage));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE
|
|
|
|
&& ((buf_block_t*) bpage)->is_hashed) {
|
|
|
|
page_no = buf_page_get_page_no(bpage);
|
2006-11-10 11:15:59 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2006-11-30 12:27:49 +00:00
|
|
|
mutex_exit(block_mutex);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Note that the following call will acquire
|
|
|
|
an S-latch on the page */
|
|
|
|
|
2007-01-18 09:59:00 +00:00
|
|
|
btr_search_drop_page_hash_when_freed(
|
|
|
|
id,
|
|
|
|
buf_page_get_zip_size(bpage),
|
|
|
|
page_no);
|
2005-10-27 07:29:40 +00:00
|
|
|
goto scan_again;
|
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (bpage->oldest_modification != 0) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-12-15 14:47:04 +00:00
|
|
|
buf_flush_remove(bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove from the LRU list */
|
2006-12-15 15:05:18 +00:00
|
|
|
if (buf_LRU_block_remove_hashed_page(bpage, TRUE)
|
|
|
|
!= BUF_BLOCK_ZIP_FREE) {
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_LRU_block_free_hashed_page((buf_block_t*)
|
|
|
|
bpage);
|
|
|
|
} else {
|
branches/innodb+: Merge revisions 3931:4006 from branches/zip:
------------------------------------------------------------------------
r3938 | marko | 2009-01-15 10:28:23 +0200 (Thu, 15 Jan 2009) | 3 lines
branches/zip: buf_LRU_invalidate_tablespace(), buf_LRU_free_block():
Add comments and assertions that buf_LRU_block_remove_hashed_page()
will release block_mutex when it returns BUF_BLOCK_ZIP_FREE.
------------------------------------------------------------------------
r3939 | marko | 2009-01-15 10:37:51 +0200 (Thu, 15 Jan 2009) | 7 lines
branches/zip: buf0lru.c: Improve debug assertions.
buf_LRU_block_free_non_file_page(): ut_ad(block) before dereferencing block.
buf_LRU_block_remove_hashed_page(): Forbid buf_pool_mutex_exit() while
calling buf_buddy_free(). Callers of buf_LRU_block_remove_hashed_page()
assume that the buffer pool mutex will not be released and reacquired.
------------------------------------------------------------------------
r3944 | vasil | 2009-01-15 21:15:00 +0200 (Thu, 15 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for the bug fixes in r3911 and r3930.
------------------------------------------------------------------------
r3958 | marko | 2009-01-16 14:53:40 +0200 (Fri, 16 Jan 2009) | 8 lines
branches/zip: Add assertions that the kernel_mutex is being held
while accessing table->locks or un_member.tab_lock.locks.
This is related to Issue #158. According to static analysis,
the added debug assertions should always hold.
lock_table_has_to_wait_in_queue(), lock_queue_iterator_reset(),
lock_queue_iterator_get_prev(), add_trx_relevant_locks_to_cache(),
fetch_data_into_cache(): Add ut_ad(mutex_own(&kernel_mutex)).
------------------------------------------------------------------------
r4006 | marko | 2009-01-20 16:29:22 +0200 (Tue, 20 Jan 2009) | 33 lines
branches/zip: Merge revisions 3930:4005 from branches/5.1:
------------------------------------------------------------------------
r4004 | marko | 2009-01-20 16:19:00 +0200 (Tue, 20 Jan 2009) | 12 lines
branches/5.1: Merge r4003 from branches/5.0:
rec_set_nth_field(): When the field already is SQL null,
do nothing when it is being changed to SQL null. (Bug #41571)
Normally, MySQL does not pass "do-nothing" updates to the storage engine.
When it does and a column of an InnoDB table that is in ROW_FORMAT=COMPACT
is being updated from NULL to NULL, the InnoDB buffer pool will be corrupted
without this fix.
rb://81 approved by Heikki Tuuri
------------------------------------------------------------------------
r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before
accessing table->locks and release kernel_mutex before returning from
the function. This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)
rb://80 approved by Heikki Tuuri
------------------------------------------------------------------------
2009-01-20 14:34:02 +00:00
|
|
|
/* The block_mutex should have been
|
|
|
|
released by buf_LRU_block_remove_hashed_page()
|
|
|
|
when it returns BUF_BLOCK_ZIP_FREE. */
|
|
|
|
ut_ad(block_mutex == &buf_pool_zip_mutex);
|
|
|
|
ut_ad(!mutex_own(block_mutex));
|
|
|
|
|
2007-01-09 15:52:08 +00:00
|
|
|
/* The compressed block descriptor
|
|
|
|
(bpage) has been deallocated and
|
|
|
|
block_mutex released. Also,
|
|
|
|
buf_buddy_free() may have relocated
|
|
|
|
prev_bpage. Rescan the LRU list. */
|
|
|
|
|
|
|
|
bpage = UT_LIST_GET_LAST(buf_pool->LRU);
|
2007-01-16 16:24:47 +00:00
|
|
|
continue;
|
2006-12-15 15:05:18 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
next_page:
|
2006-11-30 12:27:49 +00:00
|
|
|
mutex_exit(block_mutex);
|
|
|
|
bpage = prev_bpage;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (!all_freed) {
|
|
|
|
os_thread_sleep(20000);
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
goto scan_again;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Gets the minimum LRU_position field for the blocks in an initial segment
|
|
|
|
(determined by BUF_LRU_INITIAL_RATIO) of the LRU list. The limit is not
|
|
|
|
guaranteed to be precise, because the ulint_clock may wrap around. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint
|
|
|
|
buf_LRU_get_recent_limit(void)
|
|
|
|
/*==========================*/
|
|
|
|
/* out: the limit; zero if could not determine it */
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
const buf_page_t* bpage;
|
|
|
|
ulint len;
|
|
|
|
ulint limit;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
len = UT_LIST_GET_LEN(buf_pool->LRU);
|
|
|
|
|
|
|
|
if (len < BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
/* The LRU list is too short to do read-ahead */
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_FIRST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
limit = buf_page_get_LRU_position(bpage) - len / BUF_LRU_INITIAL_RATIO;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(limit);
|
|
|
|
}
|
|
|
|
|
2006-12-15 15:05:18 +00:00
|
|
|
/************************************************************************
|
|
|
|
Insert a compressed block into buf_pool->zip_clean in the LRU order. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-12-15 15:05:18 +00:00
|
|
|
void
|
|
|
|
buf_LRU_insert_zip_clean(
|
|
|
|
/*=====================*/
|
|
|
|
buf_page_t* bpage) /* in: pointer to the block in question */
|
|
|
|
{
|
|
|
|
buf_page_t* b;
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-12-15 15:05:18 +00:00
|
|
|
ut_ad(buf_page_get_state(bpage) == BUF_BLOCK_ZIP_PAGE);
|
|
|
|
|
|
|
|
/* Find the first successor of bpage in the LRU list
|
|
|
|
that is in the zip_clean list. */
|
|
|
|
b = bpage;
|
|
|
|
do {
|
|
|
|
b = UT_LIST_GET_NEXT(LRU, b);
|
|
|
|
} while (b && buf_page_get_state(b) != BUF_BLOCK_ZIP_PAGE);
|
|
|
|
|
|
|
|
/* Insert bpage before b, i.e., after the predecessor of b. */
|
|
|
|
if (b) {
|
|
|
|
b = UT_LIST_GET_PREV(list, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b) {
|
|
|
|
UT_LIST_INSERT_AFTER(list, buf_pool->zip_clean, b, bpage);
|
|
|
|
} else {
|
|
|
|
UT_LIST_ADD_FIRST(list, buf_pool->zip_clean, bpage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
2008-03-03 12:57:07 +00:00
|
|
|
Try to free an uncompressed page of a compressed block from the unzip
|
|
|
|
LRU list. The compressed page is preserved, and it need not be clean. */
|
|
|
|
UNIV_INLINE
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
2008-03-03 12:57:07 +00:00
|
|
|
buf_LRU_free_from_unzip_LRU_list(
|
|
|
|
/*=============================*/
|
2005-10-27 07:29:40 +00:00
|
|
|
/* out: TRUE if freed */
|
2006-02-23 19:25:29 +00:00
|
|
|
ulint n_iterations) /* in: how many times this has been called
|
2005-10-27 07:29:40 +00:00
|
|
|
repeatedly without result: a high value means
|
2008-03-03 12:57:07 +00:00
|
|
|
that we should search farther; we will search
|
|
|
|
n_iterations / 5 of the unzip_LRU list,
|
|
|
|
or nothing if n_iterations >= 5 */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2008-03-03 12:57:07 +00:00
|
|
|
buf_block_t* block;
|
|
|
|
ulint distance;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/* Theoratically it should be much easier to find a victim
|
|
|
|
from unzip_LRU as we can choose even a dirty block (as we'll
|
|
|
|
be evicting only the uncompressed frame). In a very unlikely
|
|
|
|
eventuality that we are unable to find a victim from
|
|
|
|
unzip_LRU, we fall back to the regular LRU list. We do this
|
|
|
|
if we have done five iterations so far. */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
if (UNIV_UNLIKELY(n_iterations >= 5)
|
|
|
|
|| !buf_LRU_evict_from_unzip_LRU()) {
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
distance = 100 + (n_iterations
|
|
|
|
* UT_LIST_GET_LEN(buf_pool->unzip_LRU)) / 5;
|
2006-11-30 12:27:49 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
for (block = UT_LIST_GET_LAST(buf_pool->unzip_LRU);
|
|
|
|
UNIV_LIKELY(block != NULL) && UNIV_LIKELY(distance > 0);
|
|
|
|
block = UT_LIST_GET_PREV(unzip_LRU, block), distance--) {
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
enum buf_lru_free_block_status freed;
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
|
|
|
|
ut_ad(block->in_unzip_LRU_list);
|
|
|
|
ut_ad(block->page.in_LRU_list);
|
|
|
|
|
|
|
|
mutex_enter(&block->mutex);
|
|
|
|
freed = buf_LRU_free_block(&block->page, FALSE, NULL);
|
|
|
|
mutex_exit(&block->mutex);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
switch (freed) {
|
|
|
|
case BUF_LRU_FREED:
|
|
|
|
return(TRUE);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
case BUF_LRU_CANNOT_RELOCATE:
|
|
|
|
/* If we failed to relocate, try
|
|
|
|
regular LRU eviction. */
|
|
|
|
return(FALSE);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
case BUF_LRU_NOT_FREED:
|
|
|
|
/* The block was buffer-fixed or I/O-fixed.
|
|
|
|
Keep looking. */
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-10 11:15:59 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/* inappropriate return value from
|
|
|
|
buf_LRU_free_block() */
|
|
|
|
ut_error;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Try to free a clean page from the common LRU list. */
|
|
|
|
UNIV_INLINE
|
|
|
|
ibool
|
|
|
|
buf_LRU_free_from_common_LRU_list(
|
|
|
|
/*==============================*/
|
|
|
|
/* out: TRUE if freed */
|
|
|
|
ulint n_iterations) /* in: how many times this has been called
|
|
|
|
repeatedly without result: a high value means
|
|
|
|
that we should search farther; if
|
|
|
|
n_iterations < 10, then we search
|
|
|
|
n_iterations / 10 * buf_pool->curr_size
|
|
|
|
pages from the end of the LRU list */
|
|
|
|
{
|
|
|
|
buf_page_t* bpage;
|
|
|
|
ulint distance;
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
distance = 100 + (n_iterations * buf_pool->curr_size) / 10;
|
2006-11-10 11:15:59 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
for (bpage = UT_LIST_GET_LAST(buf_pool->LRU);
|
|
|
|
UNIV_LIKELY(bpage != NULL) && UNIV_LIKELY(distance > 0);
|
|
|
|
bpage = UT_LIST_GET_PREV(LRU, bpage), distance--) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
enum buf_lru_free_block_status freed;
|
|
|
|
mutex_t* block_mutex
|
|
|
|
= buf_page_get_mutex(bpage);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
ut_ad(buf_page_in_file(bpage));
|
|
|
|
ut_ad(bpage->in_LRU_list);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
mutex_enter(block_mutex);
|
|
|
|
freed = buf_LRU_free_block(bpage, TRUE, NULL);
|
|
|
|
mutex_exit(block_mutex);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
switch (freed) {
|
|
|
|
case BUF_LRU_FREED:
|
|
|
|
return(TRUE);
|
2007-02-16 09:22:50 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
case BUF_LRU_NOT_FREED:
|
|
|
|
/* The block was dirty, buffer-fixed, or I/O-fixed.
|
|
|
|
Keep looking. */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case BUF_LRU_CANNOT_RELOCATE:
|
|
|
|
/* This should never occur, because we
|
|
|
|
want to discard the compressed page too. */
|
|
|
|
break;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2008-03-03 12:57:07 +00:00
|
|
|
|
|
|
|
/* inappropriate return value from
|
|
|
|
buf_LRU_free_block() */
|
|
|
|
ut_error;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-11-15 21:41:27 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Try to free a replaceable block. */
|
|
|
|
UNIV_INTERN
|
|
|
|
ibool
|
|
|
|
buf_LRU_search_and_free_block(
|
|
|
|
/*==========================*/
|
|
|
|
/* out: TRUE if found and freed */
|
|
|
|
ulint n_iterations) /* in: how many times this has been called
|
|
|
|
repeatedly without result: a high value means
|
|
|
|
that we should search farther; if
|
|
|
|
n_iterations < 10, then we search
|
|
|
|
n_iterations / 10 * buf_pool->curr_size
|
|
|
|
pages from the end of the LRU list; if
|
|
|
|
n_iterations < 5, then we will also search
|
|
|
|
n_iterations / 5 of the unzip_LRU list. */
|
|
|
|
{
|
|
|
|
ibool freed = FALSE;
|
|
|
|
|
|
|
|
buf_pool_mutex_enter();
|
|
|
|
|
|
|
|
freed = buf_LRU_free_from_unzip_LRU_list(n_iterations);
|
|
|
|
|
|
|
|
if (!freed) {
|
|
|
|
freed = buf_LRU_free_from_common_LRU_list(n_iterations);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-11-15 21:41:27 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
if (!freed) {
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_pool->LRU_flush_ended = 0;
|
2008-03-03 12:57:07 +00:00
|
|
|
} else if (buf_pool->LRU_flush_ended > 0) {
|
|
|
|
buf_pool->LRU_flush_ended--;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2008-03-03 12:57:07 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
return(freed);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Tries to remove LRU flushed blocks from the end of the LRU list and put them
|
|
|
|
to the free list. This is beneficial for the efficiency of the insert buffer
|
|
|
|
operation, as flushed pages from non-unique non-clustered indexes are here
|
|
|
|
taken out of the buffer pool, and their inserts redirected to the insert
|
|
|
|
buffer. Otherwise, the flushed blocks could get modified again before read
|
|
|
|
operations need new buffer blocks, and the i/o work done in flushing would be
|
|
|
|
wasted. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_try_free_flushed_blocks(void)
|
|
|
|
/*=================================*/
|
|
|
|
{
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
while (buf_pool->LRU_flush_ended > 0) {
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_LRU_search_and_free_block(1);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
2006-04-12 09:32:17 +00:00
|
|
|
Returns TRUE if less than 25 % of the buffer pool is available. This can be
|
2005-10-27 07:29:40 +00:00
|
|
|
used in heuristics to prevent huge transactions eating up the whole buffer
|
|
|
|
pool for their locks. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
|
|
|
buf_LRU_buf_pool_running_out(void)
|
|
|
|
/*==============================*/
|
2006-04-12 09:32:17 +00:00
|
|
|
/* out: TRUE if less than 25 % of buffer pool
|
2005-10-27 07:29:40 +00:00
|
|
|
left */
|
|
|
|
{
|
|
|
|
ibool ret = FALSE;
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
|
2006-10-30 15:15:19 +00:00
|
|
|
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 4) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2006-12-11 14:27:43 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Returns a free block from the buf_pool. The block is taken off the
|
|
|
|
free list. If it is empty, returns NULL. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2006-12-11 14:27:43 +00:00
|
|
|
buf_block_t*
|
|
|
|
buf_LRU_get_free_only(void)
|
|
|
|
/*=======================*/
|
|
|
|
/* out: a free control block, or NULL
|
|
|
|
if the buf_block->free list is empty */
|
|
|
|
{
|
|
|
|
buf_block_t* block;
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-12-11 14:27:43 +00:00
|
|
|
|
|
|
|
block = (buf_block_t*) UT_LIST_GET_FIRST(buf_pool->free);
|
|
|
|
|
|
|
|
if (block) {
|
|
|
|
ut_ad(block->page.in_free_list);
|
|
|
|
ut_d(block->page.in_free_list = FALSE);
|
2007-01-09 12:35:42 +00:00
|
|
|
ut_ad(!block->page.in_flush_list);
|
2006-12-11 14:27:43 +00:00
|
|
|
ut_ad(!block->page.in_LRU_list);
|
|
|
|
ut_a(!buf_page_in_file(&block->page));
|
|
|
|
UT_LIST_REMOVE(list, buf_pool->free, (&block->page));
|
|
|
|
|
|
|
|
mutex_enter(&block->mutex);
|
|
|
|
|
|
|
|
buf_block_set_state(block, BUF_BLOCK_READY_FOR_USE);
|
2007-01-12 12:36:40 +00:00
|
|
|
UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE);
|
2006-12-11 14:27:43 +00:00
|
|
|
|
|
|
|
mutex_exit(&block->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(block);
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
2006-05-04 11:44:49 +00:00
|
|
|
Returns a free block from the buf_pool. The block is taken off the
|
|
|
|
free list. If it is empty, blocks are moved from the end of the
|
|
|
|
LRU list to the free list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_block_t*
|
2006-05-04 11:44:49 +00:00
|
|
|
buf_LRU_get_free_block(
|
|
|
|
/*===================*/
|
2006-12-13 14:58:54 +00:00
|
|
|
/* out: the free control block,
|
|
|
|
in state BUF_BLOCK_READY_FOR_USE */
|
2006-05-04 11:44:49 +00:00
|
|
|
ulint zip_size) /* in: compressed page size in bytes,
|
|
|
|
or 0 if uncompressed tablespace */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
buf_block_t* block = NULL;
|
|
|
|
ibool freed;
|
|
|
|
ulint n_iterations = 1;
|
2006-02-23 19:25:29 +00:00
|
|
|
ibool mon_value_was = FALSE;
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool started_monitor = FALSE;
|
|
|
|
loop:
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
|
2006-10-30 15:15:19 +00:00
|
|
|
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->curr_size / 20) {
|
2006-02-23 19:25:29 +00:00
|
|
|
ut_print_timestamp(stderr);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
fprintf(stderr,
|
2006-08-29 09:30:31 +00:00
|
|
|
" InnoDB: ERROR: over 95 percent of the buffer pool"
|
|
|
|
" is occupied by\n"
|
|
|
|
"InnoDB: lock heaps or the adaptive hash index!"
|
|
|
|
" Check that your\n"
|
|
|
|
"InnoDB: transactions do not set too many row locks.\n"
|
|
|
|
"InnoDB: Your buffer pool size is %lu MB."
|
|
|
|
" Maybe you should make\n"
|
|
|
|
"InnoDB: the buffer pool bigger?\n"
|
|
|
|
"InnoDB: We intentionally generate a seg fault"
|
|
|
|
" to print a stack trace\n"
|
|
|
|
"InnoDB: on Linux!\n",
|
|
|
|
(ulong) (buf_pool->curr_size
|
|
|
|
/ (1024 * 1024 / UNIV_PAGE_SIZE)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
ut_error;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-10-30 15:15:19 +00:00
|
|
|
} else if (!recv_recovery_on
|
|
|
|
&& (UT_LIST_GET_LEN(buf_pool->free)
|
|
|
|
+ UT_LIST_GET_LEN(buf_pool->LRU))
|
|
|
|
< buf_pool->curr_size / 3) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!buf_lru_switched_on_innodb_mon) {
|
|
|
|
|
2008-02-27 07:03:34 +00:00
|
|
|
/* Over 67 % of the buffer pool is occupied by lock
|
2005-10-27 07:29:40 +00:00
|
|
|
heaps or the adaptive hash index. This may be a memory
|
|
|
|
leak! */
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
2006-08-29 09:30:31 +00:00
|
|
|
" InnoDB: WARNING: over 67 percent of"
|
|
|
|
" the buffer pool is occupied by\n"
|
|
|
|
"InnoDB: lock heaps or the adaptive"
|
|
|
|
" hash index! Check that your\n"
|
|
|
|
"InnoDB: transactions do not set too many"
|
|
|
|
" row locks.\n"
|
|
|
|
"InnoDB: Your buffer pool size is %lu MB."
|
|
|
|
" Maybe you should make\n"
|
|
|
|
"InnoDB: the buffer pool bigger?\n"
|
|
|
|
"InnoDB: Starting the InnoDB Monitor to print"
|
|
|
|
" diagnostics, including\n"
|
|
|
|
"InnoDB: lock heap and hash index sizes.\n",
|
|
|
|
(ulong) (buf_pool->curr_size
|
|
|
|
/ (1024 * 1024 / UNIV_PAGE_SIZE)));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_lru_switched_on_innodb_mon = TRUE;
|
|
|
|
srv_print_innodb_monitor = TRUE;
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
|
|
|
}
|
|
|
|
} else if (buf_lru_switched_on_innodb_mon) {
|
|
|
|
|
|
|
|
/* Switch off the InnoDB Monitor; this is a simple way
|
|
|
|
to stop the monitor if the situation becomes less urgent,
|
|
|
|
but may also surprise users if the user also switched on the
|
|
|
|
monitor! */
|
|
|
|
|
|
|
|
buf_lru_switched_on_innodb_mon = FALSE;
|
|
|
|
srv_print_innodb_monitor = FALSE;
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If there is a block in the free list, take it */
|
2006-12-15 15:05:18 +00:00
|
|
|
block = buf_LRU_get_free_only();
|
|
|
|
if (block) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 14:09:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2006-12-15 15:05:18 +00:00
|
|
|
block->page.zip.m_start =
|
2006-11-30 14:09:29 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2006-12-15 15:05:18 +00:00
|
|
|
block->page.zip.m_end =
|
|
|
|
block->page.zip.m_nonempty =
|
|
|
|
block->page.zip.n_blobs = 0;
|
2006-05-04 11:44:49 +00:00
|
|
|
|
2007-02-13 11:21:57 +00:00
|
|
|
if (UNIV_UNLIKELY(zip_size)) {
|
2007-02-08 14:19:55 +00:00
|
|
|
ibool lru;
|
2006-12-15 15:05:18 +00:00
|
|
|
page_zip_set_size(&block->page.zip, zip_size);
|
2007-02-08 14:19:55 +00:00
|
|
|
block->page.zip.data = buf_buddy_alloc(zip_size, &lru);
|
2007-01-12 12:36:40 +00:00
|
|
|
UNIV_MEM_DESC(block->page.zip.data, zip_size, block);
|
2006-12-15 15:05:18 +00:00
|
|
|
} else {
|
|
|
|
page_zip_set_size(&block->page.zip, 0);
|
|
|
|
block->page.zip.data = NULL;
|
2006-05-04 11:44:49 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (started_monitor) {
|
|
|
|
srv_print_innodb_monitor = mon_value_was;
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(block);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If no block was in the free list, search from the end of the LRU
|
|
|
|
list and try to free a block there */
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
freed = buf_LRU_search_and_free_block(n_iterations);
|
|
|
|
|
|
|
|
if (freed > 0) {
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_iterations > 30) {
|
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fprintf(stderr,
|
2008-09-17 19:52:30 +00:00
|
|
|
" InnoDB: Warning: difficult to find free blocks in\n"
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: the buffer pool (%lu search iterations)!"
|
|
|
|
" Consider\n"
|
|
|
|
"InnoDB: increasing the buffer pool size.\n"
|
|
|
|
"InnoDB: It is also possible that"
|
|
|
|
" in your Unix version\n"
|
|
|
|
"InnoDB: fsync is very slow, or"
|
|
|
|
" completely frozen inside\n"
|
|
|
|
"InnoDB: the OS kernel. Then upgrading to"
|
|
|
|
" a newer version\n"
|
|
|
|
"InnoDB: of your operating system may help."
|
|
|
|
" Look at the\n"
|
|
|
|
"InnoDB: number of fsyncs in diagnostic info below.\n"
|
|
|
|
"InnoDB: Pending flushes (fsync) log: %lu;"
|
|
|
|
" buffer pool: %lu\n"
|
|
|
|
"InnoDB: %lu OS file reads, %lu OS file writes,"
|
|
|
|
" %lu OS fsyncs\n"
|
|
|
|
"InnoDB: Starting InnoDB Monitor to print further\n"
|
|
|
|
"InnoDB: diagnostics to the standard output.\n",
|
2005-10-27 07:29:40 +00:00
|
|
|
(ulong) n_iterations,
|
|
|
|
(ulong) fil_n_pending_log_flushes,
|
|
|
|
(ulong) fil_n_pending_tablespace_flushes,
|
|
|
|
(ulong) os_n_file_reads, (ulong) os_n_file_writes,
|
2006-02-23 19:25:29 +00:00
|
|
|
(ulong) os_n_fsyncs);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
mon_value_was = srv_print_innodb_monitor;
|
|
|
|
started_monitor = TRUE;
|
|
|
|
srv_print_innodb_monitor = TRUE;
|
|
|
|
os_event_set(srv_lock_timeout_thread_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No free block was found: try to flush the LRU list */
|
|
|
|
|
|
|
|
buf_flush_free_margin();
|
2006-02-23 19:25:29 +00:00
|
|
|
++srv_buf_pool_wait_free;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
os_aio_simulated_wake_handler_threads();
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (buf_pool->LRU_flush_ended > 0) {
|
|
|
|
/* We have written pages in an LRU flush. To make the insert
|
|
|
|
buffer more efficient, we try to move these pages to the free
|
|
|
|
list. */
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_LRU_try_free_flushed_blocks();
|
|
|
|
} else {
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n_iterations > 10) {
|
|
|
|
|
|
|
|
os_thread_sleep(500000);
|
|
|
|
}
|
|
|
|
|
|
|
|
n_iterations++;
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
goto loop;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moves the LRU_old pointer so that the length of the old blocks list
|
|
|
|
is inside the allowed limits. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_LRU_old_adjust_len(void)
|
|
|
|
/*========================*/
|
|
|
|
{
|
|
|
|
ulint old_len;
|
|
|
|
ulint new_len;
|
|
|
|
|
|
|
|
ut_a(buf_pool->LRU_old);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2008-02-18 15:43:16 +00:00
|
|
|
#if 3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5
|
|
|
|
# error "3 * (BUF_LRU_OLD_MIN_LEN / 8) <= BUF_LRU_OLD_TOLERANCE + 5"
|
|
|
|
#endif
|
2008-09-17 19:52:30 +00:00
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
/* buf_pool->LRU_old must be the first item in the LRU list
|
|
|
|
whose "old" flag is set. */
|
|
|
|
ut_a(buf_pool->LRU_old->old);
|
|
|
|
ut_a(!UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)
|
|
|
|
|| !UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)->old);
|
|
|
|
ut_a(!UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)
|
|
|
|
|| UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
old_len = buf_pool->LRU_old_len;
|
|
|
|
new_len = 3 * (UT_LIST_GET_LEN(buf_pool->LRU) / 8);
|
|
|
|
|
2006-11-28 09:37:02 +00:00
|
|
|
ut_ad(buf_pool->LRU_old->in_LRU_list);
|
2008-09-17 19:52:30 +00:00
|
|
|
ut_a(buf_pool->LRU_old);
|
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
ut_a(buf_pool->LRU_old->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Update the LRU_old pointer if necessary */
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (old_len < new_len - BUF_LRU_OLD_TOLERANCE) {
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
buf_pool->LRU_old = UT_LIST_GET_PREV(
|
|
|
|
LRU, buf_pool->LRU_old);
|
2008-09-17 19:52:30 +00:00
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
ut_a(!buf_pool->LRU_old->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_set_old(buf_pool->LRU_old, TRUE);
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_pool->LRU_old_len++;
|
|
|
|
|
|
|
|
} else if (old_len > new_len + BUF_LRU_OLD_TOLERANCE) {
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_set_old(buf_pool->LRU_old, FALSE);
|
2006-09-19 10:14:07 +00:00
|
|
|
buf_pool->LRU_old = UT_LIST_GET_NEXT(
|
|
|
|
LRU, buf_pool->LRU_old);
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_pool->LRU_old_len--;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Initializes the old blocks pointer in the LRU list. This function should be
|
|
|
|
called when the LRU list grows to BUF_LRU_OLD_MIN_LEN length. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_LRU_old_init(void)
|
|
|
|
/*==================*/
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_a(UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN);
|
|
|
|
|
|
|
|
/* We first initialize all blocks in the LRU list as old and then use
|
|
|
|
the adjust function to move the LRU_old pointer to the right
|
|
|
|
position */
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_FIRST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
while (bpage != NULL) {
|
|
|
|
ut_ad(bpage->in_LRU_list);
|
|
|
|
buf_page_set_old(bpage, TRUE);
|
|
|
|
bpage = UT_LIST_GET_NEXT(LRU, bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf_pool->LRU_old = UT_LIST_GET_FIRST(buf_pool->LRU);
|
|
|
|
buf_pool->LRU_old_len = UT_LIST_GET_LEN(buf_pool->LRU);
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_LRU_old_adjust_len();
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Remove a block from the unzip_LRU list if it belonged to the list. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_unzip_LRU_remove_block_if_needed(
|
|
|
|
/*=================================*/
|
|
|
|
buf_page_t* bpage) /* in/out: control block */
|
|
|
|
{
|
|
|
|
ut_ad(buf_pool);
|
|
|
|
ut_ad(bpage);
|
|
|
|
ut_ad(buf_page_in_file(bpage));
|
|
|
|
ut_ad(buf_pool_mutex_own());
|
|
|
|
|
|
|
|
if (buf_page_belongs_to_unzip_LRU(bpage)) {
|
|
|
|
buf_block_t* block = (buf_block_t*) bpage;
|
|
|
|
|
|
|
|
ut_ad(block->in_unzip_LRU_list);
|
|
|
|
ut_d(block->in_unzip_LRU_list = FALSE);
|
|
|
|
|
|
|
|
UT_LIST_REMOVE(unzip_LRU, buf_pool->unzip_LRU, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Removes a block from the LRU list. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_LRU_remove_block(
|
|
|
|
/*=================*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage) /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ut_ad(buf_pool);
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_ad(bpage);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
|
|
|
|
ut_ad(bpage->in_LRU_list);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* If the LRU_old pointer is defined and points to just this block,
|
|
|
|
move it backward one step */
|
|
|
|
|
2008-02-15 11:45:37 +00:00
|
|
|
if (UNIV_UNLIKELY(bpage == buf_pool->LRU_old)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Below: the previous block is guaranteed to exist, because
|
|
|
|
the LRU_old pointer is only allowed to differ by the
|
|
|
|
tolerance value from strict 3/8 of the LRU list length. */
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_pool->LRU_old = UT_LIST_GET_PREV(LRU, bpage);
|
2008-02-15 11:45:37 +00:00
|
|
|
ut_a(buf_pool->LRU_old);
|
2008-09-17 19:52:30 +00:00
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
ut_a(!buf_pool->LRU_old->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_set_old(buf_pool->LRU_old, TRUE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_pool->LRU_old_len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the block from the LRU list */
|
2006-11-30 12:27:49 +00:00
|
|
|
UT_LIST_REMOVE(LRU, buf_pool->LRU, bpage);
|
2008-02-15 11:45:37 +00:00
|
|
|
ut_d(bpage->in_LRU_list = FALSE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
buf_unzip_LRU_remove_block_if_needed(bpage);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If the LRU list is so short that LRU_old not defined, return */
|
|
|
|
if (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
buf_pool->LRU_old = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-23 19:25:29 +00:00
|
|
|
ut_ad(buf_pool->LRU_old);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/* Update the LRU_old_len field if necessary */
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_is_old(bpage)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_pool->LRU_old_len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the length of the old block list if necessary */
|
|
|
|
buf_LRU_old_adjust_len();
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Adds a block to the LRU list of decompressed zip pages. */
|
|
|
|
UNIV_INTERN
|
|
|
|
void
|
|
|
|
buf_unzip_LRU_add_block(
|
|
|
|
/*====================*/
|
|
|
|
buf_block_t* block, /* in: control block */
|
|
|
|
ibool old) /* in: TRUE if should be put to the end
|
|
|
|
of the list, else put to the start */
|
|
|
|
{
|
|
|
|
ut_ad(buf_pool);
|
|
|
|
ut_ad(block);
|
|
|
|
ut_ad(buf_pool_mutex_own());
|
|
|
|
|
|
|
|
ut_a(buf_page_belongs_to_unzip_LRU(&block->page));
|
|
|
|
|
|
|
|
ut_ad(!block->in_unzip_LRU_list);
|
|
|
|
ut_d(block->in_unzip_LRU_list = TRUE);
|
|
|
|
|
|
|
|
if (old) {
|
|
|
|
UT_LIST_ADD_LAST(unzip_LRU, buf_pool->unzip_LRU, block);
|
|
|
|
} else {
|
|
|
|
UT_LIST_ADD_FIRST(unzip_LRU, buf_pool->unzip_LRU, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Adds a block to the LRU list end. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_LRU_add_block_to_end_low(
|
|
|
|
/*=========================*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage) /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* last_bpage;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(buf_pool);
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_ad(bpage);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_page_in_file(bpage));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
last_bpage = UT_LIST_GET_LAST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (last_bpage) {
|
|
|
|
bpage->LRU_position = last_bpage->LRU_position;
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage->LRU_position = buf_pool_clock_tic();
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_ad(!bpage->in_LRU_list);
|
|
|
|
UT_LIST_ADD_LAST(LRU, buf_pool->LRU, bpage);
|
2008-02-15 11:45:37 +00:00
|
|
|
ut_d(bpage->in_LRU_list = TRUE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
buf_page_set_old(bpage, TRUE);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
buf_pool->LRU_old_len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
ut_ad(buf_pool->LRU_old);
|
|
|
|
|
|
|
|
/* Adjust the length of the old block list if necessary */
|
|
|
|
|
|
|
|
buf_LRU_old_adjust_len();
|
|
|
|
|
|
|
|
} else if (UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
/* The LRU list is now long enough for LRU_old to become
|
|
|
|
defined: init it */
|
|
|
|
|
|
|
|
buf_LRU_old_init();
|
|
|
|
}
|
2008-03-03 12:57:07 +00:00
|
|
|
|
|
|
|
/* If this is a zipped block with decompressed frame as well
|
|
|
|
then put it on the unzip_LRU list */
|
|
|
|
if (buf_page_belongs_to_unzip_LRU(bpage)) {
|
|
|
|
buf_unzip_LRU_add_block((buf_block_t*) bpage, TRUE);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Adds a block to the LRU list. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
buf_LRU_add_block_low(
|
|
|
|
/*==================*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage, /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool old) /* in: TRUE if should be put to the old blocks
|
|
|
|
in the LRU list, else put to the start; if the
|
|
|
|
LRU list is very short, the block is added to
|
|
|
|
the start, regardless of this parameter */
|
|
|
|
{
|
|
|
|
ut_ad(buf_pool);
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_ad(bpage);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_page_in_file(bpage));
|
|
|
|
ut_ad(!bpage->in_LRU_list);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (!old || (UT_LIST_GET_LEN(buf_pool->LRU) < BUF_LRU_OLD_MIN_LEN)) {
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
UT_LIST_ADD_FIRST(LRU, buf_pool->LRU, bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage->LRU_position = buf_pool_clock_tic();
|
|
|
|
bpage->freed_page_clock = buf_pool->freed_page_clock;
|
2005-10-27 07:29:40 +00:00
|
|
|
} else {
|
2008-09-17 19:52:30 +00:00
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
/* buf_pool->LRU_old must be the first item in the LRU list
|
|
|
|
whose "old" flag is set. */
|
|
|
|
ut_a(buf_pool->LRU_old->old);
|
|
|
|
ut_a(!UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)
|
|
|
|
|| !UT_LIST_GET_PREV(LRU, buf_pool->LRU_old)->old);
|
|
|
|
ut_a(!UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)
|
|
|
|
|| UT_LIST_GET_NEXT(LRU, buf_pool->LRU_old)->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
UT_LIST_INSERT_AFTER(LRU, buf_pool->LRU, buf_pool->LRU_old,
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_pool->LRU_old_len++;
|
|
|
|
|
|
|
|
/* We copy the LRU position field of the previous block
|
|
|
|
to the new block */
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage->LRU_position = (buf_pool->LRU_old)->LRU_position;
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-15 11:45:37 +00:00
|
|
|
ut_d(bpage->in_LRU_list = TRUE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-09-17 19:52:30 +00:00
|
|
|
buf_page_set_old(bpage, old);
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
ut_ad(buf_pool->LRU_old);
|
|
|
|
|
|
|
|
/* Adjust the length of the old block list if necessary */
|
|
|
|
|
|
|
|
buf_LRU_old_adjust_len();
|
|
|
|
|
|
|
|
} else if (UT_LIST_GET_LEN(buf_pool->LRU) == BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
/* The LRU list is now long enough for LRU_old to become
|
|
|
|
defined: init it */
|
|
|
|
|
|
|
|
buf_LRU_old_init();
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2008-03-03 12:57:07 +00:00
|
|
|
|
|
|
|
/* If this is a zipped block with decompressed frame as well
|
|
|
|
then put it on the unzip_LRU list */
|
|
|
|
if (buf_page_belongs_to_unzip_LRU(bpage)) {
|
|
|
|
buf_unzip_LRU_add_block((buf_block_t*) bpage, old);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Adds a block to the LRU list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_add_block(
|
|
|
|
/*==============*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage, /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool old) /* in: TRUE if should be put to the old
|
|
|
|
blocks in the LRU list, else put to the start;
|
|
|
|
if the LRU list is very short, the block is
|
|
|
|
added to the start, regardless of this
|
|
|
|
parameter */
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_LRU_add_block_low(bpage, old);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Moves a block to the start of the LRU list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_make_block_young(
|
|
|
|
/*=====================*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage) /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_LRU_remove_block(bpage);
|
|
|
|
buf_LRU_add_block_low(bpage, FALSE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Moves a block to the end of the LRU list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_make_block_old(
|
|
|
|
/*===================*/
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage) /* in: control block */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_LRU_remove_block(bpage);
|
|
|
|
buf_LRU_add_block_to_end_low(bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-03 13:10:46 +00:00
|
|
|
/**********************************************************************
|
2008-03-03 12:57:07 +00:00
|
|
|
Try to free a block. If bpage is a descriptor of a compressed-only
|
branches/innodb+: Merge revisions 2986:3152 from branches/zip:
------------------------------------------------------------------------
r3036 | marko | 2008-11-12 12:34:30 +0200 (Wed, 12 Nov 2008) | 4 lines
branches/zip: dtuple_validate(): When UNIV_DEBUG_VALGRIND is defined,
rely solely on the UNIV_MEM_ASSERT_RW() check and disable the for loop
that would only cause additional noise.
------------------------------------------------------------------------
r3037 | marko | 2008-11-12 13:52:57 +0200 (Wed, 12 Nov 2008) | 6 lines
branches/zip: row_vers_impl_x_locked_off_kernel(): Remove compilation
warnings about prev_trx_id and vers_del being possibly uninitialized,
by handling the case prev_version == NULL in a single if block.
rb://45 approved by Inaam Rana.
------------------------------------------------------------------------
r3131 | michael | 2008-11-17 14:56:56 +0200 (Mon, 17 Nov 2008) | 9 lines
branches/zip:
rb://53
Improve innodb_supports_xa system variable handling and
reduces the number of retrievals of the value from MySQL.
Approved by: Marko, over IM
------------------------------------------------------------------------
r3132 | michael | 2008-11-17 16:02:01 +0200 (Mon, 17 Nov 2008) | 5 lines
branches/zip: rb://53
Final version of rb://53, fixes the styling of a comment, makes
the definition and the declaration of thd_supports_xa() identical commentwise.
------------------------------------------------------------------------
r3141 | marko | 2008-11-19 16:39:55 +0200 (Wed, 19 Nov 2008) | 1 line
branches/zip: buf_LRU_free_block(): Clarify the function comment.
------------------------------------------------------------------------
r3144 | marko | 2008-11-20 11:39:49 +0200 (Thu, 20 Nov 2008) | 2 lines
branches/zip: rec_get_nth_field_offs_old(): Add UNIV_UNLIKELY hints
to assertion-like tests.
------------------------------------------------------------------------
r3145 | marko | 2008-11-20 12:22:40 +0200 (Thu, 20 Nov 2008) | 20 lines
branches/zip: Always check for "row too large" when executing SQL to create
an index or table. We have to skip this check when loading table definitions
from the data dictionary, because we could otherwise refuse to load old
tables (even uncompressed ones). This addresses Issue #119.
The first "row too large" check was implemented in MySQL 5.0.3
to address MySQL Bug #5682. In the InnoDB Plugin 1.0.2, a more
accurate check was implemented in innodb_strict_mode. We now
make the check unconditional.
dict_create_index_step(): Pass strict=TRUE to dict_index_add_to_cache().
trx_is_strict(), thd_is_strict(): Remove.
innodb-zip.test: Test in innodb_strict_mode=OFF.
innodb_bug36169.test: Ensure that none of the tables can be created.
rb://56 approved by Sunny Bains.
------------------------------------------------------------------------
r3148 | marko | 2008-11-20 13:27:27 +0200 (Thu, 20 Nov 2008) | 3 lines
branches/zip: rec_print_old(), rec_print_comp(): Dump each field in a
separate line, so that the dumps can be read and compared more easily.
------------------------------------------------------------------------
2008-11-20 11:53:53 +00:00
|
|
|
page, the descriptor object will be freed as well.
|
|
|
|
|
|
|
|
NOTE: If this function returns BUF_LRU_FREED, it will not temporarily
|
|
|
|
release buf_pool_mutex. Furthermore, the page frame will no longer be
|
|
|
|
accessible via bpage.
|
|
|
|
|
|
|
|
The caller must hold buf_pool_mutex and buf_page_get_mutex(bpage) and
|
|
|
|
release these two mutexes after the call. No other
|
|
|
|
buf_page_get_mutex() may be held when calling this function. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2008-03-03 12:57:07 +00:00
|
|
|
enum buf_lru_free_block_status
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_LRU_free_block(
|
|
|
|
/*===============*/
|
2008-03-03 12:57:07 +00:00
|
|
|
/* out: BUF_LRU_FREED if freed,
|
|
|
|
BUF_LRU_CANNOT_RELOCATE or
|
|
|
|
BUF_LRU_NOT_FREED otherwise. */
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_page_t* bpage, /* in: block to be freed */
|
2007-12-10 09:48:28 +00:00
|
|
|
ibool zip, /* in: TRUE if should remove also the
|
2007-01-03 13:10:46 +00:00
|
|
|
compressed page of an uncompressed page */
|
2007-12-10 09:48:28 +00:00
|
|
|
ibool* buf_pool_mutex_released)
|
|
|
|
/* in: pointer to a variable that will
|
2008-01-10 09:37:13 +00:00
|
|
|
be assigned TRUE if buf_pool_mutex
|
2007-12-10 09:48:28 +00:00
|
|
|
was temporarily released, or NULL */
|
2007-01-03 13:10:46 +00:00
|
|
|
{
|
2007-01-16 16:24:47 +00:00
|
|
|
buf_page_t* b = NULL;
|
2007-01-03 13:10:46 +00:00
|
|
|
mutex_t* block_mutex = buf_page_get_mutex(bpage);
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2007-01-03 13:10:46 +00:00
|
|
|
ut_ad(mutex_own(block_mutex));
|
|
|
|
ut_ad(buf_page_in_file(bpage));
|
|
|
|
ut_ad(bpage->in_LRU_list);
|
2007-01-16 16:24:47 +00:00
|
|
|
ut_ad(!bpage->in_flush_list == !bpage->oldest_modification);
|
2007-10-30 09:27:09 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(bpage, sizeof *bpage);
|
2007-01-03 13:10:46 +00:00
|
|
|
|
2007-01-04 21:40:10 +00:00
|
|
|
if (!buf_page_can_relocate(bpage)) {
|
2007-01-03 13:10:46 +00:00
|
|
|
|
2007-01-18 15:43:59 +00:00
|
|
|
/* Do not free buffer-fixed or I/O-fixed blocks. */
|
2008-03-03 12:57:07 +00:00
|
|
|
return(BUF_LRU_NOT_FREED);
|
2007-01-03 13:10:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 14:37:52 +00:00
|
|
|
#ifdef UNIV_IBUF_COUNT_DEBUG
|
|
|
|
ut_a(ibuf_count_get(bpage->space, bpage->offset) == 0);
|
|
|
|
#endif /* UNIV_IBUF_COUNT_DEBUG */
|
|
|
|
|
2007-01-18 15:43:59 +00:00
|
|
|
if (zip || !bpage->zip.data) {
|
|
|
|
/* This would completely free the block. */
|
2007-01-04 21:40:10 +00:00
|
|
|
/* Do not completely free dirty blocks. */
|
2007-01-09 12:47:15 +00:00
|
|
|
|
2007-01-18 15:43:59 +00:00
|
|
|
if (bpage->oldest_modification) {
|
2008-03-03 12:57:07 +00:00
|
|
|
return(BUF_LRU_NOT_FREED);
|
2007-01-09 12:47:15 +00:00
|
|
|
}
|
2007-01-18 15:43:59 +00:00
|
|
|
} else if (bpage->oldest_modification) {
|
|
|
|
/* Do not completely free dirty blocks. */
|
2007-01-09 12:47:15 +00:00
|
|
|
|
|
|
|
if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE) {
|
|
|
|
ut_ad(buf_page_get_state(bpage)
|
|
|
|
== BUF_BLOCK_ZIP_DIRTY);
|
2008-03-03 12:57:07 +00:00
|
|
|
return(BUF_LRU_NOT_FREED);
|
2007-01-09 12:47:15 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 15:43:59 +00:00
|
|
|
goto alloc;
|
2007-01-18 20:29:35 +00:00
|
|
|
} else if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
|
2007-01-18 15:43:59 +00:00
|
|
|
/* Allocate the control block for the compressed page.
|
|
|
|
If it cannot be allocated (without freeing a block
|
|
|
|
from the LRU list), refuse to free bpage. */
|
|
|
|
alloc:
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_forbid();
|
2007-02-08 14:19:55 +00:00
|
|
|
b = buf_buddy_alloc(sizeof *b, NULL);
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_allow();
|
2007-01-16 16:24:47 +00:00
|
|
|
|
2007-02-08 14:19:55 +00:00
|
|
|
if (UNIV_UNLIKELY(!b)) {
|
2008-03-03 12:57:07 +00:00
|
|
|
return(BUF_LRU_CANNOT_RELOCATE);
|
2007-01-16 16:24:47 +00:00
|
|
|
}
|
2008-02-16 10:33:15 +00:00
|
|
|
|
|
|
|
memcpy(b, bpage, sizeof *b);
|
2007-01-04 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-03 13:10:46 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
if (buf_debug_prints) {
|
|
|
|
fprintf(stderr, "Putting space %lu page %lu to free list\n",
|
|
|
|
(ulong) buf_page_get_space(bpage),
|
|
|
|
(ulong) buf_page_get_page_no(bpage));
|
|
|
|
}
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
|
|
|
if (buf_LRU_block_remove_hashed_page(bpage, zip)
|
|
|
|
!= BUF_BLOCK_ZIP_FREE) {
|
2007-01-16 16:24:47 +00:00
|
|
|
ut_a(bpage->buf_fix_count == 0);
|
|
|
|
|
|
|
|
if (b) {
|
2008-02-16 10:33:15 +00:00
|
|
|
buf_page_t* prev_b = UT_LIST_GET_PREV(LRU, b);
|
2007-01-16 16:24:47 +00:00
|
|
|
const ulint fold = buf_page_address_fold(
|
|
|
|
bpage->space, bpage->offset);
|
|
|
|
|
|
|
|
ut_a(!buf_page_hash_get(bpage->space, bpage->offset));
|
|
|
|
|
|
|
|
b->state = b->oldest_modification
|
|
|
|
? BUF_BLOCK_ZIP_DIRTY
|
|
|
|
: BUF_BLOCK_ZIP_PAGE;
|
|
|
|
UNIV_MEM_DESC(b->zip.data,
|
|
|
|
page_zip_get_size(&b->zip), b);
|
|
|
|
|
2008-02-16 10:33:15 +00:00
|
|
|
/* The fields in_page_hash and in_LRU_list of
|
|
|
|
the to-be-freed block descriptor should have
|
|
|
|
been cleared in
|
|
|
|
buf_LRU_block_remove_hashed_page(), which
|
|
|
|
invokes buf_LRU_remove_block(). */
|
|
|
|
ut_ad(!bpage->in_page_hash);
|
|
|
|
ut_ad(!bpage->in_LRU_list);
|
2008-03-03 12:57:07 +00:00
|
|
|
/* bpage->state was BUF_BLOCK_FILE_PAGE because
|
|
|
|
b != NULL. The type cast below is thus valid. */
|
|
|
|
ut_ad(!((buf_block_t*) bpage)->in_unzip_LRU_list);
|
2008-02-16 10:33:15 +00:00
|
|
|
|
|
|
|
/* The fields of bpage were copied to b before
|
|
|
|
buf_LRU_block_remove_hashed_page() was invoked. */
|
2007-01-24 10:36:05 +00:00
|
|
|
ut_ad(!b->in_zip_hash);
|
2008-02-16 10:33:15 +00:00
|
|
|
ut_ad(b->in_page_hash);
|
|
|
|
ut_ad(b->in_LRU_list);
|
|
|
|
|
2007-01-16 16:24:47 +00:00
|
|
|
HASH_INSERT(buf_page_t, hash,
|
|
|
|
buf_pool->page_hash, fold, b);
|
|
|
|
|
2008-02-16 10:33:15 +00:00
|
|
|
/* Insert b where bpage was in the LRU list. */
|
|
|
|
if (UNIV_LIKELY(prev_b != NULL)) {
|
2008-02-18 15:43:16 +00:00
|
|
|
ulint lru_len;
|
|
|
|
|
2008-02-16 10:33:15 +00:00
|
|
|
ut_ad(prev_b->in_LRU_list);
|
|
|
|
ut_ad(buf_page_in_file(prev_b));
|
|
|
|
UNIV_MEM_ASSERT_RW(prev_b, sizeof *prev_b);
|
|
|
|
|
|
|
|
UT_LIST_INSERT_AFTER(LRU, buf_pool->LRU,
|
|
|
|
prev_b, b);
|
|
|
|
|
2008-02-18 15:43:16 +00:00
|
|
|
if (buf_page_is_old(b)) {
|
|
|
|
buf_pool->LRU_old_len++;
|
2008-08-09 00:15:46 +00:00
|
|
|
if (UNIV_UNLIKELY
|
|
|
|
(buf_pool->LRU_old
|
|
|
|
== UT_LIST_GET_NEXT(LRU, b))) {
|
|
|
|
|
|
|
|
buf_pool->LRU_old = b;
|
|
|
|
}
|
2008-09-17 19:52:30 +00:00
|
|
|
#ifdef UNIV_LRU_DEBUG
|
|
|
|
ut_a(prev_b->old
|
|
|
|
|| !UT_LIST_GET_NEXT(LRU, b)
|
|
|
|
|| UT_LIST_GET_NEXT(LRU, b)->old);
|
|
|
|
} else {
|
|
|
|
ut_a(!prev_b->old
|
|
|
|
|| !UT_LIST_GET_NEXT(LRU, b)
|
|
|
|
|| !UT_LIST_GET_NEXT(LRU, b)->old);
|
|
|
|
#endif /* UNIV_LRU_DEBUG */
|
2008-02-18 15:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lru_len = UT_LIST_GET_LEN(buf_pool->LRU);
|
|
|
|
|
|
|
|
if (lru_len > BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
ut_ad(buf_pool->LRU_old);
|
|
|
|
/* Adjust the length of the
|
|
|
|
old block list if necessary */
|
|
|
|
buf_LRU_old_adjust_len();
|
|
|
|
} else if (lru_len == BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
/* The LRU list is now long
|
|
|
|
enough for LRU_old to become
|
|
|
|
defined: init it */
|
|
|
|
buf_LRU_old_init();
|
2008-02-16 10:33:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ut_d(b->in_LRU_list = FALSE);
|
|
|
|
buf_LRU_add_block_low(b, buf_page_is_old(b));
|
|
|
|
}
|
2007-01-16 16:24:47 +00:00
|
|
|
|
|
|
|
if (b->state == BUF_BLOCK_ZIP_PAGE) {
|
|
|
|
buf_LRU_insert_zip_clean(b);
|
|
|
|
} else {
|
2008-12-04 08:19:12 +00:00
|
|
|
/* Relocate on buf_pool->flush_list. */
|
|
|
|
buf_flush_relocate_on_flush_list(bpage, b);
|
2007-01-16 16:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bpage->zip.data = NULL;
|
|
|
|
page_zip_set_size(&bpage->zip, 0);
|
|
|
|
|
2007-02-07 13:59:43 +00:00
|
|
|
/* Prevent buf_page_get_gen() from
|
2007-01-16 16:24:47 +00:00
|
|
|
decompressing the block while we release
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex and block_mutex. */
|
2007-01-16 16:24:47 +00:00
|
|
|
b->buf_fix_count++;
|
2007-01-16 16:39:53 +00:00
|
|
|
b->io_fix = BUF_IO_READ;
|
2007-01-16 16:24:47 +00:00
|
|
|
}
|
|
|
|
|
2007-12-10 09:48:28 +00:00
|
|
|
if (buf_pool_mutex_released) {
|
|
|
|
*buf_pool_mutex_released = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2007-01-03 13:10:46 +00:00
|
|
|
mutex_exit(block_mutex);
|
|
|
|
|
2007-01-14 20:32:44 +00:00
|
|
|
/* Remove possible adaptive hash index on the page.
|
|
|
|
The page was declared uninitialized by
|
|
|
|
buf_LRU_block_remove_hashed_page(). We need to flag
|
|
|
|
the contents of the page valid (which it still is) in
|
|
|
|
order to avoid bogus Valgrind warnings.*/
|
|
|
|
|
|
|
|
UNIV_MEM_VALID(((buf_block_t*) bpage)->frame,
|
|
|
|
UNIV_PAGE_SIZE);
|
2007-01-03 13:10:46 +00:00
|
|
|
btr_search_drop_page_hash_index((buf_block_t*) bpage);
|
2007-01-14 20:32:44 +00:00
|
|
|
UNIV_MEM_INVALID(((buf_block_t*) bpage)->frame,
|
|
|
|
UNIV_PAGE_SIZE);
|
2007-01-03 13:10:46 +00:00
|
|
|
|
2007-01-16 16:24:47 +00:00
|
|
|
if (b) {
|
2007-01-08 17:08:57 +00:00
|
|
|
/* Compute and stamp the compressed page
|
|
|
|
checksum while not holding any mutex. The
|
|
|
|
block is already half-freed
|
|
|
|
(BUF_BLOCK_REMOVE_HASH) and removed from
|
|
|
|
buf_pool->page_hash, thus inaccessible by any
|
|
|
|
other thread. */
|
|
|
|
|
|
|
|
mach_write_to_4(
|
2007-01-16 16:24:47 +00:00
|
|
|
b->zip.data + FIL_PAGE_SPACE_OR_CHKSUM,
|
|
|
|
UNIV_LIKELY(srv_use_checksums)
|
|
|
|
? page_zip_calc_checksum(
|
|
|
|
b->zip.data,
|
|
|
|
page_zip_get_size(&b->zip))
|
|
|
|
: BUF_NO_CHECKSUM_MAGIC);
|
2007-01-08 17:08:57 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2007-01-16 16:24:47 +00:00
|
|
|
mutex_enter(block_mutex);
|
2007-01-03 15:54:05 +00:00
|
|
|
|
2007-01-16 16:24:47 +00:00
|
|
|
if (b) {
|
2008-01-10 09:37:13 +00:00
|
|
|
mutex_enter(&buf_pool_zip_mutex);
|
2007-01-16 16:24:47 +00:00
|
|
|
b->buf_fix_count--;
|
|
|
|
buf_page_set_io_fix(b, BUF_IO_NONE);
|
2008-01-10 09:37:13 +00:00
|
|
|
mutex_exit(&buf_pool_zip_mutex);
|
2007-01-03 13:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf_LRU_block_free_hashed_page((buf_block_t*) bpage);
|
|
|
|
} else {
|
branches/innodb+: Merge revisions 3931:4006 from branches/zip:
------------------------------------------------------------------------
r3938 | marko | 2009-01-15 10:28:23 +0200 (Thu, 15 Jan 2009) | 3 lines
branches/zip: buf_LRU_invalidate_tablespace(), buf_LRU_free_block():
Add comments and assertions that buf_LRU_block_remove_hashed_page()
will release block_mutex when it returns BUF_BLOCK_ZIP_FREE.
------------------------------------------------------------------------
r3939 | marko | 2009-01-15 10:37:51 +0200 (Thu, 15 Jan 2009) | 7 lines
branches/zip: buf0lru.c: Improve debug assertions.
buf_LRU_block_free_non_file_page(): ut_ad(block) before dereferencing block.
buf_LRU_block_remove_hashed_page(): Forbid buf_pool_mutex_exit() while
calling buf_buddy_free(). Callers of buf_LRU_block_remove_hashed_page()
assume that the buffer pool mutex will not be released and reacquired.
------------------------------------------------------------------------
r3944 | vasil | 2009-01-15 21:15:00 +0200 (Thu, 15 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for the bug fixes in r3911 and r3930.
------------------------------------------------------------------------
r3958 | marko | 2009-01-16 14:53:40 +0200 (Fri, 16 Jan 2009) | 8 lines
branches/zip: Add assertions that the kernel_mutex is being held
while accessing table->locks or un_member.tab_lock.locks.
This is related to Issue #158. According to static analysis,
the added debug assertions should always hold.
lock_table_has_to_wait_in_queue(), lock_queue_iterator_reset(),
lock_queue_iterator_get_prev(), add_trx_relevant_locks_to_cache(),
fetch_data_into_cache(): Add ut_ad(mutex_own(&kernel_mutex)).
------------------------------------------------------------------------
r4006 | marko | 2009-01-20 16:29:22 +0200 (Tue, 20 Jan 2009) | 33 lines
branches/zip: Merge revisions 3930:4005 from branches/5.1:
------------------------------------------------------------------------
r4004 | marko | 2009-01-20 16:19:00 +0200 (Tue, 20 Jan 2009) | 12 lines
branches/5.1: Merge r4003 from branches/5.0:
rec_set_nth_field(): When the field already is SQL null,
do nothing when it is being changed to SQL null. (Bug #41571)
Normally, MySQL does not pass "do-nothing" updates to the storage engine.
When it does and a column of an InnoDB table that is in ROW_FORMAT=COMPACT
is being updated from NULL to NULL, the InnoDB buffer pool will be corrupted
without this fix.
rb://81 approved by Heikki Tuuri
------------------------------------------------------------------------
r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before
accessing table->locks and release kernel_mutex before returning from
the function. This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)
rb://80 approved by Heikki Tuuri
------------------------------------------------------------------------
2009-01-20 14:34:02 +00:00
|
|
|
/* The block_mutex should have been released by
|
|
|
|
buf_LRU_block_remove_hashed_page() when it returns
|
|
|
|
BUF_BLOCK_ZIP_FREE. */
|
|
|
|
ut_ad(block_mutex == &buf_pool_zip_mutex);
|
2007-01-03 13:10:46 +00:00
|
|
|
mutex_enter(block_mutex);
|
|
|
|
}
|
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
return(BUF_LRU_FREED);
|
2007-01-03 13:10:46 +00:00
|
|
|
}
|
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Puts a block back to the free list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_block_free_non_file_page(
|
|
|
|
/*=============================*/
|
|
|
|
buf_block_t* block) /* in: block, must not contain a file page */
|
|
|
|
{
|
2007-01-03 13:10:46 +00:00
|
|
|
void* data;
|
2007-01-18 18:29:12 +00:00
|
|
|
|
branches/innodb+: Merge revisions 3931:4006 from branches/zip:
------------------------------------------------------------------------
r3938 | marko | 2009-01-15 10:28:23 +0200 (Thu, 15 Jan 2009) | 3 lines
branches/zip: buf_LRU_invalidate_tablespace(), buf_LRU_free_block():
Add comments and assertions that buf_LRU_block_remove_hashed_page()
will release block_mutex when it returns BUF_BLOCK_ZIP_FREE.
------------------------------------------------------------------------
r3939 | marko | 2009-01-15 10:37:51 +0200 (Thu, 15 Jan 2009) | 7 lines
branches/zip: buf0lru.c: Improve debug assertions.
buf_LRU_block_free_non_file_page(): ut_ad(block) before dereferencing block.
buf_LRU_block_remove_hashed_page(): Forbid buf_pool_mutex_exit() while
calling buf_buddy_free(). Callers of buf_LRU_block_remove_hashed_page()
assume that the buffer pool mutex will not be released and reacquired.
------------------------------------------------------------------------
r3944 | vasil | 2009-01-15 21:15:00 +0200 (Thu, 15 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for the bug fixes in r3911 and r3930.
------------------------------------------------------------------------
r3958 | marko | 2009-01-16 14:53:40 +0200 (Fri, 16 Jan 2009) | 8 lines
branches/zip: Add assertions that the kernel_mutex is being held
while accessing table->locks or un_member.tab_lock.locks.
This is related to Issue #158. According to static analysis,
the added debug assertions should always hold.
lock_table_has_to_wait_in_queue(), lock_queue_iterator_reset(),
lock_queue_iterator_get_prev(), add_trx_relevant_locks_to_cache(),
fetch_data_into_cache(): Add ut_ad(mutex_own(&kernel_mutex)).
------------------------------------------------------------------------
r4006 | marko | 2009-01-20 16:29:22 +0200 (Tue, 20 Jan 2009) | 33 lines
branches/zip: Merge revisions 3930:4005 from branches/5.1:
------------------------------------------------------------------------
r4004 | marko | 2009-01-20 16:19:00 +0200 (Tue, 20 Jan 2009) | 12 lines
branches/5.1: Merge r4003 from branches/5.0:
rec_set_nth_field(): When the field already is SQL null,
do nothing when it is being changed to SQL null. (Bug #41571)
Normally, MySQL does not pass "do-nothing" updates to the storage engine.
When it does and a column of an InnoDB table that is in ROW_FORMAT=COMPACT
is being updated from NULL to NULL, the InnoDB buffer pool will be corrupted
without this fix.
rb://81 approved by Heikki Tuuri
------------------------------------------------------------------------
r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before
accessing table->locks and release kernel_mutex before returning from
the function. This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)
rb://80 approved by Heikki Tuuri
------------------------------------------------------------------------
2009-01-20 14:34:02 +00:00
|
|
|
ut_ad(block);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-11-10 11:15:59 +00:00
|
|
|
ut_ad(mutex_own(&block->mutex));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-23 13:26:01 +00:00
|
|
|
switch (buf_block_get_state(block)) {
|
|
|
|
case BUF_BLOCK_MEMORY:
|
|
|
|
case BUF_BLOCK_READY_FOR_USE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ut_error;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-12-17 12:48:23 +00:00
|
|
|
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
|
|
|
|
ut_a(block->n_pointers == 0);
|
|
|
|
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
|
2006-12-04 12:44:06 +00:00
|
|
|
ut_ad(!block->page.in_free_list);
|
2007-01-09 12:35:42 +00:00
|
|
|
ut_ad(!block->page.in_flush_list);
|
|
|
|
ut_ad(!block->page.in_LRU_list);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-23 14:12:58 +00:00
|
|
|
buf_block_set_state(block, BUF_BLOCK_NOT_USED);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-03-28 11:07:28 +00:00
|
|
|
UNIV_MEM_ALLOC(block->frame, UNIV_PAGE_SIZE);
|
2006-02-23 19:25:29 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2005-10-27 07:29:40 +00:00
|
|
|
/* Wipe contents of page to reveal possible stale pointers to it */
|
|
|
|
memset(block->frame, '\0', UNIV_PAGE_SIZE);
|
2006-11-13 09:55:31 +00:00
|
|
|
#else
|
|
|
|
/* Wipe page_no and space_id */
|
|
|
|
memset(block->frame + FIL_PAGE_OFFSET, 0xfe, 4);
|
|
|
|
memset(block->frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xfe, 4);
|
2006-02-23 19:25:29 +00:00
|
|
|
#endif
|
2007-01-03 13:10:46 +00:00
|
|
|
data = block->page.zip.data;
|
|
|
|
|
|
|
|
if (data) {
|
2006-11-24 08:32:18 +00:00
|
|
|
block->page.zip.data = NULL;
|
2007-01-03 15:54:05 +00:00
|
|
|
mutex_exit(&block->mutex);
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_forbid();
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_buddy_free(data, page_zip_get_size(&block->page.zip));
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_allow();
|
2007-01-03 15:54:05 +00:00
|
|
|
mutex_enter(&block->mutex);
|
2006-11-27 13:44:32 +00:00
|
|
|
page_zip_set_size(&block->page.zip, 0);
|
2006-11-15 21:49:14 +00:00
|
|
|
}
|
|
|
|
|
2006-12-05 12:31:38 +00:00
|
|
|
UT_LIST_ADD_FIRST(list, buf_pool->free, (&block->page));
|
2006-12-04 12:44:06 +00:00
|
|
|
ut_d(block->page.in_free_list = TRUE);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-09-06 11:36:35 +00:00
|
|
|
UNIV_MEM_ASSERT_AND_FREE(block->frame, UNIV_PAGE_SIZE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2007-01-03 13:10:46 +00:00
|
|
|
Takes a block out of the LRU list and page hash table.
|
|
|
|
If the block is compressed-only (BUF_BLOCK_ZIP_PAGE),
|
2008-01-10 09:37:13 +00:00
|
|
|
the object will be freed and buf_pool_zip_mutex will be released.
|
2007-01-09 15:52:08 +00:00
|
|
|
|
|
|
|
If a compressed page or a compressed-only block descriptor is freed,
|
|
|
|
other compressed pages or compressed-only block descriptors may be
|
|
|
|
relocated. */
|
2005-10-27 07:29:40 +00:00
|
|
|
static
|
2006-12-15 15:05:18 +00:00
|
|
|
enum buf_page_state
|
2005-10-27 07:29:40 +00:00
|
|
|
buf_LRU_block_remove_hashed_page(
|
|
|
|
/*=============================*/
|
2006-12-15 15:05:18 +00:00
|
|
|
/* out: the new state of the block
|
|
|
|
(BUF_BLOCK_ZIP_FREE if the state was
|
|
|
|
BUF_BLOCK_ZIP_PAGE, or BUF_BLOCK_REMOVE_HASH
|
|
|
|
otherwise) */
|
|
|
|
buf_page_t* bpage, /* in: block, must contain a file page and
|
2005-10-27 07:29:40 +00:00
|
|
|
be in a state where it can be freed; there
|
|
|
|
may or may not be a hash index to the page */
|
2006-12-15 15:05:18 +00:00
|
|
|
ibool zip) /* in: TRUE if should remove also the
|
|
|
|
compressed page of an uncompressed page */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
const buf_page_t* hashed_bpage;
|
|
|
|
ut_ad(bpage);
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_ad(mutex_own(buf_page_get_mutex(bpage)));
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_page_get_io_fix(bpage) == BUF_IO_NONE);
|
|
|
|
ut_a(bpage->buf_fix_count == 0);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-10-31 10:40:41 +00:00
|
|
|
UNIV_MEM_ASSERT_RW(bpage, sizeof *bpage);
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_LRU_remove_block(bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
buf_pool->freed_page_clock += 1;
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
switch (buf_page_get_state(bpage)) {
|
|
|
|
case BUF_BLOCK_FILE_PAGE:
|
2007-10-31 10:40:41 +00:00
|
|
|
UNIV_MEM_ASSERT_W(bpage, sizeof(buf_block_t));
|
|
|
|
UNIV_MEM_ASSERT_W(((buf_block_t*) bpage)->frame,
|
|
|
|
UNIV_PAGE_SIZE);
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_block_modify_clock_inc((buf_block_t*) bpage);
|
2007-01-09 12:47:15 +00:00
|
|
|
if (bpage->zip.data) {
|
2007-01-16 10:24:13 +00:00
|
|
|
const page_t* page = ((buf_block_t*) bpage)->frame;
|
2008-08-09 00:15:46 +00:00
|
|
|
const ulint zip_size
|
|
|
|
= page_zip_get_size(&bpage->zip);
|
2007-01-16 10:24:13 +00:00
|
|
|
|
2007-01-09 12:47:15 +00:00
|
|
|
ut_a(!zip || bpage->oldest_modification == 0);
|
2007-01-16 10:24:13 +00:00
|
|
|
|
|
|
|
switch (UNIV_EXPECT(fil_page_get_type(page),
|
|
|
|
FIL_PAGE_INDEX)) {
|
|
|
|
case FIL_PAGE_TYPE_ALLOCATED:
|
|
|
|
case FIL_PAGE_INODE:
|
|
|
|
case FIL_PAGE_IBUF_BITMAP:
|
|
|
|
case FIL_PAGE_TYPE_FSP_HDR:
|
|
|
|
case FIL_PAGE_TYPE_XDES:
|
|
|
|
/* These are essentially uncompressed pages. */
|
|
|
|
if (!zip) {
|
|
|
|
/* InnoDB writes the data to the
|
|
|
|
uncompressed page frame. Copy it
|
2007-01-18 15:43:59 +00:00
|
|
|
to the compressed page, which will
|
2007-01-16 10:24:13 +00:00
|
|
|
be preserved. */
|
|
|
|
memcpy(bpage->zip.data, page,
|
2008-08-09 00:15:46 +00:00
|
|
|
zip_size);
|
2007-01-16 10:24:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FIL_PAGE_TYPE_ZBLOB:
|
2008-01-24 08:12:02 +00:00
|
|
|
case FIL_PAGE_TYPE_ZBLOB2:
|
2007-01-16 10:24:13 +00:00
|
|
|
break;
|
|
|
|
case FIL_PAGE_INDEX:
|
2007-01-09 12:47:15 +00:00
|
|
|
#ifdef UNIV_ZIP_DEBUG
|
2007-01-16 10:24:13 +00:00
|
|
|
ut_a(page_zip_validate(&bpage->zip, page));
|
2007-01-09 12:47:15 +00:00
|
|
|
#endif /* UNIV_ZIP_DEBUG */
|
2007-01-16 10:24:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-08-09 00:15:46 +00:00
|
|
|
ut_print_timestamp(stderr);
|
|
|
|
fputs(" InnoDB: ERROR: The compressed page"
|
|
|
|
" to be evicted seems corrupt:", stderr);
|
|
|
|
ut_print_buf(stderr, page, zip_size);
|
|
|
|
fputs("\nInnoDB: Possibly older version"
|
|
|
|
" of the page:", stderr);
|
|
|
|
ut_print_buf(stderr, bpage->zip.data,
|
|
|
|
zip_size);
|
|
|
|
putc('\n', stderr);
|
2007-01-16 10:24:13 +00:00
|
|
|
ut_error;
|
|
|
|
}
|
|
|
|
|
2007-01-09 12:47:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2006-11-30 12:27:49 +00:00
|
|
|
case BUF_BLOCK_ZIP_PAGE:
|
2007-01-09 12:47:15 +00:00
|
|
|
ut_a(bpage->oldest_modification == 0);
|
2007-10-31 10:40:41 +00:00
|
|
|
UNIV_MEM_ASSERT_W(bpage->zip.data,
|
|
|
|
page_zip_get_size(&bpage->zip));
|
2006-11-30 12:27:49 +00:00
|
|
|
break;
|
2006-12-15 15:05:18 +00:00
|
|
|
case BUF_BLOCK_ZIP_FREE:
|
|
|
|
case BUF_BLOCK_ZIP_DIRTY:
|
|
|
|
case BUF_BLOCK_NOT_USED:
|
|
|
|
case BUF_BLOCK_READY_FOR_USE:
|
|
|
|
case BUF_BLOCK_MEMORY:
|
|
|
|
case BUF_BLOCK_REMOVE_HASH:
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_error;
|
2006-12-15 15:05:18 +00:00
|
|
|
break;
|
2006-11-30 12:27:49 +00:00
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
hashed_bpage = buf_page_hash_get(bpage->space, bpage->offset);
|
2006-10-30 09:19:41 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (UNIV_UNLIKELY(bpage != hashed_bpage)) {
|
2006-02-23 19:25:29 +00:00
|
|
|
fprintf(stderr,
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: Error: page %lu %lu not found"
|
|
|
|
" in the hash table\n",
|
2006-11-30 12:27:49 +00:00
|
|
|
(ulong) bpage->space,
|
|
|
|
(ulong) bpage->offset);
|
|
|
|
if (hashed_bpage) {
|
2006-02-23 19:25:29 +00:00
|
|
|
fprintf(stderr,
|
2006-08-29 09:30:31 +00:00
|
|
|
"InnoDB: In hash table we find block"
|
|
|
|
" %p of %lu %lu which is not %p\n",
|
2006-11-30 12:27:49 +00:00
|
|
|
(const void*) hashed_bpage,
|
|
|
|
(ulong) hashed_bpage->space,
|
|
|
|
(ulong) hashed_bpage->offset,
|
|
|
|
(const void*) bpage);
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-16 09:00:30 +00:00
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
2007-01-09 12:47:15 +00:00
|
|
|
mutex_exit(buf_page_get_mutex(bpage));
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2006-02-23 19:25:29 +00:00
|
|
|
buf_print();
|
|
|
|
buf_LRU_print();
|
|
|
|
buf_validate();
|
|
|
|
buf_LRU_validate();
|
2006-11-16 09:00:30 +00:00
|
|
|
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
|
2006-10-30 09:19:41 +00:00
|
|
|
ut_error;
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-24 10:36:05 +00:00
|
|
|
ut_ad(!bpage->in_zip_hash);
|
|
|
|
ut_ad(bpage->in_page_hash);
|
|
|
|
ut_d(bpage->in_page_hash = FALSE);
|
2006-11-29 13:23:28 +00:00
|
|
|
HASH_DELETE(buf_page_t, hash, buf_pool->page_hash,
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_address_fold(bpage->space, bpage->offset),
|
|
|
|
bpage);
|
|
|
|
switch (buf_page_get_state(bpage)) {
|
|
|
|
case BUF_BLOCK_ZIP_PAGE:
|
2006-12-15 15:05:18 +00:00
|
|
|
ut_ad(!bpage->in_free_list);
|
2007-01-09 12:35:42 +00:00
|
|
|
ut_ad(!bpage->in_flush_list);
|
2006-12-15 15:05:18 +00:00
|
|
|
ut_ad(!bpage->in_LRU_list);
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(bpage->zip.data);
|
|
|
|
ut_a(buf_page_get_zip_size(bpage));
|
2007-01-03 13:10:46 +00:00
|
|
|
|
|
|
|
UT_LIST_REMOVE(list, buf_pool->zip_clean, bpage);
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
mutex_exit(&buf_pool_zip_mutex);
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_forbid();
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_buddy_free(bpage->zip.data,
|
|
|
|
page_zip_get_size(&bpage->zip));
|
|
|
|
buf_buddy_free(bpage, sizeof(*bpage));
|
2008-01-10 09:51:57 +00:00
|
|
|
buf_pool_mutex_exit_allow();
|
2007-01-12 12:36:40 +00:00
|
|
|
UNIV_MEM_UNDESC(bpage);
|
2007-01-03 13:10:46 +00:00
|
|
|
return(BUF_BLOCK_ZIP_FREE);
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
case BUF_BLOCK_FILE_PAGE:
|
|
|
|
memset(((buf_block_t*) bpage)->frame
|
|
|
|
+ FIL_PAGE_OFFSET, 0xff, 4);
|
|
|
|
memset(((buf_block_t*) bpage)->frame
|
|
|
|
+ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0xff, 4);
|
2007-01-12 12:36:40 +00:00
|
|
|
UNIV_MEM_INVALID(((buf_block_t*) bpage)->frame,
|
|
|
|
UNIV_PAGE_SIZE);
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_set_state(bpage, BUF_BLOCK_REMOVE_HASH);
|
2006-12-15 15:05:18 +00:00
|
|
|
|
2007-01-03 13:10:46 +00:00
|
|
|
if (zip && bpage->zip.data) {
|
2006-12-15 15:05:18 +00:00
|
|
|
/* Free the compressed page. */
|
2007-01-03 13:10:46 +00:00
|
|
|
void* data = bpage->zip.data;
|
2006-12-15 15:05:18 +00:00
|
|
|
bpage->zip.data = NULL;
|
2007-01-03 13:10:46 +00:00
|
|
|
|
2007-01-03 15:54:05 +00:00
|
|
|
mutex_exit(&((buf_block_t*) bpage)->mutex);
|
branches/innodb+: Merge revisions 3931:4006 from branches/zip:
------------------------------------------------------------------------
r3938 | marko | 2009-01-15 10:28:23 +0200 (Thu, 15 Jan 2009) | 3 lines
branches/zip: buf_LRU_invalidate_tablespace(), buf_LRU_free_block():
Add comments and assertions that buf_LRU_block_remove_hashed_page()
will release block_mutex when it returns BUF_BLOCK_ZIP_FREE.
------------------------------------------------------------------------
r3939 | marko | 2009-01-15 10:37:51 +0200 (Thu, 15 Jan 2009) | 7 lines
branches/zip: buf0lru.c: Improve debug assertions.
buf_LRU_block_free_non_file_page(): ut_ad(block) before dereferencing block.
buf_LRU_block_remove_hashed_page(): Forbid buf_pool_mutex_exit() while
calling buf_buddy_free(). Callers of buf_LRU_block_remove_hashed_page()
assume that the buffer pool mutex will not be released and reacquired.
------------------------------------------------------------------------
r3944 | vasil | 2009-01-15 21:15:00 +0200 (Thu, 15 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for the bug fixes in r3911 and r3930.
------------------------------------------------------------------------
r3958 | marko | 2009-01-16 14:53:40 +0200 (Fri, 16 Jan 2009) | 8 lines
branches/zip: Add assertions that the kernel_mutex is being held
while accessing table->locks or un_member.tab_lock.locks.
This is related to Issue #158. According to static analysis,
the added debug assertions should always hold.
lock_table_has_to_wait_in_queue(), lock_queue_iterator_reset(),
lock_queue_iterator_get_prev(), add_trx_relevant_locks_to_cache(),
fetch_data_into_cache(): Add ut_ad(mutex_own(&kernel_mutex)).
------------------------------------------------------------------------
r4006 | marko | 2009-01-20 16:29:22 +0200 (Tue, 20 Jan 2009) | 33 lines
branches/zip: Merge revisions 3930:4005 from branches/5.1:
------------------------------------------------------------------------
r4004 | marko | 2009-01-20 16:19:00 +0200 (Tue, 20 Jan 2009) | 12 lines
branches/5.1: Merge r4003 from branches/5.0:
rec_set_nth_field(): When the field already is SQL null,
do nothing when it is being changed to SQL null. (Bug #41571)
Normally, MySQL does not pass "do-nothing" updates to the storage engine.
When it does and a column of an InnoDB table that is in ROW_FORMAT=COMPACT
is being updated from NULL to NULL, the InnoDB buffer pool will be corrupted
without this fix.
rb://81 approved by Heikki Tuuri
------------------------------------------------------------------------
r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before
accessing table->locks and release kernel_mutex before returning from
the function. This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)
rb://80 approved by Heikki Tuuri
------------------------------------------------------------------------
2009-01-20 14:34:02 +00:00
|
|
|
buf_pool_mutex_exit_forbid();
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_buddy_free(data, page_zip_get_size(&bpage->zip));
|
branches/innodb+: Merge revisions 3931:4006 from branches/zip:
------------------------------------------------------------------------
r3938 | marko | 2009-01-15 10:28:23 +0200 (Thu, 15 Jan 2009) | 3 lines
branches/zip: buf_LRU_invalidate_tablespace(), buf_LRU_free_block():
Add comments and assertions that buf_LRU_block_remove_hashed_page()
will release block_mutex when it returns BUF_BLOCK_ZIP_FREE.
------------------------------------------------------------------------
r3939 | marko | 2009-01-15 10:37:51 +0200 (Thu, 15 Jan 2009) | 7 lines
branches/zip: buf0lru.c: Improve debug assertions.
buf_LRU_block_free_non_file_page(): ut_ad(block) before dereferencing block.
buf_LRU_block_remove_hashed_page(): Forbid buf_pool_mutex_exit() while
calling buf_buddy_free(). Callers of buf_LRU_block_remove_hashed_page()
assume that the buffer pool mutex will not be released and reacquired.
------------------------------------------------------------------------
r3944 | vasil | 2009-01-15 21:15:00 +0200 (Thu, 15 Jan 2009) | 4 lines
branches/zip:
Add ChangeLog entries for the bug fixes in r3911 and r3930.
------------------------------------------------------------------------
r3958 | marko | 2009-01-16 14:53:40 +0200 (Fri, 16 Jan 2009) | 8 lines
branches/zip: Add assertions that the kernel_mutex is being held
while accessing table->locks or un_member.tab_lock.locks.
This is related to Issue #158. According to static analysis,
the added debug assertions should always hold.
lock_table_has_to_wait_in_queue(), lock_queue_iterator_reset(),
lock_queue_iterator_get_prev(), add_trx_relevant_locks_to_cache(),
fetch_data_into_cache(): Add ut_ad(mutex_own(&kernel_mutex)).
------------------------------------------------------------------------
r4006 | marko | 2009-01-20 16:29:22 +0200 (Tue, 20 Jan 2009) | 33 lines
branches/zip: Merge revisions 3930:4005 from branches/5.1:
------------------------------------------------------------------------
r4004 | marko | 2009-01-20 16:19:00 +0200 (Tue, 20 Jan 2009) | 12 lines
branches/5.1: Merge r4003 from branches/5.0:
rec_set_nth_field(): When the field already is SQL null,
do nothing when it is being changed to SQL null. (Bug #41571)
Normally, MySQL does not pass "do-nothing" updates to the storage engine.
When it does and a column of an InnoDB table that is in ROW_FORMAT=COMPACT
is being updated from NULL to NULL, the InnoDB buffer pool will be corrupted
without this fix.
rb://81 approved by Heikki Tuuri
------------------------------------------------------------------------
r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before
accessing table->locks and release kernel_mutex before returning from
the function. This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)
rb://80 approved by Heikki Tuuri
------------------------------------------------------------------------
2009-01-20 14:34:02 +00:00
|
|
|
buf_pool_mutex_exit_allow();
|
2007-01-03 15:54:05 +00:00
|
|
|
mutex_enter(&((buf_block_t*) bpage)->mutex);
|
2006-12-15 15:05:18 +00:00
|
|
|
page_zip_set_size(&bpage->zip, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(BUF_BLOCK_REMOVE_HASH);
|
|
|
|
|
|
|
|
case BUF_BLOCK_ZIP_FREE:
|
|
|
|
case BUF_BLOCK_ZIP_DIRTY:
|
|
|
|
case BUF_BLOCK_NOT_USED:
|
|
|
|
case BUF_BLOCK_READY_FOR_USE:
|
|
|
|
case BUF_BLOCK_MEMORY:
|
|
|
|
case BUF_BLOCK_REMOVE_HASH:
|
2006-11-30 12:27:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-15 15:05:18 +00:00
|
|
|
|
|
|
|
ut_error;
|
|
|
|
return(BUF_BLOCK_ZIP_FREE);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Puts a file page whose has no hash index to the free list. */
|
|
|
|
static
|
|
|
|
void
|
|
|
|
buf_LRU_block_free_hashed_page(
|
|
|
|
/*===========================*/
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_block_t* block) /* in: block, must contain a file page and
|
2005-10-27 07:29:40 +00:00
|
|
|
be in a state where it can be freed */
|
|
|
|
{
|
2008-01-10 09:37:13 +00:00
|
|
|
ut_ad(buf_pool_mutex_own());
|
2007-01-03 13:10:46 +00:00
|
|
|
ut_ad(mutex_own(&block->mutex));
|
2007-01-18 18:29:12 +00:00
|
|
|
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_block_set_state(block, BUF_BLOCK_MEMORY);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2007-01-03 13:10:46 +00:00
|
|
|
buf_LRU_block_free_non_file_page(block);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
/************************************************************************
|
|
|
|
Update the historical stats that we are collecting for LRU eviction
|
|
|
|
policy at the end of each interval. */
|
|
|
|
UNIV_INTERN
|
|
|
|
void
|
|
|
|
buf_LRU_stat_update(void)
|
|
|
|
/*=====================*/
|
|
|
|
{
|
|
|
|
buf_LRU_stat_t* item;
|
|
|
|
|
|
|
|
/* If we haven't started eviction yet then don't update stats. */
|
|
|
|
if (buf_pool->freed_page_clock == 0) {
|
|
|
|
goto func_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf_pool_mutex_enter();
|
|
|
|
|
|
|
|
/* Update the index. */
|
|
|
|
item = &buf_LRU_stat_arr[buf_LRU_stat_arr_ind];
|
|
|
|
buf_LRU_stat_arr_ind++;
|
|
|
|
buf_LRU_stat_arr_ind %= BUF_LRU_STAT_N_INTERVAL;
|
|
|
|
|
|
|
|
/* Add the current value and subtract the obsolete entry. */
|
|
|
|
buf_LRU_stat_sum.io += buf_LRU_stat_cur.io - item->io;
|
|
|
|
buf_LRU_stat_sum.unzip += buf_LRU_stat_cur.unzip - item->unzip;
|
|
|
|
|
|
|
|
/* Put current entry in the array. */
|
|
|
|
memcpy(item, &buf_LRU_stat_cur, sizeof *item);
|
|
|
|
|
|
|
|
buf_pool_mutex_exit();
|
|
|
|
|
|
|
|
func_exit:
|
|
|
|
/* Clear the current entry. */
|
|
|
|
memset(&buf_LRU_stat_cur, 0, sizeof buf_LRU_stat_cur);
|
|
|
|
}
|
|
|
|
|
2006-11-16 09:00:30 +00:00
|
|
|
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
2005-10-27 07:29:40 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Validates the LRU list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
ibool
|
|
|
|
buf_LRU_validate(void)
|
|
|
|
/*==================*/
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
buf_page_t* bpage;
|
2008-03-03 12:57:07 +00:00
|
|
|
buf_block_t* block;
|
2005-10-27 07:29:40 +00:00
|
|
|
ulint old_len;
|
|
|
|
ulint new_len;
|
|
|
|
ulint LRU_pos;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(buf_pool);
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
if (UT_LIST_GET_LEN(buf_pool->LRU) >= BUF_LRU_OLD_MIN_LEN) {
|
|
|
|
|
|
|
|
ut_a(buf_pool->LRU_old);
|
|
|
|
old_len = buf_pool->LRU_old_len;
|
|
|
|
new_len = 3 * (UT_LIST_GET_LEN(buf_pool->LRU) / 8);
|
|
|
|
ut_a(old_len >= new_len - BUF_LRU_OLD_TOLERANCE);
|
|
|
|
ut_a(old_len <= new_len + BUF_LRU_OLD_TOLERANCE);
|
|
|
|
}
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
UT_LIST_VALIDATE(LRU, buf_page_t, buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_FIRST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
old_len = 0;
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
while (bpage != NULL) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
switch (buf_page_get_state(bpage)) {
|
|
|
|
case BUF_BLOCK_ZIP_FREE:
|
|
|
|
case BUF_BLOCK_NOT_USED:
|
|
|
|
case BUF_BLOCK_READY_FOR_USE:
|
|
|
|
case BUF_BLOCK_MEMORY:
|
|
|
|
case BUF_BLOCK_REMOVE_HASH:
|
|
|
|
ut_error;
|
|
|
|
break;
|
|
|
|
case BUF_BLOCK_FILE_PAGE:
|
|
|
|
ut_ad(((buf_block_t*) bpage)->in_unzip_LRU_list
|
|
|
|
== buf_page_belongs_to_unzip_LRU(bpage));
|
|
|
|
case BUF_BLOCK_ZIP_PAGE:
|
|
|
|
case BUF_BLOCK_ZIP_DIRTY:
|
|
|
|
break;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_is_old(bpage)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
old_len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_pool->LRU_old && (old_len == 1)) {
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(buf_pool->LRU_old == bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
LRU_pos = buf_page_get_LRU_position(bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_NEXT(LRU, bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (bpage) {
|
2005-10-27 07:29:40 +00:00
|
|
|
/* If the following assert fails, it may
|
|
|
|
not be an error: just the buf_pool clock
|
|
|
|
has wrapped around */
|
2006-11-30 12:27:49 +00:00
|
|
|
ut_a(LRU_pos >= buf_page_get_LRU_position(bpage));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_pool->LRU_old) {
|
|
|
|
ut_a(buf_pool->LRU_old_len == old_len);
|
2006-02-23 19:25:29 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-12-05 12:31:38 +00:00
|
|
|
UT_LIST_VALIDATE(list, buf_page_t, buf_pool->free);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-12-04 12:44:06 +00:00
|
|
|
for (bpage = UT_LIST_GET_FIRST(buf_pool->free);
|
|
|
|
bpage != NULL;
|
2006-12-05 12:31:38 +00:00
|
|
|
bpage = UT_LIST_GET_NEXT(list, bpage)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-12-04 12:44:06 +00:00
|
|
|
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_NOT_USED);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-03 12:57:07 +00:00
|
|
|
UT_LIST_VALIDATE(unzip_LRU, buf_block_t, buf_pool->unzip_LRU);
|
|
|
|
|
|
|
|
for (block = UT_LIST_GET_FIRST(buf_pool->unzip_LRU);
|
|
|
|
block;
|
|
|
|
block = UT_LIST_GET_NEXT(unzip_LRU, block)) {
|
|
|
|
|
|
|
|
ut_ad(block->in_unzip_LRU_list);
|
|
|
|
ut_ad(block->page.in_LRU_list);
|
|
|
|
ut_a(buf_page_belongs_to_unzip_LRU(&block->page));
|
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
return(TRUE);
|
|
|
|
}
|
2006-11-16 09:00:30 +00:00
|
|
|
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-16 09:00:30 +00:00
|
|
|
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
|
2005-10-27 07:29:40 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Prints the LRU list. */
|
2008-02-06 14:17:36 +00:00
|
|
|
UNIV_INTERN
|
2005-10-27 07:29:40 +00:00
|
|
|
void
|
|
|
|
buf_LRU_print(void)
|
|
|
|
/*===============*/
|
|
|
|
{
|
2006-11-30 12:27:49 +00:00
|
|
|
const buf_page_t* bpage;
|
2006-02-23 19:25:29 +00:00
|
|
|
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(buf_pool);
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_enter();
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-08-29 09:30:31 +00:00
|
|
|
fprintf(stderr, "Pool ulint clock %lu\n",
|
|
|
|
(ulong) buf_pool->ulint_clock);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_FIRST(buf_pool->LRU);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
while (bpage != NULL) {
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-24 12:49:59 +00:00
|
|
|
fprintf(stderr, "BLOCK space %lu page %lu ",
|
2006-11-30 12:27:49 +00:00
|
|
|
(ulong) buf_page_get_space(bpage),
|
|
|
|
(ulong) buf_page_get_page_no(bpage));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_is_old(bpage)) {
|
2005-10-27 07:29:40 +00:00
|
|
|
fputs("old ", stderr);
|
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (bpage->buf_fix_count) {
|
2005-10-27 07:29:40 +00:00
|
|
|
fprintf(stderr, "buffix count %lu ",
|
2006-11-30 12:27:49 +00:00
|
|
|
(ulong) bpage->buf_fix_count);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (buf_page_get_io_fix(bpage)) {
|
|
|
|
fprintf(stderr, "io_fix %lu ",
|
|
|
|
(ulong) buf_page_get_io_fix(bpage));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
if (bpage->oldest_modification) {
|
2005-10-27 07:29:40 +00:00
|
|
|
fputs("modif. ", stderr);
|
|
|
|
}
|
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
switch (buf_page_get_state(bpage)) {
|
|
|
|
const byte* frame;
|
|
|
|
case BUF_BLOCK_FILE_PAGE:
|
|
|
|
frame = buf_block_get_frame((buf_block_t*) bpage);
|
|
|
|
fprintf(stderr, "\nLRU pos %lu type %lu"
|
|
|
|
" index id %lu\n",
|
|
|
|
(ulong) buf_page_get_LRU_position(bpage),
|
|
|
|
(ulong) fil_page_get_type(frame),
|
|
|
|
(ulong) ut_dulint_get_low(
|
|
|
|
btr_page_get_index_id(frame)));
|
|
|
|
break;
|
|
|
|
case BUF_BLOCK_ZIP_PAGE:
|
|
|
|
frame = bpage->zip.data;
|
|
|
|
fprintf(stderr, "\nLRU pos %lu type %lu size %lu"
|
|
|
|
" index id %lu\n",
|
|
|
|
(ulong) buf_page_get_LRU_position(bpage),
|
|
|
|
(ulong) fil_page_get_type(frame),
|
|
|
|
(ulong) buf_page_get_zip_size(bpage),
|
|
|
|
(ulong) ut_dulint_get_low(
|
|
|
|
btr_page_get_index_id(frame)));
|
|
|
|
break;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "\nLRU pos %lu !state %lu!\n",
|
|
|
|
(ulong) buf_page_get_LRU_position(bpage),
|
|
|
|
(ulong) buf_page_get_state(bpage));
|
|
|
|
break;
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2006-11-30 12:27:49 +00:00
|
|
|
bpage = UT_LIST_GET_NEXT(LRU, bpage);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 09:37:13 +00:00
|
|
|
buf_pool_mutex_exit();
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2006-11-16 09:00:30 +00:00
|
|
|
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
|