Drizzled Public API Documentation

fsp0fsp.h File Reference
#include "univ.i"
#include "mtr0mtr.h"
#include "fut0lst.h"
#include "ut0byte.h"
#include "page0types.h"
#include "fsp0types.h"

Go to the source code of this file.

Functions

UNIV_INTERN void fsp_init (void)
UNIV_INTERN ulint fsp_header_get_free_limit (void)
UNIV_INTERN ulint fsp_header_get_tablespace_size (void)
UNIV_INTERN ulint fsp_get_size_low (page_t *page)
UNIV_INTERN ulint fsp_header_get_space_id (const page_t *page)
UNIV_INTERN ulint fsp_header_get_flags (const page_t *page)
UNIV_INTERN ulint fsp_header_get_zip_size (const page_t *page)
UNIV_INTERN void fsp_header_init_fields (page_t *page, ulint space_id, ulint flags)
UNIV_INTERN void fsp_header_init (ulint space, ulint size, mtr_t *mtr)
UNIV_INTERN void fsp_header_inc_size (ulint space, ulint size_inc, mtr_t *mtr)
UNIV_INTERN buf_block_tfseg_create (ulint space, ulint page, ulint byte_offset, mtr_t *mtr)
UNIV_INTERN buf_block_tfseg_create_general (ulint space, ulint page, ulint byte_offset, ibool has_done_reservation, mtr_t *mtr)
UNIV_INTERN ulint fseg_n_reserved_pages (fseg_header_t *header, ulint *used, mtr_t *mtr)
UNIV_INTERN ulint fseg_alloc_free_page (fseg_header_t *seg_header, ulint hint, byte direction, mtr_t *mtr)
UNIV_INTERN ulint fseg_alloc_free_page_general (fseg_header_t *seg_header, ulint hint, byte direction, ibool has_done_reservation, mtr_t *mtr)
UNIV_INTERN ibool fsp_reserve_free_extents (ulint *n_reserved, ulint space, ulint n_ext, ulint alloc_type, mtr_t *mtr)
UNIV_INTERN ullint fsp_get_available_space_in_free_extents (ulint space)
UNIV_INTERN void fseg_free_page (fseg_header_t *seg_header, ulint space, ulint page, mtr_t *mtr)
UNIV_INTERN ibool fseg_free_step (fseg_header_t *header, mtr_t *mtr)
UNIV_INTERN ibool fseg_free_step_not_header (fseg_header_t *header, mtr_t *mtr)
UNIV_INLINE ibool fsp_descr_page (ulint zip_size, ulint page_no)
UNIV_INTERN byte * fsp_parse_init_file_page (byte *ptr, byte *end_ptr, buf_block_t *block)
UNIV_INTERN ibool fsp_validate (ulint space)
UNIV_INTERN void fsp_print (ulint space)

Detailed Description

File space management

Created 12/18/1995 Heikki Tuuri

Definition in file fsp0fsp.h.

Function Documentation

UNIV_INTERN ulint fseg_alloc_free_page ( fseg_header_t *  seg_header,
ulint  hint,
byte  direction,
mtr_t mtr 
)

Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Returns
the allocated page offset FIL_NULL if no page could be allocated in: mtr handle

Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Returns
allocated page offset, FIL_NULL if no page could be allocated
Parameters
seg_headerin: segment header
hintin: hint of which page would be desirable
directionin: if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR
mtrin: mtr handle

Definition at line 2833 of file fsp0fsp.cc.

UNIV_INTERN ulint fseg_alloc_free_page_general ( fseg_header_t *  seg_header,
ulint  hint,
byte  direction,
ibool  has_done_reservation,
mtr_t mtr 
)

Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Returns
allocated page offset, FIL_NULL if no page could be allocated in: mtr handle

Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space fragmentation.

Returns
allocated page offset, FIL_NULL if no page could be allocated
Parameters
seg_headerin: segment header
hintin: hint of which page would be desirable
directionin: if the new page is needed because of an index page split, and records are inserted there in order, into which direction they go alphabetically: FSP_DOWN, FSP_UP, FSP_NO_DIR
has_done_reservationin: TRUE if the caller has already done the reservation for the page with fsp_reserve_free_extents, then there is no need to do the check for this individual page
mtrin: mtr handle

