~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1995, 2012, Oracle and/or its affiliates. All Rights Reserved.
 
4
 
 
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.
 
8
 
 
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.
 
12
 
 
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.,
 
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/fsp0fsp.h
 
21
File space management
 
22
 
 
23
Created 12/18/1995 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef fsp0fsp_h
 
27
#define fsp0fsp_h
 
28
 
 
29
#include "univ.i"
 
30
 
 
31
#ifndef UNIV_INNOCHECKSUM
 
32
 
 
33
#include "mtr0mtr.h"
 
34
#include "fut0lst.h"
 
35
#include "ut0byte.h"
 
36
#include "page0types.h"
 
37
#include "fsp0types.h"
 
38
 
 
39
#endif /* !UNIV_INNOCHECKSUM */
 
40
 
 
41
/* @defgroup fsp_flags InnoDB Tablespace Flag Constants @{ */
 
42
 
 
43
/** Width of the POST_ANTELOPE flag */
 
44
#define FSP_FLAGS_WIDTH_POST_ANTELOPE   1
 
45
/** Number of flag bits used to indicate the tablespace zip page size */
 
46
#define FSP_FLAGS_WIDTH_ZIP_SSIZE       4
 
47
/** Width of the ATOMIC_BLOBS flag.  The ability to break up a long
 
48
column into an in-record prefix and an externally stored part is available
 
49
to the two Barracuda row formats COMPRESSED and DYNAMIC. */
 
50
#define FSP_FLAGS_WIDTH_ATOMIC_BLOBS    1
 
51
/** Number of flag bits used to indicate the tablespace page size */
 
52
#define FSP_FLAGS_WIDTH_PAGE_SSIZE      4
 
53
/** Width of the DATA_DIR flag.  This flag indicates that the tablespace
 
54
is found in a remote location, not the default data directory. */
 
55
#define FSP_FLAGS_WIDTH_DATA_DIR        1
 
56
/** Width of all the currently known tablespace flags */
 
57
#define FSP_FLAGS_WIDTH         (FSP_FLAGS_WIDTH_POST_ANTELOPE  \
 
58
                                + FSP_FLAGS_WIDTH_ZIP_SSIZE     \
 
59
                                + FSP_FLAGS_WIDTH_ATOMIC_BLOBS  \
 
60
                                + FSP_FLAGS_WIDTH_PAGE_SSIZE    \
 
61
                                + FSP_FLAGS_WIDTH_DATA_DIR)
 
62
 
 
63
/** A mask of all the known/used bits in tablespace flags */
 
64
#define FSP_FLAGS_MASK          (~(~0 << FSP_FLAGS_WIDTH))
 
65
 
 
66
/** Zero relative shift position of the POST_ANTELOPE field */
 
67
#define FSP_FLAGS_POS_POST_ANTELOPE     0
 
68
/** Zero relative shift position of the ZIP_SSIZE field */
 
69
#define FSP_FLAGS_POS_ZIP_SSIZE         (FSP_FLAGS_POS_POST_ANTELOPE    \
 
70
                                        + FSP_FLAGS_WIDTH_POST_ANTELOPE)
 
71
/** Zero relative shift position of the ATOMIC_BLOBS field */
 
72
#define FSP_FLAGS_POS_ATOMIC_BLOBS      (FSP_FLAGS_POS_ZIP_SSIZE        \
 
73
                                        + FSP_FLAGS_WIDTH_ZIP_SSIZE)
 
74
/** Zero relative shift position of the PAGE_SSIZE field */
 
75
#define FSP_FLAGS_POS_PAGE_SSIZE        (FSP_FLAGS_POS_ATOMIC_BLOBS     \
 
76
                                        + FSP_FLAGS_WIDTH_ATOMIC_BLOBS)
 
77
/** Zero relative shift position of the start of the UNUSED bits */
 
78
#define FSP_FLAGS_POS_DATA_DIR          (FSP_FLAGS_POS_PAGE_SSIZE       \
 
79
                                        + FSP_FLAGS_WIDTH_PAGE_SSIZE)
 
80
/** Zero relative shift position of the start of the UNUSED bits */
 
81
#define FSP_FLAGS_POS_UNUSED            (FSP_FLAGS_POS_DATA_DIR \
 
82
                                        + FSP_FLAGS_WIDTH_DATA_DIR)
 
83
 
 
84
/** Bit mask of the POST_ANTELOPE field */
 
85
#define FSP_FLAGS_MASK_POST_ANTELOPE                            \
 
86
                ((~(~0 << FSP_FLAGS_WIDTH_POST_ANTELOPE))       \
 
87
                << FSP_FLAGS_POS_POST_ANTELOPE)
 
