~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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.
 
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
34
34
#include "ut0byte.h"
35
35
#include "page0types.h"
36
36
#ifndef UNIV_HOTBACKUP
37
 
#include "ut0rbt.h"
38
37
#include "os0proc.h"
39
38
 
40
39
/** @name Modes for buf_page_get_gen */
47
46
                                        it is error-prone programming
48
47
                                        not to set a latch, and it
49
48
                                        should be used with care */
50
 
#define BUF_GET_IF_IN_POOL_OR_WATCH     15
51
 
                                        /*!< Get the page only if it's in the
52
 
                                        buffer pool, if not then set a watch
53
 
                                        on the page. */
54
49
/* @} */
55
50
/** @name Modes for buf_page_get_known_nowait */
56
51
/* @{ */
63
58
                                        position of the block. */
64
59
/* @} */
65
60
 
66
 
#define MAX_BUFFER_POOLS 64             /*!< The maximum number of buffer
67
 
                                        pools that can be defined */
68
 
 
69
 
#define BUF_POOL_WATCH_SIZE 1           /*!< Maximum number of concurrent
70
 
                                        buffer pool watches */
71
 
 
72
 
extern  buf_pool_t*     buf_pool_ptr;   /*!< The buffer pools
73
 
                                        of the database */
 
61
extern buf_pool_t*      buf_pool;       /*!< The buffer pool of the database */
74
62
#ifdef UNIV_DEBUG
75
63
extern ibool            buf_debug_prints;/*!< If this is set TRUE, the program
76
64
                                        prints info whenever read or flush
91
79
enum buf_page_state {
92
80
        BUF_BLOCK_ZIP_FREE = 0,         /*!< contains a free
93
81
                                        compressed page */
94
 
        BUF_BLOCK_POOL_WATCH = 0,       /*!< a sentinel for the buffer pool
95
 
                                        watch, element of buf_pool->watch[] */
96
82
        BUF_BLOCK_ZIP_PAGE,             /*!< contains a clean
97
83
                                        compressed page */
98
84
        BUF_BLOCK_ZIP_DIRTY,            /*!< contains a compressed
114
100
 
115
101
#ifndef UNIV_HOTBACKUP
116
102
/********************************************************************//**
117
 
Acquire mutex on all buffer pool instances */
118
 
UNIV_INLINE
119
 
void
120
 
buf_pool_mutex_enter_all(void);
121
 
/*===========================*/
122
 
 
123
 
/********************************************************************//**
124
 
Release mutex on all buffer pool instances */
125
 
UNIV_INLINE
126
 
void
127
 
buf_pool_mutex_exit_all(void);
128
 
/*==========================*/
129
 
 
130
 
/********************************************************************//**
131
103
Creates the buffer pool.
132
104
@return own: buf_pool object, NULL if not enough memory or error */
133
105
UNIV_INTERN
134
 
ulint
135
 
buf_pool_init(
136
 
/*=========*/
137
 
        ulint   size,           /*!< in: Size of the total pool in bytes */
138
 
        ulint   n_instances);   /*!< in: Number of instances */
 
106
buf_pool_t*
 
107
buf_pool_init(void);
 
108
/*===============*/
139
109
/********************************************************************//**
140
110
Frees the buffer pool at shutdown.  This must not be invoked before
141
111
freeing all mutexes. */
142
112
UNIV_INTERN
143
113
void
144
 
buf_pool_free(
145
 
/*==========*/
146
 
        ulint   n_instances);   /*!< in: numbere of instances to free */
 
114
buf_pool_free(void);
 
115
/*===============*/
147
116
 
148
117
/********************************************************************//**
149
118
Drops the adaptive hash index.  To prevent a livelock, this function
180
149
ulint
181
150
buf_pool_get_curr_size(void);
182
151
/*========================*/
183
 
/*********************************************************************//**
184
 
Gets the current size of buffer buf_pool in frames.
185
 
@return size in pages */
186
 
UNIV_INLINE
187
 
ulint
188
 
buf_pool_get_n_pages(void);
189
 
/*=======================*/
190
152
/********************************************************************//**
191
153
Gets the smallest oldest_modification lsn for any page in the pool. Returns
192
154
zero if all modified pages have been flushed to disk.
193
155
@return oldest modification in pool, zero if none */
194
 
UNIV_INTERN
 
