239
235
the read requests for the whole area.
242
#ifndef UNIV_HOTBACKUP
243
/** Value in microseconds */
238
/* Value in microseconds */
244
239
static const int WAIT_FOR_READ = 5000;
246
/** The buffer buf_pool of the database */
241
/* The buffer buf_pool of the database */
247
242
UNIV_INTERN buf_pool_t* buf_pool = NULL;
249
/** mutex protecting the buffer pool struct and control blocks, except the
244
/* mutex protecting the buffer pool struct and control blocks, except the
250
245
read-write lock in them */
251
246
UNIV_INTERN mutex_t buf_pool_mutex;
252
/** mutex protecting the control blocks of compressed-only pages
247
/* mutex protecting the control blocks of compressed-only pages
253
248
(of type buf_page_t, not buf_block_t) */
254
249
UNIV_INTERN mutex_t buf_pool_zip_mutex;
256
251
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
257
static ulint buf_dbg_counter = 0; /*!< This is used to insert validation
252
static ulint buf_dbg_counter = 0; /* This is used to insert validation
258
253
operations in excution in the
260
255
/** Flag to forbid the release of the buffer pool mutex.
262
257
UNIV_INTERN ulint buf_pool_mutex_exit_forbidden = 0;
263
258
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
264
259
#ifdef UNIV_DEBUG
265
/** If this is set TRUE, the program prints info whenever
260
/* If this is set TRUE, the program prints info whenever
266
261
read-ahead or flush occurs */
267
262
UNIV_INTERN ibool buf_debug_prints = FALSE;
268
263
#endif /* UNIV_DEBUG */
270
/** A chunk of buffers. The buffer pool is allocated in chunks. */
265
/* A chunk of buffers. The buffer pool is allocated in chunks. */
271
266
struct buf_chunk_struct{
272
ulint mem_size; /*!< allocated size of the chunk */
273
ulint size; /*!< size of frames[] and blocks[] */
274
void* mem; /*!< pointer to the memory area which
267
ulint mem_size; /* allocated size of the chunk */
268
ulint size; /* size of frames[] and blocks[] */
269
void* mem; /* pointer to the memory area which
275
270
was allocated for the frames */
276
buf_block_t* blocks; /*!< array of buffer control blocks */
271
buf_block_t* blocks; /* array of buffer control blocks */
278
#endif /* !UNIV_HOTBACKUP */
280
/********************************************************************//**
274
/************************************************************************
281
275
Calculates a page checksum which is stored to the page when it is written
282
276
to a file. Note that we must be careful to calculate the same value on
283
32-bit and 64-bit architectures.
277
32-bit and 64-bit architectures. */
287
280
buf_calc_page_new_checksum(
288
281
/*=======================*/
289
const byte* page) /*!< in: buffer page */
283
const byte* page) /* in: buffer page */
308
302
return(checksum);
311
/********************************************************************//**
305
/************************************************************************
312
306
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
313
307
looked at the first few bytes of the page. This calculates that old
315
309
NOTE: we must first store the new formula checksum to
316
310
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
317
because this takes that field as an input!
311
because this takes that field as an input! */
321
314
buf_calc_page_old_checksum(
322
315
/*=======================*/
323
const byte* page) /*!< in: buffer page */
317
const byte* page) /* in: buffer page */
331
325
return(checksum);
334
/********************************************************************//**
335
Checks if a page is corrupt.
336
@return TRUE if corrupted */
328
/************************************************************************
329
Checks if a page is corrupt. */
339
332
buf_page_is_corrupted(
340
333
/*==================*/
341
const byte* read_buf, /*!< in: a database page */
342
ulint zip_size) /*!< in: size of compressed page;
334
/* out: TRUE if corrupted */
335
const byte* read_buf, /* in: a database page */
336
ulint zip_size) /* in: size of compressed page;
343
337
0 for uncompressed pages */
345
339
ulint checksum_field;
346
340
ulint old_checksum_field;
341
#ifndef UNIV_HOTBACKUP
342
ib_uint64_t current_lsn;
348
344
if (UNIV_LIKELY(!zip_size)
349
345
&& memcmp(read_buf + FIL_PAGE_LSN + 4,
350
346
read_buf + UNIV_PAGE_SIZE
359
355
#ifndef UNIV_HOTBACKUP
360
if (recv_lsn_checks_on) {
361
ib_uint64_t current_lsn;
363
if (log_peek_lsn(¤t_lsn)
364
&& current_lsn < mach_read_ull(read_buf + FIL_PAGE_LSN)) {
356
if (recv_lsn_checks_on && log_peek_lsn(¤t_lsn)) {
357
if (current_lsn < mach_read_ull(read_buf + FIL_PAGE_LSN)) {
365
358
ut_print_timestamp(stderr);
373
366
"you may have copied the InnoDB\n"
374
367
"InnoDB: tablespace but not the InnoDB "
375
368
"log files. See\n"
376
"InnoDB: " REFMAN "forcing-recovery.html\n"
369
"InnoDB: http://dev.mysql.com/doc/refman/"
370
"5.1/en/forcing-recovery.html\n"
377
371
"InnoDB: for more information.\n",
378
372
(ulong) mach_read_from_4(read_buf
379
373
+ FIL_PAGE_OFFSET),
437
/********************************************************************//**
431
/************************************************************************
438
432
Prints a page to stderr. */
443
const byte* read_buf, /*!< in: a database page */
444
ulint zip_size) /*!< in: compressed page size, or
437
const byte* read_buf, /* in: a database page */
438
ulint zip_size) /* in: compressed page size, or
445
439
0 for uncompressed pages */
447
#ifndef UNIV_HOTBACKUP
448
441
dict_index_t* index;
449
#endif /* !UNIV_HOTBACKUP */
451
443
ulint old_checksum;
452
444
ulint size = zip_size;
582
572
btr_page_get_index_id(read_buf)),
583
573
(ulong) ut_dulint_get_low(
584
574
btr_page_get_index_id(read_buf)));
585
#ifndef UNIV_HOTBACKUP
576
#ifdef UNIV_HOTBACKUP
577
/* If the code is in ibbackup, dict_sys may be uninitialized,
580
if (dict_sys == NULL) {
583
#endif /* UNIV_HOTBACKUP */
586
585
index = dict_index_find_on_id_low(
587
586
btr_page_get_index_id(read_buf));
638
#ifndef UNIV_HOTBACKUP
639
/********************************************************************//**
636
/************************************************************************
640
637
Initializes a buffer control block when the buf_pool is created. */
645
buf_block_t* block, /*!< in: pointer to control block */
646
byte* frame) /*!< in: pointer to buffer frame */
642
buf_block_t* block, /* in: pointer to control block */
643
byte* frame) /* in: pointer to buffer frame */
648
645
UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE, block);
685
682
#endif /* UNIV_SYNC_DEBUG */
688
/********************************************************************//**
689
Allocates a chunk of buffer frames.
690
@return chunk, or NULL on failure */
685
/************************************************************************
686
Allocates a chunk of buffer frames. */
695
buf_chunk_t* chunk, /*!< out: chunk of buffers */
696
ulint mem_size) /*!< in: requested size in bytes */
691
/* out: chunk, or NULL on failure */
692
buf_chunk_t* chunk, /* out: chunk of buffers */
693
ulint mem_size) /* in: requested size in bytes */
698
695
buf_block_t* block;
767
764
#ifdef UNIV_DEBUG
768
/*********************************************************************//**
765
/*************************************************************************
769
766
Finds a block in the given buffer chunk that points to a
770
given compressed page.
771
@return buffer block pointing to the compressed page, or NULL */
767
given compressed page. */
774
770
buf_chunk_contains_zip(
775
771
/*===================*/
776
buf_chunk_t* chunk, /*!< in: chunk being checked */
777
const void* data) /*!< in: pointer to compressed page */
772
/* out: buffer block pointing to
773
the compressed page, or NULL */
774
buf_chunk_t* chunk, /* in: chunk being checked */
775
const void* data) /* in: pointer to compressed page */
779
777
buf_block_t* block;
797
/*********************************************************************//**
795
/*************************************************************************
798
796
Finds a block in the buffer pool that points to a
799
given compressed page.
800
@return buffer block pointing to the compressed page, or NULL */
797
given compressed page. */
803
800
buf_pool_contains_zip(
804
801
/*==================*/
805
const void* data) /*!< in: pointer to compressed page */
802
/* out: buffer block pointing to
803
the compressed page, or NULL */
804
const void* data) /* in: pointer to compressed page */
808
807
buf_chunk_t* chunk = buf_pool->chunks;
820
819
#endif /* UNIV_DEBUG */
822
/*********************************************************************//**
823
Checks that all file pages in the buffer chunk are in a replaceable state.
824
@return address of a non-free block, or NULL if all freed */
821
/*************************************************************************
822
Checks that all file pages in the buffer chunk are in a replaceable state. */
826
824
const buf_block_t*
827
825
buf_chunk_not_freed(
828
826
/*================*/
829
buf_chunk_t* chunk) /*!< in: chunk being checked */
827
/* out: address of a non-free block,
828
or NULL if all freed */
829
buf_chunk_t* chunk) /* in: chunk being checked */
831
831
buf_block_t* block;
855
/*********************************************************************//**
856
Checks that all blocks in the buffer chunk are in BUF_BLOCK_NOT_USED state.
857
@return TRUE if all freed */
855
/*************************************************************************
856
Checks that all blocks in the buffer chunk are in BUF_BLOCK_NOT_USED state. */
860
859
buf_chunk_all_free(
861
860
/*===============*/
862
const buf_chunk_t* chunk) /*!< in: chunk being checked */
861
/* out: TRUE if all freed */
862
const buf_chunk_t* chunk) /* in: chunk being checked */
864
864
const buf_block_t* block;
883
/********************************************************************//**
883
/************************************************************************
884
884
Frees a chunk of buffer frames. */
889
buf_chunk_t* chunk) /*!< out: chunk of buffers */
889
buf_chunk_t* chunk) /* out: chunk of buffers */
891
891
buf_block_t* block;
892
892
const buf_block_t* block_end;
918
918
os_mem_free_large(chunk->mem, chunk->mem_size);
921
/********************************************************************//**
922
Creates the buffer pool.
923
@return own: buf_pool object, NULL if not enough memory or error */
921
/************************************************************************
922
Creates the buffer pool. */
926
925
buf_pool_init(void)
927
926
/*===============*/
927
/* out, own: buf_pool object, NULL if not
928
enough memory or error */
929
930
buf_chunk_t* chunk;
1087
1089
} while (released_search_latch);
1090
/********************************************************************//**
1092
/************************************************************************
1091
1093
Relocate a buffer control block. Relocates the block on the LRU list
1092
1094
and in buf_pool->page_hash. Does not relocate bpage->list.
1093
1095
The caller must take care of relocating bpage->list. */
1098
buf_page_t* bpage, /*!< in/out: control block being relocated;
1100
buf_page_t* bpage, /* in/out: control block being relocated;
1099
1101
buf_page_get_state(bpage) must be
1100
1102
BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */
1101
buf_page_t* dpage) /*!< in/out: destination control block */
1103
buf_page_t* dpage) /* in/out: destination control block */
1153
1155
#endif /* UNIV_LRU_DEBUG */
1156
ut_d(UT_LIST_VALIDATE(LRU, buf_page_t, buf_pool->LRU,
1157
ut_ad(ut_list_node_313->in_LRU_list)));
1158
ut_d(UT_LIST_VALIDATE(LRU, buf_page_t, buf_pool->LRU));
1159
1160
/* relocate buf_pool->page_hash */
1160
1161
fold = buf_page_address_fold(bpage->space, bpage->offset);
1165
1166
UNIV_MEM_INVALID(bpage, sizeof *bpage);
1168
/********************************************************************//**
1169
/************************************************************************
1169
1170
Shrinks the buffer pool. */
1172
1173
buf_pool_shrink(
1173
1174
/*============*/
1174
ulint chunk_size) /*!< in: number of pages to remove */
1175
/* out: TRUE if shrunk */
1176
ulint chunk_size) /* in: number of pages to remove */
1176
1178
buf_chunk_t* chunks;
1177
1179
buf_chunk_t* chunk;
1470
1472
buf_pool_page_hash_rebuild();
1473
/********************************************************************//**
1474
Moves the block to the start of the LRU list if there is a danger
1475
/************************************************************************
1476
Moves to the block to the start of the LRU list if there is a danger
1475
1477
that the block would drift out of the buffer pool. */
1478
1480
buf_block_make_young(
1479
1481
/*=================*/
1480
buf_page_t* bpage) /*!< in: block to make younger */
1482
buf_page_t* bpage) /* in: block to make younger */
1482
1484
ut_ad(!buf_pool_mutex_own());
1514
1516
buf_pool_mutex_exit();
1517
/********************************************************************//**
1519
/************************************************************************
1518
1520
Resets the check_index_page_at_flush field of a page if found in the buffer
1522
1524
buf_reset_check_index_page_at_flush(
1523
1525
/*================================*/
1524
ulint space, /*!< in: space id */
1525
ulint offset) /*!< in: page number */
1526
ulint space, /* in: space id */
1527
ulint offset) /* in: page number */
1527
1529
buf_block_t* block;
1537
1539
buf_pool_mutex_exit();
1540
/********************************************************************//**
1542
/************************************************************************
1541
1543
Returns the current state of is_hashed of a page. FALSE if the page is
1542
1544
not in the pool. NOTE that this operation does not fix the page in the
1543
pool if it is found there.
1544
@return TRUE if page hash index is built in search system */
1545
pool if it is found there. */
1547
1548
buf_page_peek_if_search_hashed(
1548
1549
/*===========================*/
1549
ulint space, /*!< in: space id */
1550
ulint offset) /*!< in: page number */
1550
/* out: TRUE if page hash index is built in search
1552
ulint space, /* in: space id */
1553
ulint offset) /* in: page number */
1552
1555
buf_block_t* block;
1553
1556
ibool is_hashed;
1570
1573
#ifdef UNIV_DEBUG_FILE_ACCESSES
1571
/********************************************************************//**
1574
/************************************************************************
1572
1575
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
1573
1576
This function should be called when we free a file page and want the
1574
1577
debug version to check that it is not accessed any more unless
1576
@return control block if found in page hash table, otherwise NULL */
1579
1581
buf_page_set_file_page_was_freed(
1580
1582
/*=============================*/
1581
ulint space, /*!< in: space id */
1582
ulint offset) /*!< in: page number */
1583
/* out: control block if found in page hash table,
1585
ulint space, /* in: space id */
1586
ulint offset) /* in: page number */
1584
1588
buf_page_t* bpage;
1599
/********************************************************************//**
1603
/************************************************************************
1600
1604
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
1601
1605
This function should be called when we free a file page and want the
1602
1606
debug version to check that it is not accessed any more unless
1604
@return control block if found in page hash table, otherwise NULL */
1607
1610
buf_page_reset_file_page_was_freed(
1608
1611
/*===============================*/
1609
ulint space, /*!< in: space id */
1610
ulint offset) /*!< in: page number */
1612
/* out: control block if found in page hash table,
1614
ulint space, /* in: space id */
1615
ulint offset) /* in: page number */
1612
1617
buf_page_t* bpage;
1626
1631
#endif /* UNIV_DEBUG_FILE_ACCESSES */
1628
/********************************************************************//**
1633
/************************************************************************
1629
1634
Get read access to a compressed page (usually of type
1630
1635
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
1631
1636
The page must be released with buf_page_release_zip().
1632
1637
NOTE: the page is not protected by any latch. Mutual exclusion has to
1633
1638
be implemented at a higher level. In other words, all possible
1634
1639
accesses to a given page through this function must be protected by
1635
the same set of mutexes or latches.
1636
@return pointer to the block */
1640
the same set of mutexes or latches. */
1639
1643
buf_page_get_zip(
1640
1644
/*=============*/
1641
ulint space, /*!< in: space id */
1642
ulint zip_size,/*!< in: compressed page size */
1643
ulint offset) /*!< in: page number */
1645
/* out: pointer to the block */
1646
ulint space, /* in: space id */
1647
ulint zip_size,/* in: compressed page size */
1648
ulint offset) /* in: page number */
1645
1650
buf_page_t* bpage;
1646
1651
mutex_t* block_mutex;
1673
1678
if (UNIV_UNLIKELY(!bpage->zip.data)) {
1674
1679
/* There is no compressed page. */
1676
1680
buf_pool_mutex_exit();
1684
block_mutex = buf_page_get_mutex(bpage);
1685
mutex_enter(block_mutex);
1680
1687
switch (buf_page_get_state(bpage)) {
1681
1688
case BUF_BLOCK_NOT_USED:
1682
1689
case BUF_BLOCK_READY_FOR_USE:
1683
1690
case BUF_BLOCK_MEMORY:
1684
1691
case BUF_BLOCK_REMOVE_HASH:
1685
1692
case BUF_BLOCK_ZIP_FREE:
1687
1695
case BUF_BLOCK_ZIP_PAGE:
1688
1696
case BUF_BLOCK_ZIP_DIRTY:
1689
block_mutex = &buf_pool_zip_mutex;
1690
mutex_enter(block_mutex);
1691
1697
bpage->buf_fix_count++;
1693
1699
case BUF_BLOCK_FILE_PAGE:
1694
block_mutex = &((buf_block_t*) bpage)->mutex;
1695
mutex_enter(block_mutex);
1697
1700
/* Discard the uncompressed page frame if possible. */
1698
1701
if (buf_LRU_free_block(bpage, FALSE, NULL)
1699
1702
== BUF_LRU_FREED) {
1761
/********************************************************************//**
1760
/************************************************************************
1762
1761
Initialize some fields of a control block. */
1765
1764
buf_block_init_low(
1766
1765
/*===============*/
1767
buf_block_t* block) /*!< in: block to init */
1766
buf_block_t* block) /* in: block to init */
1769
1768
block->check_index_page_at_flush = FALSE;
1770
1769
block->index = NULL;
1775
1774
block->n_bytes = 0;
1776
1775
block->left_side = TRUE;
1778
#endif /* !UNIV_HOTBACKUP */
1780
/********************************************************************//**
1782
@return TRUE if successful */
1778
/************************************************************************
1779
Decompress a block. */
1785
1782
buf_zip_decompress(
1786
1783
/*===============*/
1787
buf_block_t* block, /*!< in/out: block */
1788
ibool check) /*!< in: TRUE=verify the page checksum */
1784
/* out: TRUE if successful */
1785
buf_block_t* block, /* in/out: block */
1786
ibool check) /* in: TRUE=verify the page checksum */
1790
1788
const byte* frame = block->page.zip.data;
1846
#ifndef UNIV_HOTBACKUP
1847
/*******************************************************************//**
1848
Gets the block to whose frame the pointer is pointing to.
1849
@return pointer to block, never NULL */
1844
/***********************************************************************
1845
Gets the block to whose frame the pointer is pointing to. */
1852
1848
buf_block_align(
1853
1849
/*============*/
1854
const byte* ptr) /*!< in: pointer to a frame */
1850
/* out: pointer to block, never NULL */
1851
const byte* ptr) /* in: pointer to a frame */
1856
1853
buf_chunk_t* chunk;
1934
/********************************************************************//**
1935
Find out if a pointer belongs to a buf_block_t. It can be a pointer to
1936
the buf_block_t itself or a member of it
1937
@return TRUE if ptr belongs to a buf_block_t struct */
1931
/************************************************************************
1932
Find out if a buffer block was created by buf_chunk_init(). */
1940
buf_pointer_is_block_field(
1941
/*=======================*/
1942
const void* ptr) /*!< in: pointer not
1935
buf_block_is_uncompressed(
1936
/*======================*/
1937
/* out: TRUE if "block" has
1938
been added to buf_pool->free
1939
by buf_chunk_init() */
1940
const buf_block_t* block) /* in: pointer to block,
1945
1943
const buf_chunk_t* chunk = buf_pool->chunks;
1946
1944
const buf_chunk_t* const echunk = chunk + buf_pool->n_chunks;
1948
/* TODO: protect buf_pool->chunks with a mutex (it will
1949
currently remain constant after buf_pool_init()) */
1946
ut_ad(buf_pool_mutex_own());
1948
if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) {
1949
/* The pointer should be aligned. */
1950
1953
while (chunk < echunk) {
1951
if (ptr >= (void *)chunk->blocks
1952
&& ptr < (void *)(chunk->blocks + chunk->size)) {
1954
if (block >= chunk->blocks
1955
&& block < chunk->blocks + chunk->size) {
1963
/********************************************************************//**
1964
Find out if a buffer block was created by buf_chunk_init().
1965
@return TRUE if "block" has been added to buf_pool->free by buf_chunk_init() */
1968
buf_block_is_uncompressed(
1969
/*======================*/
1970
const buf_block_t* block) /*!< in: pointer to block,
1973
ut_ad(buf_pool_mutex_own());
1975
if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) {
1976
/* The pointer should be aligned. */
1980
return(buf_pointer_is_block_field((void *)block));
1983
/********************************************************************//**
1984
This is the general function used to get access to a database page.
1985
@return pointer to the block or NULL */
1966
/************************************************************************
1967
This is the general function used to get access to a database page. */
1988
1970
buf_page_get_gen(
1989
1971
/*=============*/
1990
ulint space, /*!< in: space id */
1991
ulint zip_size,/*!< in: compressed page size in bytes
1972
/* out: pointer to the block or NULL */
1973
ulint space, /* in: space id */
1974
ulint zip_size,/* in: compressed page size in bytes
1992
1975
or 0 for uncompressed pages */
1993
ulint offset, /*!< in: page number */
1994
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
1995
buf_block_t* guess, /*!< in: guessed block or NULL */
1996
ulint mode, /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
1976
ulint offset, /* in: page number */
1977
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
1978
buf_block_t* guess, /* in: guessed block or NULL */
1979
ulint mode, /* in: BUF_GET, BUF_GET_IF_IN_POOL,
1997
1980
BUF_GET_NO_LATCH */
1998
const char* file, /*!< in: file name */
1999
ulint line, /*!< in: line where called */
2000
mtr_t* mtr) /*!< in: mini-transaction */
1981
const char* file, /* in: file name */
1982
ulint line, /* in: line where called */
1983
mtr_t* mtr) /* in: mini-transaction */
2002
1985
buf_block_t* block;
2003
1986
ibool accessed;
2012
1995
ut_ad((mode == BUF_GET) || (mode == BUF_GET_IF_IN_POOL)
2013
1996
|| (mode == BUF_GET_NO_LATCH));
2014
1997
ut_ad(zip_size == fil_space_get_zip_size(space));
2015
ut_ad(ut_is_2pow(zip_size));
2016
1998
#ifndef UNIV_LOG_DEBUG
2017
1999
ut_ad(!ibuf_inside() || ibuf_page(space, zip_size, offset, NULL));
2086
2068
case BUF_BLOCK_ZIP_PAGE:
2087
2069
case BUF_BLOCK_ZIP_DIRTY:
2088
2070
bpage = &block->page;
2089
/* Protect bpage->buf_fix_count. */
2090
mutex_enter(&buf_pool_zip_mutex);
2092
2072
if (bpage->buf_fix_count
2093
2073
|| buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
2094
2074
/* This condition often occurs when the buffer
2095
2075
is not buffer-fixed, but I/O-fixed by
2096
2076
buf_page_init_for_read(). */
2097
mutex_exit(&buf_pool_zip_mutex);
2098
2077
wait_until_unfixed:
2099
2078
/* The block is buffer-fixed or I/O-fixed.
2100
2079
Try again later. */
2194
2172
block->page.buf_fix_count = 1;
2195
2173
buf_block_set_io_fix(block, BUF_IO_READ);
2196
rw_lock_x_lock(&block->lock);
2197
mutex_exit(&block->mutex);
2198
mutex_exit(&buf_pool_zip_mutex);
2199
2174
buf_pool->n_pend_unzip++;
2175
rw_lock_x_lock(&block->lock);
2176
mutex_exit(&block->mutex);
2177
mutex_exit(&buf_pool_zip_mutex);
2201
2179
buf_buddy_free(bpage, sizeof *bpage);
2214
2192
/* Unfix and unlatch the block. */
2215
2193
buf_pool_mutex_enter();
2216
2194
mutex_enter(&block->mutex);
2195
buf_pool->n_pend_unzip--;
2217
2196
block->page.buf_fix_count--;
2218
2197
buf_block_set_io_fix(block, BUF_IO_NONE);
2219
2198
mutex_exit(&block->mutex);
2220
buf_pool->n_pend_unzip--;
2221
2199
rw_lock_x_unlock(&block->lock);
2223
2201
if (UNIV_UNLIKELY(!success)) {
2323
/********************************************************************//**
2301
/************************************************************************
2324
2302
This is the general function used to get optimistic access to a database
2326
@return TRUE if success */
2329
2306
buf_page_optimistic_get_func(
2330
2307
/*=========================*/
2331
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
2332
buf_block_t* block, /*!< in: guessed buffer block */
2333
ib_uint64_t modify_clock,/*!< in: modify clock value if mode is
2308
/* out: TRUE if success */
2309
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
2310
buf_block_t* block, /* in: guessed buffer block */
2311
ib_uint64_t modify_clock,/* in: modify clock value if mode is
2334
2312
..._GUESS_ON_CLOCK */
2335
const char* file, /*!< in: file name */
2336
ulint line, /*!< in: line where called */
2337
mtr_t* mtr) /*!< in: mini-transaction */
2313
const char* file, /* in: file name */
2314
ulint line, /* in: line where called */
2315
mtr_t* mtr) /* in: mini-transaction */
2339
2317
ibool accessed;
2433
/********************************************************************//**
2411
/************************************************************************
2434
2412
This is used to get access to a known database page, when no waiting can be
2435
2413
done. For example, if a search in an adaptive hash index leads us to this
2437
@return TRUE if success */
2440
2417
buf_page_get_known_nowait(
2441
2418
/*======================*/
2442
ulint rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
2443
buf_block_t* block, /*!< in: the known page */
2444
ulint mode, /*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
2445
const char* file, /*!< in: file name */
2446
ulint line, /*!< in: line where called */
2447
mtr_t* mtr) /*!< in: mini-transaction */
2419
/* out: TRUE if success */
2420
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
2421
buf_block_t* block, /* in: the known page */
2422
ulint mode, /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
2423
const char* file, /* in: file name */
2424
ulint line, /* in: line where called */
2425
mtr_t* mtr) /* in: mini-transaction */
2450
2428
ulint fix_type;
2521
/*******************************************************************//**
2499
/***********************************************************************
2522
2500
Given a tablespace id and page number tries to get that page. If the
2523
2501
page is not in the buffer pool it is not loaded and NULL is returned.
2524
Suitable for using when holding the kernel mutex.
2525
@return pointer to a page or NULL */
2502
Suitable for using when holding the kernel mutex. */
2527
2504
const buf_block_t*
2528
2505
buf_page_try_get_func(
2529
2506
/*==================*/
2530
ulint space_id,/*!< in: tablespace id */
2531
ulint page_no,/*!< in: page number */
2532
const char* file, /*!< in: file name */
2533
ulint line, /*!< in: line where called */
2534
mtr_t* mtr) /*!< in: mini-transaction */
2507
/* out: pointer to a page or NULL */
2508
ulint space_id,/* in: tablespace id */
2509
ulint page_no,/* in: page number */
2510
const char* file, /* in: file name */
2511
ulint line, /* in: line where called */
2512
mtr_t* mtr) /* in: mini-transaction */
2536
2514
buf_block_t* block;
2602
/********************************************************************//**
2580
/************************************************************************
2603
2581
Initialize some fields of a control block. */
2606
2584
buf_page_init_low(
2607
2585
/*==============*/
2608
buf_page_t* bpage) /*!< in: block to init */
2586
buf_page_t* bpage) /* in: block to init */
2610
2588
bpage->flush_type = BUF_FLUSH_LRU;
2611
2589
bpage->accessed = FALSE;
2620
2598
#endif /* UNIV_DEBUG_FILE_ACCESSES */
2623
/********************************************************************//**
2601
#ifdef UNIV_HOTBACKUP
2602
/************************************************************************
2603
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
2606
buf_page_init_for_backup_restore(
2607
/*=============================*/
2608
ulint space, /* in: space id */
2609
ulint offset, /* in: offset of the page within space
2610
in units of a page */
2611
ulint zip_size,/* in: compressed page size in bytes
2612
or 0 for uncompressed pages */
2613
buf_block_t* block) /* in: block to init */
2615
buf_block_init_low(block);
2617
block->lock_hash_val = 0;
2619
buf_page_init_low(&block->page);
2620
block->page.state = BUF_BLOCK_FILE_PAGE;
2621
block->page.space = space;
2622
block->page.offset = offset;
2624
page_zip_des_init(&block->page.zip);
2626
/* We assume that block->page.data has been allocated
2627
with zip_size == UNIV_PAGE_SIZE. */
2628
ut_ad(zip_size <= UNIV_PAGE_SIZE);
2629
ut_ad(ut_is_2pow(zip_size));
2630
page_zip_set_size(&block->page.zip, zip_size);
2632
#endif /* UNIV_HOTBACKUP */
2634
/************************************************************************
2624
2635
Inits a page to the buffer buf_pool. */
2629
ulint space, /*!< in: space id */
2630
ulint offset, /*!< in: offset of the page within space
2640
ulint space, /* in: space id */
2641
ulint offset, /* in: offset of the page within space
2631
2642
in units of a page */
2632
buf_block_t* block) /*!< in: block to init */
2643
buf_block_t* block) /* in: block to init */
2634
2645
buf_page_t* hash_page;
2684
2695
buf_page_address_fold(space, offset), &block->page);
2687
/********************************************************************//**
2698
/************************************************************************
2688
2699
Function which inits a page for read to the buffer buf_pool. If the page is
2689
2700
(1) already in buf_pool, or
2690
2701
(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
2692
2703
then this function does nothing.
2693
2704
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
2694
2705
on the buffer frame. The io-handler must take care that the flag is cleared
2695
and the lock released later.
2696
@return pointer to the block or NULL */
2706
and the lock released later. */
2699
2709
buf_page_init_for_read(
2700
2710
/*===================*/
2701
ulint* err, /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED */
2702
ulint mode, /*!< in: BUF_READ_IBUF_PAGES_ONLY, ... */
2703
ulint space, /*!< in: space id */
2704
ulint zip_size,/*!< in: compressed page size, or 0 */
2705
ibool unzip, /*!< in: TRUE=request uncompressed page */
2706
ib_int64_t tablespace_version,/*!< in: prevents reading from a wrong
2711
/* out: pointer to the block or NULL */
2712
ulint* err, /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
2713
ulint mode, /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
2714
ulint space, /* in: space id */
2715
ulint zip_size,/* in: compressed page size, or 0 */
2716
ibool unzip, /* in: TRUE=request uncompressed page */
2717
ib_int64_t tablespace_version,/* in: prevents reading from a wrong
2707
2718
version of the tablespace in case we have done
2708
2719
DISCARD + IMPORT */
2709
ulint offset) /*!< in: page number */
2720
ulint offset) /* in: page number */
2711
2722
buf_block_t* block;
2712
2723
buf_page_t* bpage;
2891
/********************************************************************//**
2902
/************************************************************************
2892
2903
Initializes a page to the buffer buf_pool. The page is usually not read
2893
2904
from a file even if it cannot be found in the buffer buf_pool. This is one
2894
2905
of the functions which perform to a block a state transition NOT_USED =>
2895
FILE_PAGE (the other is buf_page_get_gen).
2896
@return pointer to the block, page bufferfixed */
2906
FILE_PAGE (the other is buf_page_get_gen). */
2899
2909
buf_page_create(
2900
2910
/*============*/
2901
ulint space, /*!< in: space id */
2902
ulint offset, /*!< in: offset of the page within space in units of
2911
/* out: pointer to the block, page bufferfixed */
2912
ulint space, /* in: space id */
2913
ulint offset, /* in: offset of the page within space in units of
2904
ulint zip_size,/*!< in: compressed page size, or 0 */
2905
mtr_t* mtr) /*!< in: mini-transaction handle */
2915
ulint zip_size,/* in: compressed page size, or 0 */
2916
mtr_t* mtr) /* in: mini-transaction handle */
2907
2918
buf_frame_t* frame;
2908
2919
buf_block_t* block;
3033
/********************************************************************//**
3044
/************************************************************************
3034
3045
Completes an asynchronous read or write request of a file page to or from
3035
3046
the buffer pool. */
3038
3049
buf_page_io_complete(
3039
3050
/*=================*/
3040
buf_page_t* bpage) /*!< in: pointer to the block in question */
3051
buf_page_t* bpage) /* in: pointer to the block in question */
3042
3053
enum buf_io_fix io_type;
3043
3054
const ibool uncompressed = (buf_page_get_state(bpage)
3149
3160
" You can use CHECK\n"
3150
3161
"InnoDB: TABLE to scan your"
3151
3162
" table for corruption.\n"
3153
REFMAN "forcing-recovery.html\n"
3164
" http://dev.mysql.com/doc/refman/5.1/en/"
3165
"forcing-recovery.html\n"
3154
3166
"InnoDB: about forcing recovery.\n", stderr);
3156
3168
if (srv_force_recovery < SRV_FORCE_IGNORE_CORRUPT) {
3164
3176
if (recv_recovery_is_on()) {
3165
3177
/* Pages must be uncompressed for crash recovery. */
3166
3178
ut_a(uncompressed);
3167
recv_recover_page(TRUE, (buf_block_t*) bpage);
3179
recv_recover_page(FALSE, TRUE, (buf_block_t*) bpage);
3170
3182
if (uncompressed && !recv_no_ibuf_operations) {
3607
3618
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
3609
3620
#ifdef UNIV_DEBUG
3610
/*********************************************************************//**
3611
Returns the number of latched pages in the buffer pool.
3612
@return number of latched pages */
3621
/*************************************************************************
3622
Returns the number of latched pages in the buffer pool. */
3615
3625
buf_get_latched_pages_number(void)
3697
3707
#endif /* UNIV_DEBUG */
3699
/*********************************************************************//**
3700
Returns the number of pending buf pool ios.
3701
@return number of pending I/O operations */
3709
/*************************************************************************
3710
Returns the number of pending buf pool ios. */
3704
3713
buf_get_n_pending_ios(void)
3710
3719
+ buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE]);
3713
/*********************************************************************//**
3722
/*************************************************************************
3714
3723
Returns the ratio in percents of modified pages in the buffer pool /
3715
database pages in the buffer pool.
3716
@return modified page percentage ratio */
3724
database pages in the buffer pool. */
3719
3727
buf_get_modified_ratio_pct(void)
3869
/*********************************************************************//**
3876
/*************************************************************************
3870
3877
Checks that there currently are no pending i/o-operations for the buffer
3872
@return TRUE if there is no pending i/o */
3875
3881
buf_pool_check_no_pending_io(void)
3876
3882
/*==============================*/
3883
/* out: TRUE if there is no pending i/o */
3895
/*********************************************************************//**
3896
Gets the current length of the free list of buffer blocks.
3897
@return length of the free list */
3902
/*************************************************************************
3903
Gets the current length of the free list of buffer blocks. */
3900
3906
buf_get_free_list_len(void)
3913
#else /* !UNIV_HOTBACKUP */
3914
/********************************************************************//**
3915
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
3918
buf_page_init_for_backup_restore(
3919
/*=============================*/
3920
ulint space, /*!< in: space id */
3921
ulint offset, /*!< in: offset of the page within space
3922
in units of a page */
3923
ulint zip_size,/*!< in: compressed page size in bytes
3924
or 0 for uncompressed pages */
3925
buf_block_t* block) /*!< in: block to init */
3927
block->page.state = BUF_BLOCK_FILE_PAGE;
3928
block->page.space = space;
3929
block->page.offset = offset;
3931
page_zip_des_init(&block->page.zip);
3933
/* We assume that block->page.data has been allocated
3934
with zip_size == UNIV_PAGE_SIZE. */
3935
ut_ad(zip_size <= UNIV_PAGE_SIZE);
3936
ut_ad(ut_is_2pow(zip_size));
3937
page_zip_set_size(&block->page.zip, zip_size);
3939
block->page.zip.data = block->frame + UNIV_PAGE_SIZE;
3942
#endif /* !UNIV_HOTBACKUP */