~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/******************************************************
 
19
/**************************************************//**
 
20
@file include/buf0buf.h
20
21
The database buffer pool high-level routines
21
22
 
22
23
Created 11/5/1995 Heikki Tuuri
29
30
#include "fil0fil.h"
30
31
#include "mtr0types.h"
31
32
#include "buf0types.h"
32
 
#include "sync0rw.h"
33
33
#include "hash0hash.h"
34
34
#include "ut0byte.h"
 
35
#include "page0types.h"
 
36
#ifndef UNIV_HOTBACKUP
35
37
#include "os0proc.h"
36
 
#include "page0types.h"
37
 
 
38
 
/* Modes for buf_page_get_gen */
39
 
#define BUF_GET                 10      /* get always */
40
 
#define BUF_GET_IF_IN_POOL      11      /* get if in pool */
41
 
#define BUF_GET_NO_LATCH        14      /* get and bufferfix, but set no latch;
42
 
                                        we have separated this case, because
43
 
                                        it is error-prone programming not to
44
 
                                        set a latch, and it should be used
45
 
                                        with care */
46
 
/* Modes for buf_page_get_known_nowait */
47
 
#define BUF_MAKE_YOUNG  51
48
 
#define BUF_KEEP_OLD    52
49
 
/* Magic value to use instead of checksums when they are disabled */
50
 
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
51
 
 
52
 
extern buf_pool_t*      buf_pool;       /* The buffer pool of the database */
 
38
 
 
39
/** @name Modes for buf_page_get_gen */
 
40
/* @{ */
 
41
#define BUF_GET                 10      /*!< get always */
 
42
#define BUF_GET_IF_IN_POOL      11      /*!< get if in pool */
 
43
#define BUF_GET_NO_LATCH        14      /*!< get and bufferfix, but
 
44
                                        set no latch; we have
 
45
                                        separated this case, because
 
46
                                        it is error-prone programming
 
47
                                        not to set a latch, and it
 
48
                                        should be used with care */
 
49
/* @} */
 
50
/** @name Modes for buf_page_get_known_nowait */
 
51
/* @{ */
 
52
#define BUF_MAKE_YOUNG  51              /*!< Move the block to the
 
53
                                        start of the LRU list if there
 
54
                                        is a danger that the block
 
55
                                        would drift out of the buffer
 
56
                                        pool*/
 
57
#define BUF_KEEP_OLD    52              /*!< Preserve the current LRU
 
58
                                        position of the block. */
 
59
/* @} */
 
60
 
 
61
extern buf_pool_t*      buf_pool;       /*!< The buffer pool of the database */
53
62
#ifdef UNIV_DEBUG
54
 
extern ibool            buf_debug_prints;/* If this is set TRUE, the program
 
63
extern ibool            buf_debug_prints;/*!< If this is set TRUE, the program
55
64
                                        prints info whenever read or flush
56
65
                                        occurs */
57
66
#endif /* UNIV_DEBUG */
58
 
 
59
 
/* States of a control block (@see buf_page_struct).
 
67
#else /* !UNIV_HOTBACKUP */
 
68
extern buf_block_t*     back_block1;    /*!< first block, for --apply-log */
 
69
extern buf_block_t*     back_block2;    /*!< second block, for page reorganize */
 
70
#endif /* !UNIV_HOTBACKUP */
 
71
 
 
72
/** Magic value to use instead of checksums when they are disabled */
 
73
#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
 
74
 
 
75
/** @brief States of a control block
 
76
@see buf_page_struct
 
77
 
60
78
The enumeration values must be 0..7. */
61
79
enum buf_page_state {
62
 
        BUF_BLOCK_ZIP_FREE = 0,         /* contains a free compressed page */
63
 
        BUF_BLOCK_ZIP_PAGE,             /* contains a clean compressed page */
64
 
        BUF_BLOCK_ZIP_DIRTY,            /* contains a compressed page that is
65
 
                                        in the buf_pool->flush_list */
66
 
 
67
 
        /* The constants for compressed-only pages must precede
68
 
        BUF_BLOCK_NOT_USED; @see buf_block_state_valid() */
69
 
 
70
 
        BUF_BLOCK_NOT_USED,             /* is in the free list */
71
 
        BUF_BLOCK_READY_FOR_USE,        /* when buf_LRU_get_free_block returns
72
 
                                        a block, it is in this state */
73
 
        BUF_BLOCK_FILE_PAGE,            /* contains a buffered file page */
74
 
        BUF_BLOCK_MEMORY,               /* contains some main memory object */
75
 
        BUF_BLOCK_REMOVE_HASH           /* hash index should be removed
 
80
        BUF_BLOCK_ZIP_FREE = 0,         /*!< contains a free
 
81
                                        compressed page */
 
82
        BUF_BLOCK_ZIP_PAGE,             /*!< contains a clean
 
83
                                        compressed page */
 
84
        BUF_BLOCK_ZIP_DIRTY,            /*!< contains a compressed
 
85
                                        page that is in the
 
86
                                        buf_pool->flush_list */
 
87
 
 
88
        BUF_BLOCK_NOT_USED,             /*!< is in the free list;
 
89
                                        must be after the BUF_BLOCK_ZIP_
 
90
                                        constants for compressed-only pages
 
91
                                        @see buf_block_state_valid() */
 
92
        BUF_BLOCK_READY_FOR_USE,        /*!< when buf_LRU_get_free_block
 
93
                                        returns a block, it is in this state */
 
94
        BUF_BLOCK_FILE_PAGE,            /*!< contains a buffered file page */
 
95
        BUF_BLOCK_MEMORY,               /*!< contains some main memory
 
96
                                        object */
 
97
        BUF_BLOCK_REMOVE_HASH           /*!< hash index should be removed
76
98
                                        before putting to the free list */
77
99
};
78
100
 
79
 
/************************************************************************
80
 
Creates the buffer pool. */
 
101
#ifndef UNIV_HOTBACKUP
 
102
/********************************************************************//**
 
103
Creates the buffer pool.
 
104
@return own: buf_pool object, NULL if not enough memory or error */
81
105
UNIV_INTERN
82
106
buf_pool_t*
83
107
buf_pool_init(void);
84
108
/*===============*/
85
 
                                /* out, own: buf_pool object, NULL if not
86
 
                                enough memory or error */
87
 
/************************************************************************
 
109
/********************************************************************//**
88
110
Frees the buffer pool at shutdown.  This must not be invoked before
89
111
freeing all mutexes. */
90
112
UNIV_INTERN
92
114
buf_pool_free(void);
93
115
/*===============*/
94
116
 
95
 
/************************************************************************
 
117
/********************************************************************//**
96
118
Drops the adaptive hash index.  To prevent a livelock, this function
97
119
is only to be called while holding btr_search_latch and while
98
120
btr_search_enabled == FALSE. */
101
123
buf_pool_drop_hash_index(void);
102
124
/*==========================*/
103
125
 
104
 
/************************************************************************
 
126
/********************************************************************//**
105
127
Relocate a buffer control block.  Relocates the block on the LRU list
106
128
and in buf_pool->page_hash.  Does not relocate bpage->list.
107
129
The caller must take care of relocating bpage->list. */
109
131
void
110
132
buf_relocate(
111
133
/*=========*/
112
 
        buf_page_t*     bpage,  /* in/out: control block being relocated;
 
134
        buf_page_t*     bpage,  /*!< in/out: control block being relocated;
113
135
                                buf_page_get_state(bpage) must be
114
136
                                BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */
115
 
        buf_page_t*     dpage)  /* in/out: destination control block */
 
137
        buf_page_t*     dpage)  /*!< in/out: destination control block */
116
138
        __attribute__((nonnull));
117
 
/************************************************************************
 
139
/********************************************************************//**
118
140
Resizes the buffer pool. */
119
141
UNIV_INTERN
120
142
void
121
143
buf_pool_resize(void);
122
144
/*=================*/
123
 
/*************************************************************************
124
 
Gets the current size of buffer buf_pool in bytes. */
 
145
/*********************************************************************//**
 
146
Gets the current size of buffer buf_pool in bytes.
 
147
@return size in bytes */
125
148
UNIV_INLINE
126
149
ulint
127
150
buf_pool_get_curr_size(void);
128
151
/*========================*/
129
 
                        /* out: size in bytes */
130
 
/************************************************************************
 
152
/********************************************************************//**
131
153
Gets the smallest oldest_modification lsn for any page in the pool. Returns
132
 
zero if all modified pages have been flushed to disk. */
 
154
zero if all modified pages have been flushed to disk.
 
155
@return oldest modification in pool, zero if none */
133
156
UNIV_INLINE
134
157
ib_uint64_t
135
158
buf_pool_get_oldest_modification(void);
136
159
/*==================================*/
137
 
                                /* out: oldest modification in pool,
138
 
                                zero if none */
139
 
/************************************************************************
140
 
Allocates a buffer block. */
 
160
/********************************************************************//**
 
161
Allocates a buffer block.
 
162
@return own: the allocated block, in state BUF_BLOCK_MEMORY */
141
163
UNIV_INLINE
142
164
buf_block_t*
143
165
buf_block_alloc(
144
166
/*============*/
145
 
                                /* out, own: the allocated block,
146
 
                                in state BUF_BLOCK_MEMORY */
147
 
        ulint   zip_size);      /* in: compressed page size in bytes,
 
167
        ulint   zip_size);      /*!< in: compressed page size in bytes,
148
168
                                or 0 if uncompressed tablespace */
149
 
/************************************************************************
 
169
/********************************************************************//**
150
170
Frees a buffer block which does not contain a file page. */
151
171
UNIV_INLINE
152
172
void
153
173
buf_block_free(
154
174
/*===========*/
155
 
        buf_block_t*    block); /* in, own: block to be freed */
156
 
/*************************************************************************
157
 
Copies contents of a buffer frame to a given buffer. */
 
175
        buf_block_t*    block); /*!< in, own: block to be freed */
 
176
#endif /* !UNIV_HOTBACKUP */
 
177
/*********************************************************************//**
 
178
Copies contents of a buffer frame to a given buffer.
 
179
@return buf */
158
180
UNIV_INLINE
159
181
byte*
160
182
buf_frame_copy(
161
183
/*===========*/
162
 
                                        /* out: buf */
163
 
        byte*                   buf,    /* in: buffer to copy to */
164
 
        const buf_frame_t*      frame); /* in: buffer frame */
165
 
/******************************************************************
 
184
        byte*                   buf,    /*!< in: buffer to copy to */
 
185
        const buf_frame_t*      frame); /*!< in: buffer frame */
 
186
#ifndef UNIV_HOTBACKUP
 
187
/**************************************************************//**
166
188
NOTE! The following macros should be used instead of buf_page_get_gen,
167
189
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
168
190
in LA! */
169
191
#define buf_page_get(SP, ZS, OF, LA, MTR)        buf_page_get_gen(\
170
192
                                SP, ZS, OF, LA, NULL,\
171
193
                                BUF_GET, __FILE__, __LINE__, MTR)
172
 
/******************************************************************
 
194
/**************************************************************//**
173
195
Use these macros to bufferfix a page with no latching. Remember not to
174
196
read the contents of the page unless you know it is safe. Do not modify
175
197
the contents of the page! We have separated this case, because it is
178
200
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR)        buf_page_get_gen(\
179
201
                                SP, ZS, OF, RW_NO_LATCH, NULL,\
180
202
                                BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
181
 
/******************************************************************
 
203
/**************************************************************//**
182
204
NOTE! The following macros should be used instead of
183
205
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
184
206
RW_X_LATCH are allowed as LA! */
185
207
#define buf_page_optimistic_get(LA, BL, MC, MTR)                             \
186
208
        buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
187
 