88
/** Bit mask of the ZIP_SSIZE field */
 
89
#define FSP_FLAGS_MASK_ZIP_SSIZE                                \
 
90
                ((~(~0 << FSP_FLAGS_WIDTH_ZIP_SSIZE))           \
 
91
                << FSP_FLAGS_POS_ZIP_SSIZE)
 
92
/** Bit mask of the ATOMIC_BLOBS field */
 
93
#define FSP_FLAGS_MASK_ATOMIC_BLOBS                             \
 
94
                ((~(~0 << FSP_FLAGS_WIDTH_ATOMIC_BLOBS))        \
 
95
                << FSP_FLAGS_POS_ATOMIC_BLOBS)
 
96
/** Bit mask of the PAGE_SSIZE field */
 
97
#define FSP_FLAGS_MASK_PAGE_SSIZE                               \
 
98
                ((~(~0 << FSP_FLAGS_WIDTH_PAGE_SSIZE))          \
 
99
                << FSP_FLAGS_POS_PAGE_SSIZE)
 
100
/** Bit mask of the DATA_DIR field */
 
101
#define FSP_FLAGS_MASK_DATA_DIR                                 \
 
102
                ((~(~0 << FSP_FLAGS_WIDTH_DATA_DIR))            \
 
103
                << FSP_FLAGS_POS_DATA_DIR)
 
104
 
 
105
/** Return the value of the POST_ANTELOPE field */
 
106
#define FSP_FLAGS_GET_POST_ANTELOPE(flags)                      \
 
107
                ((flags & FSP_FLAGS_MASK_POST_ANTELOPE)         \
 
108
                >> FSP_FLAGS_POS_POST_ANTELOPE)
 
109
/** Return the value of the ZIP_SSIZE field */
 
110
#define FSP_FLAGS_GET_ZIP_SSIZE(flags)                          \
 
111
                ((flags & FSP_FLAGS_MASK_ZIP_SSIZE)             \
 
112
                >> FSP_FLAGS_POS_ZIP_SSIZE)
 
113
/** Return the value of the ATOMIC_BLOBS field */
 
114
#define FSP_FLAGS_HAS_ATOMIC_BLOBS(flags)                       \
 
115
                ((flags & FSP_FLAGS_MASK_ATOMIC_BLOBS)          \
 
116
                >> FSP_FLAGS_POS_ATOMIC_BLOBS)
 
117
/** Return the value of the PAGE_SSIZE field */
 
118
#define FSP_FLAGS_GET_PAGE_SSIZE(flags)                         \
 
119
                ((flags & FSP_FLAGS_MASK_PAGE_SSIZE)            \
 
120
                >> FSP_FLAGS_POS_PAGE_SSIZE)
 
121
/** Return the value of the DATA_DIR field */
 
122
#define FSP_FLAGS_HAS_DATA_DIR(flags)                           \
 
123
                ((flags & FSP_FLAGS_MASK_DATA_DIR)              \
 
124
                >> FSP_FLAGS_POS_DATA_DIR)
 
125
/** Return the contents of the UNUSED bits */
 
126
#define FSP_FLAGS_GET_UNUSED(flags)                             \
 
127
                (flags >> FSP_FLAGS_POS_UNUSED)
 
128
 
 
129
/** Set a PAGE_SSIZE into the correct bits in a given
 
130
tablespace flags. */
 
131
#define FSP_FLAGS_SET_PAGE_SSIZE(flags, ssize)                  \
 
132
                (flags | (ssize << FSP_FLAGS_POS_PAGE_SSIZE))
 
133
 
 
134
/* @} */
 
135
 
 
136
/* @defgroup Tablespace Header Constants (moved from fsp0fsp.c) @{ */
 
137
 
 
138
/** Offset of the space header within a file page */
 
139
#define FSP_HEADER_OFFSET       FIL_PAGE_DATA
 
140
 
 
141
/* The data structures in files are defined just as byte strings in C */
 
142
typedef byte    fsp_header_t;
 
143
typedef byte    xdes_t;
 
144
 
 
145
/*                      SPACE HEADER
 
146
                        ============
 
147
 
 
148
File space header data structure: this data structure is contained in the
 
149
first page of a space. The space for this header is reserved in every extent
 
150
descriptor page, but used only in the first. */
 
151
 
 
152
/*-------------------------------------*/
 
153
#define FSP_SPACE_ID            0       /* space id */
 
154
#define FSP_NOT_USED            4       /* this field contained a value up to
 
155
                                        which we know that the modifications
 
156
                                        in the database have been flushed to
 
157
                                        the file space; not used now */
 
158
#define FSP_SIZE                8       /* Current size of the space in
 
159
                                        pages */
 
160
#define FSP_FREE_LIMIT          12      /* Minimum page number for which the
 
