~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/buf/buf0buf.c

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
*****************************************************************************/
25
25
 
26
 
/**************************************************//**
27
 
@file buf/buf0buf.c
 
26
/******************************************************
28
27
The database buffer buf_pool
29
28
 
30
29
Created 11/5/1995 Heikki Tuuri
36
35
#include "buf0buf.ic"
37
36
#endif
38
37
 
 
38
#include "buf0buddy.h"
39
39
#include "mem0mem.h"
40
40
#include "btr0btr.h"
41
41
#include "fil0fil.h"
42
 
#ifndef UNIV_HOTBACKUP
43
 
#include "buf0buddy.h"
44
42
#include "lock0lock.h"
45
43
#include "btr0sea.h"
46
44
#include "ibuf0ibuf.h"
 
45
#include "dict0dict.h"
 
46
#include "log0recv.h"
47
47
#include "trx0undo.h"
48
 
#include "log0log.h"
49
 
#endif /* !UNIV_HOTBACKUP */
50
48
#include "srv0srv.h"
51
 
#include "dict0dict.h"
52
 
#include "log0recv.h"
53
49
#include "page0zip.h"
54
50
 
55
51
/*
239
235
the read requests for the whole area.
240
236
*/
241
237
 
242
 
#ifndef UNIV_HOTBACKUP
243
 
/** Value in microseconds */
 
238
/* Value in microseconds */
244
239
static const int WAIT_FOR_READ  = 5000;
245
240
 
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;
248
243
 
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;
255
250
 
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
259
254
                                        debug version */
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 */
269
264
 
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 */
277
272
};
278
 
#endif /* !UNIV_HOTBACKUP */
279
273
 
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.
284
 
@return checksum */
 
277
32-bit and 64-bit architectures. */
285
278
UNIV_INTERN
286
279
ulint
287
280
buf_calc_page_new_checksum(
288
281
/*=======================*/
289
 
        const byte*     page)   /*!< in: buffer page */
 
282
                                /* out: checksum */
 
283
        const byte*     page)   /* in: buffer page */
290
284
{
291
285
        ulint checksum;
292
286
 
308
302
        return(checksum);
309
303
}
310
304
 
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
314
308
checksum.
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!
318
 
@return checksum */
 
311
because this takes that field as an input! */
319
312
UNIV_INTERN
320
313
ulint
321
314
buf_calc_page_old_checksum(
322
315
/*=======================*/
323
 
        const byte*     page)   /*!< in: buffer page */
 
316
                                /* out: checksum */
 
317
        const byte*     page)   /* in: buffer page */
324
318
{
325
319
        ulint checksum;
326
320
 
331
325
        return(checksum);
332
326
}
333
327
 
334
 
/********************************************************************//**
335
 
Checks if a page is corrupt.
336
 
@return TRUE if corrupted */
 
