~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

Viewing changes to storage/innobase/include/fsp0fsp.h

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
File space management
 
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
 
6
Created 12/18/1995 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef fsp0fsp_h
 
10
#define fsp0fsp_h
 
11
 
 
12
#include "univ.i"
 
13
 
 
14
#include "mtr0mtr.h"
 
15
#include "fut0lst.h"
 
16
#include "ut0byte.h"
 
17
#include "page0types.h"
 
18
 
 
19
/* If records are inserted in order, there are the following
 
20
flags to tell this (their type is made byte for the compiler
 
21
to warn if direction and hint parameters are switched in
 
22
fseg_alloc_free_page): */
 
23
#define FSP_UP          ((byte)111)     /* alphabetically upwards */
 
24
#define FSP_DOWN        ((byte)112)     /* alphabetically downwards */
 
25
#define FSP_NO_DIR      ((byte)113)     /* no order */
 
26
 
 
27
/* File space extent size (one megabyte) in pages */
 
28
#define FSP_EXTENT_SIZE         (1 << (20 - UNIV_PAGE_SIZE_SHIFT))
 
29
 
 
30
/* On a page of any file segment, data may be put starting from this offset: */
 
31
#define FSEG_PAGE_DATA          FIL_PAGE_DATA
 
32
 
 
33
/* File segment header which points to the inode describing the file segment */
 
34
typedef byte    fseg_header_t;
 
35
 
 
36
#define FSEG_HDR_SPACE          0       /* space id of the inode */
 
37
#define FSEG_HDR_PAGE_NO        4       /* page number of the inode */
 
38
#define FSEG_HDR_OFFSET         8       /* byte offset of the inode */
 
39
 
 
40
#define FSEG_HEADER_SIZE        10
 
41
 
 
42
/**************************************************************************
 
43
Initializes the file space system. */
 
44
UNIV_INTERN
 
45
void
 
46
fsp_init(void);
 
47
/*==========*/
 
48
/**************************************************************************
 
49
Gets the current free limit of the system tablespace.  The free limit
 
50
means the place of the first page which has never been put to the the
 
51
free list for allocation.  The space above that address is initialized
 
52
to zero.  Sets also the global variable log_fsp_current_free_limit. */
 
53
UNIV_INTERN
 
54
ulint
 
55
fsp_header_get_free_limit(void);
 
56
/*===========================*/
 
57
                        /* out: free limit in megabytes */
 
58
/**************************************************************************
 
59
Gets the size of the system tablespace from the tablespace header.  If
 
60
we do not have an auto-extending data file, this should be equal to
 
61
the size of the data files.  If there is an auto-extending data file,
 
62
this can be smaller. */
 
63
UNIV_INTERN
 
64
ulint
 
65
fsp_header_get_tablespace_size(void);
 
66
/*================================*/
 
67
                        /* out: size in pages */
 
68
/**************************************************************************
 
69
Reads the file space size stored in the header page. */
 
70
UNIV_INTERN
 
71
ulint
 
72
fsp_get_size_low(
 
73
/*=============*/
 
74
                        /* out: tablespace size stored in the space header */
 
75
        page_t* page);  /* in: header page (page 0 in the tablespace) */
 
76
/**************************************************************************
 
77
Reads the space id from the first page of a tablespace. */
 
78
UNIV_INTERN
 
79
ulint
 
80
fsp_header_get_space_id(
 
81
/*====================*/
 
82
                                /* out: space id, ULINT UNDEFINED if error */
 
83
        const page_t*   page);  /* in: first page of a tablespace */
 
84
/**************************************************************************
 
85
Reads the space flags from the first page of a tablespace. */
 
86
UNIV_INTERN
 
87
ulint
 
88
fsp_header_get_flags(
 
89
/*=================*/
 
90
                                /* out: flags */
 
91
        const page_t*   page);  /* in: first page of a tablespace */
 