161
                                        free list has not been initialized:
 
162
                                        the pages >= this limit are, by
 
163
                                        definition, free; note that in a
 
164
                                        single-table tablespace where size
 
165
                                        < 64 pages, this number is 64, i.e.,
 
166
                                        we have initialized the space
 
167
                                        about the first extent, but have not
 
168
                                        physically allocted those pages to the
 
169
                                        file */
 
170
#define FSP_SPACE_FLAGS         16      /* fsp_space_t.flags, similar to
 
171
                                        dict_table_t::flags */
 
172
#define FSP_FRAG_N_USED         20      /* number of used pages in the
 
173
                                        FSP_FREE_FRAG list */
 
174
#define FSP_FREE                24      /* list of free extents */
 
175
#define FSP_FREE_FRAG           (24 + FLST_BASE_NODE_SIZE)
 
176
                                        /* list of partially free extents not
 
177
                                        belonging to any segment */
 
178
#define FSP_FULL_FRAG           (24 + 2 * FLST_BASE_NODE_SIZE)
 
179
                                        /* list of full extents not belonging
 
180
                                        to any segment */
 
181
#define FSP_SEG_ID              (24 + 3 * FLST_BASE_NODE_SIZE)
 
182
                                        /* 8 bytes which give the first unused
 
183
                                        segment id */
 
184
#define FSP_SEG_INODES_FULL     (32 + 3 * FLST_BASE_NODE_SIZE)
 
185
                                        /* list of pages containing segment
 
186
                                        headers, where all the segment inode
 
187
                                        slots are reserved */
 
188
#define FSP_SEG_INODES_FREE     (32 + 4 * FLST_BASE_NODE_SIZE)
 
189
                                        /* list of pages containing segment
 
190
                                        headers, where not all the segment
 
191
                                        header slots are reserved */
 
192
/*-------------------------------------*/
 
193
/* File space header size */
 
194
#define FSP_HEADER_SIZE         (32 + 5 * FLST_BASE_NODE_SIZE)
 
195
 
 
196
#define FSP_FREE_ADD            4       /* this many free extents are added
 
197
                                        to the free list from above
 
198
                                        FSP_FREE_LIMIT at a time */
 
199
/* @} */
 
200
 
 
201
#ifndef UNIV_INNOCHECKSUM
 
202
 
 
203
/* @defgroup File Segment Inode Constants (moved from fsp0fsp.c) @{ */
 
204
 
 
205
/*                      FILE SEGMENT INODE
 
206
                        ==================
 
207
 
 
208
Segment inode which is created for each segment in a tablespace. NOTE: in
 
209
purge we assume that a segment having only one currently used page can be
 
210
freed in a few steps, so that the freeing cannot fill the file buffer with
 
211
bufferfixed file pages. */
 
212
 
 
213
typedef byte    fseg_inode_t;
 
214
 
 
215
#define FSEG_INODE_PAGE_NODE    FSEG_PAGE_DATA
 
216
                                        /* the list node for linking
 
217
                                        segment inode pages */
 
218
 
 
219
#define FSEG_ARR_OFFSET         (FSEG_PAGE_DATA + FLST_NODE_SIZE)
 
220
/*-------------------------------------*/
 
221
#define FSEG_ID                 0       /* 8 bytes of segment id: if this is 0,
 
222
                                        it means that the header is unused */
 
223
#define FSEG_NOT_FULL_N_USED    8
 
224
                                        /* number of used segment pages in
 
225
                                        the FSEG_NOT_FULL list */
 
226
#define FSEG_FREE               12
 
227
                                        /* list of free extents of this
 
228
                                        segment */
 
229
#define FSEG_NOT_FULL           (12 + FLST_BASE_NODE_SIZE)
 
230
                                        /* list of partially free extents */
 
231
#define FSEG_FULL               (12 + 2 * FLST_BASE_NODE_SIZE)
 
232
                                        /* list of full extents */
 
233
#define FSEG_MAGIC_N            (12 + 3 * FLST_BASE_NODE_SIZE)
 
234
                                        /* magic number used in debugging */
 
235
#define FSEG_FRAG_ARR           (16 + 3 * FLST_BASE_NODE_SIZE)
 
236
                                        /* array of individual pages
 
237
                                        belonging to this segment in fsp
 
238
                                        fragment extent lists */
 
239
#define FSEG_FRAG_ARR_N_SLOTS   (FSP_EXTENT_SIZE / 2)
 
240
                                        /* number of slots in the array for
 
241
                                        the fragment pages */
 
242
#define FSEG_FRAG_SLOT_SIZE     4       /* a fragment page slot contains its
 
243
                                        page number within space, FIL_NULL
 