156
UNIV_INLINE
195
157
ib_uint64_t
196
158
buf_pool_get_oldest_modification(void);
197
159
/*==================================*/
198
160
/********************************************************************//**
199
161
Allocates a buffer block.
200
162
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
201
 
UNIV_INTERN
 
163
UNIV_INLINE
202
164
buf_block_t*
203
165
buf_block_alloc(
204
166
/*============*/
205
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
206
 
        ulint           zip_size);      /*!< in: compressed page size in bytes,
207
 
                                        or 0 if uncompressed tablespace */
 
167
        ulint   zip_size);      /*!< in: compressed page size in bytes,
 
168
                                or 0 if uncompressed tablespace */
208
169
/********************************************************************//**
209
170
Frees a buffer block which does not contain a file page. */
210
171
UNIV_INLINE
239
200
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR)        buf_page_get_gen(\
240
201
                                SP, ZS, OF, RW_NO_LATCH, NULL,\
241
202
                                BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
 
203
/**************************************************************//**
 
204
NOTE! The following macros should be used instead of
 
205
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
 
206
RW_X_LATCH are allowed as LA! */
 
207
#define buf_page_optimistic_get(LA, BL, MC, MTR)                             \
 
208
        buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
242
209
/********************************************************************//**
243
210
This is the general function used to get optimistic access to a database
244
211
page.
245
212
@return TRUE if success */
246
213
UNIV_INTERN
247
214
ibool
248
 
buf_page_optimistic_get(
249
 
/*====================*/
 
215
buf_page_optimistic_get_func(
 
216
/*=========================*/
250
217
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
251
218
        buf_block_t*    block,  /*!< in: guessed block */
252
219
        ib_uint64_t     modify_clock,/*!< in: modify clock value if mode is
322
289
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
323
290
        buf_block_t*    guess,  /*!< in: guessed block or NULL */
324
291
        ulint           mode,   /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
325
 
                                BUF_GET_NO_LATCH or
326
 
                                BUF_GET_IF_IN_POOL_OR_WATCH */
 
292
                                BUF_GET_NO_LATCH */
327
293
        const char*     file,   /*!< in: file name */
328
294
        ulint           line,   /*!< in: line where called */
329
295
        mtr_t*          mtr);   /*!< in: mini-transaction */
373
339
buf_page_release(
374
340
/*=============*/
375
341
        buf_block_t*    block,          /*!< in: buffer block */
376
 
        ulint           rw_latch);      /*!< in: RW_S_LATCH, RW_X_LATCH,
 
342
        ulint           rw_latch,       /*!< in: RW_S_LATCH, RW_X_LATCH,
377
343
                                        RW_NO_LATCH */
 
344
        mtr_t*          mtr);           /*!< in: mtr */
378
345
/********************************************************************//**
379
346
Moves a page to the start of the buffer pool LRU list. This high-level
380
347
function can be used to prevent an important page from slipping out of
484
451
                                        page frame */
485
452
/********************************************************************//**
486
453
Increments the modify clock of a frame by 1. The caller must (1) own the
487
 
buf_pool->mutex and block bufferfix count has to be zero, (2) or own an x-lock
 
454
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
488
455
on the block. */
489
456
UNIV_INLINE
490
457
void
566
533
buf_block_t*
567
534
buf_pool_contains_zip(
568
535
/*==================*/
569
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
570
 
        const void*     data);          /*!< in: pointer to compressed page */
 
536
        const void*     data);  /*!< in: pointer to compressed page */
571
537
#endif /* UNIV_DEBUG */
572
538
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
573
539
/*********************************************************************//**
641
607
Refreshes the statistics used to print per-second averages. */
642
608
UNIV_INTERN
643
609
void
644
 
buf_refresh_io_stats(
645
 
/*=================*/
646
 
        buf_pool_t*     buf_pool);      /*!< buffer pool instance */
647
 
/**********************************************************************//**
648
 
Refreshes the statistics used to print per-second averages. */
649
 
UNIV_INTERN
650
 
void
651
 
buf_refresh_io_stats_all(void);
652
 
/*=================*/
 
610
buf_refresh_io_stats(void);
 
611
/*======================*/
653
612
/*********************************************************************//**
654
613
Asserts that all file pages in the buffer are in a replaceable state.
655
614
@return TRUE */
865
824
        __attribute__((nonnull));