92
/**************************************************************************
 
93
Reads the compressed page size from the first page of a tablespace. */
 
94
UNIV_INTERN
 
95
ulint
 
96
fsp_header_get_zip_size(
 
97
/*====================*/
 
98
                                /* out: compressed page size in bytes,
 
99
                                or 0 if uncompressed */
 
100
        const page_t*   page);  /* in: first page of a tablespace */
 
101
/**************************************************************************
 
102
Writes the space id and compressed page size to a tablespace header.
 
103
This function is used past the buffer pool when we in fil0fil.c create
 
104
a new single-table tablespace. */
 
105
UNIV_INTERN
 
106
void
 
107
fsp_header_init_fields(
 
108
/*===================*/
 
109
        page_t* page,           /* in/out: first page in the space */
 
110
        ulint   space_id,       /* in: space id */
 
111
        ulint   flags);         /* in: tablespace flags (FSP_SPACE_FLAGS):
 
112
                                0, or table->flags if newer than COMPACT */
 
113
/**************************************************************************
 
114
Initializes the space header of a new created space and creates also the
 
115
insert buffer tree root if space == 0. */
 
116
UNIV_INTERN
 
117
void
 
118
fsp_header_init(
 
119
/*============*/
 
120
        ulint   space,          /* in: space id */
 
121
        ulint   size,           /* in: current size in blocks */
 
122
        mtr_t*  mtr);           /* in: mini-transaction handle */
 
123
/**************************************************************************
 
124
Increases the space size field of a space. */
 
125
UNIV_INTERN
 
126
void
 
127
fsp_header_inc_size(
 
128
/*================*/
 
129
        ulint   space,  /* in: space id */
 
130
        ulint   size_inc,/* in: size increment in pages */
 
131
        mtr_t*  mtr);   /* in: mini-transaction handle */
 
132
/**************************************************************************
 
133
Creates a new segment. */
 
134
UNIV_INTERN
 
135
buf_block_t*
 
136
fseg_create(
 
137
/*========*/
 
138
                        /* out: the block where the segment header is placed,
 
139
                        x-latched, NULL if could not create segment
 
140
                        because of lack of space */
 
141
        ulint   space,  /* in: space id */
 
142
        ulint   page,   /* in: page where the segment header is placed: if
 
143
                        this is != 0, the page must belong to another segment,
 
144
                        if this is 0, a new page will be allocated and it
 
145
                        will belong to the created segment */
 
146
        ulint   byte_offset, /* in: byte offset of the created segment header
 
147
                        on the page */
 
148
        mtr_t*  mtr);   /* in: mtr */
 
149
/**************************************************************************
 
150
Creates a new segment. */
 
151
UNIV_INTERN
 
152
buf_block_t*
 
153
fseg_create_general(
 
154
/*================*/
 
155
                        /* out: the block where the segment header is placed,
 
156
                        x-latched, NULL if could not create segment
 
157
                        because of lack of space */
 
158
        ulint   space,  /* in: space id */
 
159
        ulint   page,   /* in: page where the segment header is placed: if
 
160
                        this is != 0, the page must belong to another segment,
 
161
                        if this is 0, a new page will be allocated and it
 
162
                        will belong to the created segment */
 
163
        ulint   byte_offset, /* in: byte offset of the created segment header
 
164
                        on the page */
 
165
        ibool   has_done_reservation, /* in: TRUE if the caller has already
 
166
                        done the reservation for the pages with
 
167
                        fsp_reserve_free_extents (at least 2 extents: one for
 
168
                        the inode and the other for the segment) then there is
 
169
                        no need to do the check for this individual
 
170
                        operation */
 
171
        mtr_t*  mtr);   /* in: mtr */
 
172
/**************************************************************************
 
173
Calculates the number of pages reserved by a segment, and how many pages are
 
174
currently used. */
 
175
UNIV_INTERN
 
176
ulint
 