328
/************************************************************************
 
329
Checks if a page is corrupt. */
337
330
UNIV_INTERN
338
331
ibool
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 */
344
338
{
345
339
        ulint           checksum_field;
346
340
        ulint           old_checksum_field;
347
 
 
 
341
#ifndef UNIV_HOTBACKUP
 
342
        ib_uint64_t     current_lsn;
 
343
#endif
348
344
        if (UNIV_LIKELY(!zip_size)
349
345
            && memcmp(read_buf + FIL_PAGE_LSN + 4,
350
346
                      read_buf + UNIV_PAGE_SIZE
357
353
        }
358
354
 
359
355
#ifndef UNIV_HOTBACKUP
360
 
        if (recv_lsn_checks_on) {
361
 
                ib_uint64_t     current_lsn;
362
 
 
363
 
                if (log_peek_lsn(&current_lsn)
364
 
                    && current_lsn < mach_read_ull(read_buf + FIL_PAGE_LSN)) {
 
356
        if (recv_lsn_checks_on && log_peek_lsn(&current_lsn)) {
 
357
                if (current_lsn < mach_read_ull(read_buf + FIL_PAGE_LSN)) {
365
358
                        ut_print_timestamp(stderr);
366
359
 
367
360
                        fprintf(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),
434
428
        return(FALSE);
435
429
}
436
430
 
437
 
/********************************************************************//**
 
431
/************************************************************************
438
432
Prints a page to stderr. */
439
433
UNIV_INTERN
440
434
void
441
435
buf_page_print(
442
436
/*===========*/
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 */
446
440
{
447
 
#ifndef UNIV_HOTBACKUP
448
441
        dict_index_t*   index;
449
 
#endif /* !UNIV_HOTBACKUP */
450
442
        ulint           checksum;
451
443
        ulint           old_checksum;
452
444
        ulint           size    = zip_size;
560
552
                (ulong) mach_read_from_4(read_buf
561
553
                                         + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID));
562
554
 
563
 
#ifndef UNIV_HOTBACKUP
564
555
        if (mach_read_from_2(read_buf + TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE)
565
556
            == TRX_UNDO_INSERT) {
566
557
                fprintf(stderr,
571
562
                fprintf(stderr,
572
563
                        "InnoDB: Page may be an update undo log page\n");
573
564
        }
574
 
#endif /* !UNIV_HOTBACKUP */
575
565
 
576
566
        switch (fil_page_get_type(read_buf)) {
577
567
        case FIL_PAGE_INDEX:
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
 
575
 
 
576
#ifdef UNIV_HOTBACKUP
 
577
                /* If the code is in ibbackup, dict_sys may be uninitialized,
 
578
                i.e., NULL */
 
579
 
 
580
                if (dict_sys == NULL) {
 
581
                        break;
 
582
                }
 
583
#endif /* UNIV_HOTBACKUP */
 
584
 
586
585
                index = dict_index_find_on_id_low(
587
586
                        btr_page_get_index_id(read_buf));
588
587
                if (index) {
590
589
                        dict_index_name_print(stderr, NULL, index);
591
590
                        fputs(")\n", stderr);
592
591
                }
593
 
#endif /* !UNIV_HOTBACKUP */
594
592
                break;
595
593
        case FIL_PAGE_INODE:
596
594
                fputs("InnoDB: Page may be an 'inode' page\n", stderr);
635
633
        }
636
634
}
637
635
 
638
 
#ifndef UNIV_HOTBACKUP
639
 
/********************************************************************//**
 
636
/************************************************************************
640
637
Initializes a buffer control block when the buf_pool is created. */
641
638
static
642
639
void
643
640
buf_block_init(
644
641
/*===========*/
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 */
647
644
{
648
645
        UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE, block);
649
646
 
685
682
#endif /* UNIV_SYNC_DEBUG */
686
683
}
687
684
 
688
 
/********************************************************************//**
689
 
Allocates a chunk of buffer frames.
690
 
@return chunk, or NULL on failure */
 
685
/************************************************************************
 
686
Allocates a chunk of buffer frames. */
691
687
static
692
688
buf_chunk_t*
693
689
buf_chunk_init(
694
690
/*===========*/
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 */
697
694
{
698
695
        buf_block_t*    block;
699
696
        byte*           frame;
765
762
}
766
763
 
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. */
772
768
static
773
769
buf_block_t*
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 */
778
776
{
779
777
        buf_block_t*    block;
780
778
        ulint           i;
794
792
        return(NULL);
795
793
}
796
794
 
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. */
801
798
UNIV_INTERN
802
799
buf_block_t*
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 */
806
805
{
807
806
        ulint           n;
808
807
        buf_chunk_t*    chunk = buf_pool->chunks;
819
818
}
820
819
#endif /* UNIV_DEBUG */
821
820
 
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. */
825
823
static
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 */
830
830
{
831
831
        buf_block_t*    block;
832
832
        ulint           i;
852
852
        return(NULL);
853
853
}
854
854
 
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. */
858
857
static
859
858
ibool
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 */
863
863
{
864
864
        const buf_block_t*      block;
865
865
        ulint                   i;
880
880
        return(TRUE);
881
881
}
882
882
 
883
 
/********************************************************************//**
 
883
/************************************************************************
884
884
Frees a chunk of buffer frames. */
885
885
static
886
886
void
887
887
buf_chunk_free(
888
888
/*===========*/
889
 
        buf_chunk_t*    chunk)          /*!< out: chunk of buffers */
 
889
        buf_chunk_t*    chunk)          /* out: chunk of buffers */
890
890
{
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);
919
919
}
920
920
 
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. */
924
923
UNIV_INTERN
925
924
buf_pool_t*
926
925
buf_pool_init(void)
927
926
/*===============*/
 
927
                                /* out, own: buf_pool object, NULL if not
 
928
                                enough memory or error */
928
929
{
929
930
        buf_chunk_t*    chunk;
930
931
        ulint           i;
983
984
        return(buf_pool);
984
985
}
985
986
 
986
 
/********************************************************************//**
 
987
/************************************************************************
987
988
Frees the buffer pool at shutdown.  This must not be invoked before
988
989
freeing all mutexes. */
989
990
UNIV_INTERN
1006
1007
        buf_pool->n_chunks = 0;
1007
1008
}
1008
1009
 
1009
 
/********************************************************************//**
 
1010
 
 
1011
/************************************************************************
1010
1012
Drops the adaptive hash index.  To prevent a livelock, this function
1011
1013
is only to be called while holding btr_search_latch and while
1012
1014
btr_search_enabled == FALSE. */
1087
1089
        } while (released_search_latch);
1088
1090
}
1089
1091
 
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. */
1095
1097
void
1096
1098
buf_relocate(
1097
1099
/*=========*/
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 */
1102
1104
{
1103
1105
        buf_page_t*     b;
1104
1106
        ulint           fold;
1153
1155
#endif /* UNIV_LRU_DEBUG */
1154
1156
        }
1155
1157
 
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));
1158
1159
 
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);
1166
1167
}
1167
1168
 