244
                                        means that the slot is not in use */
 
245
/*-------------------------------------*/
 
246
#define FSEG_INODE_SIZE                                 \
 
247
        (16 + 3 * FLST_BASE_NODE_SIZE                   \
 
248
         + FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE)
 
249
 
 
250
#define FSP_SEG_INODES_PER_PAGE(zip_size)               \
 
251
        (((zip_size ? zip_size : UNIV_PAGE_SIZE)        \
 
252
          - FSEG_ARR_OFFSET - 10) / FSEG_INODE_SIZE)
 
253
                                /* Number of segment inodes which fit on a
 
254
                                single page */
 
255
 
 
256
#define FSEG_MAGIC_N_VALUE      97937874
 
257
 
 
258
#define FSEG_FILLFACTOR         8       /* If this value is x, then if
 
259
                                        the number of unused but reserved
 
260
                                        pages in a segment is less than
 
261
                                        reserved pages * 1/x, and there are
 
262
                                        at least FSEG_FRAG_LIMIT used pages,
 
263
                                        then we allow a new empty extent to
 
264
                                        be added to the segment in
 
265
                                        fseg_alloc_free_page. Otherwise, we
 
266
                                        use unused pages of the segment. */
 
267
 
 
268
#define FSEG_FRAG_LIMIT         FSEG_FRAG_ARR_N_SLOTS
 
269
                                        /* If the segment has >= this many
 
270
                                        used pages, it may be expanded by
 
271
                                        allocating extents to the segment;
 
272
                                        until that only individual fragment
 
273
                                        pages are allocated from the space */
 
274
 
 
275
#define FSEG_FREE_LIST_LIMIT    40      /* If the reserved size of a segment
 
276
                                        is at least this many extents, we
 
277
                                        allow extents to be put to the free
 
278
                                        list of the extent: at most
 
279
                                        FSEG_FREE_LIST_MAX_LEN many */
 
280
#define FSEG_FREE_LIST_MAX_LEN  4
 
281
/* @} */
 
282
 
 
283
/* @defgroup Extent Descriptor Constants (moved from fsp0fsp.c) @{ */
 
284
 
 
285
/*                      EXTENT DESCRIPTOR
 
286
                        =================
 
287
 
 
288
File extent descriptor data structure: contains bits to tell which pages in
 
289
the extent are free and which contain old tuple version to clean. */
 
290
 
 
291
/*-------------------------------------*/
 
292
#define XDES_ID                 0       /* The identifier of the segment
 
293
                                        to which this extent belongs */
 
294
#define XDES_FLST_NODE          8       /* The list node data structure
 
295
                                        for the descriptors */
 
296
#define XDES_STATE              (FLST_NODE_SIZE + 8)
 
297
                                        /* contains state information
 
298
                                        of the extent */
 
299
#define XDES_BITMAP             (FLST_NODE_SIZE + 12)
 
300
                                        /* Descriptor bitmap of the pages
 
301
                                        in the extent */
 
302
/*-------------------------------------*/
 
303
 
 
304
#define XDES_BITS_PER_PAGE      2       /* How many bits are there per page */
 
305
#define XDES_FREE_BIT           0       /* Index of the bit which tells if
 
306
                                        the page is free */
 
307
#define XDES_CLEAN_BIT          1       /* NOTE: currently not used!
 
308
                                        Index of the bit which tells if
 
309
                                        there are old versions of tuples
 
310
                                        on the page */
 
311
/* States of a descriptor */
 
312
#define XDES_FREE               1       /* extent is in free list of space */
 
313
#define XDES_FREE_FRAG          2       /* extent is in free fragment list of
 
314
                                        space */
 
315
#define XDES_FULL_FRAG          3       /* extent is in full fragment list of
 
316
                                        space */
 
317
#define XDES_FSEG               4       /* extent belongs to a segment */
 
318
 
 
319
/** File extent data structure size in bytes. */
 
320
#define XDES_SIZE                                                       \
 
321
        (XDES_BITMAP                                                    \
 
322
        + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
 
323
 
 
324
/** File extent data structure size in bytes for MAX page size. */
 
325
#define XDES_SIZE_MAX                                                   \
 
326
        (XDES_BITMAP                                                    \
 
327
        + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MAX * XDES_BITS_PER_PAGE))
 
328
 
 
329
/** File extent data structure size in bytes for MIN page size. */
 
330
#define XDES_SIZE_MIN                                                   \
 
331
        (XDES_BITMAP                                                    \
 
332
        + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MIN * XDES_BITS_PER_PAGE))
 
333
 
 
334
/** Offset of the descriptor array on a descriptor page */
 
335
#define XDES_ARR_OFFSET         (FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
 