177
fseg_n_reserved_pages(
 
178
/*==================*/
 
179
                                /* out: number of reserved pages */
 
180
        fseg_header_t*  header, /* in: segment header */
 
181
        ulint*          used,   /* out: number of pages used (<= reserved) */
 
182
        mtr_t*          mtr);   /* in: mtr handle */
 
183
/**************************************************************************
 
184
Allocates a single free page from a segment. This function implements
 
185
the intelligent allocation strategy which tries to minimize
 
186
file space fragmentation. */
 
187
UNIV_INTERN
 
188
ulint
 
189
fseg_alloc_free_page(
 
190
/*=================*/
 
191
                                /* out: the allocated page offset
 
192
                                FIL_NULL if no page could be allocated */
 
193
        fseg_header_t*  seg_header, /* in: segment header */
 
194
        ulint           hint,   /* in: hint of which page would be desirable */
 
195
        byte            direction, /* in: if the new page is needed because
 
196
                                of an index page split, and records are
 
197
                                inserted there in order, into which
 
198
                                direction they go alphabetically: FSP_DOWN,
 
199
                                FSP_UP, FSP_NO_DIR */
 
200
        mtr_t*          mtr);   /* in: mtr handle */
 
201
/**************************************************************************
 
202
Allocates a single free page from a segment. This function implements
 
203
the intelligent allocation strategy which tries to minimize file space
 
204
fragmentation. */
 
205
UNIV_INTERN
 
206
ulint
 
207
fseg_alloc_free_page_general(
 
208
/*=========================*/
 
209
                                /* out: allocated page offset, FIL_NULL if no
 
210
                                page could be allocated */
 
211
        fseg_header_t*  seg_header,/* in: segment header */
 
212
        ulint           hint,   /* in: hint of which page would be desirable */
 
213
        byte            direction,/* in: if the new page is needed because
 
214
                                of an index page split, and records are
 
215
                                inserted there in order, into which
 
216
                                direction they go alphabetically: FSP_DOWN,
 
217
                                FSP_UP, FSP_NO_DIR */
 
218
        ibool           has_done_reservation, /* in: TRUE if the caller has
 
219
                                already done the reservation for the page
 
220
                                with fsp_reserve_free_extents, then there
 
221
                                is no need to do the check for this individual
 
222
                                page */
 
223
        mtr_t*          mtr);   /* in: mtr handle */
 
224
/**************************************************************************
 
225
Reserves free pages from a tablespace. All mini-transactions which may
 
226
use several pages from the tablespace should call this function beforehand
 
227
and reserve enough free extents so that they certainly will be able
 
228
to do their operation, like a B-tree page split, fully. Reservations
 
229
must be released with function fil_space_release_free_extents!
 
230
 
 
231
The alloc_type below has the following meaning: FSP_NORMAL means an
 
232
operation which will probably result in more space usage, like an
 
233
insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
 
234
deleting rows, then this allocation will in the long run result in
 
235
less space usage (after a purge); FSP_CLEANING means allocation done
 
236
in a physical record delete (like in a purge) or other cleaning operation
 
237
which will result in less space usage in the long run. We prefer the latter
 
238
two types of allocation: when space is scarce, FSP_NORMAL allocations
 
239
will not succeed, but the latter two allocations will succeed, if possible.
 
240
The purpose is to avoid dead end where the database is full but the
 
241
user cannot free any space because these freeing operations temporarily
 
242
reserve some space.
 
243
 
 
244
Single-table tablespaces whose size is < 32 pages are a special case. In this
 
245
function we would liberally reserve several 64 page extents for every page
 
246
split or merge in a B-tree. But we do not want to waste disk space if the table
 
247
only occupies < 32 pages. That is why we apply different rules in that special
 
248
case, just ensuring that there are 3 free pages available. */
 
249
UNIV_INTERN
 
250
ibool
 