1168
 
/********************************************************************//**
 
1169
/************************************************************************
1169
1170
Shrinks the buffer pool. */
1170
1171
static
1171
1172
void
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 */
1175
1177
{
1176
1178
        buf_chunk_t*    chunks;
1177
1179
        buf_chunk_t*    chunk;
1316
1318
        btr_search_enable();
1317
1319
}
1318
1320
 
1319
 
/********************************************************************//**
 
1321
/************************************************************************
1320
1322
Rebuild buf_pool->page_hash. */
1321
1323
static
1322
1324
void
1413
1415
        buf_pool_mutex_exit();
1414
1416
}
1415
1417
 
1416
 
/********************************************************************//**
 
1418
/************************************************************************
1417
1419
Resizes the buffer pool. */
1418
1420
UNIV_INTERN
1419
1421
void
1470
1472
        buf_pool_page_hash_rebuild();
1471
1473
}
1472
1474
 
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. */
1476
1478
UNIV_INLINE
1477
1479
void
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 */
1481
1483
{
1482
1484
        ut_ad(!buf_pool_mutex_own());
1483
1485
 
1495
1497
        }
1496
1498
}
1497
1499
 
1498
 
/********************************************************************//**
 
1500
/************************************************************************
1499
1501
Moves a page to the start of the buffer pool LRU list. This high-level
1500
1502
function can be used to prevent an important page from from slipping out of
1501
1503
the buffer pool. */
1503
1505
void
1504
1506
buf_page_make_young(
1505
1507
/*================*/
1506
 
        buf_page_t*     bpage)  /*!< in: buffer block of a file page */
 
1508
        buf_page_t*     bpage)  /* in: buffer block of a file page */
1507
1509
{
1508
1510
        buf_pool_mutex_enter();
1509
1511
 
1514
1516
        buf_pool_mutex_exit();
1515
1517
}
1516
1518
 
1517
 
