1
/******************************************************
6
Created 12/18/1995 Heikki Tuuri
7
*******************************************************/
17
#include "page0types.h"
18
#include "fsp0types.h"
20
/**************************************************************************
21
Initializes the file space system. */
26
/**************************************************************************
27
Gets the current free limit of a tablespace. The free limit means the
28
place of the first page which has never been put to the the free list
29
for allocation. The space above that address is initialized to zero.
30
Sets also the global variable log_fsp_current_free_limit. */
33
fsp_header_get_free_limit(
34
/*======================*/
35
/* out: free limit in megabytes */
36
ulint space); /* in: space id, must be 0 */
37
/**************************************************************************
38
Gets the size of the tablespace from the tablespace header. If we do not
39
have an auto-extending data file, this should be equal to the size of the
40
data files. If there is an auto-extending data file, this can be smaller. */
43
fsp_header_get_tablespace_size(
44
/*===========================*/
45
/* out: size in pages */
46
ulint space); /* in: space id, must be 0 */
47
/**************************************************************************
48
Reads the file space size stored in the header page. */
53
/* out: tablespace size stored in the space header */
54
page_t* page); /* in: header page (page 0 in the tablespace) */
55
/**************************************************************************
56
Reads the space id from the first page of a tablespace. */
59
fsp_header_get_space_id(
60
/*====================*/
61
/* out: space id, ULINT UNDEFINED if error */
62
page_t* page); /* in: first page of a tablespace */
63
/**************************************************************************
64
Writes the space id to a tablespace header. This function is used past the
65
buffer pool when we in fil0fil.c create a new single-table tablespace. */
68
fsp_header_write_space_id(
69
/*======================*/
70
page_t* page, /* in: first page in the space */
71
ulint space_id); /* in: space id */
72
/**************************************************************************
73
Initializes the space header of a new created space and creates also the
74
insert buffer tree root if space == 0. */
79
ulint space, /* in: space id */
80
ulint size, /* in: current size in blocks */
81
mtr_t* mtr); /* in: mini-transaction handle */
82
/**************************************************************************
83
Increases the space size field of a space. */
88
ulint space, /* in: space id */
89
ulint size_inc,/* in: size increment in pages */
90
mtr_t* mtr); /* in: mini-transaction handle */
91
/**************************************************************************
92
Creates a new segment. */
97
/* out: the page where the segment header is placed,
98
x-latched, NULL if could not create segment
99
because of lack of space */
100
ulint space, /* in: space id */
101
ulint page, /* in: page where the segment header is placed: if
102
this is != 0, the page must belong to another segment,
103
if this is 0, a new page will be allocated and it
104
will belong to the created segment */
105
ulint byte_offset, /* in: byte offset of the created segment header
107
mtr_t* mtr); /* in: mtr */
108
/**************************************************************************
109
Creates a new segment. */
114
/* out: the page where the segment header is placed,
115
x-latched, NULL if could not create segment
116
because of lack of space */
117
ulint space, /* in: space id */
118
ulint page, /* in: page where the segment header is placed: if
119
this is != 0, the page must belong to another segment,
120
if this is 0, a new page will be allocated and it
121
will belong to the created segment */
122
ulint byte_offset, /* in: byte offset of the created segment header
124
ibool has_done_reservation, /* in: TRUE if the caller has already
125
done the reservation for the pages with
126
fsp_reserve_free_extents (at least 2 extents: one for
127
the inode and the other for the segment) then there is
128
no need to do the check for this individual
130
mtr_t* mtr); /* in: mtr */
131
/**************************************************************************
132
Calculates the number of pages reserved by a segment, and how many pages are
136
fseg_n_reserved_pages(
137
/*==================*/
138
/* out: number of reserved pages */
139
fseg_header_t* header, /* in: segment header */
140
ulint* used, /* out: number of pages used (<= reserved) */
141
mtr_t* mtr); /* in: mtr handle */
142
/**************************************************************************
143
Allocates a single free page from a segment. This function implements
144
the intelligent allocation strategy which tries to minimize
145
file space fragmentation. */
148
fseg_alloc_free_page(
149
/*=================*/
150
/* out: the allocated page offset
151
FIL_NULL if no page could be allocated */
152
fseg_header_t* seg_header, /* in: segment header */
153
ulint hint, /* in: hint of which page would be desirable */
154
byte direction, /* in: if the new page is needed because
155
of an index page split, and records are
156
inserted there in order, into which
157
direction they go alphabetically: FSP_DOWN,
158
FSP_UP, FSP_NO_DIR */
159
mtr_t* mtr); /* in: mtr handle */
160
/**************************************************************************
161
Allocates a single free page from a segment. This function implements
162
the intelligent allocation strategy which tries to minimize file space
166
fseg_alloc_free_page_general(
167
/*=========================*/
168
/* out: allocated page offset, FIL_NULL if no
169
page could be allocated */
170
fseg_header_t* seg_header,/* in: segment header */
171
ulint hint, /* in: hint of which page would be desirable */
172
byte direction,/* in: if the new page is needed because
173
of an index page split, and records are
174
inserted there in order, into which
175
direction they go alphabetically: FSP_DOWN,
176
FSP_UP, FSP_NO_DIR */
177
ibool has_done_reservation, /* in: TRUE if the caller has
178
already done the reservation for the page
179
with fsp_reserve_free_extents, then there
180
is no need to do the check for this individual
182
mtr_t* mtr); /* in: mtr handle */
183
/**************************************************************************
184
Reserves free pages from a tablespace. All mini-transactions which may
185
use several pages from the tablespace should call this function beforehand
186
and reserve enough free extents so that they certainly will be able
187
to do their operation, like a B-tree page split, fully. Reservations
188
must be released with function fil_space_release_free_extents!
190
The alloc_type below has the following meaning: FSP_NORMAL means an
191
operation which will probably result in more space usage, like an
192
insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
193
deleting rows, then this allocation will in the long run result in
194
less space usage (after a purge); FSP_CLEANING means allocation done
195
in a physical record delete (like in a purge) or other cleaning operation
196
which will result in less space usage in the long run. We prefer the latter
197
two types of allocation: when space is scarce, FSP_NORMAL allocations
198
will not succeed, but the latter two allocations will succeed, if possible.
199
The purpose is to avoid dead end where the database is full but the
200
user cannot free any space because these freeing operations temporarily
203
Single-table tablespaces whose size is < 32 pages are a special case. In this
204
function we would liberally reserve several 64 page extents for every page
205
split or merge in a B-tree. But we do not want to waste disk space if the table
206
only occupies < 32 pages. That is why we apply different rules in that special
207
case, just ensuring that there are 3 free pages available. */
210
fsp_reserve_free_extents(
211
/*=====================*/
212
/* out: TRUE if we were able to make the reservation */
213
ulint* n_reserved,/* out: number of extents actually reserved; if we
214
return TRUE and the tablespace size is < 64 pages,
215
then this can be 0, otherwise it is n_ext */
216
ulint space, /* in: space id */
217
ulint n_ext, /* in: number of extents to reserve */
218
ulint alloc_type,/* in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */
219
mtr_t* mtr); /* in: mtr */
220
/**************************************************************************
221
This function should be used to get information on how much we still
222
will be able to insert new data to the database without running out the
223
tablespace. Only free extents are taken into account and we also subtract
224
the safety margin required by the above function fsp_reserve_free_extents. */
227
fsp_get_available_space_in_free_extents(
228
/*====================================*/
229
/* out: available space in kB */
230
ulint space); /* in: space id */
231
/**************************************************************************
232
Frees a single page of a segment. */
237
fseg_header_t* seg_header, /* in: segment header */
238
ulint space, /* in: space id */
239
ulint page, /* in: page offset */
240
mtr_t* mtr); /* in: mtr handle */
241
/***********************************************************************
242
Frees a segment. The freeing is performed in several mini-transactions,
243
so that there is no danger of bufferfixing too many buffer pages. */
248
ulint space, /* in: space id */
249
ulint page_no,/* in: page number where the segment header is
251
ulint offset);/* in: byte offset of the segment header on that
253
/**************************************************************************
254
Frees part of a segment. This function can be used to free a segment
255
by repeatedly calling this function in different mini-transactions.
256
Doing the freeing in a single mini-transaction might result in
257
too big a mini-transaction. */
262
/* out: TRUE if freeing completed */
263
fseg_header_t* header, /* in, own: segment header; NOTE: if the header
264
resides on the first page of the frag list
265
of the segment, this pointer becomes obsolete
266
after the last freeing step */
267
mtr_t* mtr); /* in: mtr */
268
/**************************************************************************
269
Frees part of a segment. Differs from fseg_free_step because this function
270
leaves the header page unfreed. */
273
fseg_free_step_not_header(
274
/*======================*/
275
/* out: TRUE if freeing completed, except the
277
fseg_header_t* header, /* in: segment header which must reside on
278
the first fragment page of the segment */
279
mtr_t* mtr); /* in: mtr */
280
/***************************************************************************
281
Checks if a page address is an extent descriptor page address. */
286
/* out: TRUE if a descriptor page */
287
ulint page_no);/* in: page number */
288
/***************************************************************
289
Parses a redo log record of a file page init. */
292
fsp_parse_init_file_page(
293
/*=====================*/
294
/* out: end of log record or NULL */
295
byte* ptr, /* in: buffer */
296
byte* end_ptr,/* in: buffer end */
297
page_t* page); /* in: page or NULL */
298
/***********************************************************************
299
Validates the file space system and its segments. */
304
/* out: TRUE if ok */
305
ulint space); /* in: space id */
306
/***********************************************************************
307
Prints info of a file space. */
312
ulint space); /* in: space id */
313
/***********************************************************************
314
Validates a segment. */
319
/* out: TRUE if ok */
320
fseg_header_t* header, /* in: segment header */
321
mtr_t* mtr2); /* in: mtr */
322
/***********************************************************************
323
Writes info of a segment. */
328
fseg_header_t* header, /* in: segment header */
329
mtr_t* mtr); /* in: mtr */
332
#include "fsp0fsp.ic"