336
 
 
337
/* @} */
 
338
 
 
339
/**********************************************************************//**
 
340
Initializes the file space system. */
 
341
UNIV_INTERN
 
342
void
 
343
fsp_init(void);
 
344
/*==========*/
 
345
/**********************************************************************//**
 
346
Gets the size of the system tablespace from the tablespace header.  If
 
347
we do not have an auto-extending data file, this should be equal to
 
348
the size of the data files.  If there is an auto-extending data file,
 
349
this can be smaller.
 
350
@return size in pages */
 
351
UNIV_INTERN
 
352
ulint
 
353
fsp_header_get_tablespace_size(void);
 
354
/*================================*/
 
355
/**********************************************************************//**
 
356
Reads the file space size stored in the header page.
 
357
@return tablespace size stored in the space header */
 
358
UNIV_INTERN
 
359
ulint
 
360
fsp_get_size_low(
 
361
/*=============*/
 
362
        page_t* page);  /*!< in: header page (page 0 in the tablespace) */
 
363
/**********************************************************************//**
 
364
Reads the space id from the first page of a tablespace.
 
365
@return space id, ULINT UNDEFINED if error */
 
366
UNIV_INTERN
 
367
ulint
 
368
fsp_header_get_space_id(
 
369
/*====================*/
 
370
        const page_t*   page);  /*!< in: first page of a tablespace */
 
371
/**********************************************************************//**
 
372
Reads the space flags from the first page of a tablespace.
 
373
@return flags */
 
374
UNIV_INTERN
 
375
ulint
 
376
fsp_header_get_flags(
 
377
/*=================*/
 
378
        const page_t*   page);  /*!< in: first page of a tablespace */
 
379
/**********************************************************************//**
 
380
Reads the compressed page size from the first page of a tablespace.
 
381
@return compressed page size in bytes, or 0 if uncompressed */
 
382
UNIV_INTERN
 
383
ulint
 
384
fsp_header_get_zip_size(
 
385
/*====================*/
 
386
        const page_t*   page);  /*!< in: first page of a tablespace */
 
387
/**********************************************************************//**
 
388
Writes the space id and flags to a tablespace header.  The flags contain
 
389
row type, physical/compressed page size, and logical/uncompressed page
 
390
size of the tablespace. */
 
391
UNIV_INTERN
 
392
void
 
393
fsp_header_init_fields(
 
394
/*===================*/
 
395
        page_t* page,           /*!< in/out: first page in the space */
 
396
        ulint   space_id,       /*!< in: space id */
 
397
        ulint   flags);         /*!< in: tablespace flags (FSP_SPACE_FLAGS):
 
398
                                0, or table->flags if newer than COMPACT */
 
399
/**********************************************************************//**
 
400
Initializes the space header of a new created space and creates also the
 
401
insert buffer tree root if space == 0. */
 
402
UNIV_INTERN
 
403
void
 
404
fsp_header_init(
 
405
/*============*/
 
406
        ulint   space,          /*!< in: space id */
 
407
        ulint   size,           /*!< in: current size in blocks */
 
408
        mtr_t*  mtr);           /*!< in/out: mini-transaction */
 
409
/**********************************************************************//**
 
410
Increases the space size field of a space. */
 
411
UNIV_INTERN
 
412
void
 
413
fsp_header_inc_size(
 
414
/*================*/
 
415
        ulint   space,          /*!< in: space id */
 
416
        ulint   size_inc,       /*!< in: size increment in pages */
 
417
        mtr_t*  mtr);           /*!< in/out: mini-transaction */
 
418
/**********************************************************************//**
 
419
Creates a new segment.
 
420
@return the block where the segment header is placed, x-latched, NULL
 
421
if could not create segment because of lack of space */
 
422
UNIV_INTERN
 
423
buf_block_t*
 
424
fseg_create(
 
425
/*========*/
 
426
        ulint   space,  /*!< in: space id */
 
427
        ulint   page,   /*!< in: page where the segment header is placed: if
 
428
                        this is != 0, the page must belong to another segment,
 
429
                        if this is 0, a new page will be allocated and it
 
430
                        will belong to the created segment */
 
431
        ulint   byte_offset, /*!< in: byte offset of the created segment header
 
432
                        on the page */
 
433
        mtr_t*  mtr);   /*!< in/out: mini-transaction */
 
434
/**********************************************************************//**
 
435
Creates a new segment.
 
436
@return the block where the segment header is placed, x-latched, NULL
 
437
if could not create segment because of lack of space */
 
438
UNIV_INTERN
 
439
buf_block_t*
 