/********************************************************************//**
 
1519
/************************************************************************
1518
1520
Resets the check_index_page_at_flush field of a page if found in the buffer
1519
1521
pool. */
1520
1522
UNIV_INTERN
1521
1523
void
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 */
1526
1528
{
1527
1529
        buf_block_t*    block;
1528
1530
 
1537
1539
        buf_pool_mutex_exit();
1538
1540
}
1539
1541
 
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. */
1545
1546
UNIV_INTERN
1546
1547
ibool
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
 
1551
                        system */
 
1552
        ulint   space,  /* in: space id */
 
1553
        ulint   offset) /* in: page number */
1551
1554
{
1552
1555
        buf_block_t*    block;
1553
1556
        ibool           is_hashed;
1568
1571
}
1569
1572
 
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
1575
 
reallocated.
1576
 
@return control block if found in page hash table, otherwise NULL */
 
1578
reallocated. */
1577
1579
UNIV_INTERN
1578
1580
buf_page_t*
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,
 
1584
                        otherwise NULL */
 
1585
        ulint   space,  /* in: space id */
 
1586
        ulint   offset) /* in: page number */
1583
1587
{
1584
1588
        buf_page_t*     bpage;
1585
1589
 
1596
1600
        return(bpage);
1597
1601
}
1598
1602
 
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
1603
 
reallocated.
1604
 
@return control block if found in page hash table, otherwise NULL */
 
1607
reallocated. */
1605
1608
UNIV_INTERN
1606
1609
buf_page_t*
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,
 
1613
                        otherwise NULL */
 
1614
        ulint   space,  /* in: space id */
 
1615
        ulint   offset) /* in: page number */
1611
1616
{
1612
1617
        buf_page_t*     bpage;
1613
1618
 
1625
1630
}
1626
1631
#endif /* UNIV_DEBUG_FILE_ACCESSES */
1627
1632
 
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. */
1637
1641
UNIV_INTERN
1638
1642
buf_page_t*
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 */
1644
1649
{
1645
1650
        buf_page_t*     bpage;
1646
1651
        mutex_t*        block_mutex;
1672
1677
 
1673
1678
        if (UNIV_UNLIKELY(!bpage->zip.data)) {
1674
1679
                /* There is no compressed page. */
1675
 
err_exit:
1676
1680
                buf_pool_mutex_exit();
1677
1681
                return(NULL);
1678
1682
        }
1679
1683
 
 
1684
        block_mutex = buf_page_get_mutex(bpage);
 
1685
        mutex_enter(block_mutex);
 
1686
 
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:
 
1693
                ut_error;
1686
1694
                break;
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++;
1692
 
                goto got_block;
 
1698
                break;
1693
1699
        case BUF_BLOCK_FILE_PAGE:
1694
 
                block_mutex = &((buf_block_t*) bpage)->mutex;
1695
 
                mutex_enter(block_mutex);
1696
 
 
1697
1700
                /* Discard the uncompressed page frame if possible. */
1698
1701
                if (buf_LRU_free_block(bpage, FALSE, NULL)
1699
1702
                    == BUF_LRU_FREED) {
1704
1707
 
1705
1708
                buf_block_buf_fix_inc((buf_block_t*) bpage,
1706
1709
                                      __FILE__, __LINE__);
1707
 
                goto got_block;
 
1710
                break;
1708
1711
        }
1709
1712
 
1710
 
        ut_error;
1711
 
        goto err_exit;
1712
 
 
1713
 
got_block:
1714
1713
        must_read = buf_page_get_io_fix(bpage) == BUF_IO_READ;
1715
1714
 
1716
1715
        buf_pool_mutex_exit();
1758
1757
        return(bpage);
1759
1758
}
1760
1759
 
1761
 
/********************************************************************//**
 
1760
/************************************************************************
1762
1761
Initialize some fields of a control block. */
1763
1762
UNIV_INLINE
1764
1763
void
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 */
1768
1767
{
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;
1777
1776
}
1778
 