866
825
/*********************************************************************//**
867
826
Gets the buf_block_t handle of a buffered file block if an uncompressed
868
 
page frame exists, or NULL. Note: even though bpage is not declared a
869
 
const we don't update its value. It is safe to make this pure.
 
827
page frame exists, or NULL.
870
828
@return control block, or NULL */
871
829
UNIV_INLINE
872
830
buf_block_t*
1030
988
        ulint   space,  /*!< in: space id */
1031
989
        ulint   offset) /*!< in: offset of the page within space */
1032
990
        __attribute__((const));
1033
 
/********************************************************************//**
1034
 
Calculates the index of a buffer pool to the buf_pool[] array.
1035
 
@return the position of the buffer pool in buf_pool[] */
1036
 
UNIV_INLINE
1037
 
ulint
1038
 
buf_pool_index(
1039
 
/*===========*/
1040
 
        const buf_pool_t*       buf_pool)       /*!< in: buffer pool */
1041
 
        __attribute__((nonnull, const));
1042
 
/******************************************************************//**
1043
 
Returns the buffer pool instance given a page instance
1044
 
@return buf_pool */
1045
 
UNIV_INLINE
1046
 
buf_pool_t*
1047
 
buf_pool_from_bpage(
1048
 
/*================*/
1049
 
        const buf_page_t*       bpage); /*!< in: buffer pool page */
1050
 
/******************************************************************//**
1051
 
Returns the buffer pool instance given a block instance
1052
 
@return buf_pool */
1053
 
UNIV_INLINE
1054
 
buf_pool_t*
1055
 
buf_pool_from_block(
1056
 
/*================*/
1057
 
        const buf_block_t*      block); /*!< in: block */
1058
 
/******************************************************************//**
1059
 
Returns the buffer pool instance given space and offset of page
1060
 
@return buffer pool */
1061
 
UNIV_INLINE
1062
 
buf_pool_t*
1063
 
buf_pool_get(
1064
 
/*==========*/
1065
 
        ulint   space,  /*!< in: space id */
1066
 
        ulint   offset);/*!< in: offset of the page within space */
1067
 
/******************************************************************//**
1068
 
Returns the buffer pool instance given its array index
1069
 
@return buffer pool */
1070
 
UNIV_INLINE
1071
 
buf_pool_t*
1072
 
buf_pool_from_array(
1073
 
/*================*/
1074
 
        ulint   index);         /*!< in: array index to get
1075
 
                                buffer pool instance from */
1076
991
/******************************************************************//**
1077
992
Returns the control block of a file page, NULL if not found.
1078
993
@return block, NULL if not found */
1079
994
UNIV_INLINE
1080
995
buf_page_t*
1081
 
buf_page_hash_get_low(
1082
 
/*==================*/
1083
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
1084
 
        ulint           space,          /*!< in: space id */
1085
 
        ulint           offset,         /*!< in: offset of the page
1086
 
                                        within space */
1087
 
        ulint           fold);          /*!< in: buf_page_address_fold(
1088
 
                                        space, offset) */
1089
 
/******************************************************************//**
1090
 
Returns the control block of a file page, NULL if not found.
1091
 
@return block, NULL if not found or not a real control block */
1092
 
UNIV_INLINE
1093
 
buf_page_t*
1094
996
buf_page_hash_get(
1095
997
/*==============*/
1096
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1097
 
        ulint           space,          /*!< in: space id */
1098
 
        ulint           offset);        /*!< in: offset of the page
1099
 
                                        within space */
 
998
        ulint   space,  /*!< in: space id */
 
999
        ulint   offset);/*!< in: offset of the page within space */
1100
1000
/******************************************************************//**
1101
1001
Returns the control block of a file page, NULL if not found
1102
1002
or an uncompressed page frame does not exist.
1105
1005
buf_block_t*
1106
1006
buf_block_hash_get(
1107
1007
/*===============*/
1108
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1109
 
        ulint           space,          /*!< in: space id */
1110
 
        ulint           offset);        /*!< in: offset of the page
1111
 
                                        within space */
 
1008
        ulint   space,  /*!< in: space id */
 
1009
        ulint   offset);/*!< in: offset of the page within space */
1112
1010
/*********************************************************************//**
1113
1011
Gets the current length of the free list of buffer blocks.
1114
1012
@return length of the free list */
1116
1014
ulint
1117
1015
buf_get_free_list_len(void);
1118
1016
/*=======================*/
1119
 
 
1120
 