440
fseg_create_general(
 
441
/*================*/
 
442
        ulint   space,  /*!< in: space id */
 
443
        ulint   page,   /*!< in: page where the segment header is placed: if
 
444
                        this is != 0, the page must belong to another segment,
 
445
                        if this is 0, a new page will be allocated and it
 
446
                        will belong to the created segment */
 
447
        ulint   byte_offset, /*!< in: byte offset of the created segment header
 
448
                        on the page */
 
449
        ibool   has_done_reservation, /*!< in: TRUE if the caller has already
 
450
                        done the reservation for the pages with
 
451
                        fsp_reserve_free_extents (at least 2 extents: one for
 
452
                        the inode and the other for the segment) then there is
 
453
                        no need to do the check for this individual
 
454
                        operation */
 
455
        mtr_t*  mtr);   /*!< in/out: mini-transaction */
 
456
/**********************************************************************//**
 
457
Calculates the number of pages reserved by a segment, and how many pages are
 
458
currently used.
 
459
@return number of reserved pages */
 
460
UNIV_INTERN
 
461
ulint
 
462
fseg_n_reserved_pages(
 
463
/*==================*/
 
464
        fseg_header_t*  header, /*!< in: segment header */
 
465
        ulint*          used,   /*!< out: number of pages used (<= reserved) */
 
466
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
467
/**********************************************************************//**
 
468
Allocates a single free page from a segment. This function implements
 
469
the intelligent allocation strategy which tries to minimize
 
470
file space fragmentation.
 
471
@param[in/out] seg_header       segment header
 
472
@param[in] hint                 hint of which page would be desirable
 
473
@param[in] direction            if the new page is needed because
 
474
                                of an index page split, and records are
 
475
                                inserted there in order, into which
 
476
                                direction they go alphabetically: FSP_DOWN,
 
477
                                FSP_UP, FSP_NO_DIR
 
478
@param[in/out] mtr              mini-transaction
 
479
@return X-latched block, or NULL if no page could be allocated */
 
480
#define fseg_alloc_free_page(seg_header, hint, direction, mtr)          \
 
481
        fseg_alloc_free_page_general(seg_header, hint, direction,       \
 
482
                                     FALSE, mtr, mtr)
 
483
/**********************************************************************//**
 
484
Allocates a single free page from a segment. This function implements
 
485
the intelligent allocation strategy which tries to minimize file space
 
486
fragmentation.
 
487
@retval NULL if no page could be allocated
 
488
@retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded
 
489
(init_mtr == mtr, or the page was not previously freed in mtr)
 
490
@retval block (not allocated or initialized) otherwise */
 
491
UNIV_INTERN
 
492
buf_block_t*
 
493
fseg_alloc_free_page_general(
 
494
/*=========================*/
 
495
        fseg_header_t*  seg_header,/*!< in/out: segment header */
 
496
        ulint           hint,   /*!< in: hint of which page would be
 
497
                                desirable */
 
498
        byte            direction,/*!< in: if the new page is needed because
 
499
                                of an index page split, and records are
 
500
                                inserted there in order, into which
 
501
                                direction they go alphabetically: FSP_DOWN,
 
502
                                FSP_UP, FSP_NO_DIR */
 
503
        ibool           has_done_reservation, /*!< in: TRUE if the caller has
 
504
                                already done the reservation for the page
 
505
                                with fsp_reserve_free_extents, then there
 
506
                                is no need to do the check for this individual
 
507
                                page */
 
508
        mtr_t*          mtr,    /*!< in/out: mini-transaction */
 
509
        mtr_t*          init_mtr)/*!< in/out: mtr or another mini-transaction
 
510
                                in which the page should be initialized.
 
511
                                If init_mtr!=mtr, but the page is already
 
512
                                latched in mtr, do not initialize the page. */
 
513
        __attribute__((warn_unused_result, nonnull));
 
514
/**********************************************************************//**
 
515
Reserves free pages from a tablespace. All mini-transactions which may
 
516
use several pages from the tablespace should call this function beforehand
 
517
and reserve enough free extents so that they certainly will be able
 
518
to do their operation, like a B-tree page split, fully. Reservations
 
519
must be released with function fil_space_release_free_extents!
 
520
 
 
521
The alloc_type below has the following meaning: FSP_NORMAL means an
 
522
operation which will probably result in more space usage, like an
 
523
insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
 
524
deleting rows, then this allocation will in the long run result in
 
525
less space usage (after a purge); FSP_CLEANING means allocation done
 
526
in a physical record delete (like in a purge) or other cleaning operation
 
527
which will result in less space usage in the long run. We prefer the latter
 
528
two types of allocation: when space is scarce, FSP_NORMAL allocations
 
529
will not succeed, but the latter two allocations will succeed, if possible.
 
530
The purpose is to avoid dead end where the database is full but the
 
531
user cannot free any space because these freeing operations temporarily
 
532
reserve some space.
 
533
 
 
534
Single-table tablespaces whose size is < 32 pages are a special case. In this
 
535
function we would liberally reserve several 64 page extents for every page
 
536
split or merge in a B-tree. But we do not want to waste disk space if the table
 
537
only occupies < 32 pages. That is why we apply different rules in that special
 
538
case, just ensuring that there are 3 free pages available.
 
539
@return TRUE if we were able to make the reservation */
 
540
UNIV_INTERN
 
541
ibool
 
542
fsp_reserve_free_extents(
 
543
/*=====================*/
 
544
        ulint*  n_reserved,/*!< out: number of extents actually reserved; if we
 
545
                        return TRUE and the tablespace size is < 64 pages,
 
546
                        then this can be 0, otherwise it is n_ext */
 
547
        ulint   space,  /*!< in: space id */
 
548
        ulint   n_ext,  /*!< in: number of extents to reserve */
 
549
        ulint   alloc_type,/*!< in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */
 
550
        mtr_t*  mtr);   /*!< in: mini-transaction */
 
551
/**********************************************************************//**
 
552
This function should be used to get information on how much we still
 
553
will be able to insert new data to the database without running out the
 
554
tablespace. Only free extents are taken into account and we also subtract
 
555
the safety margin required by the above function fsp_reserve_free_extents.
 
556
@return available space in kB */
 
557
UNIV_INTERN
 
558
ullint
 
559
fsp_get_available_space_in_free_extents(
 
560
/*====================================*/
 
561
        ulint   space); /*!< in: space id */
 
562
/**********************************************************************//**
 
563
Frees a single page of a segment. */
 
564
UNIV_INTERN
 
565
void
 
566
fseg_free_page(
 
567
/*===========*/
 
568
        fseg_header_t*  seg_header, /*!< in: segment header */
 
569
        ulint           space,  /*!< in: space id */
 
570
        ulint           page,   /*!< in: page offset */
 
571
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
572
/**********************************************************************//**
 
573
Checks if a single page of a segment is free.
 
574
@return true if free */
 
575
UNIV_INTERN
 
576
bool
 
577
fseg_page_is_free(
 
578
/*==============*/
 
579
        fseg_header_t*  seg_header,     /*!< in: segment header */
 
580
        ulint           space,          /*!< in: space id */
 
581
        ulint           page)           /*!< in: page offset */
 
582
        __attribute__((nonnull, warn_unused_result));
 
583
/**********************************************************************//**
 
584
Frees part of a segment. This function can be used to free a segment
 
585
by repeatedly calling this function in different mini-transactions.
 
586
Doing the freeing in a single mini-transaction might result in
 
587
too big a mini-transaction.
 
588
@return TRUE if freeing completed */
 
589
UNIV_INTERN
 
590
ibool
 
591
fseg_free_step(
 
592
/*===========*/
 
593
        fseg_header_t*  header, /*!< in, own: segment header; NOTE: if the header
 
594
                                resides on the first page of the frag list
 
595
                                of the segment, this pointer becomes obsolete
 
596
                                after the last freeing step */
 
597
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
598
/**********************************************************************//**
 
599
Frees part of a segment. Differs from fseg_free_step because this function
 
600
leaves the header page unfreed.
 
601
@return TRUE if freeing completed, except the header page */
 
602
UNIV_INTERN
 
603
ibool
 
604
fseg_free_step_not_header(
 
605
/*======================*/
 
606
        fseg_header_t*  header, /*!< in: segment header which must reside on
 
607
                                the first fragment page of the segment */
 
608
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
609
/***********************************************************************//**
 
610
Checks if a page address is an extent descriptor page address.
 
611
@return TRUE if a descriptor page */
 
612
UNIV_INLINE
 
613
ibool
 
614
fsp_descr_page(
 
615
/*===========*/
 
616
        ulint   zip_size,/*!< in: compressed page size in bytes;
 
617
                        0 for uncompressed pages */
 
618
        ulint   page_no);/*!< in: page number */
 
619
/***********************************************************//**
 
620
Parses a redo log record of a file page init.
 
621
@return end of log record or NULL */
 
622
UNIV_INTERN
 
623
byte*
 
624
fsp_parse_init_file_page(
 
625
/*=====================*/
 
626
        byte*           ptr,    /*!< in: buffer */
 
627
        byte*           end_ptr, /*!< in: buffer end */
 
628
        buf_block_t*    block); /*!< in: block or NULL */
 
629
/*******************************************************************//**
 
630
Validates the file space system and its segments.
 
631
@return TRUE if ok */
 
632
UNIV_INTERN
 
633
ibool
 
634
fsp_validate(
 
635
/*=========*/
 
636
        ulint   space); /*!< in: space id */
 
637
/*******************************************************************//**
 
638
Prints info of a file space. */
 
639
UNIV_INTERN
 
640
void
 
641
fsp_print(
 
642
/*======*/
 
643
        ulint   space); /*!< in: space id */
 
644
#ifdef UNIV_DEBUG
 
645
/*******************************************************************//**
 
646
Validates a segment.
 
647
@return TRUE if ok */
 
648
UNIV_INTERN
 
649
ibool
 
650
fseg_validate(
 
651
/*==========*/
 
652
        fseg_header_t*  header, /*!< in: segment header */
 
653
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
654
#endif /* UNIV_DEBUG */
 
655
#ifdef UNIV_BTR_PRINT
 
656
/*******************************************************************//**
 
657
Writes info of a segment. */
 
658
UNIV_INTERN
 
659
void
 
660
fseg_print(
 
661
/*=======*/
 
662
        fseg_header_t*  header, /*!< in: segment header */
 
663
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
664
#endif /* UNIV_BTR_PRINT */
 
665
 
 
666
/********************************************************************//**
 
667
Validate and return the tablespace flags, which are stored in the
 
668
tablespace header at offset FSP_SPACE_FLAGS.  They should be 0 for
 
669
ROW_FORMAT=COMPACT and ROW_FORMAT=REDUNDANT. The newer row formats,
 
670
COMPRESSED and DYNAMIC, use a file format > Antelope so they should
 
671
have a file format number plus the DICT_TF_COMPACT bit set.
 
672
@return true if check ok */
 
673
UNIV_INLINE
 
674
bool
 
675
fsp_flags_is_valid(
 
676
/*===============*/
 
677
        ulint   flags)          /*!< in: tablespace flags */
 
678
        __attribute__((warn_unused_result, const));
 
679
/********************************************************************//**
 
680
Determine if the tablespace is compressed from dict_table_t::flags.
 
681
@return TRUE if compressed, FALSE if not compressed */
 
682
UNIV_INLINE
 
683
ibool
 
684
fsp_flags_is_compressed(
 
685
/*====================*/
 
686
        ulint   flags); /*!< in: tablespace flags */
 
687
 
 
688
/********************************************************************//**
 
689
Calculates the descriptor index within a descriptor page.
 
690
@return descriptor index */
 
691
UNIV_INLINE
 
692
ulint
 
693
xdes_calc_descriptor_index(
 
694
/*=======================*/
 
695
        ulint   zip_size,       /*!< in: compressed page size in bytes;
 
696
                                0 for uncompressed pages */
 
697
        ulint   offset);        /*!< in: page offset */
 
698
 
 
699
/**********************************************************************//**
 
700
Gets a descriptor bit of a page.
 
701
@return TRUE if free */
 
702
UNIV_INLINE
 
703
ibool
 
704
xdes_get_bit(
 
705
/*=========*/
 
706
        const xdes_t*   descr,  /*!< in: descriptor */
 
707
        ulint           bit,    /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
 
708
        ulint           offset);/*!< in: page offset within extent:
 
709
                                0 ... FSP_EXTENT_SIZE - 1 */
 
710
 
 
711
/********************************************************************//**
 
712
Calculates the page where the descriptor of a page resides.
 
713
@return descriptor page offset */
 
714
UNIV_INLINE
 
715
ulint
 
716
xdes_calc_descriptor_page(
 
717
/*======================*/
 
718
        ulint   zip_size,       /*!< in: compressed page size in bytes;
 
719
                                0 for uncompressed pages */
 
720
        ulint   offset);        /*!< in: page offset */
 
721
 
 
722
#endif /* !UNIV_INNOCHECKSUM */
 
723
 
 
724
/********************************************************************//**
 
725
Extract the zip size from tablespace flags.  A tablespace has only one
 
726
physical page size whether that page is compressed or not.
 
727
@return compressed page size of the file-per-table tablespace in bytes,
 
728
or zero if the table is not compressed.  */
 
729
UNIV_INLINE
 
730
ulint
 
731
fsp_flags_get_zip_size(
 
732
/*====================*/
 
733
        ulint   flags);         /*!< in: tablespace flags */
 
734
/********************************************************************//**
 
735
Extract the page size from tablespace flags.
 
736
@return page size of the tablespace in bytes */
 
737
UNIV_INLINE
 
738
ulint
 
739
fsp_flags_get_page_size(
 
740
/*====================*/
 
741
        ulint   flags);         /*!< in: tablespace flags */
 
742
 
 
743
#ifndef UNIV_NONINL
 
744
#include "fsp0fsp.ic"
 
745
#endif
 
746
 
 
747
#endif