#endif /* !UNIV_HOTBACKUP */
1779
1777
 
1780
 
/********************************************************************//**
1781
 
Decompress a block.
1782
 
@return TRUE if successful */
1783
 
UNIV_INTERN
 
1778
/************************************************************************
 
1779
Decompress a block. */
 
1780
static
1784
1781
ibool
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 */
1789
1787
{
1790
1788
        const byte* frame = block->page.zip.data;
1791
1789
 
1843
1841
        return(FALSE);
1844
1842
}
1845
1843
 
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. */
1850
1846
UNIV_INTERN
1851
1847
buf_block_t*
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 */
1855
1852
{
1856
1853
        buf_chunk_t*    chunk;
1857
1854
        ulint           i;
1931
1928
        return(NULL);
1932
1929
}
1933
1930
 
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 */
1938
 
UNIV_INTERN
 
1931
/************************************************************************
 
1932
Find out if a buffer block was created by buf_chunk_init(). */
 
1933
static
1939
1934
ibool
1940
 
buf_pointer_is_block_field(
1941
 
/*=======================*/
1942
 
        const void*             ptr)    /*!< in: pointer not
1943
 
                                        dereferenced */
 
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,
 
1941
                                        not dereferenced */
1944
1942
{
1945
1943
        const buf_chunk_t*              chunk   = buf_pool->chunks;
1946
1944
        const buf_chunk_t* const        echunk  = chunk + buf_pool->n_chunks;
1947
1945
 
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());
 
1947
 
 
1948
        if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) {
 
1949
                /* The pointer should be aligned. */
 
1950
                return(FALSE);
 
1951
        }
 
1952
 
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) {
1953
1956
 
1954
1957
                        return(TRUE);
1955
1958
                }
1960
1963
        return(FALSE);
1961
1964
}
1962
1965
 
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() */
1966
 
static
1967
 
ibool
1968
 
buf_block_is_uncompressed(
1969
 
/*======================*/
1970
 
        const buf_block_t*      block)  /*!< in: pointer to block,
1971
 
                                        not dereferenced */
1972
 
{
1973
 
        ut_ad(buf_pool_mutex_own());
1974
 
 
1975
 
        if (UNIV_UNLIKELY((((ulint) block) % sizeof *block) != 0)) {
1976
 
                /* The pointer should be aligned. */
1977
 
                return(FALSE);
1978
 
        }
1979
 
 
1980
 
        return(buf_pointer_is_block_field((void *)block));
1981
 
}
1982
 
 
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. */
1986
1968
UNIV_INTERN
1987
1969
buf_block_t*
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 */
2001
1984
{
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));
2018
2000
#endif
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);
2091
2071
 
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. */
2106
2085
 
2107
2086
                /* Allocate an uncompressed page. */
2108
2087
                buf_pool_mutex_exit();
2109
 
                mutex_exit(&buf_pool_zip_mutex);
2110
2088
 
2111
2089
                block = buf_LRU_get_free_block(0);
2112
2090
                ut_a(block);
2193
2171
 
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);
2200
2178
 
2201
2179
                buf_buddy_free(bpage, sizeof *bpage);
2202
2180
 
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);
2222
2200
 
2223
2201
                if (UNIV_UNLIKELY(!success)) {
2320
2298
        return(block);
2321
2299
}
2322
2300
 
2323
 
/********************************************************************//**
 
2301
/************************************************************************
2324
2302
This is the general function used to get optimistic access to a database
2325
 
page.
2326
 
@return TRUE if success */
 
2303
page. */
2327
2304
UNIV_INTERN
2328
2305
ibool
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 */
2338
2316
{
2339
2317
        ibool           accessed;
2340
2318
        ibool           success;
2430
2408
        return(TRUE);
2431
2409
}
2432
2410
 
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
2436
 
frame.
2437
 
@return TRUE if success */
 