251
fsp_reserve_free_extents(
 
252
/*=====================*/
 
253
                        /* out: TRUE if we were able to make the reservation */
 
254
        ulint*  n_reserved,/* out: number of extents actually reserved; if we
 
255
                        return TRUE and the tablespace size is < 64 pages,
 
256
                        then this can be 0, otherwise it is n_ext */
 
257
        ulint   space,  /* in: space id */
 
258
        ulint   n_ext,  /* in: number of extents to reserve */
 
259
        ulint   alloc_type,/* in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */
 
260
        mtr_t*  mtr);   /* in: mtr */
 
261
/**************************************************************************
 
262
This function should be used to get information on how much we still
 
263
will be able to insert new data to the database without running out the
 
264
tablespace. Only free extents are taken into account and we also subtract
 
265
the safety margin required by the above function fsp_reserve_free_extents. */
 
266
UNIV_INTERN
 
267
ullint
 
268
fsp_get_available_space_in_free_extents(
 
269
/*====================================*/
 
270
                        /* out: available space in kB */
 
271
        ulint   space); /* in: space id */
 
272
/**************************************************************************
 
273
Frees a single page of a segment. */
 
274
UNIV_INTERN
 
275
void
 
276
fseg_free_page(
 
277
/*===========*/
 
278
        fseg_header_t*  seg_header, /* in: segment header */
 
279
        ulint           space,  /* in: space id */
 
280
        ulint           page,   /* in: page offset */
 
281
        mtr_t*          mtr);   /* in: mtr handle */
 
282
/***********************************************************************
 
283
Frees a segment. The freeing is performed in several mini-transactions,
 
284
so that there is no danger of bufferfixing too many buffer pages. */
 
285
UNIV_INTERN
 
286
void
 
287
fseg_free(
 
288
/*======*/
 
289
        ulint   space,  /* in: space id */
 
290
        ulint   zip_size,/* in: compressed page size in bytes
 
291
                        or 0 for uncompressed pages */
 
292
        ulint   page_no,/* in: page number where the segment header is
 
293
                        placed */
 
294
        ulint   offset);/* in: byte offset of the segment header on that
 
295
                        page */
 
296
/**************************************************************************
 
297
Frees part of a segment. This function can be used to free a segment
 
298
by repeatedly calling this function in different mini-transactions.
 
299
Doing the freeing in a single mini-transaction might result in
 
300
too big a mini-transaction. */
 
301
UNIV_INTERN
 
302
ibool
 
303
fseg_free_step(
 
304
/*===========*/
 
305
                                /* out: TRUE if freeing completed */
 
306
        fseg_header_t*  header, /* in, own: segment header; NOTE: if the header
 
307
                                resides on the first page of the frag list
 
308
                                of the segment, this pointer becomes obsolete
 
309
                                after the last freeing step */
 
310
        mtr_t*          mtr);   /* in: mtr */
 
311
/**************************************************************************
 
312
Frees part of a segment. Differs from fseg_free_step because this function
 
313
leaves the header page unfreed. */
 
314
UNIV_INTERN
 
315
ibool
 
316
fseg_free_step_not_header(
 
317
/*======================*/
 
318
                                /* out: TRUE if freeing completed, except the
 
319
                                header page */
 
320
        fseg_header_t*  header, /* in: segment header which must reside on
 
321
                                the first fragment page of the segment */
 
322
        mtr_t*          mtr);   /* in: mtr */
 
323
/***************************************************************************
 
324
Checks if a page address is an extent descriptor page address. */
 
325
UNIV_INLINE
 
326
ibool
 
327
fsp_descr_page(
 
328
/*===========*/
 
329
                        /* out: TRUE if a descriptor page */
 
330
        ulint   zip_size,/* in: compressed page size in bytes;
 
331
                        0 for uncompressed pages */
 
332
        ulint   page_no);/* in: page number */
 
333
/***************************************************************
 
334
Parses a redo log record of a file page init. */
 
335
UNIV_INTERN
 
336
byte*
 