Definition at line 2762 of file fsp0fsp.cc.

UNIV_INTERN buf_block_t* fseg_create ( ulint  space,
ulint  page,
ulint  byte_offset,
mtr_t mtr 
)

Creates a new segment.

Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space in: mtr

Creates a new segment.

Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space
Parameters
spacein: space id
pagein: page where the segment header is placed: if this is != 0, the page must belong to another segment, if this is 0, a new page will be allocated and it will belong to the created segment
byte_offsetin: byte offset of the created segment header on the page
mtrin: mtr

Definition at line 2311 of file fsp0fsp.cc.

UNIV_INTERN buf_block_t* fseg_create_general ( ulint  space,
ulint  page,
ulint  byte_offset,
ibool  has_done_reservation,
mtr_t mtr 
)

Creates a new segment.

Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space in: mtr

Creates a new segment.

Returns
the block where the segment header is placed, x-latched, NULL if could not create segment because of lack of space
Parameters
spacein: space id
pagein: page where the segment header is placed: if this is != 0, the page must belong to another segment, if this is 0, a new page will be allocated and it will belong to the created segment
byte_offsetin: byte offset of the created segment header on the page
has_done_reservationin: TRUE if the caller has already done the reservation for the pages with fsp_reserve_free_extents (at least 2 extents: one for the inode and the other for the segment) then there is no need to do the check for this individual operation
mtrin: mtr

Definition at line 2178 of file fsp0fsp.cc.

UNIV_INTERN void fseg_free_page ( fseg_header_t *  seg_header,
ulint  space,
ulint  page,
mtr_t mtr 
)

Frees a single page of a segment. in: mtr handle

Frees a single page of a segment.

Parameters
seg_headerin: segment header
spacein: space id
pagein: page offset
mtrin: mtr handle

Definition at line 3363 of file fsp0fsp.cc.

UNIV_INTERN ibool fseg_free_step ( fseg_header_t *  header,
mtr_t mtr 
)

Frees part of a segment. This function can be used to free a segment by repeatedly calling this function in different mini-transactions. Doing the freeing in a single mini-transaction might result in too big a mini-transaction.

Returns
TRUE if freeing completed in: mtr

Frees part of a segment. This function can be used to free a segment by repeatedly calling this function in different mini-transactions. Doing the freeing in a single mini-transaction might result in too big a mini-transaction.

Returns
TRUE if freeing completed
Parameters
headerin, own: segment header; NOTE: if the header resides on the first page of the frag list of the segment, this pointer becomes obsolete after the last freeing step
mtrin: mtr

Definition at line 3472 of file fsp0fsp.cc.

UNIV_INTERN ibool fseg_free_step_not_header ( fseg_header_t *  header,
mtr_t mtr 
)

Frees part of a segment. Differs from fseg_free_step because this function leaves the header page unfreed.

Returns
TRUE if freeing completed, except the header page in: mtr

Frees part of a segment. Differs from fseg_free_step because this function leaves the header page unfreed.

Returns
TRUE if freeing completed, except the header page
Parameters
headerin: segment header which must reside on the first fragment page of the segment
mtrin: mtr

Definition at line 3559 of file fsp0fsp.cc.

UNIV_INTERN ulint fseg_n_reserved_pages ( fseg_header_t *  header,
ulint *  used,
mtr_t mtr 
)

Calculates the number of pages reserved by a segment, and how many pages are currently used.

Returns
number of reserved pages in: mtr handle

Calculates the number of pages reserved by a segment, and how many pages are currently used.

Returns
number of reserved pages
Parameters
headerin: segment header
usedout: number of pages used (<= reserved)
mtrin: mtr handle

Definition at line 2361 of file fsp0fsp.cc.

UNIV_INLINE ibool fsp_descr_page ( ulint  zip_size,
ulint  page_no 
)

Checks if a page address is an extent descriptor page address.

Returns
TRUE if a descriptor page in: page number
Parameters
zip_sizein: compressed page size in bytes; 0 for uncompressed pages
UNIV_INTERN ullint fsp_get_available_space_in_free_extents ( ulint  space)