/************************************************************************
 
209
/********************************************************************//**
188
210
This is the general function used to get optimistic access to a database
189
 
page. */
 
211
page.
 
212
@return TRUE if success */
190
213
UNIV_INTERN
191
214
ibool
192
215
buf_page_optimistic_get_func(
193
216
/*=========================*/
194
 
                                /* out: TRUE if success */
195
 
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
196
 
        buf_block_t*    block,  /* in: guessed block */
197
 
        ib_uint64_t     modify_clock,/* in: modify clock value if mode is
 
217
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
 
218
        buf_block_t*    block,  /*!< in: guessed block */
 
219
        ib_uint64_t     modify_clock,/*!< in: modify clock value if mode is
198
220
                                ..._GUESS_ON_CLOCK */
199
 
        const char*     file,   /* in: file name */
200
 
        ulint           line,   /* in: line where called */
201
 
        mtr_t*          mtr);   /* in: mini-transaction */
202
 
/************************************************************************
 
221
        const char*     file,   /*!< in: file name */
 
222
        ulint           line,   /*!< in: line where called */
 
223
        mtr_t*          mtr);   /*!< in: mini-transaction */
 
224
/********************************************************************//**
203
225
This is used to get access to a known database page, when no waiting can be
204
 
done. */
 
226
done.
 
227
@return TRUE if success */
205
228
UNIV_INTERN
206
229
ibool
207
230
buf_page_get_known_nowait(
208
231
/*======================*/
209
 
                                /* out: TRUE if success */
210
 
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
211
 
        buf_block_t*    block,  /* in: the known page */
212
 
        ulint           mode,   /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
213
 
        const char*     file,   /* in: file name */
214
 
        ulint           line,   /* in: line where called */
215
 
        mtr_t*          mtr);   /* in: mini-transaction */
 
232
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH */
 
233
        buf_block_t*    block,  /*!< in: the known page */
 
234
        ulint           mode,   /*!< in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
 
235
        const char*     file,   /*!< in: file name */
 
236
        ulint           line,   /*!< in: line where called */
 
237
        mtr_t*          mtr);   /*!< in: mini-transaction */
216
238
 
217
 
/***********************************************************************
 
239
/*******************************************************************//**
218
240
Given a tablespace id and page number tries to get that page. If the
219
241
page is not in the buffer pool it is not loaded and NULL is returned.
220
242
Suitable for using when holding the kernel mutex. */
221
 
 
 
243
UNIV_INTERN
222
244
const buf_block_t*
223
245
buf_page_try_get_func(
224
246
/*==================*/
225
 
        ulint           space_id,/* in: tablespace id */
226
 
        ulint           page_no,/* in: page number */
227
 
        const char*     file,   /* in: file name */
228
 
        ulint           line,   /* in: line where called */
229
 
        mtr_t*          mtr);   /* in: mini-transaction */
 
247
        ulint           space_id,/*!< in: tablespace id */
 
248
        ulint           page_no,/*!< in: page number */
 
249
        const char*     file,   /*!< in: file name */
 
250
        ulint           line,   /*!< in: line where called */
 
251
        mtr_t*          mtr);   /*!< in: mini-transaction */
230
252
 
 
253
/** Tries to get a page. If the page is not in the buffer pool it is
 
254
not loaded.  Suitable for using when holding the kernel mutex.
 
255
@param space_id in: tablespace id
 
256
@param page_no  in: page number
 
257
@param mtr      in: mini-transaction
 
258
@return         the page if in buffer pool, NULL if not */
231
259
#define buf_page_try_get(space_id, page_no, mtr)        \
232
260
        buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
233
261
 
234
 
/************************************************************************
 
262
/********************************************************************//**
235
263
Get read access to a compressed page (usually of type
236
264
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
237
265
The page must be released with buf_page_release_zip().
238
266
NOTE: the page is not protected by any latch.  Mutual exclusion has to
239
267
be implemented at a higher level.  In other words, all possible
240
268
accesses to a given page through this function must be protected by
241
 
the same set of mutexes or latches. */
 
269
the same set of mutexes or latches.
 
270
@return pointer to the block, or NULL if not compressed */
242
271
UNIV_INTERN
243
272
buf_page_t*
244
273
buf_page_get_zip(
245
274
/*=============*/
246
 
                                /* out: pointer to the block,
247
 
                                or NULL if not compressed */
248
 
        ulint           space,  /* in: space id */
249
 
        ulint           zip_size,/* in: compressed page size */
250
 
        ulint           offset);/* in: page number */
251
 
/************************************************************************
252
 
This is the general function used to get access to a database page. */
 
275
        ulint           space,  /*!< in: space id */
 
276
        ulint           zip_size,/*!< in: compressed page size */
 
277
        ulint           offset);/*!< in: page number */
 
278
/********************************************************************//**
 
279
This is the general function used to get access to a database page.
 
280
@return pointer to the block or NULL */
253
281
UNIV_INTERN
254
282
buf_block_t*
255
283
buf_page_get_gen(
256
284
/*=============*/
257
 
                                /* out: pointer to the block or NULL */
258
 
        ulint           space,  /* in: space id */
259
 
        ulint           zip_size,/* in: compressed page size in bytes
 
285
        ulint           space,  /*!< in: space id */
 
286
        ulint           zip_size,/*!< in: compressed page size in bytes
260
287
                                or 0 for uncompressed pages */
261
 
        ulint           offset, /* in: page number */
262
 
        ulint           rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
263
 
        buf_block_t*    guess,  /* in: guessed block or NULL */
264
 
        ulint           mode,   /* in: BUF_GET, BUF_GET_IF_IN_POOL,
 
288
        ulint           offset, /*!< in: page number */
 
289
        ulint           rw_latch,/*!< in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
 
290
        buf_block_t*    guess,  /*!< in: guessed block or NULL */
 
291
        ulint           mode,   /*!< in: BUF_GET, BUF_GET_IF_IN_POOL,
265
292
                                BUF_GET_NO_LATCH */
266
 
        const char*     file,   /* in: file name */
267
 
        ulint           line,   /* in: line where called */
268
 
        mtr_t*          mtr);   /* in: mini-transaction */
269
 
/************************************************************************
 
293
        const char*     file,   /*!< in: file name */
 
294
        ulint           line,   /*!< in: line where called */
 
295
        mtr_t*          mtr);   /*!< in: mini-transaction */
 
296
/********************************************************************//**
270
297
Initializes a page to the buffer buf_pool. The page is usually not read
271
298
from a file even if it cannot be found in the buffer buf_pool. This is one
272
299
of the functions which perform to a block a state transition NOT_USED =>
273
 
FILE_PAGE (the other is buf_page_get_gen). */
 
300
FILE_PAGE (the other is buf_page_get_gen).
 
301
@return pointer to the block, page bufferfixed */
274
302
UNIV_INTERN
275
303
buf_block_t*
276
304
buf_page_create(
277
305
/*============*/
278
 
                        /* out: pointer to the block, page bufferfixed */
279
 
        ulint   space,  /* in: space id */
280
 
        ulint   offset, /* in: offset of the page within space in units of
 
306
        ulint   space,  /*!< in: space id */
 
307
        ulint   offset, /*!< in: offset of the page within space in units of
281
308
                        a page */
282
 
        ulint   zip_size,/* in: compressed page size, or 0 */
283
 
        mtr_t*  mtr);   /* in: mini-transaction handle */
284
 
#ifdef UNIV_HOTBACKUP
285
 
/************************************************************************
 
309
        ulint   zip_size,/*!< in: compressed page size, or 0 */
 
310
        mtr_t*  mtr);   /*!< in: mini-transaction handle */
 
311
#else /* !UNIV_HOTBACKUP */
 
312
/********************************************************************//**
286
313
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
287
314
UNIV_INTERN
288
315
void
289
316
buf_page_init_for_backup_restore(
290
317
/*=============================*/
291
 
        ulint           space,  /* in: space id */
292
 
        ulint           offset, /* in: offset of the page within space
 
318
        ulint           space,  /*!< in: space id */
 
319
        ulint           offset, /*!< in: offset of the page within space
293
320
                                in units of a page */
294
 
        ulint           zip_size,/* in: compressed page size in bytes
 
321
        ulint           zip_size,/*!< in: compressed page size in bytes
295
322
                                or 0 for uncompressed pages */
296
 
        buf_block_t*    block); /* in: block to init */
297
 
#endif /* UNIV_HOTBACKUP */
298
 
/************************************************************************
 
323
        buf_block_t*    block); /*!< in: block to init */
 
324
#endif /* !UNIV_HOTBACKUP */
 
325
 
 
326
#ifndef UNIV_HOTBACKUP
 
327
/********************************************************************//**
299
328
Releases a compressed-only page acquired with buf_page_get_zip(). */
300
329
UNIV_INLINE
301
330
void
302
331
buf_page_release_zip(
303
332
/*=================*/
304
 
        buf_page_t*     bpage);         /* in: buffer block */
305
 
/************************************************************************
 
333
        buf_page_t*     bpage);         /*!< in: buffer block */
 
334
/********************************************************************//**
306
335
Decrements the bufferfix count of a buffer control block and releases
307
336
a latch, if specified. */
308
337
UNIV_INLINE
309
338
void
310
339
buf_page_release(
311
340
/*=============*/
312
 
        buf_block_t*    block,          /* in: buffer block */
313
 
        ulint           rw_latch,       /* in: RW_S_LATCH, RW_X_LATCH,
 
341
        buf_block_t*    block,          /*!< in: buffer block */
 
342
        ulint           rw_latch,       /*!< in: RW_S_LATCH, RW_X_LATCH,
314
343
                                        RW_NO_LATCH */
315
 
        mtr_t*          mtr);           /* in: mtr */
316
 
/************************************************************************
 
344
        mtr_t*          mtr);           /*!< in: mtr */
 
345
/********************************************************************//**
317
346
Moves a page to the start of the buffer pool LRU list. This high-level
318
347
function can be used to prevent an important page from from slipping out of
319
348
the buffer pool. */
321
350
void
322
351
buf_page_make_young(
323
352
/*================*/
324
 
        buf_page_t*     bpage); /* in: buffer block of a file page */
325
 
/************************************************************************
326
 
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
327
 
that it is possible that the page is not yet read from disk, though. */
 
353
        buf_page_t*     bpage); /*!< in: buffer block of a file page */
 
354
/********************************************************************//**
 
355
Returns TRUE if the page can be found in the buffer pool hash table.
 
356
 
 
357
NOTE that it is possible that the page is not yet read from disk,
 
358
though.
 
359
 
 
360
@return TRUE if found in the page hash table */
328
361
UNIV_INLINE
329
362
ibool
330
363
buf_page_peek(
331
364
/*==========*/
332
 
                        /* out: TRUE if found from page hash table,
333
 
                        NOTE that the page is not necessarily yet read
334
 
                        from disk! */
335
 
        ulint   space,  /* in: space id */
336
 
        ulint   offset);/* in: page number */
337
 
/************************************************************************
 
365
        ulint   space,  /*!< in: space id */
 
366
        ulint   offset);/*!< in: page number */
 
367
/********************************************************************//**
338
368
Resets the check_index_page_at_flush field of a page if found in the buffer
339
369
pool. */
340
370
UNIV_INTERN
341
371
void
342
372
buf_reset_check_index_page_at_flush(
343
373
/*================================*/
344
 
        ulint   space,  /* in: space id */
345
 
        ulint   offset);/* in: page number */
 
374
        ulint   space,  /*!< in: space id */
 
375
        ulint   offset);/*!< in: page number */
346
376
#ifdef UNIV_DEBUG_FILE_ACCESSES
347
 
/************************************************************************
 
377
/********************************************************************//**
348
378
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
349
379
This function should be called when we free a file page and want the
350
380
debug version to check that it is not accessed any more unless
351
 
reallocated. */
 