/********************************************************************
1121
 
Determine if a block is a sentinel for a buffer pool watch.
1122
 
@return TRUE if a sentinel for a buffer pool watch, FALSE if not */
1123
 
UNIV_INTERN
1124
 
ibool
1125
 
buf_pool_watch_is_sentinel(
1126
 
/*=======================*/
1127
 
        buf_pool_t*             buf_pool,       /*!< buffer pool instance */
1128
 
        const buf_page_t*       bpage)          /*!< in: block */
1129
 
  UNIV_WARN_UNUSED_RESULT;
1130
 
/****************************************************************//**
1131
 
Add watch for the given page to be read in. Caller must have the buffer pool
1132
 
@return NULL if watch set, block if the page is in the buffer pool */
1133
 
UNIV_INTERN
1134
 
buf_page_t*
1135
 
buf_pool_watch_set(
1136
 
/*===============*/
1137
 
        ulint   space,  /*!< in: space id */
1138
 
        ulint   offset, /*!< in: page number */
1139
 
        ulint   fold)   /*!< in: buf_page_address_fold(space, offset) */
1140
 
  UNIV_WARN_UNUSED_RESULT;
1141
 
/****************************************************************//**
1142
 
Stop watching if the page has been read in.
1143
 
buf_pool_watch_set(space,offset) must have returned NULL before. */
1144
 
UNIV_INTERN
1145
 
void
1146
 
buf_pool_watch_unset(
1147
 
/*=================*/
1148
 
        ulint   space,  /*!< in: space id */
1149
 
        ulint   offset);/*!< in: page number */
1150
 
/****************************************************************//**
1151
 
Check if the page has been read in.
1152
 
This may only be called after buf_pool_watch_set(space,offset)
1153
 
has returned NULL and before invoking buf_pool_watch_unset(space,offset).
1154
 
@return FALSE if the given page was not read in, TRUE if it was */
1155
 
UNIV_INTERN
1156
 
ibool
1157
 
buf_pool_watch_occurred(
1158
 
/*====================*/
1159
 
        ulint   space,  /*!< in: space id */
1160
 
        ulint   offset) /*!< in: page number */
1161
 
  UNIV_WARN_UNUSED_RESULT;
1162
 
/********************************************************************//**
1163
 
Get total buffer pool statistics. */
1164
 
UNIV_INTERN
1165
 
void
1166
 
buf_get_total_list_len(
1167
 
/*===================*/
1168
 
        ulint*          LRU_len,        /*!< out: length of all LRU lists */
1169
 
        ulint*          free_len,       /*!< out: length of all free lists */
1170
 
        ulint*          flush_list_len);/*!< out: length of all flush lists */
1171
 
/********************************************************************//**
1172
 
Get total buffer pool statistics. */
1173
 
UNIV_INTERN
1174
 
void
1175
 
buf_get_total_stat(
1176
 
/*===============*/
1177
 
        buf_pool_stat_t*tot_stat);      /*!< out: buffer pool stats */
1178
 
 
1179
1017
#endif /* !UNIV_HOTBACKUP */
1180
1018
 
 
1019
 
1181
1020
/** The common buffer control block structure
1182
1021
for compressed and uncompressed frames */
1183
1022
 
1185
1024
        /** @name General fields
1186
1025
        None of these bit-fields must be modified without holding
1187
1026
        buf_page_get_mutex() [buf_block_struct::mutex or
1188
 
        buf_pool->zip_mutex], since they can be stored in the same
 
1027
        buf_pool_zip_mutex], since they can be stored in the same
1189
1028
        machine word.  Some of these fields are additionally protected
1190
 
        by buf_pool->mutex. */
 
1029
        by buf_pool_mutex. */
1191
1030
        /* @{ */
1192
1031
 
1193
1032
        unsigned        space:32;       /*!< tablespace id; also protected
1194
 
                                        by buf_pool->mutex. */
 
1033
                                        by buf_pool_mutex. */
1195
1034
        unsigned        offset:32;      /*!< page number; also protected
1196
 
                                        by buf_pool->mutex. */
 
1035
                                        by buf_pool_mutex. */
1197
1036
 
1198
1037
        unsigned        state:3;        /*!< state of the control block; also
1199
 
                                        protected by buf_pool->mutex.
 
1038
                                        protected by buf_pool_mutex.
1200
1039
                                        State transitions from
1201
1040
                                        BUF_BLOCK_READY_FOR_USE to
1202
1041
                                        BUF_BLOCK_MEMORY need not be
1208
1047
                                        flush_type.
1209
1048
                                        @see enum buf_flush */