337
fsp_parse_init_file_page(
 
338
/*=====================*/
 
339
                                /* out: end of log record or NULL */
 
340
        byte*           ptr,    /* in: buffer */
 
341
        byte*           end_ptr, /* in: buffer end */
 
342
        buf_block_t*    block); /* in: block or NULL */
 
343
/***********************************************************************
 
344
Validates the file space system and its segments. */
 
345
UNIV_INTERN
 
346
ibool
 
347
fsp_validate(
 
348
/*=========*/
 
349
                        /* out: TRUE if ok */
 
350
        ulint   space); /* in: space id */
 
351
/***********************************************************************
 
352
Prints info of a file space. */
 
353
UNIV_INTERN
 
354
void
 
355
fsp_print(
 
356
/*======*/
 
357
        ulint   space); /* in: space id */
 
358
/***********************************************************************
 
359
Validates a segment. */
 
360
UNIV_INTERN
 
361
ibool
 
362
fseg_validate(
 
363
/*==========*/
 
364
                                /* out: TRUE if ok */
 
365
        fseg_header_t*  header, /* in: segment header */
 
366
        mtr_t*          mtr2);  /* in: mtr */
 
367
#ifdef UNIV_BTR_PRINT
 
368
/***********************************************************************
 
369
Writes info of a segment. */
 
370
UNIV_INTERN
 
371
void
 
372
fseg_print(
 
373
/*=======*/
 
374
        fseg_header_t*  header, /* in: segment header */
 
375
        mtr_t*          mtr);   /* in: mtr */
 
376
#endif /* UNIV_BTR_PRINT */
 
377
 
 
378
/* Flags for fsp_reserve_free_extents */
 
379
#define FSP_NORMAL      1000000
 
380
#define FSP_UNDO        2000000
 
381
#define FSP_CLEANING    3000000
 
382
 
 
383
/* Number of pages described in a single descriptor page: currently each page
 
384
description takes less than 1 byte; a descriptor page is repeated every
 
385
this many file pages */
 
386
/* #define XDES_DESCRIBED_PER_PAGE              UNIV_PAGE_SIZE */
 
387
/* This has been replaced with either UNIV_PAGE_SIZE or page_zip->size. */
 
388
 
 
389
/* The space low address page map */
 
390
/*--------------------------------------*/
 
391
                                /* The following two pages are repeated
 
392
                                every XDES_DESCRIBED_PER_PAGE pages in
 
393
                                every tablespace. */
 
394
#define FSP_XDES_OFFSET                 0       /* extent descriptor */
 
395
#define FSP_IBUF_BITMAP_OFFSET          1       /* insert buffer bitmap */
 
396
                                /* The ibuf bitmap pages are the ones whose
 
397
                                page number is the number above plus a
 
398
                                multiple of XDES_DESCRIBED_PER_PAGE */
 
399
 
 
400
#define FSP_FIRST_INODE_PAGE_NO         2       /* in every tablespace */
 
401
                                /* The following pages exist
 
402
                                in the system tablespace (space 0). */
 
403
#define FSP_IBUF_HEADER_PAGE_NO         3       /* in tablespace 0 */
 
404
#define FSP_IBUF_TREE_ROOT_PAGE_NO      4       /* in tablespace 0 */
 
405
                                /* The ibuf tree root page number in
 
406
                                tablespace 0; its fseg inode is on the page
 
407
                                number FSP_FIRST_INODE_PAGE_NO */
 
408
#define FSP_TRX_SYS_PAGE_NO             5       /* in tablespace 0 */
 
409
#define FSP_FIRST_RSEG_PAGE_NO          6       /* in tablespace 0 */
 
410
#define FSP_DICT_HDR_PAGE_NO            7       /* in tablespace 0 */
 
411
/*--------------------------------------*/
 
412
 
 
413
#ifndef UNIV_NONINL
 
414
#include "fsp0fsp.ic"
 
415
#endif
 
416
 
 
417
#endif