InnoDB Plugin  1.0
fsp0fsp.h
Go to the documentation of this file.
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 /**************************************************/
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 
44 #define FSP_FLAGS_WIDTH_POST_ANTELOPE 1
45 
46 #define FSP_FLAGS_WIDTH_ZIP_SSIZE 4
47 
50 #define FSP_FLAGS_WIDTH_ATOMIC_BLOBS 1
51 
52 #define FSP_FLAGS_WIDTH_PAGE_SSIZE 4
53 
55 #define FSP_FLAGS_WIDTH_DATA_DIR 1
56 
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 
64 #define FSP_FLAGS_MASK (~(~0 << FSP_FLAGS_WIDTH))
65 
67 #define FSP_FLAGS_POS_POST_ANTELOPE 0
68 
69 #define FSP_FLAGS_POS_ZIP_SSIZE (FSP_FLAGS_POS_POST_ANTELOPE \
70  + FSP_FLAGS_WIDTH_POST_ANTELOPE)
71 
72 #define FSP_FLAGS_POS_ATOMIC_BLOBS (FSP_FLAGS_POS_ZIP_SSIZE \
73  + FSP_FLAGS_WIDTH_ZIP_SSIZE)
74 
75 #define FSP_FLAGS_POS_PAGE_SSIZE (FSP_FLAGS_POS_ATOMIC_BLOBS \
76  + FSP_FLAGS_WIDTH_ATOMIC_BLOBS)
77 
78 #define FSP_FLAGS_POS_DATA_DIR (FSP_FLAGS_POS_PAGE_SSIZE \
79  + FSP_FLAGS_WIDTH_PAGE_SSIZE)
80 
81 #define FSP_FLAGS_POS_UNUSED (FSP_FLAGS_POS_DATA_DIR \
82  + FSP_FLAGS_WIDTH_DATA_DIR)
83 
85 #define FSP_FLAGS_MASK_POST_ANTELOPE \
86  ((~(~0 << FSP_FLAGS_WIDTH_POST_ANTELOPE)) \
87  << FSP_FLAGS_POS_POST_ANTELOPE)
88 
89 #define FSP_FLAGS_MASK_ZIP_SSIZE \
90  ((~(~0 << FSP_FLAGS_WIDTH_ZIP_SSIZE)) \
91  << FSP_FLAGS_POS_ZIP_SSIZE)
92 
93 #define FSP_FLAGS_MASK_ATOMIC_BLOBS \
94  ((~(~0 << FSP_FLAGS_WIDTH_ATOMIC_BLOBS)) \
95  << FSP_FLAGS_POS_ATOMIC_BLOBS)
96 
97 #define FSP_FLAGS_MASK_PAGE_SSIZE \
98  ((~(~0 << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \
99  << FSP_FLAGS_POS_PAGE_SSIZE)
100 
101 #define FSP_FLAGS_MASK_DATA_DIR \
102  ((~(~0 << FSP_FLAGS_WIDTH_DATA_DIR)) \
103  << FSP_FLAGS_POS_DATA_DIR)
104 
106 #define FSP_FLAGS_GET_POST_ANTELOPE(flags) \
107  ((flags & FSP_FLAGS_MASK_POST_ANTELOPE) \
108  >> FSP_FLAGS_POS_POST_ANTELOPE)
109 
110 #define FSP_FLAGS_GET_ZIP_SSIZE(flags) \
111  ((flags & FSP_FLAGS_MASK_ZIP_SSIZE) \
112  >> FSP_FLAGS_POS_ZIP_SSIZE)
113 
114 #define FSP_FLAGS_HAS_ATOMIC_BLOBS(flags) \
115  ((flags & FSP_FLAGS_MASK_ATOMIC_BLOBS) \
116  >> FSP_FLAGS_POS_ATOMIC_BLOBS)
117 
118 #define FSP_FLAGS_GET_PAGE_SSIZE(flags) \
119  ((flags & FSP_FLAGS_MASK_PAGE_SSIZE) \
120  >> FSP_FLAGS_POS_PAGE_SSIZE)
121 
122 #define FSP_FLAGS_HAS_DATA_DIR(flags) \
123  ((flags & FSP_FLAGS_MASK_DATA_DIR) \
124  >> FSP_FLAGS_POS_DATA_DIR)
125 
126 #define FSP_FLAGS_GET_UNUSED(flags) \
127  (flags >> FSP_FLAGS_POS_UNUSED)
128 
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 
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. */
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 
320 #define XDES_SIZE \
321  (XDES_BITMAP \
322  + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
323 
325 #define XDES_SIZE_MAX \
326  (XDES_BITMAP \
327  + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MAX * XDES_BITS_PER_PAGE))
328 
330 #define XDES_SIZE_MIN \
331  (XDES_BITMAP \
332  + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE_MIN * XDES_BITS_PER_PAGE))
333 
335 #define XDES_ARR_OFFSET (FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
336 
337 /* @} */
338 
339 /**********************************************************************/
341 UNIV_INTERN
342 void
343 fsp_init(void);
344 /*==========*/
345 /**********************************************************************/
351 UNIV_INTERN
352 ulint
354 /*================================*/
355 /**********************************************************************/
358 UNIV_INTERN
359 ulint
361 /*=============*/
362  page_t* page);
363 /**********************************************************************/
366 UNIV_INTERN
367 ulint
369 /*====================*/
370  const page_t* page);
371 /**********************************************************************/
374 UNIV_INTERN
375 ulint
377 /*=================*/
378  const page_t* page);
379 /**********************************************************************/
382 UNIV_INTERN
383 ulint
385 /*====================*/
386  const page_t* page);
387 /**********************************************************************/
391 UNIV_INTERN
392 void
394 /*===================*/
395  page_t* page,
396  ulint space_id,
397  ulint flags);
399 /**********************************************************************/
402 UNIV_INTERN
403 void
405 /*============*/
406  ulint space,
407  ulint size,
408  mtr_t* mtr);
409 /**********************************************************************/
411 UNIV_INTERN
412 void
414 /*================*/
415  ulint space,
416  ulint size_inc,
417  mtr_t* mtr);
418 /**********************************************************************/
422 UNIV_INTERN
425 /*========*/
426  ulint space,
427  ulint page,
431  ulint byte_offset,
433  mtr_t* mtr);
434 /**********************************************************************/
438 UNIV_INTERN
441 /*================*/
442  ulint space,
443  ulint page,
447  ulint byte_offset,
449  ibool has_done_reservation,
455  mtr_t* mtr);
456 /**********************************************************************/
460 UNIV_INTERN
461 ulint
463 /*==================*/
464  fseg_header_t* header,
465  ulint* used,
466  mtr_t* mtr);
467 /**********************************************************************/
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 /**********************************************************************/
491 UNIV_INTERN
494 /*=========================*/
495  fseg_header_t* seg_header,
496  ulint hint,
498  byte direction,
503  ibool has_done_reservation,
508  mtr_t* mtr,
509  mtr_t* init_mtr)
513  __attribute__((warn_unused_result, nonnull));
514 /**********************************************************************/
540 UNIV_INTERN
541 ibool
543 /*=====================*/
544  ulint* n_reserved,
547  ulint space,
548  ulint n_ext,
549  ulint alloc_type,
550  mtr_t* mtr);
551 /**********************************************************************/
557 UNIV_INTERN
558 ullint
560 /*====================================*/
561  ulint space);
562 /**********************************************************************/
564 UNIV_INTERN
565 void
567 /*===========*/
568  fseg_header_t* seg_header,
569  ulint space,
570  ulint page,
571  mtr_t* mtr);
572 /**********************************************************************/
575 UNIV_INTERN
576 bool
578 /*==============*/
579  fseg_header_t* seg_header,
580  ulint space,
581  ulint page)
582  __attribute__((nonnull, warn_unused_result));
583 /**********************************************************************/
589 UNIV_INTERN
590 ibool
592 /*===========*/
593  fseg_header_t* header,
597  mtr_t* mtr);
598 /**********************************************************************/
602 UNIV_INTERN
603 ibool
605 /*======================*/
606  fseg_header_t* header,
608  mtr_t* mtr);
609 /***********************************************************************/
612 UNIV_INLINE
613 ibool
615 /*===========*/
616  ulint zip_size,
618  ulint page_no);
619 /***********************************************************/
622 UNIV_INTERN
623 byte*
625 /*=====================*/
626  byte* ptr,
627  byte* end_ptr,
628  buf_block_t* block);
629 /*******************************************************************/
632 UNIV_INTERN
633 ibool
635 /*=========*/
636  ulint space);
637 /*******************************************************************/
639 UNIV_INTERN
640 void
641 fsp_print(
642 /*======*/
643  ulint space);
644 #ifdef UNIV_DEBUG
645 /*******************************************************************/
648 UNIV_INTERN
649 ibool
651 /*==========*/
652  fseg_header_t* header,
653  mtr_t* mtr);
654 #endif /* UNIV_DEBUG */
655 #ifdef UNIV_BTR_PRINT
656 /*******************************************************************/
658 UNIV_INTERN
659 void
660 fseg_print(
661 /*=======*/
662  fseg_header_t* header,
663  mtr_t* mtr);
664 #endif /* UNIV_BTR_PRINT */
665 
666 /********************************************************************/
673 UNIV_INLINE
674 bool
676 /*===============*/
677  ulint flags)
678  __attribute__((warn_unused_result, const));
679 /********************************************************************/
682 UNIV_INLINE
683 ibool
685 /*====================*/
686  ulint flags);
688 /********************************************************************/
691 UNIV_INLINE
692 ulint
694 /*=======================*/
695  ulint zip_size,
697  ulint offset);
699 /**********************************************************************/
702 UNIV_INLINE
703 ibool
705 /*=========*/
706  const xdes_t* descr,
707  ulint bit,
708  ulint offset);
711 /********************************************************************/
714 UNIV_INLINE
715 ulint
717 /*======================*/
718  ulint zip_size,
720  ulint offset);
722 #endif /* !UNIV_INNOCHECKSUM */
723 
724 /********************************************************************/
729 UNIV_INLINE
730 ulint
732 /*====================*/
733  ulint flags);
734 /********************************************************************/
737 UNIV_INLINE
738 ulint
740 /*====================*/
741  ulint flags);
743 #ifndef UNIV_NONINL
744 #include "fsp0fsp.ic"
745 #endif
746 
747 #endif