1210
1049
        unsigned        io_fix:2;       /*!< type of pending I/O operation;
1211
 
                                        also protected by buf_pool->mutex
 
1050
                                        also protected by buf_pool_mutex
1212
1051
                                        @see enum buf_io_fix */
1213
 
        unsigned        buf_fix_count:19;/*!< count of how manyfold this block
 
1052
        unsigned        buf_fix_count:25;/*!< count of how manyfold this block
1214
1053
                                        is currently bufferfixed */
1215
 
        unsigned        buf_pool_index:6;/*!< index number of the buffer pool
1216
 
                                        that this block belongs to */
1217
 
# if MAX_BUFFER_POOLS > 64
1218
 
#  error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
1219
 
# endif
1220
1054
        /* @} */
1221
1055
#endif /* !UNIV_HOTBACKUP */
1222
1056
        page_zip_des_t  zip;            /*!< compressed page; zip.data
1223
1057
                                        (but not the data it points to) is
1224
 
                                        also protected by buf_pool->mutex;
1225
 
                                        state == BUF_BLOCK_ZIP_PAGE and
1226
 
                                        zip.data == NULL means an active
1227
 
                                        buf_pool->watch */
 
1058
                                        also protected by buf_pool_mutex */
1228
1059
#ifndef UNIV_HOTBACKUP
1229
1060
        buf_page_t*     hash;           /*!< node used in chaining to
1230
1061
                                        buf_pool->page_hash or
1235
1066
#endif /* UNIV_DEBUG */
1236
1067
 
1237
1068
        /** @name Page flushing fields
1238
 
        All these are protected by buf_pool->mutex. */
 
1069
        All these are protected by buf_pool_mutex. */
1239
1070
        /* @{ */
1240
1071
 
1241
1072
        UT_LIST_NODE_T(buf_page_t) list;
1242
1073
                                        /*!< based on state, this is a
1243
 
                                        list node, protected either by
1244
 
                                        buf_pool->mutex or by
1245
 
                                        buf_pool->flush_list_mutex,
1246
 
                                        in one of the following lists in
1247
 
                                        buf_pool:
 
1074
                                        list node, protected only by
 
1075
                                        buf_pool_mutex, in one of the
 
1076
                                        following lists in buf_pool:
1248
1077
 
1249
1078
                                        - BUF_BLOCK_NOT_USED:   free
1250
1079
                                        - BUF_BLOCK_FILE_PAGE:  flush_list
1252
1081
                                        - BUF_BLOCK_ZIP_PAGE:   zip_clean
1253
1082
                                        - BUF_BLOCK_ZIP_FREE:   zip_free[]
1254
1083
 
1255
 
                                        If bpage is part of flush_list
1256
 
                                        then the node pointers are
1257
 
                                        covered by buf_pool->flush_list_mutex.
1258
 
                                        Otherwise these pointers are
1259
 
                                        protected by buf_pool->mutex.
1260
 
 
1261
1084
                                        The contents of the list node
1262
1085
                                        is undefined if !in_flush_list
1263
1086
                                        && state == BUF_BLOCK_FILE_PAGE,
1268
1091
 
1269
1092
#ifdef UNIV_DEBUG
1270
1093
        ibool           in_flush_list;  /*!< TRUE if in buf_pool->flush_list;
1271
 
                                        when buf_pool->flush_list_mutex is
1272
 
                                        free, the following should hold:
1273
 
                                        in_flush_list
 
1094
                                        when buf_pool_mutex is free, the
 
1095
                                        following should hold: in_flush_list
1274
1096
                                        == (state == BUF_BLOCK_FILE_PAGE
1275
 
                                            || state == BUF_BLOCK_ZIP_DIRTY)
1276
 
                                        Writes to this field must be
1277
 
                                        covered by both block->mutex
1278
 
                                        and buf_pool->flush_list_mutex. Hence
1279
 
                                        reads can happen while holding
1280
 
                                        any one of the two mutexes */
 
1097
                                            || state == BUF_BLOCK_ZIP_DIRTY) */