This function should be used to get information on how much we still will be able to insert new data to the database without running out the tablespace. Only free extents are taken into account and we also subtract the safety margin required by the above function fsp_reserve_free_extents.

Returns
available space in kB in: space id

This function should be used to get information on how much we still will be able to insert new data to the database without running out the tablespace. Only free extents are taken into account and we also subtract the safety margin required by the above function fsp_reserve_free_extents.

Returns
available space in kB
Parameters
spacein: space id

Definition at line 3031 of file fsp0fsp.cc.

UNIV_INTERN ulint fsp_get_size_low ( page_t page)

Reads the file space size stored in the header page.

Returns
tablespace size stored in the space header in: header page (page 0 in the tablespace)

Reads the file space size stored in the header page.

Returns
tablespace size stored in the space header
Parameters
pagein: header page (page 0 in the tablespace)

Definition at line 303 of file fsp0fsp.cc.

UNIV_INTERN ulint fsp_header_get_flags ( const page_t page)

Reads the space flags from the first page of a tablespace.

Returns
flags in: first page of a tablespace

Reads the space flags from the first page of a tablespace.

Returns
flags
Parameters
pagein: first page of a tablespace

Definition at line 1002 of file fsp0fsp.cc.

UNIV_INTERN ulint fsp_header_get_free_limit ( void  )

Gets the current free limit of the system tablespace. The free limit means the place of the first page which has never been put to the the free list for allocation. The space above that address is initialized to zero. Sets also the global variable log_fsp_current_free_limit.

Returns
free limit in megabytes

Definition at line 1062 of file fsp0fsp.cc.

UNIV_INTERN ulint fsp_header_get_space_id ( const page_t page)

Reads the space id from the first page of a tablespace.

Returns
space id, ULINT UNDEFINED if error in: first page of a tablespace

Reads the space id from the first page of a tablespace.

Returns
space id, ULINT UNDEFINED if error
Parameters
pagein: first page of a tablespace

Definition at line 974 of file fsp0fsp.cc.

References mlog_write_ulint(), and mlog_write_ull().

UNIV_INTERN ulint fsp_header_get_tablespace_size ( void  )

Gets the size of the system tablespace from the tablespace header. If we do not have an auto-extending data file, this should be equal to the size of the data files. If there is an auto-extending data file, this can be smaller.

Returns
size in pages

Definition at line 1094 of file fsp0fsp.cc.

References log_fsp_current_free_limit_set_and_checkpoint(), MLOG_4BYTES, mtr_commit(), mtr_read_ulint(), mtr_start(), and mtr_x_lock.

UNIV_INTERN ulint fsp_header_get_zip_size ( const page_t page)

Reads the compressed page size from the first page of a tablespace.

Returns
compressed page size in bytes, or 0 if uncompressed in: first page of a tablespace

Reads the compressed page size from the first page of a tablespace.

Returns
compressed page size in bytes, or 0 if uncompressed
Parameters
pagein: first page of a tablespace

Definition at line 1016 of file fsp0fsp.cc.

References FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, and mach_read_from_4().

UNIV_INTERN void fsp_header_inc_size ( ulint  space,
ulint  size_inc,
mtr_t mtr 
)

Increases the space size field of a space. in: mini-transaction handle

Increases the space size field of a space.

Parameters
spacein: space id
size_incin: size increment in pages
mtrin: mini-transaction handle

Definition at line 1030 of file fsp0fsp.cc.

UNIV_INTERN void fsp_header_init ( ulint  space,
ulint  size,
mtr_t mtr 
)

Initializes the space header of a new created space and creates also the insert buffer tree root if space == 0. in: mini-transaction handle

Initializes the space header of a new created space and creates also the insert buffer tree root if space == 0.

Parameters
spacein: space id
sizein: current size in blocks
mtrin: mini-transaction handle

Definition at line 911 of file fsp0fsp.cc.

UNIV_INTERN void fsp_header_init_fields ( page_t page,
ulint  space_id,
ulint  flags 
)

Writes the space id and compressed page size to a tablespace header. This function is used past the buffer pool when we in fil0fil.c create a new single-table tablespace. in: tablespace flags (FSP_SPACE_FLAGS): 0, or table->flags if newer than COMPACT