381
reallocated.
 
382
@return control block if found in page hash table, otherwise NULL */
352
383
UNIV_INTERN
353
384
buf_page_t*
354
385
buf_page_set_file_page_was_freed(
355
386
/*=============================*/
356
 
                        /* out: control block if found in page hash table,
357
 
                        otherwise NULL */
358
 
        ulint   space,  /* in: space id */
359
 
        ulint   offset);/* in: page number */
360
 
/************************************************************************
 
387
        ulint   space,  /*!< in: space id */
 
388
        ulint   offset);/*!< in: page number */
 
389
/********************************************************************//**
361
390
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
362
391
This function should be called when we free a file page and want the
363
392
debug version to check that it is not accessed any more unless
364
 
reallocated. */
 
393
reallocated.
 
394
@return control block if found in page hash table, otherwise NULL */
365
395
UNIV_INTERN
366
396
buf_page_t*
367
397
buf_page_reset_file_page_was_freed(
368
398
/*===============================*/
369
 
                        /* out: control block if found in page hash table,
370
 
                        otherwise NULL */
371
 
        ulint   space,  /* in: space id */
372
 
        ulint   offset);        /* in: page number */
 
399
        ulint   space,  /*!< in: space id */
 
400
        ulint   offset);        /*!< in: page number */
373
401
#endif /* UNIV_DEBUG_FILE_ACCESSES */
374
 
/************************************************************************
375
 
Reads the freed_page_clock of a buffer block. */
 
402
/********************************************************************//**
 
403
Reads the freed_page_clock of a buffer block.
 
404
@return freed_page_clock */
376
405
UNIV_INLINE
377
406
ulint
378
407
buf_page_get_freed_page_clock(
379
408
/*==========================*/
380
 
                                        /* out: freed_page_clock */
381
 
        const buf_page_t*       bpage)  /* in: block */
 
409
        const buf_page_t*       bpage)  /*!< in: block */
382
410
        __attribute__((pure));
383
 
/************************************************************************
384
 
Reads the freed_page_clock of a buffer block. */
 
411
/********************************************************************//**
 
412
Reads the freed_page_clock of a buffer block.
 
413
@return freed_page_clock */
385
414
UNIV_INLINE
386
415
ulint
387
416
buf_block_get_freed_page_clock(
388
417
/*===========================*/
389
 
                                        /* out: freed_page_clock */
390
 
        const buf_block_t*      block)  /* in: block */
 
418
        const buf_block_t*      block)  /*!< in: block */
391
419
        __attribute__((pure));
392
420
 
393
 
/************************************************************************
 
421
/********************************************************************//**
394
422
Recommends a move of a block to the start of the LRU list if there is danger
395
423
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
396
 
mutex. */
 
424
mutex.
 
425
@return TRUE if should be made younger */
397
426
UNIV_INLINE
398
427
ibool
399
428
buf_page_peek_if_too_old(
400
429
/*=====================*/
401
 
                                        /* out: TRUE if should be made
402
 
                                        younger */
403
 
        const buf_page_t*       bpage); /* in: block to make younger */
404
 
/************************************************************************
 
430
        const buf_page_t*       bpage); /*!< in: block to make younger */
 
431
/********************************************************************//**
405
432
Returns the current state of is_hashed of a page. FALSE if the page is
406
433
not in the pool. NOTE that this operation does not fix the page in the
407
 
pool if it is found there. */
 
434
pool if it is found there.
 
435
@return TRUE if page hash index is built in search system */
408
436
UNIV_INTERN
409
437
ibool
410
438
buf_page_peek_if_search_hashed(
411
439
/*===========================*/
412
 
                        /* out: TRUE if page hash index is built in search
413
 
                        system */
414
 
        ulint   space,  /* in: space id */
415
 
        ulint   offset);/* in: page number */
416
 
/************************************************************************
 
440
        ulint   space,  /*!< in: space id */
 
441
        ulint   offset);/*!< in: page number */
 
442
/********************************************************************//**
417
443
Gets the youngest modification log sequence number for a frame.
418
 
Returns zero if not file page or no modification occurred yet. */
 
444
Returns zero if not file page or no modification occurred yet.
 
445
@return newest modification to page */
419
446
UNIV_INLINE
420
447
ib_uint64_t
421
448
buf_page_get_newest_modification(
422
449
/*=============================*/
423
 
                                        /* out: newest modification to page */
424
 
        const buf_page_t*       bpage); /* in: block containing the
 
450
        const buf_page_t*       bpage); /*!< in: block containing the
425
451
                                        page frame */
426
 
/************************************************************************
 
452
/********************************************************************//**
427
453
Increments the modify clock of a frame by 1. The caller must (1) own the
428
454
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
429
455
on the block. */
431
457
void
432
458
buf_block_modify_clock_inc(
433
459
/*=======================*/
434
 
        buf_block_t*    block); /* in: block */
435
 
/************************************************************************
 
460
        buf_block_t*    block); /*!< in: block */
 
461
/********************************************************************//**
436
462
Returns the value of the modify clock. The caller must have an s-lock
437
 
or x-lock on the block. */
 
463
or x-lock on the block.
 
464
@return value */
438
465
UNIV_INLINE
439
466
ib_uint64_t
440
467
buf_block_get_modify_clock(
441
468
/*=======================*/
442
 
                                /* out: value */
443
 
        buf_block_t*    block); /* in: block */
444
 
/************************************************************************
 
469
        buf_block_t*    block); /*!< in: block */
 
470
#else /* !UNIV_HOTBACKUP */
 
471
# define buf_block_modify_clock_inc(block) ((void) 0)
 
472
#endif /* !UNIV_HOTBACKUP */
 
473
/********************************************************************//**
445
474
Calculates a page checksum which is stored to the page when it is written
446
475
to a file. Note that we must be careful to calculate the same value
447
 
on 32-bit and 64-bit architectures. */
 
476
on 32-bit and 64-bit architectures.
 
477
@return checksum */
448
478
UNIV_INTERN
449
479
ulint
450
480
buf_calc_page_new_checksum(
451
481
/*=======================*/
452
 
                                /* out: checksum */
453
 
        const byte*     page);  /* in: buffer page */
454
 
/************************************************************************
 
482
        const byte*     page);  /*!< in: buffer page */
 
483
/********************************************************************//**
455
484
In versions < 4.0.14 and < 4.1.1 there was a bug that the checksum only
456
485
looked at the first few bytes of the page. This calculates that old
457
486
checksum.
458
487
NOTE: we must first store the new formula checksum to
459
488
FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
460
 
because this takes that field as an input! */
 
489
because this takes that field as an input!
 
490
@return checksum */
461
491
UNIV_INTERN
462
492
ulint
463
493
buf_calc_page_old_checksum(
464
494
/*=======================*/
465
 
                                /* out: checksum */
466
 
        const byte*      page); /* in: buffer page */
467
 
/************************************************************************
468
 
Checks if a page is corrupt. */
 
495
        const byte*      page); /*!< in: buffer page */
 
496
/********************************************************************//**
 
497
Checks if a page is corrupt.
 
498
@return TRUE if corrupted */
469
499
UNIV_INTERN
470
500
ibool
471
501
buf_page_is_corrupted(
472
502
/*==================*/
473
 
                                        /* out: TRUE if corrupted */
474
 
        const byte*     read_buf,       /* in: a database page */
475
 
        ulint           zip_size);      /* in: size of compressed page;
 
503
        const byte*     read_buf,       /*!< in: a database page */
 
504
        ulint           zip_size);      /*!< in: size of compressed page;
476
505
                                        0 for uncompressed pages */
477
 
/**************************************************************************
 
506
#ifndef UNIV_HOTBACKUP
 
507
/**********************************************************************//**
478
508
Gets the space id, page offset, and byte offset within page of a
479
509
pointer pointing to a buffer frame containing a file page. */
480
510
UNIV_INLINE
481
511
void
482
512
buf_ptr_get_fsp_addr(
483
513
/*=================*/
484
 
        const void*     ptr,    /* in: pointer to a buffer frame */
485
 
        ulint*          space,  /* out: space id */
486
 
        fil_addr_t*     addr);  /* out: page offset and byte offset */
487
 
/**************************************************************************
 
514
        const void*     ptr,    /*!< in: pointer to a buffer frame */
 
515
        ulint*          space,  /*!< out: space id */
 
516
        fil_addr_t*     addr);  /*!< out: page offset and byte offset */
 
517
/**********************************************************************//**
488
518
Gets the hash value of a block. This can be used in searches in the
489
 
lock hash table. */
 
519
lock hash table.
 
520
@return lock hash value */
490
521
UNIV_INLINE
491
522
ulint
492
523
buf_block_get_lock_hash_val(
493
524
/*========================*/
494
 
                                        /* out: lock hash value */
495
 
        const buf_block_t*      block)  /* in: block */
 
525
        const buf_block_t*      block)  /*!< in: block */
496
526
        __attribute__((pure));
497
527
#ifdef UNIV_DEBUG
498
 
/*************************************************************************
 
528
/*********************************************************************//**
499
529
Finds a block in the buffer pool that points to a
500
 
given compressed page. */
 
530
given compressed page.
 
531
@return buffer block pointing to the compressed page, or NULL */
501
532
UNIV_INTERN
502
533
buf_block_t*
503
534
buf_pool_contains_zip(
504
535
/*==================*/
505
 
                                /* out: buffer block pointing to
506
 
                                the compressed page, or NULL */
507
 
        const void*     data);  /* in: pointer to compressed page */
 
536
        const void*     data);  /*!< in: pointer to compressed page */
508
537
#endif /* UNIV_DEBUG */
509
538
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
510
 
/*************************************************************************
511
 
Validates the buffer pool data structure. */
 
539
/*********************************************************************//**
 
540
Validates the buffer pool data structure.
 
541
@return TRUE */
512
542
UNIV_INTERN
513
543
ibool
514
544
buf_validate(void);
515
545
/*==============*/
516
546
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
517
547
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
518
 
/*************************************************************************
 
548
/*********************************************************************//**
519
549
Prints info of the buffer pool data structure. */
520
550
UNIV_INTERN
521
551
void
522
552
buf_print(void);
523
553
/*============*/
524
554
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
525
 
/************************************************************************
 
555
#endif /* !UNIV_HOTBACKUP */
 
556
/********************************************************************//**
526
557
Prints a page to stderr. */
527
558
UNIV_INTERN
528
559
void
529
560
buf_page_print(
530
561
/*===========*/
531
 
        const byte*     read_buf,       /* in: a database page */
532
 
        ulint           zip_size);      /* in: compressed page size, or
 
562
        const byte*     read_buf,       /*!< in: a database page */
 
563
        ulint           zip_size);      /*!< in: compressed page size, or
533
564
                                        0 for uncompressed pages */
 
565
/********************************************************************//**
 
566
Decompress a block.
 
567
@return TRUE if successful */
 
568
UNIV_INTERN
 
569
ibool
 
570
buf_zip_decompress(
 
571
/*===============*/
 
572
        buf_block_t*    block,  /*!< in/out: block */
 
573
        ibool           check); /*!< in: TRUE=verify the page checksum */
 
574
#ifndef UNIV_HOTBACKUP
534
575
#ifdef UNIV_DEBUG
535
 
/*************************************************************************
536
 
Returns the number of latched pages in the buffer pool. */
 
576
/*********************************************************************//**
 
577
Returns the number of latched pages in the buffer pool.
 
578
@return number of latched pages */
537
579
UNIV_INTERN
538
580
ulint
539
581
buf_get_latched_pages_number(void);
540
582
/*==============================*/
541
583
#endif /* UNIV_DEBUG */
542
 
/*************************************************************************
543
 
Returns the number of pending buf pool ios. */
 