1281
1098
        ibool           in_free_list;   /*!< TRUE if in buf_pool->free; when
1282
 
                                        buf_pool->mutex is free, the following
 
1099
                                        buf_pool_mutex is free, the following
1283
1100
                                        should hold: in_free_list
1284
1101
                                        == (state == BUF_BLOCK_NOT_USED) */
1285
1102
#endif /* UNIV_DEBUG */
1287
1104
                                        /*!< log sequence number of
1288
1105
                                        the youngest modification to
1289
1106
                                        this block, zero if not
1290
 
                                        modified. Protected by block
1291
 
                                        mutex */
 
1107
                                        modified */
1292
1108
        ib_uint64_t     oldest_modification;
1293
1109
                                        /*!< log sequence number of
1294
1110
                                        the START of the log entry
1296
1112
                                        modification to this block
1297
1113
                                        which has not yet been flushed
1298
1114
                                        on disk; zero if all
1299
 
                                        modifications are on disk.
1300
 
                                        Writes to this field must be
1301
 
                                        covered by both block->mutex
1302
 
                                        and buf_pool->flush_list_mutex. Hence
1303
 
                                        reads can happen while holding
1304
 
                                        any one of the two mutexes */
 
1115
                                        modifications are on disk */
1305
1116
        /* @} */
1306
1117
        /** @name LRU replacement algorithm fields
1307
 
        These fields are protected by buf_pool->mutex only (not
1308
 
        buf_pool->zip_mutex or buf_block_struct::mutex). */
 
1118
        These fields are protected by buf_pool_mutex only (not
 
1119
        buf_pool_zip_mutex or buf_block_struct::mutex). */
1309
1120
        /* @{ */
1310
1121
 
1311
1122
        UT_LIST_NODE_T(buf_page_t) LRU;
1372
1183
        rw_lock_t       lock;           /*!< read-write lock of the buffer
1373
1184
                                        frame */
1374
1185
        unsigned        lock_hash_val:32;/*!< hashed value of the page address
1375
 
                                        in the record lock hash table;
1376
 
                                        protected by buf_block_t::lock
1377
 
                                        (or buf_block_t::mutex, buf_pool->mutex
1378
 
                                        in buf_page_get_gen(),
1379
 
                                        buf_page_init_for_read()
1380
 
                                        and buf_page_create()) */
1381
 
        ibool           check_index_page_at_flush;
 
1186
                                        in the record lock hash table */
 
1187
        unsigned        check_index_page_at_flush:1;
1382
1188
                                        /*!< TRUE if we know that this is
1383
1189
                                        an index page, and want the database
1384
1190
                                        to check its consistency before flush;
1385
1191
                                        note that there may be pages in the
1386
1192
                                        buffer pool which are index pages,
1387
1193
                                        but this flag is not set because
1388
 
                                        we do not keep track of all pages;
1389
 
                                        NOT protected by any mutex */
 
1194
                                        we do not keep track of all pages */
1390
1195
        /* @} */
1391
1196
        /** @name Optimistic search field */
1392
1197
        /* @{ */
1503
1308
                                buf_page_peek_if_too_old() */
1504
1309
};
1505
1310
 
1506
 
/** Statistics of buddy blocks of a given size. */
1507
 
struct buf_buddy_stat_struct {
1508
 
        /** Number of blocks allocated from the buddy system. */
1509
 
        ulint           used;
1510
 
        /** Number of blocks relocated by the buddy system. */
1511
 
        ib_uint64_t     relocated;
1512
 
        /** Total duration of block relocations, in microseconds. */
1513
 
        ib_uint64_t     relocated_usec;
1514
 
};
1515
 
 
1516
1311
/** @brief The buffer pool structure.
1517
1312
 
1518
1313
NOTE! The definition appears here only for other modules of this
1522
1317
 
1523
1318
        /** @name General fields */
1524
1319
        /* @{ */
1525
 
        mutex_t         mutex;          /*!< Buffer pool mutex of this
1526
 
                                        instance */
1527
 
        mutex_t         zip_mutex;      /*!< Zip mutex of this buffer
1528
 
                                        pool instance, protects compressed
1529
 
                                        only pages (of type buf_page_t, not
1530
 
                                        buf_block_t */
1531
 
        ulint           instance_no;    /*!< Array index of this buffer
1532
 
                                        pool instance */
1533
 
        ulint           old_pool_size;  /*!< Old pool size in bytes */
1534
 
        ulint           curr_pool_size; /*!< Current pool size in bytes */
