📄 buf0buf.h
字号:
/* Innobase relational database engine; Copyright (C) 2001 Innobase Oy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 2 as published by the Free Software Foundation in June 1991. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License 2 along with this program (in file COPYING); if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//******************************************************The database buffer pool high-level routines(c) 1995 Innobase OyCreated 11/5/1995 Heikki Tuuri*******************************************************/#ifndef buf0buf_h#define buf0buf_h#include "univ.i"#include "fil0fil.h"#include "mtr0types.h"#include "buf0types.h"#include "sync0rw.h"#include "hash0hash.h"#include "ut0byte.h"#include "os0proc.h"/* Flags for flush types */#define BUF_FLUSH_LRU 1#define BUF_FLUSH_SINGLE_PAGE 2#define BUF_FLUSH_LIST 3 /* An array in the pool struct has size BUF_FLUSH_LIST + 1: if you add more flush types, put them in the middle! *//* Modes for buf_page_get_gen */#define BUF_GET 10 /* get always */#define BUF_GET_IF_IN_POOL 11 /* get if in pool */#define BUF_GET_NOWAIT 12 /* get if can set the latch without waiting */#define BUF_GET_NO_LATCH 14 /* get and bufferfix, but set no latch; we have separated this case, because it is error-prone programming not to set a latch, and it should be used with care *//* Modes for buf_page_get_known_nowait */#define BUF_MAKE_YOUNG 51#define BUF_KEEP_OLD 52/* Magic value to use instead of checksums when they are disabled */#define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFULextern buf_pool_t* buf_pool; /* The buffer pool of the database */#ifdef UNIV_DEBUGextern ibool buf_debug_prints;/* If this is set TRUE, the program prints info whenever read or flush occurs */#endif /* UNIV_DEBUG */extern ulint srv_buf_pool_write_requests; /* variable to count write request issued *//************************************************************************Creates the buffer pool. */buf_pool_t*buf_pool_init(/*==========*/ /* out, own: buf_pool object, NULL if not enough memory or error */ ulint max_size, /* in: maximum size of the buf_pool in blocks */ ulint curr_size, /* in: current size to use, must be <= max_size, currently must be equal to max_size */ ulint n_frames); /* in: number of frames; if AWE is used, this is the size of the address space window where physical memory pages are mapped; if AWE is not used then this must be the same as max_size *//*************************************************************************Gets the current size of buffer buf_pool in bytes. In the case of AWE, thesize of AWE window (= the frames). */UNIV_INLINEulintbuf_pool_get_curr_size(void);/*========================*/ /* out: size in bytes *//*************************************************************************Gets the maximum size of buffer pool in bytes. In the case of AWE, thesize of AWE window (= the frames). */UNIV_INLINEulintbuf_pool_get_max_size(void);/*=======================*/ /* out: size in bytes *//************************************************************************Gets the smallest oldest_modification lsn for any page in the pool. Returnsut_dulint_zero if all modified pages have been flushed to disk. */UNIV_INLINEdulintbuf_pool_get_oldest_modification(void);/*==================================*/ /* out: oldest modification in pool, ut_dulint_zero if none *//*************************************************************************Allocates a buffer frame. */buf_frame_t*buf_frame_alloc(void);/*==================*/ /* out: buffer frame *//*************************************************************************Frees a buffer frame which does not contain a file page. */voidbuf_frame_free(/*===========*/ buf_frame_t* frame); /* in: buffer frame *//*************************************************************************Copies contents of a buffer frame to a given buffer. */UNIV_INLINEbyte*buf_frame_copy(/*===========*/ /* out: buf */ byte* buf, /* in: buffer to copy to */ buf_frame_t* frame); /* in: buffer frame *//******************************************************************NOTE! The following macros should be used instead of buf_page_get_gen,to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowedin LA! */#define buf_page_get(SP, OF, LA, MTR) buf_page_get_gen(\ SP, OF, LA, NULL,\ BUF_GET, __FILE__, __LINE__, MTR)/******************************************************************Use these macros to bufferfix a page with no latching. Remember not toread the contents of the page unless you know it is safe. Do not modifythe contents of the page! We have separated this case, because it iserror-prone programming not to set a latch, and it should be usedwith care. */#define buf_page_get_with_no_latch(SP, OF, MTR) buf_page_get_gen(\ SP, OF, RW_NO_LATCH, NULL,\ BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)/******************************************************************NOTE! The following macros should be used instead of buf_page_get_gen, toimprove debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed as LA! */#define buf_page_get_nowait(SP, OF, LA, MTR) buf_page_get_gen(\ SP, OF, LA, NULL,\ BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)/******************************************************************NOTE! The following macros should be used instead ofbuf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH andRW_X_LATCH are allowed as LA! */#define buf_page_optimistic_get(LA, BL, G, MC, MTR) buf_page_optimistic_get_func(\ LA, BL, G, MC, __FILE__, __LINE__, MTR)/************************************************************************This is the general function used to get optimistic access to a databasepage. */iboolbuf_page_optimistic_get_func(/*=========================*/ /* out: TRUE if success */ ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */ buf_block_t* block, /* in: guessed block */ buf_frame_t* guess, /* in: guessed frame; note that AWE may move frames */ dulint modify_clock,/* in: modify clock value if mode is ..._GUESS_ON_CLOCK */ const char* file, /* in: file name */ ulint line, /* in: line where called */ mtr_t* mtr); /* in: mini-transaction *//************************************************************************Tries to get the page, but if file io is required, releases all latchesin mtr down to the given savepoint. If io is required, this functionretrieves the page to buffer buf_pool, but does not bufferfix it or latchit. */UNIV_INLINEbuf_frame_t*buf_page_get_release_on_io(/*=======================*/ /* out: pointer to the frame, or NULL if not in buffer buf_pool */ ulint space, /* in: space id */ ulint offset, /* in: offset of the page within space in units of a page */ buf_frame_t* guess, /* in: guessed frame or NULL */ ulint rw_latch, /* in: RW_X_LATCH, RW_S_LATCH, or RW_NO_LATCH */ ulint savepoint, /* in: mtr savepoint */ mtr_t* mtr); /* in: mtr *//************************************************************************This is used to get access to a known database page, when no waiting can bedone. */iboolbuf_page_get_known_nowait(/*======================*/ /* out: TRUE if success */ ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */ buf_frame_t* guess, /* in: the known page frame */ ulint mode, /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */ const char* file, /* in: file name */ ulint line, /* in: line where called */ mtr_t* mtr); /* in: mini-transaction *//************************************************************************This is the general function used to get access to a database page. */buf_frame_t*buf_page_get_gen(/*=============*/ /* out: pointer to the frame or NULL */ ulint space, /* in: space id */ ulint offset, /* in: page number */ ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */ buf_frame_t* guess, /* in: guessed frame or NULL */ ulint mode, /* in: BUF_GET, BUF_GET_IF_IN_POOL, BUF_GET_NO_LATCH */ const char* file, /* in: file name */ ulint line, /* in: line where called */ mtr_t* mtr); /* in: mini-transaction *//************************************************************************Initializes a page to the buffer buf_pool. The page is usually not readfrom a file even if it cannot be found in the buffer buf_pool. This is oneof the functions which perform to a block a state transition NOT_USED =>FILE_PAGE (the other is buf_page_init_for_read above). */buf_frame_t*buf_page_create(/*============*/ /* out: pointer to the frame, page bufferfixed */ ulint space, /* in: space id */ ulint offset, /* in: offset of the page within space in units of a page */ mtr_t* mtr); /* in: mini-transaction handle *//************************************************************************Inits a page to the buffer buf_pool, for use in ibbackup --restore. */voidbuf_page_init_for_backup_restore(/*=============================*/ ulint space, /* in: space id */ ulint offset, /* in: offset of the page within space in units of a page */ buf_block_t* block); /* in: block to init *//************************************************************************Decrements the bufferfix count of a buffer control block and releasesa latch, if specified. */UNIV_INLINEvoidbuf_page_release(/*=============*/ buf_block_t* block, /* in: buffer block */ ulint rw_latch, /* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */ mtr_t* mtr); /* in: mtr *//************************************************************************Moves a page to the start of the buffer pool LRU list. This high-levelfunction can be used to prevent an important page from from slipping out ofthe buffer pool. */voidbuf_page_make_young(/*=================*/ buf_frame_t* frame); /* in: buffer frame of a file page *//************************************************************************Returns TRUE if the page can be found in the buffer pool hash table. NOTEthat it is possible that the page is not yet read from disk, though. */iboolbuf_page_peek(/*==========*/ /* out: TRUE if found from page hash table, NOTE that the page is not necessarily yet read from disk! */ ulint space, /* in: space id */ ulint offset);/* in: page number *//************************************************************************Returns the buffer control block if the page can be found in the bufferpool. NOTE that it is possible that the page is not yet readfrom disk, though. This is a very low-level function: use with care! */buf_block_t*buf_page_peek_block(/*================*/ /* out: control block if found from page hash table, otherwise NULL; NOTE that the page is not necessarily yet read from disk! */ ulint space, /* in: space id */ ulint offset);/* in: page number *//************************************************************************Resets the check_index_page_at_flush field of a page if found in the bufferpool. */voidbuf_reset_check_index_page_at_flush(/*================================*/ ulint space, /* in: space id */ ulint offset);/* in: page number *//************************************************************************Sets file_page_was_freed TRUE if the page is found in the buffer pool.This function should be called when we free a file page and want thedebug version to check that it is not accessed any more unlessreallocated. */buf_block_t*buf_page_set_file_page_was_freed(/*=============================*/ /* out: control block if found from page hash table, otherwise NULL */ ulint space, /* in: space id */ ulint offset); /* in: page number *//************************************************************************Sets file_page_was_freed FALSE if the page is found in the buffer pool.This function should be called when we free a file page and want thedebug version to check that it is not accessed any more unlessreallocated. */buf_block_t*buf_page_reset_file_page_was_freed(/*===============================*/ /* out: control block if found from page hash table, otherwise NULL */ ulint space, /* in: space id */ ulint offset); /* in: page number *//************************************************************************Recommends a move of a block to the start of the LRU list if there is dangerof dropping from the buffer pool. NOTE: does not reserve the buffer poolmutex. */UNIV_INLINEiboolbuf_block_peek_if_too_old(/*======================*/ /* out: TRUE if should be made younger */ buf_block_t* block); /* in: block to make younger *//************************************************************************Returns the current state of is_hashed of a page. FALSE if the page isnot in the pool. NOTE that this operation does not fix the page in thepool if it is found there. */iboolbuf_page_peek_if_search_hashed(/*===========================*/ /* out: TRUE if page hash index is built in search system */ ulint space, /* in: space id */ ulint offset);/* in: page number *//************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -