~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/buf0buf.ic

  • Committer: Marisa Plumb
  • Date: 2010-12-04 02:38:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101204023829-2khzxh30wxi256db
updates to a few sql docs 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2008, Google Inc.
 
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (c) 2008, Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
31
31
*******************************************************/
32
32
 
33
33
#include "mtr0mtr.h"
 
34
#ifndef UNIV_HOTBACKUP
34
35
#include "buf0flu.h"
35
36
#include "buf0lru.h"
36
37
#include "buf0rea.h"
37
 
#include "srv0srv.h"
38
 
 
39
 
/*********************************************************************//**
40
 
Gets the current size of buffer buf_pool in bytes.
41
 
@return size in bytes */
42
 
UNIV_INLINE
43
 
ulint
44
 
buf_pool_get_curr_size(void)
45
 
/*========================*/
46
 
{
47
 
        return(srv_buf_pool_curr_size);
48
 
}
49
 
 
50
 
/********************************************************************//**
51
 
Calculates the index of a buffer pool to the buf_pool[] array.
52
 
@return the position of the buffer pool in buf_pool[] */
53
 
UNIV_INLINE
54
 
ulint
55
 
buf_pool_index(
56
 
/*===========*/
57
 
        const buf_pool_t*       buf_pool)       /*!< in: buffer pool */
58
 
{
59
 
        ulint   i = buf_pool - buf_pool_ptr;
60
 
        ut_ad(i < MAX_BUFFER_POOLS);
61
 
        ut_ad(i < srv_buf_pool_instances);
62
 
        return(i);
63
 
}
64
 
 
65
 
/******************************************************************//**
66
 
Returns the buffer pool instance given a page instance
67
 
@return buf_pool */
68
 
UNIV_INLINE
69
 
buf_pool_t*
70
 
buf_pool_from_bpage(
71
 
/*================*/
72
 
        const buf_page_t*       bpage) /*!< in: buffer pool page */
73
 
{
74
 
        ulint   i;
75
 
        i = bpage->buf_pool_index;
76
 
        ut_ad(i < srv_buf_pool_instances);
77
 
        return(&buf_pool_ptr[i]);
78
 
}
79
 
 
80
 
/******************************************************************//**
81
 
Returns the buffer pool instance given a block instance
82
 
@return buf_pool */
83
 
UNIV_INLINE
84
 
buf_pool_t*
85
 
buf_pool_from_block(
86
 
/*================*/
87
 
        const buf_block_t*      block) /*!< in: block */
88
 
{
89
 
        return(buf_pool_from_bpage(&block->page));
90
 
}
91
 
 
92
 
/*********************************************************************//**
93
 
Gets the current size of buffer buf_pool in pages.
94
 
@return size in pages*/
95
 
UNIV_INLINE
96
 
ulint
97
 
buf_pool_get_n_pages(void)
98
 
/*======================*/
99
 
{
100
 
        return(buf_pool_get_curr_size() / UNIV_PAGE_SIZE);
101
 
}
102
38
 
103
39
/********************************************************************//**
104
40
Reads the freed_page_clock of a buffer block.
109
45
/*==========================*/
110
46
        const buf_page_t*       bpage)  /*!< in: block */
111
47
{
112
 
        /* This is sometimes read without holding buf_pool->mutex. */
 
48
        /* This is sometimes read without holding buf_pool_mutex. */
113
49
        return(bpage->freed_page_clock);
114
50
}
115
51
 
136
72
/*=====================*/
137
73
        const buf_page_t*       bpage)  /*!< in: block to make younger */