2414
frame. */
2438
2415
UNIV_INTERN
2439
2416
ibool
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 */
2448
2426
{
2449
2427
        ibool           success;
2450
2428
        ulint           fix_type;
2518
2496
        return(TRUE);
2519
2497
}
2520
2498
 
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. */
2526
2503
UNIV_INTERN
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 */
2535
2513
{
2536
2514
        buf_block_t*    block;
2537
2515
        ibool           success;
2599
2577
        return(block);
2600
2578
}
2601
2579
 
2602
 
/********************************************************************//**
 
2580
/************************************************************************
2603
2581
Initialize some fields of a control block. */
2604
2582
UNIV_INLINE
2605
2583
void
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 */
2609
2587
{
2610
2588
        bpage->flush_type = BUF_FLUSH_LRU;
2611
2589
        bpage->accessed = FALSE;
2620
2598
#endif /* UNIV_DEBUG_FILE_ACCESSES */
2621
2599
}
2622
2600
 
2623
 
/********************************************************************//**
 
2601
#ifdef UNIV_HOTBACKUP
 
2602
/************************************************************************
 
2603
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
 
2604
UNIV_INTERN
 
2605
void
 
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 */
 
2614
{
 
2615
        buf_block_init_low(block);
 
2616
 
 
2617
        block->lock_hash_val    = 0;
 
2618
 
 
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;
 
2623
 
 
2624
        page_zip_des_init(&block->page.zip);
 
2625
 
 
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);
 
2631
}
 
2632
#endif /* UNIV_HOTBACKUP */
 
2633
 
 
2634
/************************************************************************
2624
2635
Inits a page to the buffer buf_pool. */
2625
2636
static
2626
2637
void
2627
2638
buf_page_init(
2628
2639
/*==========*/
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 */
2633
2644
{
2634
2645
        buf_page_t*     hash_page;
2635
2646
 
2684
2695
                    buf_page_address_fold(space, offset), &block->page);
2685
2696
}
2686
2697
 
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. */
2697
2707
UNIV_INTERN
2698
2708
buf_page_t*
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 */
2710
2721
{
2711
2722
        buf_block_t*    block;
2712
2723
        buf_page_t*     bpage;
2888
2899
        return(bpage);
2889
2900
}
2890
2901
 
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). */
2897
2907
UNIV_INTERN
2898
2908
buf_block_t*
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
2903
2914
                        a page */
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 */
2906
2917
{
2907
2918
        buf_frame_t*    frame;
2908
2919
        buf_block_t*    block;
3030
3041
        return(block);
3031
3042
}
3032
3043
 
3033
 
/********************************************************************//**
 
3044
/************************************************************************
3034
3045
Completes an asynchronous read or write request of a file page to or from
3035
3046
the buffer pool. */
3036
3047
UNIV_INTERN
3037
3048
void
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 */
3041
3052
{
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"
3152
 
                              "InnoDB: See also "
3153
 
                              REFMAN "forcing-recovery.html\n"
 
3163
                              "InnoDB: See also"
 
3164
                              " http://dev.mysql.com/doc/refman/5.1/en/"
 
3165
                              "forcing-recovery.html\n"
3154
3166
                              "InnoDB: about forcing recovery.\n", stderr);
3155
3167
 
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);
3168
3180
                }
3169
3181
 
3170
3182
                if (uncompressed && !recv_no_ibuf_operations) {
3242
3254
        buf_pool_mutex_exit();
3243
3255
}
3244
3256
 
3245
 
/*********************************************************************//**
 
3257
/*************************************************************************
3246
3258
Invalidates the file pages in the buffer pool when an archive recovery is
3247
3259
completed. All the file pages buffered must be in a replaceable state when
3248
3260
this function is called: not latched and not modified. */
3270
3282
}
3271
3283
 
3272
3284
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3273
 
/*********************************************************************//**
3274
 
Validates the buffer buf_pool data structure.
3275
 
@return TRUE */
 
3285
/*************************************************************************
 
3286
Validates the buffer buf_pool data structure. */
3276
3287
UNIV_INTERN
3277
3288
ibool
3278
3289
buf_validate(void)
3494
3505
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
3495
3506
 