1535
 
        ulint           LRU_old_ratio;  /*!< Reserve this much of the buffer
1536
 
                                        pool for "old" blocks */
1537
 
#ifdef UNIV_DEBUG
1538
 
        ulint           buddy_n_frames; /*!< Number of frames allocated from
1539
 
                                        the buffer pool to the buddy system */
1540
 
#endif
1541
 
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1542
 
        ulint           mutex_exit_forbidden; /*!< Forbid release mutex */
1543
 
#endif
 
1320
 
1544
1321
        ulint           n_chunks;       /*!< number of buffer pool chunks */
1545
1322
        buf_chunk_t*    chunks;         /*!< buffer pool chunks */
1546
1323
        ulint           curr_size;      /*!< current pool size in pages */
1552
1329
                                        whose frames are allocated to the
1553
1330
                                        zip buddy system,
1554
1331
                                        indexed by block->frame */
1555
 
        ulint           n_pend_reads;   /*!< number of pending read
1556
 
                                        operations */
 
1332
        ulint           n_pend_reads;   /*!< number of pending read operations */
1557
1333
        ulint           n_pend_unzip;   /*!< number of pending decompressions */
1558
1334
 
1559
1335
        time_t          last_printout_time;
1560
1336
                                        /*!< when buf_print_io was last time
1561
1337
                                        called */
1562
 
        buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES + 1];
1563
 
                                        /*!< Statistics of buddy system,
1564
 
                                        indexed by block size */
1565
1338
        buf_pool_stat_t stat;           /*!< current statistics */
1566
1339
        buf_pool_stat_t old_stat;       /*!< old statistics */
1567
1340
 
1571
1344
 
1572
1345
        /* @{ */
1573
1346
 
1574
 
        mutex_t         flush_list_mutex;/*!< mutex protecting the
1575
 
                                        flush list access. This mutex
1576
 
                                        protects flush_list, flush_rbt
1577
 
                                        and bpage::list pointers when
1578
 
                                        the bpage is on flush_list. It
1579
 
                                        also protects writes to
1580
 
                                        bpage::oldest_modification */
1581
1347
        UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1582
1348
                                        /*!< base node of the modified block
1583
1349
                                        list */
1591
1357
                                        /*!< this is in the set state
1592
1358
                                        when there is no flush batch
1593
1359
                                        of the given type running */
1594
 
        ib_rbt_t*       flush_rbt;      /*!< a red-black tree is used
1595
 
                                        exclusively during recovery to
1596
 
                                        speed up insertions in the
1597
 
                                        flush_list. This tree contains
1598
 
                                        blocks in order of
1599
 
                                        oldest_modification LSN and is
1600
 
                                        kept in sync with the
1601
 
                                        flush_list.
1602
 
                                        Each member of the tree MUST
1603
 
                                        also be on the flush_list.
1604
 
                                        This tree is relevant only in
1605
 
                                        recovery and is set to NULL
1606
 
                                        once the recovery is over.
1607
 
                                        Protected by flush_list_mutex */
1608
1360
        ulint           freed_page_clock;/*!< a sequence number used
1609
1361
                                        to count the number of buffer
1610
1362
                                        blocks removed from the end of
1618
1370
                                        this is incremented by one; this is
1619
1371
                                        set to zero when a buffer block is
1620
1372
                                        allocated */
 
1373
 
1621
1374
        /* @} */
1622
 
 
1623
1375
        /** @name LRU replacement algorithm fields */
1624
1376
        /* @{ */
1625
1377
 
1657
1409
                                        /*!< unmodified compressed pages */
1658
1410
        UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1659
1411
                                        /*!< buddy free lists */
1660
 
 
1661
 
        buf_page_t                      watch[BUF_POOL_WATCH_SIZE];
1662
 
                                        /*!< Sentinel records for buffer
1663
 
                                        pool watches. Protected by
1664
 
                                        buf_pool->mutex. */
1665
 
 
1666
1412
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1667
1413
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1668
1414
#endif
1672
1418
        /* @} */
1673
1419
};
1674
1420
 
1675
 
/** @name Accessors for buf_pool->mutex.
1676
 
Use these instead of accessing buf_pool->mutex directly. */
 
1421
/** mutex protecting the buffer pool struct and control blocks, except the
 
1422
read-write lock in them */
 
1423
extern mutex_t  buf_pool_mutex;
 