138
74
{
139
 
        buf_pool_t*             buf_pool = buf_pool_from_bpage(bpage);
140
 
 
141
75
        if (UNIV_UNLIKELY(buf_pool->freed_page_clock == 0)) {
142
76
                /* If eviction has not started yet, do not update the
143
77
                statistics or move blocks in the LRU list.  This is
159
93
                return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
160
94
                       > ((ulint) bpage->freed_page_clock
161
95
                          + (buf_pool->curr_size
162
 
                             * (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
 
96
                             * (BUF_LRU_OLD_RATIO_DIV - buf_LRU_old_ratio)
163
97
                             / (BUF_LRU_OLD_RATIO_DIV * 4))));
164
98
        }
165
99
}
166
100
 
167
101
/*********************************************************************//**
 
102
Gets the current size of buffer buf_pool in bytes.
 
103
@return size in bytes */
 
104
UNIV_INLINE
 
105
ulint
 
106
buf_pool_get_curr_size(void)
 
107
/*========================*/
 
108
{
 
109
        return(buf_pool->curr_size * UNIV_PAGE_SIZE);
 
110
}
 
111
 
 
112
/********************************************************************//**
 
113
Gets the smallest oldest_modification lsn for any page in the pool. Returns
 
114
zero if all modified pages have been flushed to disk.
 
115
@return oldest modification in pool, zero if none */
 
116
UNIV_INLINE
 
117
ib_uint64_t
 
118
buf_pool_get_oldest_modification(void)
 
119
/*==================================*/
 
120
{
 
121
        buf_page_t*     bpage;
 
122
        ib_uint64_t     lsn;
 
123
 
 
124
        buf_pool_mutex_enter();
 
125
 
 
126
        bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
 
127
 
 
128
        if (bpage == NULL) {
 
129
                lsn = 0;
 
130
        } else {
 
131
                ut_ad(bpage->in_flush_list);
 
132
                lsn = bpage->oldest_modification;
 
133
        }
 
134
 
 
135
        buf_pool_mutex_exit();
 
136
 
 
137
        /* The returned answer may be out of date: the flush_list can
 
138
        change after the mutex has been released. */
 
139
 
 
140
        return(lsn);
 
141
}
 
142
#endif /* !UNIV_HOTBACKUP */
 
143
 
 
144
/*********************************************************************//**
168
145
Gets the state of a block.
169
146
@return state */
170
147
UNIV_INLINE
316
293
/*===============*/
317
294
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
318
295
{
319
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
320
 
 
321
296
        switch (buf_page_get_state(bpage)) {
322
297
        case BUF_BLOCK_ZIP_FREE:
323
298
                ut_error;
324
299
                return(NULL);
325
300
        case BUF_BLOCK_ZIP_PAGE:
326
301
        case BUF_BLOCK_ZIP_DIRTY:
327
 
                return(&buf_pool->zip_mutex);
 
302
                return(&buf_pool_zip_mutex);
328
303
        default:
329
304
                return(&((buf_block_t*) bpage)->mutex);
330
305
        }
410
385
UNIV_INLINE
411
386
enum buf_io_fix
412
387
buf_block_get_io_fix(
413
 
/*=================*/
 
388
/*================*/
414
389
        const buf_block_t*      block)  /*!< in: pointer to the control block */
415
390
{
416
391
        return(buf_page_get_io_fix(&block->page));
425
400
        buf_page_t*     bpage,  /*!< in/out: control block */
426
401
        enum buf_io_fix io_fix) /*!< in: io_fix state */
427
402
{
428
 
#ifdef UNIV_DEBUG
429
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
430
 
        ut_ad(buf_pool_mutex_own(buf_pool));
431
 
#endif
 
403
        ut_ad(buf_pool_mutex_own());
432
404
        ut_ad(mutex_own(buf_page_get_mutex(bpage)));
433
405
 
434
406
        bpage->io_fix = io_fix;
456
428
/*==================*/
457
429
        const buf_page_t*       bpage)  /*!< control block being relocated */
458
430
{
459
 
#ifdef UNIV_DEBUG
460
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
461
 
        ut_ad(buf_pool_mutex_own(buf_pool));
462
 
#endif
 
431
        ut_ad(buf_pool_mutex_own());
463
432
        ut_ad(mutex_own(buf_page_get_mutex(bpage)));
464
433
        ut_ad(buf_page_in_file(bpage));
465
434
        ut_ad(bpage->in_LRU_list);
477
446
/*============*/
478
447
        const buf_page_t*       bpage)  /*!< in: control block */
479
448
{
480
 
#ifdef UNIV_DEBUG
481
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
482
 
        ut_ad(buf_pool_mutex_own(buf_pool));
483
 
#endif
484
449
        ut_ad(buf_page_in_file(bpage));
 
450
        ut_ad(buf_pool_mutex_own());
485
451
 
486
452
        return(bpage->old);
487
453
}
495
461
        buf_page_t*     bpage,  /*!< in/out: control block */
496
462
        ibool           old)    /*!< in: old */
497
463
{
498
 
#ifdef UNIV_DEBUG
499
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
500
 
#endif /* UNIV_DEBUG */
501
464
        ut_a(buf_page_in_file(bpage));
502
 
        ut_ad(buf_pool_mutex_own(buf_pool));
 
465
        ut_ad(buf_pool_mutex_own());
503
466
        ut_ad(bpage->in_LRU_list);
504
467
 
505
468
#ifdef UNIV_LRU_DEBUG
545
508
        buf_page_t*     bpage,          /*!< in/out: control block */
546
509
        ulint           time_ms)        /*!< in: ut_time_ms() */
547
510
{
548
 
#ifdef UNIV_DEBUG
549
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
550
 
        ut_ad(buf_pool_mutex_own(buf_pool));
551
 
#endif
552
511
        ut_a(buf_page_in_file(bpage));
 
512
        ut_ad(buf_pool_mutex_own());
553
513
 
554
514
        if (!bpage->access_time) {
555
515
                /* Make this the time of the first access. */
755
715
}
756
716
 
757
717
/********************************************************************//**
 
718
Allocates a buffer block.
 
719
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
 
720
UNIV_INLINE
 
721
buf_block_t*
 
722
buf_block_alloc(
 
723
/*============*/
 
724
        ulint   zip_size)       /*!< in: compressed page size in bytes,
 
725
                                or 0 if uncompressed tablespace */
 
726
{
 
727
        buf_block_t*    block;
 
728
 
 
729
        block = buf_LRU_get_free_block(zip_size);
 
730
 
 
731
        buf_block_set_state(block, BUF_BLOCK_MEMORY);
 
732
 
 
733
        return(block);
 
734
}
 
735
 
 
736
/********************************************************************//**
758
737
Frees a buffer block which does not contain a file page. */
759
738
UNIV_INLINE
760
739
void
762
741
/*===========*/
763
742
        buf_block_t*    block)  /*!< in, own: block to be freed */
764
743
{
765
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage((buf_page_t*)block);
766
 
 
767
 
        buf_pool_mutex_enter(buf_pool);
 
744
        buf_pool_mutex_enter();
768
745
 
769
746
        mutex_enter(&block->mutex);
770
747
 
774
751
 
775
752
        mutex_exit(&block->mutex);
776
753
 
777
 
        buf_pool_mutex_exit(buf_pool);
 
754
        buf_pool_mutex_exit();
778
755
}
779
756
#endif /* !UNIV_HOTBACKUP */
780
757
 
848
825
        buf_block_t*    block)  /*!< in: block */
