1
/*****************************************************************************
3
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/fsp0fsp.h
23
Created 12/18/1995 Heikki Tuuri
24
*******************************************************/
34
#include "page0types.h"
35
#include "fsp0types.h"
37
/**********************************************************************//**
38
Initializes the file space system. */
43
/**********************************************************************//**
44
Gets the current free limit of the system tablespace. The free limit
45
means the place of the first page which has never been put to the the
46
free list for allocation. The space above that address is initialized
47
to zero. Sets also the global variable log_fsp_current_free_limit.
48
@return free limit in megabytes */
51
fsp_header_get_free_limit(void);
52
/*===========================*/
53
/**********************************************************************//**
54
Gets the size of the system tablespace from the tablespace header. If
55
we do not have an auto-extending data file, this should be equal to
56
the size of the data files. If there is an auto-extending data file,
58
@return size in pages */
61
fsp_header_get_tablespace_size(void);
62
/*================================*/
63
/**********************************************************************//**
64
Reads the file space size stored in the header page.
65
@return tablespace size stored in the space header */
70
page_t* page); /*!< in: header page (page 0 in the tablespace) */
71
/**********************************************************************//**
72
Reads the space id from the first page of a tablespace.
73
@return space id, ULINT UNDEFINED if error */
76
fsp_header_get_space_id(
77
/*====================*/
78
const page_t* page); /*!< in: first page of a tablespace */
79
/**********************************************************************//**
80
Reads the space flags from the first page of a tablespace.
86
const page_t* page); /*!< in: first page of a tablespace */
87
/**********************************************************************//**
88
Reads the compressed page size from the first page of a tablespace.
89
@return compressed page size in bytes, or 0 if uncompressed */
92
fsp_header_get_zip_size(
93
/*====================*/
94
const page_t* page); /*!< in: first page of a tablespace */
95
/**********************************************************************//**
96
Writes the space id and compressed page size to a tablespace header.
97
This function is used past the buffer pool when we in fil0fil.c create
98
a new single-table tablespace. */
101
fsp_header_init_fields(
102
/*===================*/
103
page_t* page, /*!< in/out: first page in the space */
104
ulint space_id, /*!< in: space id */
105
ulint flags); /*!< in: tablespace flags (FSP_SPACE_FLAGS):
106
0, or table->flags if newer than COMPACT */
107
/**********************************************************************//**
108
Initializes the space header of a new created space and creates also the
109
insert buffer tree root if space == 0. */
114
ulint space, /*!< in: space id */
115
ulint size, /*!< in: current size in blocks */
116
mtr_t* mtr); /*!< in: mini-transaction handle */
117
/**********************************************************************//**
118
Increases the space size field of a space. */
123
ulint space, /*!< in: space id */
124
ulint size_inc,/*!< in: size increment in pages */
125
mtr_t* mtr); /*!< in: mini-transaction handle */
126
/**********************************************************************//**
127
Creates a new segment.
128
@return the block where the segment header is placed, x-latched, NULL
129
if could not create segment because of lack of space */
134
ulint space, /*!< in: space id */
135
ulint page, /*!< in: page where the segment header is placed: if
136
this is != 0, the page must belong to another segment,
137
if this is 0, a new page will be allocated and it
138
will belong to the created segment */
139
ulint byte_offset, /*!< in: byte offset of the created segment header
141
mtr_t* mtr); /*!< in: mtr */
142
/**********************************************************************//**
143
Creates a new segment.
144
@return the block where the segment header is placed, x-latched, NULL
145
if could not create segment because of lack of space */
150
ulint space, /*!< in: space id */
151
ulint page, /*!< in: page where the segment header is placed: if
152
this is != 0, the page must belong to another segment,
153
if this is 0, a new page will be allocated and it
154
will belong to the created segment */
155
ulint byte_offset, /*!< in: byte offset of the created segment header
157
ibool has_done_reservation, /*!< in: TRUE if the caller has already
158
done the reservation for the pages with
159
fsp_reserve_free_extents (at least 2 extents: one for
160
the inode and the other for the segment) then there is
161
no need to do the check for this individual
163
mtr_t* mtr); /*!< in: mtr */
164
/**********************************************************************//**
165
Calculates the number of pages reserved by a segment, and how many pages are
167
@return number of reserved pages */
170
fseg_n_reserved_pages(
171
/*==================*/
172
fseg_header_t* header, /*!< in: segment header */
173
ulint* used, /*!< out: number of pages used (<= reserved) */
174
mtr_t* mtr); /*!< in: mtr handle */
175
/**********************************************************************//**
176
Allocates a single free page from a segment. This function implements
177
the intelligent allocation strategy which tries to minimize
178
file space fragmentation.
179
@return the allocated page offset FIL_NULL if no page could be allocated */
182
fseg_alloc_free_page(
183
/*=================*/
184
fseg_header_t* seg_header, /*!< in: segment header */
185
ulint hint, /*!< in: hint of which page would be desirable */
186
byte direction, /*!< in: if the new page is needed because
187
of an index page split, and records are
188
inserted there in order, into which
189
direction they go alphabetically: FSP_DOWN,
190
FSP_UP, FSP_NO_DIR */
191
mtr_t* mtr); /*!< in: mtr handle */
192
/**********************************************************************//**
193
Allocates a single free page from a segment. This function implements
194
the intelligent allocation strategy which tries to minimize file space
196
@return allocated page offset, FIL_NULL if no page could be allocated */
199
fseg_alloc_free_page_general(
200
/*=========================*/
201
fseg_header_t* seg_header,/*!< in: segment header */
202
ulint hint, /*!< in: hint of which page would be desirable */
203
byte direction,/*!< in: if the new page is needed because
204
of an index page split, and records are
205
inserted there in order, into which
206
direction they go alphabetically: FSP_DOWN,
207
FSP_UP, FSP_NO_DIR */
208
ibool has_done_reservation, /*!< in: TRUE if the caller has
209
already done the reservation for the page
210
with fsp_reserve_free_extents, then there
211
is no need to do the check for this individual
213
mtr_t* mtr); /*!< in: mtr handle */
214
/**********************************************************************//**
215
Reserves free pages from a tablespace. All mini-transactions which may
216
use several pages from the tablespace should call this function beforehand
217
and reserve enough free extents so that they certainly will be able
218
to do their operation, like a B-tree page split, fully. Reservations
219
must be released with function fil_space_release_free_extents!
221
The alloc_type below has the following meaning: FSP_NORMAL means an
222
operation which will probably result in more space usage, like an
223
insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
224
deleting rows, then this allocation will in the long run result in
225
less space usage (after a purge); FSP_CLEANING means allocation done
226
in a physical record delete (like in a purge) or other cleaning operation
227
which will result in less space usage in the long run. We prefer the latter
228
two types of allocation: when space is scarce, FSP_NORMAL allocations
229
will not succeed, but the latter two allocations will succeed, if possible.
230
The purpose is to avoid dead end where the database is full but the
231
user cannot free any space because these freeing operations temporarily
234
Single-table tablespaces whose size is < 32 pages are a special case. In this
235
function we would liberally reserve several 64 page extents for every page
236
split or merge in a B-tree. But we do not want to waste disk space if the table
237
only occupies < 32 pages. That is why we apply different rules in that special
238
case, just ensuring that there are 3 free pages available.
239
@return TRUE if we were able to make the reservation */
242
fsp_reserve_free_extents(
243
/*=====================*/
244
ulint* n_reserved,/*!< out: number of extents actually reserved; if we
245
return TRUE and the tablespace size is < 64 pages,
246
then this can be 0, otherwise it is n_ext */
247
ulint space, /*!< in: space id */
248
ulint n_ext, /*!< in: number of extents to reserve */
249
ulint alloc_type,/*!< in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */
250
mtr_t* mtr); /*!< in: mtr */
251
/**********************************************************************//**
252
This function should be used to get information on how much we still
253
will be able to insert new data to the database without running out the
254
tablespace. Only free extents are taken into account and we also subtract
255
the safety margin required by the above function fsp_reserve_free_extents.
256
@return available space in kB */
259
fsp_get_available_space_in_free_extents(
260
/*====================================*/
261
ulint space); /*!< in: space id */
262
/**********************************************************************//**
263
Frees a single page of a segment. */
268
fseg_header_t* seg_header, /*!< in: segment header */
269
ulint space, /*!< in: space id */
270
ulint page, /*!< in: page offset */
271
mtr_t* mtr); /*!< in: mtr handle */
272
/**********************************************************************//**
273
Frees part of a segment. This function can be used to free a segment
274
by repeatedly calling this function in different mini-transactions.
275
Doing the freeing in a single mini-transaction might result in
276
too big a mini-transaction.
277
@return TRUE if freeing completed */
282
fseg_header_t* header, /*!< in, own: segment header; NOTE: if the header
283
resides on the first page of the frag list
284
of the segment, this pointer becomes obsolete
285
after the last freeing step */
286
mtr_t* mtr); /*!< in: mtr */
287
/**********************************************************************//**
288
Frees part of a segment. Differs from fseg_free_step because this function
289
leaves the header page unfreed.
290
@return TRUE if freeing completed, except the header page */
293
fseg_free_step_not_header(
294
/*======================*/
295
fseg_header_t* header, /*!< in: segment header which must reside on
296
the first fragment page of the segment */
297
mtr_t* mtr); /*!< in: mtr */
298
/***********************************************************************//**
299
Checks if a page address is an extent descriptor page address.
300
@return TRUE if a descriptor page */
305
ulint zip_size,/*!< in: compressed page size in bytes;
306
0 for uncompressed pages */
307
ulint page_no);/*!< in: page number */
308
/***********************************************************//**
309
Parses a redo log record of a file page init.
310
@return end of log record or NULL */
313
fsp_parse_init_file_page(
314
/*=====================*/
315
byte* ptr, /*!< in: buffer */
316
byte* end_ptr, /*!< in: buffer end */
317
buf_block_t* block); /*!< in: block or NULL */
318
/*******************************************************************//**
319
Validates the file space system and its segments.
320
@return TRUE if ok */
325
ulint space); /*!< in: space id */
326
/*******************************************************************//**
327
Prints info of a file space. */
332
ulint space); /*!< in: space id */
334
/*******************************************************************//**
336
@return TRUE if ok */
341
fseg_header_t* header, /*!< in: segment header */
342
mtr_t* mtr); /*!< in: mtr */
343
#endif /* UNIV_DEBUG */
344
#ifdef UNIV_BTR_PRINT
345
/*******************************************************************//**
346
Writes info of a segment. */
351
fseg_header_t* header, /*!< in: segment header */
352
mtr_t* mtr); /*!< in: mtr */
353
#endif /* UNIV_BTR_PRINT */
356
#include "fsp0fsp.ic"