584
/*********************************************************************//**
 
585
Returns the number of pending buf pool ios.
 
586
@return number of pending I/O operations */
544
587
UNIV_INTERN
545
588
ulint
546
589
buf_get_n_pending_ios(void);
547
590
/*=======================*/
548
 
/*************************************************************************
 
591
/*********************************************************************//**
549
592
Prints info of the buffer i/o. */
550
593
UNIV_INTERN
551
594
void
552
595
buf_print_io(
553
596
/*=========*/
554
 
        FILE*   file);  /* in: file where to print */
555
 
/*************************************************************************
 
597
        FILE*   file);  /*!< in: file where to print */
 
598
/*********************************************************************//**
556
599
Returns the ratio in percents of modified pages in the buffer pool /
557
 
database pages in the buffer pool. */
 
600
database pages in the buffer pool.
 
601
@return modified page percentage ratio */
558
602
UNIV_INTERN
559
603
ulint
560
604
buf_get_modified_ratio_pct(void);
561
605
/*============================*/
562
 
/**************************************************************************
 
606
/**********************************************************************//**
563
607
Refreshes the statistics used to print per-second averages. */
564
608
UNIV_INTERN
565
609
void
566
610
buf_refresh_io_stats(void);
567
611
/*======================*/
568
 
/*************************************************************************
569
 
Checks that all file pages in the buffer are in a replaceable state. */
 
612
/*********************************************************************//**
 
613
Asserts that all file pages in the buffer are in a replaceable state.
 
614
@return TRUE */
570
615
UNIV_INTERN
571
616
ibool
572
617
buf_all_freed(void);
573
618
/*===============*/
574
 
/*************************************************************************
 
619
/*********************************************************************//**
575
620
Checks that there currently are no pending i/o-operations for the buffer
576
 
pool. */
 
621
pool.
 
622
@return TRUE if there is no pending i/o */
577
623
UNIV_INTERN
578
624
ibool
579
625
buf_pool_check_no_pending_io(void);
580
626
/*==============================*/
581
 
                                /* out: TRUE if there is no pending i/o */
582
 
/*************************************************************************
 
627
/*********************************************************************//**
583
628
Invalidates the file pages in the buffer pool when an archive recovery is
584
629
completed. All the file pages buffered must be in a replaceable state when
585
630
this function is called: not latched and not modified. */
587
632
void
588
633
buf_pool_invalidate(void);
589
634
/*=====================*/
 
635
#endif /* !UNIV_HOTBACKUP */
590
636
 
591
637
/*========================================================================
592
638
--------------------------- LOWER LEVEL ROUTINES -------------------------
593
639
=========================================================================*/
594
640
 
595
641
#ifdef UNIV_SYNC_DEBUG
596
 
/*************************************************************************
 
642
/*********************************************************************//**
597
643
Adds latch level info for the rw-lock protecting the buffer frame. This
598
644
should be called in the debug version after a successful latching of a
599
645
page if we know the latching order level of the acquired latch. */
601
647
void
602
648
buf_block_dbg_add_level(
603
649
/*====================*/
604
 
        buf_block_t*    block,  /* in: buffer page
 
650
        buf_block_t*    block,  /*!< in: buffer page
605
651
                                where we have acquired latch */
606
 
        ulint           level); /* in: latching order level */
 
652
        ulint           level); /*!< in: latching order level */
607
653
#else /* UNIV_SYNC_DEBUG */
608
654
# define buf_block_dbg_add_level(block, level) /* nothing */
609
655
#endif /* UNIV_SYNC_DEBUG */
610
 
/*************************************************************************
611
 
Gets the state of a block. */
 
656
/*********************************************************************//**
 
657
Gets the state of a block.
 
658
@return state */
612
659
UNIV_INLINE
613
660
enum buf_page_state
614
661
buf_page_get_state(
615
662
/*===============*/
616
 
                                        /* out: state */
617
 
        const buf_page_t*       bpage); /* in: pointer to the control block */
618
 
/*************************************************************************
619
 
Gets the state of a block. */
 
663
        const buf_page_t*       bpage); /*!< in: pointer to the control block */
 
664
/*********************************************************************//**
 
665
Gets the state of a block.
 
666
@return state */
620
667
UNIV_INLINE
621
668
enum buf_page_state
622
669
buf_block_get_state(
623
670
/*================*/
624
 
                                        /* out: state */
625
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
671
        const buf_block_t*      block)  /*!< in: pointer to the control block */
626
672
        __attribute__((pure));
627
 
/*************************************************************************
 
673
/*********************************************************************//**
628
674
Sets the state of a block. */
629
675
UNIV_INLINE
630
676
void
631
677
buf_page_set_state(
632
678
/*===============*/
633
 
        buf_page_t*             bpage,  /* in/out: pointer to control block */
634
 
        enum buf_page_state     state); /* in: state */
635
 
/*************************************************************************
 
679
        buf_page_t*             bpage,  /*!< in/out: pointer to control block */
 
680
        enum buf_page_state     state); /*!< in: state */
 
681
/*********************************************************************//**
636
682
Sets the state of a block. */
637
683
UNIV_INLINE
638
684
void
639
685
buf_block_set_state(
640
686
/*================*/
641
 
        buf_block_t*            block,  /* in/out: pointer to control block */
642
 
        enum buf_page_state     state); /* in: state */
643
 
/*************************************************************************
644
 
Determines if a block is mapped to a tablespace. */
 
687
        buf_block_t*            block,  /*!< in/out: pointer to control block */
 
688
        enum buf_page_state     state); /*!< in: state */
 
689
/*********************************************************************//**
 
690
Determines if a block is mapped to a tablespace.
 
691
@return TRUE if mapped */
645
692
UNIV_INLINE
646
693
ibool
647
694
buf_page_in_file(
648
695
/*=============*/
649
 
                                        /* out: TRUE if mapped */
650
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
 
696
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
651
697
        __attribute__((pure));
652
 
/*************************************************************************
653
 
Determines if a block should be on unzip_LRU list. */
 
698
#ifndef UNIV_HOTBACKUP
 
699
/*********************************************************************//**
 
700
Determines if a block should be on unzip_LRU list.
 
701
@return TRUE if block belongs to unzip_LRU */
654
702
UNIV_INLINE
655
703
ibool
656
704
buf_page_belongs_to_unzip_LRU(
657
705
/*==========================*/
658
 
                                        /* out: TRUE if block belongs
659
 
                                        to unzip_LRU */
660
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
 
706
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
661
707
        __attribute__((pure));
662
 
/*************************************************************************
663
 
Determine the approximate LRU list position of a block. */
 
708
/*********************************************************************//**
 
709
Determine the approximate LRU list position of a block.
 
710
@return LRU list position */
664
711
UNIV_INLINE
665
712
ulint
666
713
buf_page_get_LRU_position(
667
714
/*======================*/
668
 
                                        /* out: LRU list position */
669
 
        const buf_page_t*       bpage)  /* in: control block */
 
715
        const buf_page_t*       bpage)  /*!< in: control block */
670
716
        __attribute__((pure));
671
717
 
672
 
/*************************************************************************
673
 
Gets the mutex of a block. */
 
718
/*********************************************************************//**
 
719
Gets the mutex of a block.
 
720
@return pointer to mutex protecting bpage */
674
721
UNIV_INLINE
675
722
mutex_t*
676
723
buf_page_get_mutex(
677
724
/*===============*/
678
 
                                        /* out: pointer to mutex
679
 
                                        protecting bpage */
680
 
        const buf_page_t*       bpage)  /* in: pointer to control block */
 
725
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
681
726
        __attribute__((pure));
682
727
 
683
 
/*************************************************************************
684
 
Get the flush type of a page. */
 
728
/*********************************************************************//**
 
729
Get the flush type of a page.
 
730
@return flush type */
685
731
UNIV_INLINE
686
732
enum buf_flush
687
733
buf_page_get_flush_type(
688
734
/*====================*/
689
 
                                        /* out: flush type */
690
 
        const buf_page_t*       bpage)  /* in: buffer page */
 
735
        const buf_page_t*       bpage)  /*!< in: buffer page */
691
736
        __attribute__((pure));
692
 
/*************************************************************************
 
737
/*********************************************************************//**
693
738
Set the flush type of a page. */
694
739
UNIV_INLINE
695
740
void
696
741
buf_page_set_flush_type(
697
742
/*====================*/
698
 
        buf_page_t*     bpage,          /* in: buffer page */
699
 
        enum buf_flush  flush_type);    /* in: flush type */
700
 
/*************************************************************************
 
743
        buf_page_t*     bpage,          /*!< in: buffer page */
 
744
        enum buf_flush  flush_type);    /*!< in: flush type */
 
745
/*********************************************************************//**
701
746
Map a block to a file page. */
702
747
UNIV_INLINE
703
748
void
704
749
buf_block_set_file_page(
705
750
/*====================*/
706
 
        buf_block_t*            block,  /* in/out: pointer to control block */
707
 
        ulint                   space,  /* in: tablespace id */
708
 
        ulint                   page_no);/* in: page number */
709
 
/*************************************************************************
710
 
Gets the io_fix state of a block. */
 
751
        buf_block_t*            block,  /*!< in/out: pointer to control block */
 
752
        ulint                   space,  /*!< in: tablespace id */
 
753
        ulint                   page_no);/*!< in: page number */
 
754
/*********************************************************************//**
 
755
Gets the io_fix state of a block.
 
756
@return io_fix state */
711
757
UNIV_INLINE
712
758
enum buf_io_fix
713
759
buf_page_get_io_fix(
714
760
/*================*/
715
 
                                        /* out: io_fix state */
716
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
 
761
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
717
762
        __attribute__((pure));
718
 
/*************************************************************************
719
 
Gets the io_fix state of a block. */
 
763
/*********************************************************************//**
 
764
Gets the io_fix state of a block.
 
765
@return io_fix state */
720
766
UNIV_INLINE
721
767
enum buf_io_fix
722
768
buf_block_get_io_fix(
723
769
/*================*/
724
 
                                        /* out: io_fix state */
725
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
770
        const buf_block_t*      block)  /*!< in: pointer to the control block */
726
771
        __attribute__((pure));
727
 
/*************************************************************************
 
772
/*********************************************************************//**
728
773
Sets the io_fix state of a block. */
729
774
UNIV_INLINE
730
775
void
731
776
buf_page_set_io_fix(
732
777
/*================*/
733
 
        buf_page_t*     bpage,  /* in/out: control block */
734
 
        enum buf_io_fix io_fix);/* in: io_fix state */
735
 
/*************************************************************************
 
778
        buf_page_t*     bpage,  /*!< in/out: control block */
 
779
        enum buf_io_fix io_fix);/*!< in: io_fix state */
 
780
/*********************************************************************//**
736
781
Sets the io_fix state of a block. */
737
782
UNIV_INLINE
738
783
void
739
784
buf_block_set_io_fix(
740
785
/*=================*/
741
 
        buf_block_t*    block,  /* in/out: control block */
742
 
        enum buf_io_fix io_fix);/* in: io_fix state */
 
786
        buf_block_t*    block,  /*!< in/out: control block */
 
787
        enum buf_io_fix io_fix);/*!< in: io_fix state */
743
788
 
744
 
/************************************************************************
 
789
/********************************************************************//**
745
790
Determine if a buffer block can be relocated in memory.  The block
746
791
can be dirty, but it must not be I/O-fixed or bufferfixed. */
747
792
UNIV_INLINE
748
793
ibool
749
794
buf_page_can_relocate(
750
795
/*==================*/
751
 
        const buf_page_t*       bpage)  /* control block being relocated */
 
796
        const buf_page_t*       bpage)  /*!< control block being relocated */
752
797
        __attribute__((pure));
753
798
 
754
 
/*************************************************************************
755
 
Determine if a block has been flagged old. */
 