849
826
{
850
827
#ifdef UNIV_SYNC_DEBUG
851
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage((buf_page_t*)block);
852
 
 
853
 
        ut_ad((buf_pool_mutex_own(buf_pool)
 
828
        ut_ad((buf_pool_mutex_own()
854
829
               && (block->page.buf_fix_count == 0))
855
830
              || rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
856
831
#endif /* UNIV_SYNC_DEBUG */
929
904
}
930
905
 
931
906
/******************************************************************//**
932
 
Returns the buffer pool instance given space and offset of page
933
 
@return buffer pool */
934
 
UNIV_INLINE
935
 
buf_pool_t*
936
 
buf_pool_get(
937
 
/*==========*/
938
 
        ulint   space,  /*!< in: space id */
939
 
        ulint   offset) /*!< in: offset of the page within space */
940
 
{
941
 
        ulint   fold;
942
 
        ulint   index;
943
 
        ulint   ignored_offset;
944
 
 
945
 
        ignored_offset = offset >> 6; /* 2log of BUF_READ_AHEAD_AREA (64)*/
946
 
        fold = buf_page_address_fold(space, ignored_offset);
947
 
        index = fold % srv_buf_pool_instances;
948
 
        return(&buf_pool_ptr[index]);
949
 
}
950
 
 
951
 
/******************************************************************//**
952
 
Returns the buffer pool instance given its array index
953
 
@return buffer pool */
954
 
UNIV_INLINE
955
 
buf_pool_t*
956
 
buf_pool_from_array(
957
 
/*================*/
958
 
        ulint   index)          /*!< in: array index to get
959
 
                                buffer pool instance from */
960
 
{
961
 
        ut_ad(index < MAX_BUFFER_POOLS);
962
 
        ut_ad(index < srv_buf_pool_instances);
963
 
        return(&buf_pool_ptr[index]);
964
 
}
965
 
 
966
 
/******************************************************************//**
967
907
Returns the control block of a file page, NULL if not found.
968
908
@return block, NULL if not found */
969
909
UNIV_INLINE
970
910
buf_page_t*
971
 
buf_page_hash_get_low(
972
 
/*==================*/
973
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
974
 
        ulint           space,          /*!< in: space id */
975
 
        ulint           offset,         /*!< in: offset of the page
976
 
                                        within space */
977
 
        ulint           fold)           /*!< in: buf_page_address_fold(
978
 
                                        space, offset) */
 
911
buf_page_hash_get(
 
912
/*==============*/
 
913
        ulint   space,  /*!< in: space id */
 
914
        ulint   offset) /*!< in: offset of the page within space */
979
915
{
980
916
        buf_page_t*     bpage;
 
917
        ulint           fold;
981
918
 
982
919
        ut_ad(buf_pool);
983
 
        ut_ad(buf_pool_mutex_own(buf_pool));
984
 
        ut_ad(fold == buf_page_address_fold(space, offset));
 
920
        ut_ad(buf_pool_mutex_own());
985
921
 
986
922
        /* Look for the page in the hash table */
987
923
 
 
924
        fold = buf_page_address_fold(space, offset);
 
925
 
988
926
        HASH_SEARCH(hash, buf_pool->page_hash, fold, buf_page_t*, bpage,
989
927
                    ut_ad(bpage->in_page_hash && !bpage->in_zip_hash
990
928
                          && buf_page_in_file(bpage)),
1005
943
}
1006
944
 
1007
945
/******************************************************************//**
1008
 
Returns the control block of a file page, NULL if not found.
1009
 
@return block, NULL if not found or not a real control block */
1010
 
UNIV_INLINE
1011
 
buf_page_t*
1012
 
buf_page_hash_get(
1013
 
/*==============*/
1014
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1015
 
        ulint           space,          /*!< in: space id */
1016
 
        ulint           offset)         /*!< in: offset of the page
1017
 
                                        within space */
1018
 
{
1019
 
        buf_page_t*     bpage;
1020
 
        ulint           fold    = buf_page_address_fold(space, offset);
1021
 
 
1022
 
        bpage   = buf_page_hash_get_low(buf_pool, space, offset, fold);
1023
 
 
1024
 
        if (bpage && buf_pool_watch_is_sentinel(buf_pool, bpage)) {
1025
 
                bpage = NULL;
1026
 
        }
1027
 
 
1028
 
        return(bpage);
1029
 
}
1030
 
 
1031
 
/******************************************************************//**
1032
946
Returns the control block of a file page, NULL if not found
1033
947
or an uncompressed page frame does not exist.
1034
948
@return block, NULL if not found */
1036
950
buf_block_t*
1037
951
buf_block_hash_get(
1038
952
/*===============*/
1039
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1040
 
        ulint           space,          /*!< in: space id */
1041
 
        ulint           offset)         /*!< in: offset of the page
1042
 
                                        within space */
 
953
        ulint   space,  /*!< in: space id */
 
954
        ulint   offset) /*!< in: offset of the page within space */
1043
955
{
1044
 
        buf_block_t*    block;
1045
 
 
1046
 
        block = buf_page_get_block(buf_page_hash_get(buf_pool, space, offset));
1047
 
 
1048
 
        return(block);
 
956
        return(buf_page_get_block(buf_page_hash_get(space, offset)));
1049
957
}
1050
958
 
1051
959
/********************************************************************//**
1063
971
        ulint   offset) /*!< in: page number */
1064
972
{
1065
973
        const buf_page_t*       bpage;
1066
 
        buf_pool_t*             buf_pool = buf_pool_get(space, offset);
1067
 
 
1068
 
        buf_pool_mutex_enter(buf_pool);
1069
 
 
1070
 
        bpage = buf_page_hash_get(buf_pool, space, offset);
1071
 
 
1072
 
        buf_pool_mutex_exit(buf_pool);
 
974
 
 
975
        buf_pool_mutex_enter();
 
976
 
 
977
        bpage = buf_page_hash_get(space, offset);
 
978
 
 
979
        buf_pool_mutex_exit();
1073
980
 
1074
981
        return(bpage != NULL);
1075
982
}
1083
990
        buf_page_t*     bpage)          /*!< in: buffer block */
1084
991
{
1085
992
        buf_block_t*    block;
1086
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
1087
993
 
1088
994
        ut_ad(bpage);
1089
995
        ut_a(bpage->buf_fix_count > 0);
1091
997
        switch (buf_page_get_state(bpage)) {
1092
998
        case BUF_BLOCK_ZIP_PAGE:
1093
999
        case BUF_BLOCK_ZIP_DIRTY:
1094
 
                mutex_enter(&buf_pool->zip_mutex);
 
1000
                mutex_enter(&buf_pool_zip_mutex);
1095
1001
                bpage->buf_fix_count--;
1096
 
                mutex_exit(&buf_pool->zip_mutex);
 
1002
                mutex_exit(&buf_pool_zip_mutex);
1097
1003
                return;
1098
1004
        case BUF_BLOCK_FILE_PAGE:
1099
1005
                block = (buf_block_t*) bpage;
1112
1018
                break;
1113
1019
        }
1114
1020
 
1115
 
        
1116
1021
        ut_error;
1117
1022
}
1118
1023
 
1124
1029
buf_page_release(
1125
1030
/*=============*/
1126
1031
        buf_block_t*    block,          /*!< in: buffer block */
1127
 
        ulint           rw_latch)       /*!< in: RW_S_LATCH, RW_X_LATCH,
 
1032
        ulint           rw_latch,       /*!< in: RW_S_LATCH, RW_X_LATCH,
1128
1033
                                        RW_NO_LATCH */
 
1034
        mtr_t*          mtr)            /*!< in: mtr */
1129
1035
{
1130
1036
        ut_ad(block);
1131
1037
 
1132
1038
        ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
1133
1039
        ut_a(block->page.buf_fix_count > 0);
1134
1040
 
 
1041
        if (rw_latch == RW_X_LATCH && mtr->modifications) {
 
1042
                buf_pool_mutex_enter();
 
1043
                buf_flush_note_modification(block, mtr);
 
1044
                buf_pool_mutex_exit();
 
1045
        }
 
1046
 
1135
1047
        mutex_enter(&block->mutex);
1136
1048
 
1137
1049
#ifdef UNIV_SYNC_DEBUG
1164
1076
        sync_thread_add_level(&block->lock, level);
1165
1077
}
1166
1078
#endif /* UNIV_SYNC_DEBUG */
1167
 
/********************************************************************//**
1168
 
Acquire mutex on all buffer pool instances. */
1169
 
UNIV_INLINE
1170
 
void
1171
 
buf_pool_mutex_enter_all(void)
1172
 
/*==========================*/
1173
 
{
1174
 
        ulint   i;
1175
 
 
1176
 
        for (i = 0; i < srv_buf_pool_instances; i++) {
1177
 
                buf_pool_t*     buf_pool;
1178
 
 
1179
 
                buf_pool = buf_pool_from_array(i);
1180
 
                buf_pool_mutex_enter(buf_pool);
1181
 
        }
1182
 
}
1183
 
 
1184
 
/********************************************************************//**
1185
 
Release mutex on all buffer pool instances. */
1186
 
UNIV_INLINE
1187
 
void
1188
 
buf_pool_mutex_exit_all(void)
1189
 
/*=========================*/
1190
 
{
1191
 
        ulint   i;
1192
 
 
1193
 
        for (i = 0; i < srv_buf_pool_instances; i++) {
1194
 
                buf_pool_t*     buf_pool;
1195
 
 
1196
 
                buf_pool = buf_pool_from_array(i);
1197
 
                buf_pool_mutex_exit(buf_pool);
1198
 
        }
1199
 
}
1200
1079
#endif /* !UNIV_HOTBACKUP */