1424
/** mutex protecting the control blocks of compressed-only pages
 
1425
(of type buf_page_t, not buf_block_t) */
 
1426
extern mutex_t  buf_pool_zip_mutex;
 
1427
 
 
1428
/** @name Accessors for buf_pool_mutex.
 
1429
Use these instead of accessing buf_pool_mutex directly. */
1677
1430
/* @{ */
1678
1431
 
1679
 
/** Test if a buffer pool mutex is owned. */
1680
 
#define buf_pool_mutex_own(b) mutex_own(&b->mutex)
1681
 
/** Acquire a buffer pool mutex. */
1682
 
#define buf_pool_mutex_enter(b) do {            \
1683
 
        ut_ad(!mutex_own(&b->zip_mutex));       \
1684
 
        mutex_enter(&b->mutex);         \
1685
 
} while (0)
1686
 
 
1687
 
/** Test if flush list mutex is owned. */
1688
 
#define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1689
 
 
1690
 
/** Acquire the flush list mutex. */
1691
 
#define buf_flush_list_mutex_enter(b) do {      \
1692
 
        mutex_enter(&b->flush_list_mutex);      \
1693
 
} while (0)
1694
 
/** Release the flush list mutex. */
1695
 
# define buf_flush_list_mutex_exit(b) do {      \
1696
 
        mutex_exit(&b->flush_list_mutex);       \
1697
 
} while (0)
1698
 
 
1699
 
 
 
1432
/** Test if buf_pool_mutex is owned. */
 
1433
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
 
1434
/** Acquire the buffer pool mutex. */
 
1435
#define buf_pool_mutex_enter() do {             \
 
1436
        ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
 
1437
        mutex_enter(&buf_pool_mutex);           \
 
1438
} while (0)
1700
1439
 
1701
1440
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
 
1441
/** Flag to forbid the release of the buffer pool mutex.
 
1442
Protected by buf_pool_mutex. */
 
1443
extern ulint    buf_pool_mutex_exit_forbidden;
1702
1444
/** Forbid the release of the buffer pool mutex. */
1703
 
# define buf_pool_mutex_exit_forbid(b) do {     \
1704
 
        ut_ad(buf_pool_mutex_own(b));           \
1705
 
        b->mutex_exit_forbidden++;              \
 
1445
# define buf_pool_mutex_exit_forbid() do {      \
 
1446
        ut_ad(buf_pool_mutex_own());            \
 
1447
        buf_pool_mutex_exit_forbidden++;        \
1706
1448
} while (0)
1707
1449
/** Allow the release of the buffer pool mutex. */
1708
 
# define buf_pool_mutex_exit_allow(b) do {      \
1709
 
        ut_ad(buf_pool_mutex_own(b));           \
1710
 
        ut_a(b->mutex_exit_forbidden);  \
1711
 
        b->mutex_exit_forbidden--;              \
 
1450
# define buf_pool_mutex_exit_allow() do {       \
 
1451
        ut_ad(buf_pool_mutex_own());            \
 
1452
        ut_a(buf_pool_mutex_exit_forbidden);    \
 
1453
        buf_pool_mutex_exit_forbidden--;        \
1712
1454
} while (0)
1713
1455
/** Release the buffer pool mutex. */
1714
 
# define buf_pool_mutex_exit(b) do {            \
1715
 
        ut_a(!b->mutex_exit_forbidden);         \
1716
 
        mutex_exit(&b->mutex);                  \
 
1456
# define buf_pool_mutex_exit() do {             \
 
1457
        ut_a(!buf_pool_mutex_exit_forbidden);   \
 
1458
        mutex_exit(&buf_pool_mutex);            \
1717
1459
} while (0)
1718
1460
#else
1719
1461
/** Forbid the release of the buffer pool mutex. */
1720
 
# define buf_pool_mutex_exit_forbid(b) ((void) 0)
 
1462
# define buf_pool_mutex_exit_forbid() ((void) 0)
1721
1463
/** Allow the release of the buffer pool mutex. */
1722
 
# define buf_pool_mutex_exit_allow(b) ((void) 0)
 
1464
# define buf_pool_mutex_exit_allow() ((void) 0)
1723
1465
/** Release the buffer pool mutex. */
1724
 
# define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
 
1466
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1725
1467
#endif
1726
1468
#endif /* !UNIV_HOTBACKUP */
1727
1469
/* @} */