799
/*********************************************************************//**
 
800
Determine if a block has been flagged old.
 
801
@return TRUE if old */
756
802
UNIV_INLINE
757
803
ibool
758
804
buf_page_is_old(
759
805
/*============*/
760
 
                                        /* out: TRUE if old */
761
 
        const buf_page_t*       bpage)  /* in: control block */
 
806
        const buf_page_t*       bpage)  /*!< in: control block */
762
807
        __attribute__((pure));
763
 
/*************************************************************************
 
808
/*********************************************************************//**
764
809
Flag a block old. */
765
810
UNIV_INLINE
766
811
void
767
812
buf_page_set_old(
768
813
/*=============*/
769
 
        buf_page_t*     bpage,  /* in/out: control block */
770
 
        ibool           old);   /* in: old */
771
 
/*************************************************************************
772
 
Determine if a block has been accessed in the buffer pool. */
 
814
        buf_page_t*     bpage,  /*!< in/out: control block */
 
815
        ibool           old);   /*!< in: old */
 
816
/*********************************************************************//**
 
817
Determine if a block has been accessed in the buffer pool.
 
818
@return TRUE if accessed */
773
819
UNIV_INLINE
774
820
ibool
775
821
buf_page_is_accessed(
776
822
/*=================*/
777
 
                                        /* out: TRUE if accessed */
778
 
        const buf_page_t*       bpage)  /* in: control block */
 
823
        const buf_page_t*       bpage)  /*!< in: control block */
779
824
        __attribute__((pure));
780
 
/*************************************************************************
 
825
/*********************************************************************//**
781
826
Flag a block accessed. */
782
827
UNIV_INLINE
783
828
void
784
829
buf_page_set_accessed(
785
830
/*==================*/
786
 
        buf_page_t*     bpage,          /* in/out: control block */
787
 
        ibool           accessed);      /* in: accessed */
788
 
/*************************************************************************
 
831
        buf_page_t*     bpage,          /*!< in/out: control block */
 
832
        ibool           accessed);      /*!< in: accessed */
 
833
/*********************************************************************//**
789
834
Gets the buf_block_t handle of a buffered file block if an uncompressed
790
 
page frame exists, or NULL. */
 
835
page frame exists, or NULL.
 
836
@return control block, or NULL */
791
837
UNIV_INLINE
792
838
buf_block_t*
793
839
buf_page_get_block(
794
840
/*===============*/
795
 
                                /* out: control block, or NULL */
796
 
        buf_page_t*     bpage)  /* in: control block, or NULL */
 
841
        buf_page_t*     bpage)  /*!< in: control block, or NULL */
797
842
        __attribute__((pure));
 
843
#endif /* !UNIV_HOTBACKUP */
798
844
#ifdef UNIV_DEBUG
799
 
/*************************************************************************
800
 
Gets a pointer to the memory frame of a block. */
 
845
/*********************************************************************//**
 
846
Gets a pointer to the memory frame of a block.
 
847
@return pointer to the frame */
801
848
UNIV_INLINE
802
849
buf_frame_t*
803
850
buf_block_get_frame(
804
851
/*================*/
805
 
                                        /* out: pointer to the frame */
806
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
852
        const buf_block_t*      block)  /*!< in: pointer to the control block */
807
853
        __attribute__((pure));
808
854
#else /* UNIV_DEBUG */
809
855
# define buf_block_get_frame(block) (block)->frame
810
856
#endif /* UNIV_DEBUG */
811
 
/*************************************************************************
812
 
Gets the space id of a block. */
 
857
/*********************************************************************//**
 
858
Gets the space id of a block.
 
859
@return space id */
813
860
UNIV_INLINE
814
861
ulint
815
862
buf_page_get_space(
816
863
/*===============*/
817
 
                                        /* out: space id */
818
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
 
864
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
819
865
        __attribute__((pure));
820
 
/*************************************************************************
821
 
Gets the space id of a block. */
 
866
/*********************************************************************//**
 
867
Gets the space id of a block.
 
868
@return space id */
822
869
UNIV_INLINE
823
870
ulint
824
871
buf_block_get_space(
825
872
/*================*/
826
 
                                        /* out: space id */
827
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
873
        const buf_block_t*      block)  /*!< in: pointer to the control block */
828
874
        __attribute__((pure));
829
 
/*************************************************************************
830
 
Gets the page number of a block. */
 
875
/*********************************************************************//**
 
876
Gets the page number of a block.
 
877
@return page number */
831
878
UNIV_INLINE
832
879
ulint
833
880
buf_page_get_page_no(
834
881
/*=================*/
835
 
                                        /* out: page number */
836
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
 
882
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
837
883
        __attribute__((pure));
838
 
/*************************************************************************
839
 
Gets the page number of a block. */
 
884
/*********************************************************************//**
 
885
Gets the page number of a block.
 
886
@return page number */
840
887
UNIV_INLINE
841
888
ulint
842
889
buf_block_get_page_no(
843
890
/*==================*/
844
 
                                        /* out: page number */
845
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
891
        const buf_block_t*      block)  /*!< in: pointer to the control block */
846
892
        __attribute__((pure));
847
 
/*************************************************************************
848
 
Gets the compressed page size of a block. */
 
893
/*********************************************************************//**
 
894
Gets the compressed page size of a block.
 
895
@return compressed page size, or 0 */
849
896
UNIV_INLINE
850
897
ulint
851
898
buf_page_get_zip_size(
852
899
/*==================*/
853
 
                                        /* out: compressed page size, or 0 */
854
 
        const buf_page_t*       bpage)  /* in: pointer to the control block */
 
900
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
855
901
        __attribute__((pure));
856
 
/*************************************************************************
857
 
Gets the compressed page size of a block. */
 
902
/*********************************************************************//**
 
903
Gets the compressed page size of a block.
 
904
@return compressed page size, or 0 */
858
905
UNIV_INLINE
859
906
ulint
860
907
buf_block_get_zip_size(
861
908
/*===================*/
862
 
                                        /* out: compressed page size, or 0 */
863
 
        const buf_block_t*      block)  /* in: pointer to the control block */
 
909
        const buf_block_t*      block)  /*!< in: pointer to the control block */
864
910
        __attribute__((pure));
865
 
/*************************************************************************
 
911
/*********************************************************************//**
866
912
Gets the compressed page descriptor corresponding to an uncompressed page
867
913
if applicable. */
868
914
#define buf_block_get_page_zip(block) \
869
915
        (UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
870
 
/***********************************************************************
871
 
Gets the block to whose frame the pointer is pointing to. */
 
916
#ifndef UNIV_HOTBACKUP
 
917
/*******************************************************************//**
 
918
Gets the block to whose frame the pointer is pointing to.
 
919
@return pointer to block, never NULL */
872
920
UNIV_INTERN
873
921
buf_block_t*
874
922
buf_block_align(
875
923
/*============*/
876
 
                                /* out: pointer to block, never NULL */
877
 
        const byte*     ptr);   /* in: pointer to a frame */
 
924
        const byte*     ptr);   /*!< in: pointer to a frame */
 
925
/********************************************************************//**
 
926
Find out if a pointer belongs to a buf_block_t. It can be a pointer to
 
927
the buf_block_t itself or a member of it
 
928
@return TRUE if ptr belongs to a buf_block_t struct */
 
929
UNIV_INTERN
 
930
ibool
 
931
buf_pointer_is_block_field(
 
932
/*=======================*/
 
933
        const void*             ptr);   /*!< in: pointer not
 
934
                                        dereferenced */
 
935
/** Find out if a pointer corresponds to a buf_block_t::mutex.
 
936
@param m        in: mutex candidate
 
937
@return         TRUE if m is a buf_block_t::mutex */
 
938
#define buf_pool_is_block_mutex(m)                      \
 
939
        buf_pointer_is_block_field((const void*)(m))
 
940
/** Find out if a pointer corresponds to a buf_block_t::lock.
 
941
@param l        in: rw-lock candidate
 
942
@return         TRUE if l is a buf_block_t::lock */
 
943
#define buf_pool_is_block_lock(l)                       \
 
944
        buf_pointer_is_block_field((const void*)(l))
 
945
 
878
946
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
879
 
/*************************************************************************
 
947
/*********************************************************************//**
880
948
Gets the compressed page descriptor corresponding to an uncompressed page
881
 
if applicable. */
 
949
if applicable.
 
950
@return compressed page descriptor, or NULL */
882
951
UNIV_INLINE
883
952
const page_zip_des_t*
884
953
buf_frame_get_page_zip(
885
954
/*===================*/
886
 
                                /* out: compressed page descriptor, or NULL */
887
 
        const byte*     ptr);   /* in: pointer to the page */
 
955
        const byte*     ptr);   /*!< in: pointer to the page */
888
956
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
889
 
/************************************************************************
890
 
This function is used to get info if there is an io operation
891
 
going on on a buffer page. */
892
 
UNIV_INLINE
893
 
ibool
894
 
buf_page_io_query(
895
 
/*==============*/
896
 
                                /* out: TRUE if io going on */
897
 
        buf_page_t*     bpage); /* in: pool block, must be bufferfixed */
898
 
/************************************************************************
 
957
/********************************************************************//**
899
958
Function which inits a page for read to the buffer buf_pool. If the page is
900
959
(1) already in buf_pool, or
901
960
(2) if we specify to read only ibuf pages and the page is not an ibuf page, or
903
962
then this function does nothing.
904
963
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
905
964
on the buffer frame. The io-handler must take care that the flag is cleared
906
 
and the lock released later. */
 
965
and the lock released later.
 
966
@return pointer to the block or NULL */
907
967
UNIV_INTERN
908
968
buf_page_t*
909
969
buf_page_init_for_read(
910
970
/*===================*/
911
 
                                /* out: pointer to the block or NULL */
912
 
        ulint*          err,    /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
913
 
        ulint           mode,   /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
914
 
        ulint           space,  /* in: space id */
915
 
        ulint           zip_size,/* in: compressed page size, or 0 */
916
 
        ibool           unzip,  /* in: TRUE=request uncompressed page */
917
 
        ib_int64_t      tablespace_version,/* in: prevents reading from a wrong
 
971
        ulint*          err,    /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED */
 
972
        ulint           mode,   /*!< in: BUF_READ_IBUF_PAGES_ONLY, ... */
 
973
        ulint           space,  /*!< in: space id */
 
974
        ulint           zip_size,/*!< in: compressed page size, or 0 */
 
975
        ibool           unzip,  /*!< in: TRUE=request uncompressed page */
 
976
        ib_int64_t      tablespace_version,/*!< in: prevents reading from a wrong
918
977
                                version of the tablespace in case we have done
919
978
                                DISCARD + IMPORT */
920
 
        ulint           offset);/* in: page number */
921
 
/************************************************************************
 
979
        ulint           offset);/*!< in: page number */
 
980
/********************************************************************//**
922
981
Completes an asynchronous read or write request of a file page to or from
923
982
the buffer pool. */
924
983
UNIV_INTERN
925
984
void
926
985
buf_page_io_complete(
927
986
/*=================*/
928
 
        buf_page_t*     bpage); /* in: pointer to the block in question */
929
 
/************************************************************************
 
987
        buf_page_t*     bpage); /*!< in: pointer to the block in question */
 
988
/********************************************************************//**
930
989
Calculates a folded value of a file page address to use in the page hash
931
 
table. */
 
990
table.
 
991
@return the folded value */
932
992
UNIV_INLINE
933
993
ulint
934
994
buf_page_address_fold(
935
995
/*==================*/
936
 
                        /* out: the folded value */
937
 
        ulint   space,  /* in: space id */
938
 
        ulint   offset) /* in: offset of the page within space */
939
 
        __attribute__((__const__));
940
 