3496
3507
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3497
 
/*********************************************************************//**
 
3508
/*************************************************************************
3498
3509
Prints info of the buffer buf_pool data structure. */
3499
3510
UNIV_INTERN
3500
3511
void
3607
3618
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
3608
3619
 
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. */
3613
3623
UNIV_INTERN
3614
3624
ulint
3615
3625
buf_get_latched_pages_number(void)
3696
3706
}
3697
3707
#endif /* UNIV_DEBUG */
3698
3708
 
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. */
3702
3711
UNIV_INTERN
3703
3712
ulint
3704
3713
buf_get_n_pending_ios(void)
3710
3719
               + buf_pool->n_flush[BUF_FLUSH_SINGLE_PAGE]);
3711
3720
}
3712
3721
 
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. */
3717
3725
UNIV_INTERN
3718
3726
ulint
3719
3727
buf_get_modified_ratio_pct(void)
3734
3742
        return(ratio);
3735
3743
}
3736
3744
 
3737
 
/*********************************************************************//**
 
3745
/*************************************************************************
3738
3746
Prints info of the buffer i/o. */
3739
3747
UNIV_INTERN
3740
3748
void
3741
3749
buf_print_io(
3742
3750
/*=========*/
3743
 
        FILE*   file)   /*!< in/out: buffer where to print */
 
3751
        FILE*   file)   /* in/out: buffer where to print */
3744
3752
{
3745
3753
        time_t  current_time;
3746
3754
        double  time_elapsed;
3817
3825
        buf_pool_mutex_exit();
3818
3826
}
3819
3827
 
3820
 
/**********************************************************************//**
 
3828
/**************************************************************************
3821
3829
Refreshes the statistics used to print per-second averages. */
3822
3830
UNIV_INTERN
3823
3831
void
3831
3839
        buf_pool->n_pages_written_old = buf_pool->n_pages_written;
3832
3840
}
3833
3841
 
3834
 
/*********************************************************************//**
3835
 
Asserts that all file pages in the buffer are in a replaceable state.
3836
 
@return TRUE */
 
3842
/*************************************************************************
 
3843
Checks that all file pages in the buffer are in a replaceable state. */
3837
3844
UNIV_INTERN
3838
3845
ibool
3839
3846
buf_all_freed(void)
3866
3873
        return(TRUE);
3867
3874
}
3868
3875
 
3869
 
/*********************************************************************//**
 
3876
/*************************************************************************
3870
3877
Checks that there currently are no pending i/o-operations for the buffer
3871
 
pool.
3872
 
@return TRUE if there is no pending i/o */
 
3878
pool. */
3873
3879
UNIV_INTERN
3874
3880
ibool
3875
3881
buf_pool_check_no_pending_io(void)
3876
3882
/*==============================*/
 
3883
                                /* out: TRUE if there is no pending i/o */
3877
3884
{
3878
3885
        ibool   ret;
3879
3886
 
3892
3899
        return(ret);
3893
3900
}
3894
3901
 
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. */
3898
3904
UNIV_INTERN
3899
3905
ulint
3900
3906
buf_get_free_list_len(void)
3910
3916
 
3911
3917
        return(len);
3912
3918
}
3913
 
#else /* !UNIV_HOTBACKUP */
3914
 
/********************************************************************//**
3915
 
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
3916
 
UNIV_INTERN
3917
 
void
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 */
3926
 
{
3927
 
        block->page.state       = BUF_BLOCK_FILE_PAGE;
3928
 
        block->page.space       = space;
3929
 
        block->page.offset      = offset;
3930
 
 
3931
 
        page_zip_des_init(&block->page.zip);
3932
 
 
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);
3938
 
        if (zip_size) {
3939
 
                block->page.zip.data = block->frame + UNIV_PAGE_SIZE;
3940
 
        }
3941
 
}
3942
 
#endif /* !UNIV_HOTBACKUP */