Writes the space id and compressed page size to a tablespace header. This function is used past the buffer pool when we in fil0fil.c create a new single-table tablespace.

Parameters
pagein/out: first page in the space
space_idin: space id
flagsin: tablespace flags (FSP_SPACE_FLAGS): 0, or table->flags if newer than COMPACT

Definition at line 886 of file fsp0fsp.cc.

UNIV_INTERN void fsp_init ( void  )

Initializes the file space system.

Initializes the fsp system.

Definition at line 874 of file fsp0fsp.cc.

References mlog_write_initial_log_record().

UNIV_INTERN byte* fsp_parse_init_file_page ( byte *  ptr,
byte *  ,
buf_block_t block 
)

Parses a redo log record of a file page init.

Returns
end of log record or NULL in: block or NULL

Parses a redo log record of a file page init.

Returns
end of log record or NULL
Parameters
ptrin: buffer
blockin: block or NULL

Definition at line 855 of file fsp0fsp.cc.

UNIV_INTERN void fsp_print ( ulint  space)

Prints info of a file space. in: space id

Prints info of a file space.

Parameters
spacein: space id

Definition at line 4132 of file fsp0fsp.cc.

UNIV_INTERN ibool fsp_reserve_free_extents ( ulint *  n_reserved,
ulint  space,
ulint  n_ext,
ulint  alloc_type,
mtr_t mtr 
)

Reserves free pages from a tablespace. All mini-transactions which may use several pages from the tablespace should call this function beforehand and reserve enough free extents so that they certainly will be able to do their operation, like a B-tree page split, fully. Reservations must be released with function fil_space_release_free_extents!

The alloc_type below has the following meaning: FSP_NORMAL means an operation which will probably result in more space usage, like an insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are deleting rows, then this allocation will in the long run result in less space usage (after a purge); FSP_CLEANING means allocation done in a physical record delete (like in a purge) or other cleaning operation which will result in less space usage in the long run. We prefer the latter two types of allocation: when space is scarce, FSP_NORMAL allocations will not succeed, but the latter two allocations will succeed, if possible. The purpose is to avoid dead end where the database is full but the user cannot free any space because these freeing operations temporarily reserve some space.

Single-table tablespaces whose size is < 32 pages are a special case. In this function we would liberally reserve several 64 page extents for every page split or merge in a B-tree. But we do not want to waste disk space if the table only occupies < 32 pages. That is why we apply different rules in that special case, just ensuring that there are 3 free pages available.

Returns
TRUE if we were able to make the reservation in: mtr

Reserves free pages from a tablespace. All mini-transactions which may use several pages from the tablespace should call this function beforehand and reserve enough free extents so that they certainly will be able to do their operation, like a B-tree page split, fully. Reservations must be released with function fil_space_release_free_extents!

The alloc_type below has the following meaning: FSP_NORMAL means an operation which will probably result in more space usage, like an insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are deleting rows, then this allocation will in the long run result in less space usage (after a purge); FSP_CLEANING means allocation done in a physical record delete (like in a purge) or other cleaning operation which will result in less space usage in the long run. We prefer the latter two types of allocation: when space is scarce, FSP_NORMAL allocations will not succeed, but the latter two allocations will succeed, if possible. The purpose is to avoid dead end where the database is full but the user cannot free any space because these freeing operations temporarily reserve some space.

Single-table tablespaces whose size is < 32 pages are a special case. In this function we would liberally reserve several 64 page extents for every page split or merge in a B-tree. But we do not want to waste disk space if the table only occupies < 32 pages. That is why we apply different rules in that special case, just ensuring that there are 3 free pages available.

Returns
TRUE if we were able to make the reservation
Parameters
n_reservedout: number of extents actually reserved; if we return TRUE and the tablespace size is < 64 pages, then this can be 0, otherwise it is n_ext
spacein: space id
n_extin: number of extents to reserve
alloc_typein: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING
mtrin: mtr

Definition at line 2915 of file fsp0fsp.cc.

UNIV_INTERN ibool fsp_validate ( ulint  space)

Validates the file space system and its segments.

Returns
TRUE if ok in: space id

Validates the file space system and its segments.

Returns
TRUE if ok
Parameters
spacein: space id

Definition at line 3880 of file fsp0fsp.cc.