/**********************************************************************
941
 
Returns the control block of a file page, NULL if not found. */
 
996
        ulint   space,  /*!< in: space id */
 
997
        ulint   offset) /*!< in: offset of the page within space */
 
998
        __attribute__((const));
 
999
/******************************************************************//**
 
1000
Returns the control block of a file page, NULL if not found.
 
1001
@return block, NULL if not found */
942
1002
UNIV_INLINE
943
1003
buf_page_t*
944
1004
buf_page_hash_get(
945
1005
/*==============*/
946
 
                        /* out: block, NULL if not found */
947
 
        ulint   space,  /* in: space id */
948
 
        ulint   offset);/* in: offset of the page within space */
949
 
/**********************************************************************
 
1006
        ulint   space,  /*!< in: space id */
 
1007
        ulint   offset);/*!< in: offset of the page within space */
 
1008
/******************************************************************//**
950
1009
Returns the control block of a file page, NULL if not found
951
 
or an uncompressed page frame does not exist. */
 
1010
or an uncompressed page frame does not exist.
 
1011
@return block, NULL if not found */
952
1012
UNIV_INLINE
953
1013
buf_block_t*
954
1014
buf_block_hash_get(
955
1015
/*===============*/
956
 
                        /* out: block, NULL if not found */
957
 
        ulint   space,  /* in: space id */
958
 
        ulint   offset);/* in: offset of the page within space */
959
 
/***********************************************************************
 
1016
        ulint   space,  /*!< in: space id */
 
1017
        ulint   offset);/*!< in: offset of the page within space */
 
1018
/*******************************************************************//**
960
1019
Increments the pool clock by one and returns its new value. Remember that
961
 
in the 32 bit version the clock wraps around at 4 billion! */
 
1020
in the 32 bit version the clock wraps around at 4 billion!
 
1021
@return new clock value */
962
1022
UNIV_INLINE
963
1023
ulint
964
1024
buf_pool_clock_tic(void);
965
1025
/*====================*/
966
 
                        /* out: new clock value */
967
 
/*************************************************************************
968
 
Gets the current length of the free list of buffer blocks. */
 
1026
/*********************************************************************//**
 
1027
Gets the current length of the free list of buffer blocks.
 
1028
@return length of the free list */
969
1029
UNIV_INTERN
970
1030
ulint
971
1031
buf_get_free_list_len(void);
972
1032
/*=======================*/
973
 
 
974
 
 
975
 
 
976
 
/* The common buffer control block structure
 
1033
#endif /* !UNIV_HOTBACKUP */
 
1034
 
 
1035
 
 
1036
/** The common buffer control block structure
977
1037
for compressed and uncompressed frames */
978
1038
 
979
1039
struct buf_page_struct{
980
 
        /* None of the following bit-fields must be modified without
981
 
        holding buf_page_get_mutex() [block->mutex or buf_pool_zip_mutex],
982
 
        since they can be stored in the same machine word.  Some of them are
983
 
        additionally protected by buf_pool_mutex. */
984
 
 
985
 
        unsigned        space:32;       /* tablespace id; also protected
986
 
                                        by buf_pool_mutex. */
987
 
        unsigned        offset:32;      /* page number; also protected
988
 
                                        by buf_pool_mutex. */
989
 
 
990
 
        unsigned        state:3;        /* state of the control block
991
 
                                        (@see enum buf_page_state); also
 
1040
        /** @name General fields
 
1041
        None of these bit-fields must be modified without holding
 
1042
        buf_page_get_mutex() [buf_block_struct::mutex or
 
1043
        buf_pool_zip_mutex], since they can be stored in the same
 
1044
        machine word.  Some of these fields are additionally protected
 
1045
        by buf_pool_mutex. */
 
1046
        /* @{ */
 
1047
 
 
1048
        unsigned        space:32;       /*!< tablespace id; also protected
 
1049
                                        by buf_pool_mutex. */
 
1050
        unsigned        offset:32;      /*!< page number; also protected
 
1051
                                        by buf_pool_mutex. */
 
1052
 
 
1053
        unsigned        state:3;        /*!< state of the control block; also
992
1054
                                        protected by buf_pool_mutex.
993
1055
                                        State transitions from
994
1056
                                        BUF_BLOCK_READY_FOR_USE to
995
1057
                                        BUF_BLOCK_MEMORY need not be
996
 
                                        protected by buf_page_get_mutex(). */
997
 
        unsigned        flush_type:2;   /* if this block is currently being
 
1058
                                        protected by buf_page_get_mutex().
 
1059
                                        @see enum buf_page_state */
 
1060
#ifndef UNIV_HOTBACKUP
 
1061
        unsigned        flush_type:2;   /*!< if this block is currently being
998
1062
                                        flushed to disk, this tells the
999
 
                                        flush_type (@see enum buf_flush) */
1000
 
        unsigned        accessed:1;     /* TRUE if the page has been accessed
 
1063
                                        flush_type.
 
1064
                                        @see enum buf_flush */
 
1065
        unsigned        accessed:1;     /*!< TRUE if the page has been accessed
1001
1066
                                        while in the buffer pool: read-ahead
1002
1067
                                        may read in pages which have not been
1003
1068
                                        accessed yet; a thread is allowed to
1004
1069
                                        read this for heuristic purposes
1005
1070
                                        without holding any mutex or latch */
1006
 
        unsigned        io_fix:2;       /* type of pending I/O operation
1007
 
                                        (@see enum buf_io_fix); also
1008
 
                                        protected by buf_pool_mutex */
1009
 
        unsigned        buf_fix_count:24;/* count of how manyfold this block
 
1071
        unsigned        io_fix:2;       /*!< type of pending I/O operation;
 
1072
                                        also protected by buf_pool_mutex
 
1073
                                        @see enum buf_io_fix */
 
1074
        unsigned        buf_fix_count:24;/*!< count of how manyfold this block
1010
1075
                                        is currently bufferfixed */
1011
 
 
1012
 
        page_zip_des_t  zip;            /* compressed page; zip.data
 
1076
        /* @} */
 
1077
#endif /* !UNIV_HOTBACKUP */
 
1078
        page_zip_des_t  zip;            /*!< compressed page; zip.data
1013
1079
                                        (but not the data it points to) is
1014
1080
                                        also protected by buf_pool_mutex */
1015
 
        buf_page_t*     hash;           /* node used in chaining to
 
1081
#ifndef UNIV_HOTBACKUP
 
1082
        buf_page_t*     hash;           /*!< node used in chaining to
1016
1083
                                        buf_pool->page_hash or
1017
1084
                                        buf_pool->zip_hash */
1018
1085
#ifdef UNIV_DEBUG
1019
 
        ibool           in_page_hash;   /* TRUE if in buf_pool->page_hash */
1020
 
        ibool           in_zip_hash;    /* TRUE if in buf_pool->zip_hash */
 
1086
        ibool           in_page_hash;   /*!< TRUE if in buf_pool->page_hash */
 
1087
        ibool           in_zip_hash;    /*!< TRUE if in buf_pool->zip_hash */
1021
1088
#endif /* UNIV_DEBUG */
1022
1089
 
1023
 
        /* 2. Page flushing fields; protected by buf_pool_mutex */
 
1090
        /** @name Page flushing fields
 
1091
        All these are protected by buf_pool_mutex. */
 
1092
        /* @{ */
1024
1093
 
1025
1094
        UT_LIST_NODE_T(buf_page_t) list;
1026
 
                                        /* based on state, this is a list
1027
 
                                        node in one of the following lists
1028
 
                                        in buf_pool:
 
1095
                                        /*!< based on state, this is a
 
1096
                                        list node, protected only by
 
1097
                                        buf_pool_mutex, in one of the
 
1098
                                        following lists in buf_pool:
1029
1099
 
1030
 
                                        BUF_BLOCK_NOT_USED:     free
1031
 
                                        BUF_BLOCK_FILE_PAGE:    flush_list
1032
 
                                        BUF_BLOCK_ZIP_DIRTY:    flush_list
1033
 
                                        BUF_BLOCK_ZIP_PAGE:     zip_clean
1034
 
                                        BUF_BLOCK_ZIP_FREE:     zip_free[] */
 
1100
                                        - BUF_BLOCK_NOT_USED:   free
 
1101
                                        - BUF_BLOCK_FILE_PAGE:  flush_list
 
1102
                                        - BUF_BLOCK_ZIP_DIRTY:  flush_list
 
1103
                                        - BUF_BLOCK_ZIP_PAGE:   zip_clean
 
1104
                                        - BUF_BLOCK_ZIP_FREE:   zip_free[] */
1035
1105
#ifdef UNIV_DEBUG
1036
 
        ibool           in_flush_list;  /* TRUE if in buf_pool->flush_list;
 
1106
        ibool           in_flush_list;  /*!< TRUE if in buf_pool->flush_list;
1037
1107
                                        when buf_pool_mutex is free, the
1038
1108
                                        following should hold: in_flush_list
1039
1109
                                        == (state == BUF_BLOCK_FILE_PAGE
1040
1110
                                            || state == BUF_BLOCK_ZIP_DIRTY) */
1041
 
        ibool           in_free_list;   /* TRUE if in buf_pool->free; when
 
1111
        ibool           in_free_list;   /*!< TRUE if in buf_pool->free; when
1042
1112
                                        buf_pool_mutex is free, the following
1043
1113
                                        should hold: in_free_list
1044
1114
                                        == (state == BUF_BLOCK_NOT_USED) */
1045
1115
#endif /* UNIV_DEBUG */
1046
1116
        ib_uint64_t     newest_modification;
1047
 
                                        /* log sequence number of the youngest
1048
 
                                        modification to this block, zero if
1049
 
                                        not modified */
 
1117
                                        /*!< log sequence number of
 
1118
                                        the youngest modification to
 
1119
                                        this block, zero if not
 
1120
                                        modified */
1050
1121
        ib_uint64_t     oldest_modification;
1051
 
                                        /* log sequence number of the START of
1052
 
                                        the log entry written of the oldest
1053
 
                                        modification to this block which has
1054
 
                                        not yet been flushed on disk; zero if
1055
 
                                        all modifications are on disk */
1056
 
 
1057
 
        /* 3. LRU replacement algorithm fields; protected by
1058
 
        buf_pool_mutex only (not buf_pool_zip_mutex or block->mutex) */
 
1122
                                        /*!< log sequence number of
 
1123
                                        the START of the log entry
 
1124
                                        written of the oldest
 
1125
                                        modification to this block
 
1126
                                        which has not yet been flushed
 
1127
                                        on disk; zero if all
 
1128
                                        modifications are on disk */
 
1129
        /* @} */
 
1130
        /** @name LRU replacement algorithm fields
 
1131
        These fields are protected by buf_pool_mutex only (not
 
1132
        buf_pool_zip_mutex or buf_block_struct::mutex). */
 
1133
        /* @{ */
1059
1134
 
1060
1135
        UT_LIST_NODE_T(buf_page_t) LRU;
1061
 
                                        /* node of the LRU list */
 
1136
                                        /*!< node of the LRU list */
1062
1137
#ifdef UNIV_DEBUG
1063
 
        ibool           in_LRU_list;    /* TRUE if the page is in the LRU list;
1064
 
                                        used in debugging */
 
1138
        ibool           in_LRU_list;    /*!< TRUE if the page is in
 
1139
                                        the LRU list; used in
 
1140
                                        debugging */
1065
1141
#endif /* UNIV_DEBUG */
1066
 
        unsigned        old:1;          /* TRUE if the block is in the old
 
1142
        unsigned        old:1;          /*!< TRUE if the block is in the old
1067
1143
                                        blocks in the LRU list */
1068
 
        unsigned        LRU_position:31;/* value which monotonically decreases
1069
 
                                        (or may stay constant if old==TRUE)
1070
 
                                        toward the end of the LRU list, if
1071
 
                                        buf_pool->ulint_clock has not wrapped
1072
 
                                        around: NOTE that this value can only
1073
 
                                        be used in heuristic algorithms,
1074
 
                                        because of the possibility of a
 
1144
        unsigned        LRU_position:31;/*!< value which monotonically
 
1145
                                        decreases (or may stay
 
1146
                                        constant if old==TRUE) toward
 
1147
                                        the end of the LRU list, if
 
1148
                                        buf_pool->ulint_clock has not
 
1149
                                        wrapped around: NOTE that this
 
1150
                                        value can only be used in
 
1151
                                        heuristic algorithms, because
 
1152
                                        of the possibility of a
1075
1153
                                        wrap-around! */
1076
 
        unsigned        freed_page_clock:32;/* the value of
1077
 
                                        buf_pool->freed_page_clock when this
1078
 
                                        block was the last time put to the
1079
 
                                        head of the LRU list; a thread is
1080
 
                                        allowed to read this for heuristic
1081
 
                                        purposes without holding any mutex or
1082
 
                                        latch */
1083
 
#ifdef UNIV_DEBUG_FILE_ACCESSES
 
1154
        unsigned        freed_page_clock:32;/*!< the value of
 
1155
                                        buf_pool->freed_page_clock
 
1156
                                        when this block was the last
 
1157
                                        time put to the head of the
 
1158
                                        LRU list; a thread is allowed
 
1159
                                        to read this for heuristic
 
1160
                                        purposes without holding any
 
1161
                                        mutex or latch */
 
1162
        /* @} */
 
1163
# ifdef UNIV_DEBUG_FILE_ACCESSES
1084
1164
        ibool           file_page_was_freed;
1085
 
                                        /* this is set to TRUE when fsp
 
1165
                                        /*!< this is set to TRUE when fsp
1086
1166
                                        frees a page in buffer pool */
1087
 
#endif /* UNIV_DEBUG_FILE_ACCESSES */
 
1167
# endif /* UNIV_DEBUG_FILE_ACCESSES */
 
1168
#endif /* !UNIV_HOTBACKUP */
1088
1169
};
1089
1170
 
1090
 
/* The buffer control block structure */
 
1171
/** The buffer control block structure */
1091
1172
 
1092
1173
struct buf_block_struct{
1093
1174
 
1094
 
        /* 1. General fields */
 
1175
        /** @name General fields */
 
1176
        /* @{ */
1095
1177
 
1096
 
        buf_page_t      page;           /* page information; this must
 
1178
        buf_page_t      page;           /*!< page information; this must
1097
1179
                                        be the first field, so that
1098
1180
                                        buf_pool->page_hash can point
1099
1181
                                        to buf_page_t or buf_block_t */
 
1182
        byte*           frame;          /*!< pointer to buffer frame which
 
1183
                                        is of size UNIV_PAGE_SIZE, and
 
1184
                                        aligned to an address divisible by
 
1185
                                        UNIV_PAGE_SIZE */
 
1186
#ifndef UNIV_HOTBACKUP
1100
1187
        UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1101
 
                                        /* node of the decompressed LRU list;
 
1188
                                        /*!< node of the decompressed LRU list;
1102
1189
                                        a block is in the unzip_LRU list
1103
1190
                                        if page.state == BUF_BLOCK_FILE_PAGE
1104
1191
                                        and page.zip.data != NULL */
1105
1192
#ifdef UNIV_DEBUG
1106
 
        ibool           in_unzip_LRU_list;/* TRUE if the page is in the
 
1193
        ibool           in_unzip_LRU_list;/*!< TRUE if the page is in the
1107
1194
                                        decompressed LRU list;
1108
1195
                                        used in debugging */
1109
1196
#endif /* UNIV_DEBUG */
1110
 
        byte*           frame;          /* pointer to buffer frame which
1111
 
                                        is of size UNIV_PAGE_SIZE, and
1112
 
                                        aligned to an address divisible by
1113
 
                                        UNIV_PAGE_SIZE */
1114
 
        mutex_t         mutex;          /* mutex protecting this block:
 
1197
        mutex_t         mutex;          /*!< mutex protecting this block:
1115
1198
                                        state (also protected by the buffer
1116
1199
                                        pool mutex), io_fix, buf_fix_count,
1117
1200
                                        and accessed; we introduce this new
1118
1201
                                        mutex in InnoDB-5.1 to relieve
1119
1202
                                        contention on the buffer pool mutex */
1120
 
        rw_lock_t       lock;           /* read-write lock of the buffer
 
1203
        rw_lock_t       lock;           /*!< read-write lock of the buffer
1121
1204
                                        frame */
1122
 
        unsigned        lock_hash_val:32;/* hashed value of the page address
 
1205
        unsigned        lock_hash_val:32;/*!< hashed value of the page address
1123
1206
                                        in the record lock hash table */
1124
1207
        unsigned        check_index_page_at_flush:1;
1125
 
                                        /* TRUE if we know that this is
 
1208
                                        /*!< TRUE if we know that this is
1126
1209
                                        an index page, and want the database
1127
1210
                                        to check its consistency before flush;
1128
1211
                                        note that there may be pages in the
1129
1212
                                        buffer pool which are index pages,
1130
1213
                                        but this flag is not set because
1131
1214
                                        we do not keep track of all pages */
1132
 
 
1133
 
        /* 2. Optimistic search field */
1134
 
 
1135
 
        ib_uint64_t     modify_clock;   /* this clock is incremented every
 
1215
        /* @} */
 
1216
        /** @name Optimistic search field */
 
1217
        /* @{ */
 
1218
 
 
1219
        ib_uint64_t     modify_clock;   /*!< this clock is incremented every
1136
1220
                                        time a pointer to a record on the
1137
1221
                                        page may become obsolete; this is
1138
1222
                                        used in the optimistic cursor
1143
1227
                                        pool mutex and the page is not
1144
1228
                                        bufferfixed, or (2) the thread has an
1145
1229
                                        x-latch on the block */
1146
 
 
1147
 
        /* 3. Hash search fields: NOTE that the first 4 fields are NOT
1148
 
        protected by any semaphore! */
1149
 
 
1150
 
        ulint           n_hash_helps;   /* counter which controls building
 
1230
        /* @} */
 
1231
        /** @name Hash search fields (unprotected)
 
1232
        NOTE that these fields are NOT protected by any semaphore! */
 
1233
        /* @{ */
 
1234
 
 
1235
        ulint           n_hash_helps;   /*!< counter which controls building
1151
1236
                                        of a new hash index for the page */
1152
 
        ulint           n_fields;       /* recommended prefix length for hash
 
1237
        ulint           n_fields;       /*!< recommended prefix length for hash
1153
1238
                                        search: number of full fields */
1154
 
        ulint           n_bytes;        /* recommended prefix: number of bytes
 
1239
        ulint           n_bytes;        /*!< recommended prefix: number of bytes
1155
1240
                                        in an incomplete field */
1156
 
        ibool           left_side;      /* TRUE or FALSE, depending on
 
1241
        ibool           left_side;      /*!< TRUE or FALSE, depending on
1157
1242
                                        whether the leftmost record of several
1158
1243
                                        records with the same prefix should be
1159
1244
                                        indexed in the hash index */
 
1245
        /* @} */
1160
1246
 
1161
 
        /* These 6 fields may only be modified when we have
 
1247
        /** @name Hash search fields
 
1248
        These 6 fields may only be modified when we have
1162
1249
        an x-latch on btr_search_latch AND
1163
 
        a) we are holding an s-latch or x-latch on block->lock or
1164
 
        b) we know that block->buf_fix_count == 0.
 
1250
        - we are holding an s-latch or x-latch on buf_block_struct::lock or
 
1251
        - we know that buf_block_struct::buf_fix_count == 0.
1165
1252
 
1166
1253
        An exception to this is when we init or create a page
1167
1254
        in the buffer pool in buf0buf.c. */
1168
1255
 
 
1256
        /* @{ */
 
1257
 
1169
1258
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1170
 
        ulint           n_pointers;     /* used in debugging: the number of
 
1259
        ulint           n_pointers;     /*!< used in debugging: the number of
1171
1260
                                        pointers in the adaptive hash index
1172
1261
                                        pointing to this frame */
1173
1262
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1174
 
        unsigned        is_hashed:1;    /* TRUE if hash index has already been
1175
 
                                        built on this page; note that it does
1176
 
                                        not guarantee that the index is
1177
 
                                        complete, though: there may have been
1178
 
                                        hash collisions, record deletions,
1179
 
                                        etc. */
1180
 
        unsigned        curr_n_fields:10;/* prefix length for hash indexing:
 
1263
        unsigned        is_hashed:1;    /*!< TRUE if hash index has
 
1264
                                        already been built on this
 
1265
                                        page; note that it does not
 
1266
                                        guarantee that the index is
 
1267
                                        complete, though: there may
 
1268
                                        have been hash collisions,
 
1269
                                        record deletions, etc. */
 
1270
        unsigned        curr_n_fields:10;/*!< prefix length for hash indexing:
1181
1271
                                        number of full fields */
1182
 
        unsigned        curr_n_bytes:15;/* number of bytes in hash indexing */
1183
 
        unsigned        curr_left_side:1;/* TRUE or FALSE in hash indexing */
1184
 
        dict_index_t*   index;          /* Index for which the adaptive
 
1272
        unsigned        curr_n_bytes:15;/*!< number of bytes in hash
 
1273
                                        indexing */
 
1274
        unsigned        curr_left_side:1;/*!< TRUE or FALSE in hash indexing */
 
1275
        dict_index_t*   index;          /*!< Index for which the adaptive
1185
1276
                                        hash index has been created. */
1186
 
        /* 4. Debug fields */
1187
 
#ifdef UNIV_SYNC_DEBUG
1188
 
        rw_lock_t       debug_latch;    /* in the debug version, each thread
 
1277
        /* @} */
 
1278
# ifdef UNIV_SYNC_DEBUG
 
1279
        /** @name Debug fields */
 
1280
        /* @{ */
 
1281
        rw_lock_t       debug_latch;    /*!< in the debug version, each thread
1189
1282
                                        which bufferfixes the block acquires
1190
1283
                                        an s-latch here; so we can use the
1191
1284
                                        debug utilities in sync0rw */
1192
 
#endif
 
1285
        /* @} */
 
1286
# endif
 
1287
#endif /* !UNIV_HOTBACKUP */
1193
1288
};
1194
1289
 
1195
 
/* Check if a buf_block_t object is in a valid state. */
 
1290
/** Check if a buf_block_t object is in a valid state
 
1291
@param block    buffer block
 
1292
@return         TRUE if valid */
1196
1293
#define buf_block_state_valid(block)                            \
1197
1294
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED               \
1198
1295
 && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1199
1296
 
1200
 
/**************************************************************************
 
1297
#ifndef UNIV_HOTBACKUP
 
1298
/**********************************************************************//**
1201
1299
Compute the hash fold value for blocks in buf_pool->zip_hash. */
 
1300
/* @{ */
1202
1301
#define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1203
1302
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1204
1303
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1205
 
 
1206
 
/* The buffer pool structure. NOTE! The definition appears here only for
1207
 
other modules of this directory (buf) to see it. Do not use from outside! */
 
1304
/* @} */
 
1305
 
 
1306
/** @brief The buffer pool structure.
 
1307
 
 
1308
NOTE! The definition appears here only for other modules of this
 
1309
directory (buf) to see it. Do not use from outside! */
1208
1310
 
1209
1311
struct buf_pool_struct{
1210
1312
 
1211
 
        /* 1. General fields */
 
1313
        /** @name General fields */
 
1314
        /* @{ */
1212
1315
 
1213
 
        ulint           n_chunks;       /* number of buffer pool chunks */
1214
 
        buf_chunk_t*    chunks;         /* buffer pool chunks */
1215
 
        ulint           curr_size;      /* current pool size in pages */
1216
 
        hash_table_t*   page_hash;      /* hash table of buf_page_t or
 
1316
        ulint           n_chunks;       /*!< number of buffer pool chunks */
 
1317
        buf_chunk_t*    chunks;         /*!< buffer pool chunks */
 
1318
        ulint           curr_size;      /*!< current pool size in pages */
 
1319
        hash_table_t*   page_hash;      /*!< hash table of buf_page_t or
1217
1320
                                        buf_block_t file pages,
1218
1321
                                        buf_page_in_file() == TRUE,
1219
1322
                                        indexed by (space_id, offset) */
1220
 
        hash_table_t*   zip_hash;       /* hash table of buf_block_t blocks
 
1323
        hash_table_t*   zip_hash;       /*!< hash table of buf_block_t blocks
1221
1324
                                        whose frames are allocated to the
1222
1325
                                        zip buddy system,
1223
1326
                                        indexed by block->frame */
1224
 
        ulint           n_pend_reads;   /* number of pending read operations */
1225
 
        ulint           n_pend_unzip;   /* number of pending decompressions */
 
1327
        ulint           n_pend_reads;   /*!< number of pending read operations */
 
1328
        ulint           n_pend_unzip;   /*!< number of pending decompressions */
1226
1329
 
1227
 
        time_t          last_printout_time; /* when buf_print was last time
 
1330
        time_t          last_printout_time; /*!< when buf_print was last time
1228
1331
                                        called */
1229
 
        ulint           n_pages_read;   /* number read operations */
1230
 
        ulint           n_pages_written;/* number write operations */
1231
 
        ulint           n_pages_created;/* number of pages created in the pool
1232
 
                                        with no read */
1233
 
        ulint           n_page_gets;    /* number of page gets performed;
 
1332
        ulint           n_pages_read;   /*!< number read operations */
 
1333
        ulint           n_pages_written;/*!< number write operations */
 
1334
        ulint           n_pages_created;/*!< number of pages created
 
1335
                                        in the pool with no read */
 
1336
        ulint           n_page_gets;    /*!< number of page gets performed;
1234
1337
                                        also successful searches through
1235
1338
                                        the adaptive hash index are
1236
1339
                                        counted as page gets; this field
1237
1340
                                        is NOT protected by the buffer
1238
1341
                                        pool mutex */
1239
 
        ulint           n_page_gets_old;/* n_page_gets when buf_print was
 
1342
        ulint           n_page_gets_old;/*!< n_page_gets when buf_print was
1240
1343
                                        last time called: used to calculate
1241
1344
                                        hit rate */
1242
 
        ulint           n_pages_read_old;/* n_pages_read when buf_print was
 
1345
        ulint           n_pages_read_old;/*!< n_pages_read when buf_print was
1243
1346
                                        last time called */
1244
 
        ulint           n_pages_written_old;/* number write operations */
1245
 
        ulint           n_pages_created_old;/* number of pages created in
 
1347
        ulint           n_pages_written_old;/*!< number write operations */
 
1348
        ulint           n_pages_created_old;/*!< number of pages created in
1246
1349
                                        the pool with no read */
1247
 
        /* 2. Page flushing algorithm fields */
 
1350
        /* @} */
 
1351
        /** @name Page flushing algorithm fields */
 
1352
        /* @{ */
1248
1353
 
1249
1354
        UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1250
 
                                        /* base node of the modified block
 
1355
                                        /*!< base node of the modified block
1251
1356
                                        list */
1252
1357
        ibool           init_flush[BUF_FLUSH_N_TYPES];
1253
 
                                        /* this is TRUE when a flush of the
 
1358
                                        /*!< this is TRUE when a flush of the
1254
1359
                                        given type is being initialized */
1255
1360
        ulint           n_flush[BUF_FLUSH_N_TYPES];
1256
 
                                        /* this is the number of pending
 
1361
                                        /*!< this is the number of pending
1257
1362
                                        writes in the given flush type */
1258
1363
        os_event_t      no_flush[BUF_FLUSH_N_TYPES];
1259
 
                                        /* this is in the set state when there
1260
 
                                        is no flush batch of the given type
1261
 
                                        running */
1262
 
        ulint           ulint_clock;    /* a sequence number used to count
 
1364
                                        /*!< this is in the set state
 
1365
                                        when there is no flush batch
 
1366
                                        of the given type running */
 
1367
        ulint           ulint_clock;    /*!< a sequence number used to count
1263
1368
                                        time. NOTE! This counter wraps
1264
1369
                                        around at 4 billion (if ulint ==
1265
1370
                                        32 bits)! */
1266
 
        ulint           freed_page_clock;/* a sequence number used to count the
1267
 
                                        number of buffer blocks removed from
1268
 
                                        the end of the LRU list; NOTE that
1269
 
                                        this counter may wrap around at 4
1270
 
                                        billion! A thread is allowed to
1271
 
                                        read this for heuristic purposes
1272
 
                                        without holding any mutex or latch */
1273
 
        ulint           LRU_flush_ended;/* when an LRU flush ends for a page,
 
1371
        ulint           freed_page_clock;/*!< a sequence number used
 
1372
                                        to count the number of buffer
 
1373
                                        blocks removed from the end of
 
1374
                                        the LRU list; NOTE that this
 
1375
                                        counter may wrap around at 4
 
1376
                                        billion! A thread is allowed
 
1377
                                        to read this for heuristic
 
1378
                                        purposes without holding any
 
1379
                                        mutex or latch */
 
1380
        ulint           LRU_flush_ended;/*!< when an LRU flush ends for a page,
1274
1381
                                        this is incremented by one; this is
1275
1382
                                        set to zero when a buffer block is
1276
1383
                                        allocated */
1277
1384
 
1278
 
        /* 3. LRU replacement algorithm fields */
 
1385
        /* @} */
 
1386
        /** @name LRU replacement algorithm fields */
 
1387
        /* @{ */
1279
1388
 
1280
1389
        UT_LIST_BASE_NODE_T(buf_page_t) free;
1281
 
                                        /* base node of the free block list */
 
1390
                                        /*!< base node of the free
 
1391
                                        block list */
1282
1392
        UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1283
 
                                        /* base node of the LRU list */
1284
 
        buf_page_t*     LRU_old;        /* pointer to the about 3/8 oldest
 
1393
                                        /*!< base node of the LRU list */
 
1394
        buf_page_t*     LRU_old;        /*!< pointer to the about 3/8 oldest
1285
1395
                                        blocks in the LRU list; NULL if LRU
1286
1396
                                        length less than BUF_LRU_OLD_MIN_LEN;
1287
1397
                                        NOTE: when LRU_old != NULL, its length
1288
1398
                                        should always equal LRU_old_len */
1289
 
        ulint           LRU_old_len;    /* length of the LRU list from
 
1399
        ulint           LRU_old_len;    /*!< length of the LRU list from
1290
1400
                                        the block to which LRU_old points
1291
1401
                                        onward, including that block;
1292
1402
                                        see buf0lru.c for the restrictions
1296
1406
                                        whenever LRU_old shrinks or grows! */
1297
1407
 
1298
1408
        UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1299
 
                                        /* base node of the unzip_LRU list */
 
1409
                                        /*!< base node of the
 
1410
                                        unzip_LRU list */
1300
1411
 
1301
 
        /* 4. Fields for the buddy allocator of compressed pages */
 
1412
        /* @} */
 
1413
        /** @name Buddy allocator fields
 
1414
        The buddy allocator is used for allocating compressed page
 
1415
        frames and buf_page_t descriptors of blocks that exist
 
1416
        in the buffer pool only in compressed form. */
 
1417
        /* @{ */
1302
1418
        UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1303
 
                                        /* unmodified compressed pages */
 
1419
                                        /*!< unmodified compressed pages */
1304
1420
        UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1305
 
                                        /* buddy free lists */
 
1421
                                        /*!< buddy free lists */
1306
1422
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1307
1423
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1308
1424
#endif
1309
1425
#if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1310
1426
# error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1311
1427
#endif
 
1428
        /* @} */
1312
1429
};
1313
1430
 
1314
 
/* mutex protecting the buffer pool struct and control blocks, except the
 
1431
/** mutex protecting the buffer pool struct and control blocks, except the
1315
1432
read-write lock in them */
1316
1433
extern mutex_t  buf_pool_mutex;
1317
 
/* mutex protecting the control blocks of compressed-only pages
 
1434
/** mutex protecting the control blocks of compressed-only pages
1318
1435
(of type buf_page_t, not buf_block_t) */
1319
1436
extern mutex_t  buf_pool_zip_mutex;
1320
1437
 
1321
 
/* Accessors for buf_pool_mutex.  Use these instead of accessing
1322
 
buf_pool_mutex directly. */
 
1438
/** @name Accessors for buf_pool_mutex.
 
1439
Use these instead of accessing buf_pool_mutex directly. */
 
1440
/* @{ */
1323
1441
 
1324
 
/* Test if buf_pool_mutex is owned. */
 
1442
/** Test if buf_pool_mutex is owned. */
1325
1443
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
1326
 
/* Acquire the buffer pool mutex. */
 
1444
/** Acquire the buffer pool mutex. */
1327
1445
#define buf_pool_mutex_enter() do {             \
1328
1446
        ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
1329
1447
        mutex_enter(&buf_pool_mutex);           \
1333
1451
/** Flag to forbid the release of the buffer pool mutex.
1334
1452
Protected by buf_pool_mutex. */
1335
1453
extern ulint    buf_pool_mutex_exit_forbidden;
1336
 
/* Forbid the release of the buffer pool mutex. */
 
1454
/** Forbid the release of the buffer pool mutex. */
1337
1455
# define buf_pool_mutex_exit_forbid() do {      \
1338
1456
        ut_ad(buf_pool_mutex_own());            \
1339
1457
        buf_pool_mutex_exit_forbidden++;        \
1340
1458
} while (0)
1341
 
/* Allow the release of the buffer pool mutex. */
 
1459
/** Allow the release of the buffer pool mutex. */
1342
1460
# define buf_pool_mutex_exit_allow() do {       \
1343
1461
        ut_ad(buf_pool_mutex_own());            \
1344
1462
        ut_a(buf_pool_mutex_exit_forbidden);    \
1345
1463
        buf_pool_mutex_exit_forbidden--;        \
1346
1464
} while (0)
1347
 
/* Release the buffer pool mutex. */
 
1465
/** Release the buffer pool mutex. */
1348
1466
# define buf_pool_mutex_exit() do {             \
1349
1467
        ut_a(!buf_pool_mutex_exit_forbidden);   \
1350
1468
        mutex_exit(&buf_pool_mutex);            \
1351
1469
} while (0)
1352
1470
#else
1353
 
/* Forbid the release of the buffer pool mutex. */
 
1471
/** Forbid the release of the buffer pool mutex. */
1354
1472
# define buf_pool_mutex_exit_forbid() ((void) 0)
1355
 
/* Allow the release of the buffer pool mutex. */
 
1473
/** Allow the release of the buffer pool mutex. */
1356
1474
# define buf_pool_mutex_exit_allow() ((void) 0)
1357
 
/* Release the buffer pool mutex. */
 
1475
/** Release the buffer pool mutex. */
1358
1476
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1359
1477
#endif
 
1478
#endif /* !UNIV_HOTBACKUP */
 
1479
/* @} */
1360
1480
 
1361
 
/************************************************************************
 
1481
/**********************************************************************
1362
1482
Let us list the consistency conditions for different control block states.
1363
1483
 
1364
1484
NOT_USED:       is in free list, not in LRU list, not in flush list, nor