InnoDB Plugin  1.0
fil0fil.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2014, 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 fil0fil_h
27 #define fil0fil_h
28 
29 #include "univ.i"
30 
31 #ifndef UNIV_INNOCHECKSUM
32 
33 #include "dict0types.h"
34 #include "ut0byte.h"
35 #include "os0file.h"
36 #ifndef UNIV_HOTBACKUP
37 #include "sync0rw.h"
38 #include "ibuf0types.h"
39 #include "log0log.h"
40 #endif /* !UNIV_HOTBACKUP */
41 
42 #include <list>
43 
44 extern my_bool lower_case_file_system;
45 // Forward declaration
46 struct trx_t;
47 struct fil_space_t;
48 
49 typedef std::list<const char*> space_name_list_t;
50 
54 extern const char* fil_path_to_mysql_datadir;
55 
57 #define FIL_IBD_FILE_INITIAL_SIZE 4
58 
60 #define FIL_NULL ULINT32_UNDEFINED
61 
62 /* Space address data type; this is intended to be used when
63 addresses accurate to a byte are stored in file pages. If the page part
64 of the address is FIL_NULL, the address is considered undefined. */
65 
66 typedef byte fil_faddr_t;
68 #define FIL_ADDR_PAGE 0 /* first in address is the page offset */
69 #define FIL_ADDR_BYTE 4 /* then comes 2-byte byte offset within page*/
70 
71 #define FIL_ADDR_SIZE 6 /* address size is 6 bytes */
72 
74 struct fil_addr_t{
75  ulint page;
76  ulint boffset;
77 };
78 
81 
82 #endif /* !UNIV_INNOCHECKSUM */
83 
85 #define FIL_PAGE_SPACE_OR_CHKSUM 0
89 #define FIL_PAGE_OFFSET 4
90 #define FIL_PAGE_PREV 8
97 #define FIL_PAGE_NEXT 12
107 #define FIL_PAGE_LSN 16
109 #define FIL_PAGE_TYPE 24
124 #define FIL_PAGE_FILE_FLUSH_LSN 26
129 #define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID 34
131 #define FIL_PAGE_SPACE_ID FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID
132 
133 #define FIL_PAGE_DATA 38
134 /* @} */
135 
136 #define FIL_PAGE_END_LSN_OLD_CHKSUM 8
140 #define FIL_PAGE_DATA_END 8
141 /* @} */
142 
143 #ifndef UNIV_INNOCHECKSUM
144 
146 #define FIL_PAGE_INDEX 17855
147 #define FIL_PAGE_UNDO_LOG 2
148 #define FIL_PAGE_INODE 3
149 #define FIL_PAGE_IBUF_FREE_LIST 4
150 /* File page types introduced in MySQL/InnoDB 5.1.7 */
151 #define FIL_PAGE_TYPE_ALLOCATED 0
152 #define FIL_PAGE_IBUF_BITMAP 5
153 #define FIL_PAGE_TYPE_SYS 6
154 #define FIL_PAGE_TYPE_TRX_SYS 7
155 #define FIL_PAGE_TYPE_FSP_HDR 8
156 #define FIL_PAGE_TYPE_XDES 9
157 #define FIL_PAGE_TYPE_BLOB 10
158 #define FIL_PAGE_TYPE_ZBLOB 11
159 #define FIL_PAGE_TYPE_ZBLOB2 12
160 #define FIL_PAGE_TYPE_LAST FIL_PAGE_TYPE_ZBLOB2
161 
162 /* @} */
163 
165 #define FIL_TABLESPACE 501
166 #define FIL_LOG 502
167 /* @} */
168 
170 extern ulint fil_n_log_flushes;
171 
173 extern ulint fil_n_pending_log_flushes;
176 
178 extern ulint fil_n_file_opened;
179 
182  const char* check_msg;
185  char* filepath;
186  lsn_t lsn;
187  ulint id;
188  ulint flags;
189 #ifdef UNIV_LOG_ARCHIVE
190  ulint arch_log_no;
191 #endif /* UNIV_LOG_ARCHIVE */
192 };
193 
194 #ifndef UNIV_HOTBACKUP
195 /*******************************************************************/
199 UNIV_INTERN
200 ib_int64_t
202 /*==================*/
203  ulint id);
204 /*******************************************************************/
207 UNIV_INTERN
208 rw_lock_t*
210 /*================*/
211  ulint id,
212  ulint* zip_size);
214 /*******************************************************************/
217 UNIV_INTERN
218 ulint
220 /*===============*/
221  ulint id);
222 #endif /* !UNIV_HOTBACKUP */
223 /*******************************************************************/
226 UNIV_INTERN
227 char*
229 /*============*/
230  const char* name,
231  ulint size,
233  ulint id,
234  ibool is_raw)
236  __attribute__((nonnull, warn_unused_result));
237 #ifdef UNIV_LOG_ARCHIVE
238 /****************************************************************/
241 UNIV_INTERN
242 void
243 fil_space_truncate_start(
244 /*=====================*/
245  ulint id,
246  ulint trunc_len);
249 #endif /* UNIV_LOG_ARCHIVE */
250 /*******************************************************************/
254 UNIV_INTERN
255 ibool
257 /*=============*/
258  const char* name,
259  ulint id,
260  ulint zip_size,
262  ulint purpose);
263 /*******************************************************************/
268 UNIV_INTERN
269 ibool
271 /*====================*/
272  ulint* space_id);
273 /*******************************************************************/
278 UNIV_INTERN
279 char*
281 /*=====================*/
282  ulint id);
283 /*******************************************************************/
287 UNIV_INTERN
288 ulint
290 /*===============*/
291  ulint id);
292 /*******************************************************************/
296 UNIV_INTERN
297 ulint
299 /*================*/
300  ulint id);
301 /*******************************************************************/
305 UNIV_INTERN
306 ulint
308 /*===================*/
309  ulint id);
310 /*******************************************************************/
314 UNIV_INTERN
315 ibool
317 /*===========================*/
318  ulint id,
319  ulint page_no);
320 /****************************************************************/
322 UNIV_INTERN
323 void
324 fil_init(
325 /*=====*/
326  ulint hash_size,
327  ulint max_n_open);
328 /*******************************************************************/
330 UNIV_INTERN
331 void
332 fil_close(void);
333 /*===========*/
334 /*******************************************************************/
340 UNIV_INTERN
341 void
343 /*==========================================*/
344 /*******************************************************************/
347 UNIV_INTERN
348 void
349 fil_close_all_files(void);
350 /*=====================*/
351 /*******************************************************************/
354 UNIV_INTERN
355 void
357 /*================*/
358  bool free);
359 /*******************************************************************/
362 UNIV_INTERN
363 void
365 /*===========================*/
366  ulint max_id);
367 #ifndef UNIV_HOTBACKUP
368 /****************************************************************/
372 UNIV_INTERN
373 dberr_t
375 /*================================*/
376  lsn_t lsn,
377  ulint arch_log_no);
378 /*******************************************************************/
383 UNIV_INTERN
384 const char*
386 /*================*/
387  os_file_t data_file,
388  ibool one_read_already,
391  ulint* flags,
392  ulint* space_id,
393 #ifdef UNIV_LOG_ARCHIVE
394  ulint* min_arch_log_no,
396  ulint* max_arch_log_no,
398 #endif /* UNIV_LOG_ARCHIVE */
399  lsn_t* min_flushed_lsn,
401  lsn_t* max_flushed_lsn)
403  __attribute__((warn_unused_result));
404 /*******************************************************************/
407 UNIV_INTERN
408 ibool
410 /*================*/
411  ulint id,
412  ibool print_err);
413 /*******************************************************************/
415 UNIV_INTERN
416 void
418 /*=================*/
419  ulint id);
420 #endif /* !UNIV_HOTBACKUP */
421 /*******************************************************************/
435 UNIV_INTERN
436 byte*
438 /*=======================*/
439  byte* ptr,
442  byte* end_ptr,
443  ulint type,
444  ulint space_id,
447  ulint log_flags);
449 /*******************************************************************/
453 UNIV_INTERN
454 dberr_t
456 /*==================*/
457  ulint id,
458  buf_remove_t buf_remove);
461 /*******************************************************************/
465 UNIV_INTERN
466 dberr_t
468 /*=================*/
469  trx_t* trx,
470  ulint id);
471 #ifndef UNIV_HOTBACKUP
472 /*******************************************************************/
486 UNIV_INTERN
487 dberr_t
489 /*===================*/
490  ulint id)
491  __attribute__((warn_unused_result));
492 #endif /* !UNIV_HOTBACKUP */
493 /*******************************************************************/
497 UNIV_INTERN
498 ibool
500 /*==================*/
501  const char* old_name_in,
506  ulint id,
507  const char* new_name,
510  const char* new_path);
515 /*******************************************************************/
519 UNIV_INTERN
520 char*
522 /*==============*/
523  const char* name,
524  bool is_full_path);
525 /*******************************************************************/
529 UNIV_INTERN
530 char*
532 /*==============*/
533  const char* name);
534 /*******************************************************************/
539 UNIV_INTERN
540 dberr_t
542 /*=================*/
543  const char* tablename,
544  const char* filepath);
545 /*******************************************************************/
547 UNIV_INTERN
548 void
550 /*==================*/
551  const char* tablename);
552 /*******************************************************************/
559 UNIV_INTERN
560 char*
562 /*===============*/
563  const char* name);
564 /*******************************************************************/
571 UNIV_INTERN
572 dberr_t
574 /*===================================*/
575  ulint space_id,
576  const char* tablename,
579  const char* dir_path,
580  ulint flags,
581  ulint flags2,
582  ulint size)
585  __attribute__((nonnull, warn_unused_result));
586 #ifndef UNIV_HOTBACKUP
587 /********************************************************************/
608 UNIV_INTERN
609 dberr_t
611 /*=============================*/
612  bool validate,
613  bool fix_dict,
614  ulint id,
615  ulint flags,
616  const char* tablename,
618  const char* filepath)
619  __attribute__((nonnull(5), warn_unused_result));
620 
621 #endif /* !UNIV_HOTBACKUP */
622 /********************************************************************/
630 UNIV_INTERN
631 dberr_t
633 /*===================================*/
634 /*******************************************************************/
638 UNIV_INTERN
639 ibool
641 /*===========================================*/
642  ulint id,
643  ib_int64_t version);
646 /*******************************************************************/
649 UNIV_INTERN
650 ibool
652 /*=========================*/
653  ulint id);
654 #ifndef UNIV_HOTBACKUP
655 /*******************************************************************/
660 UNIV_INTERN
661 ibool
663 /*==============================*/
664  ulint id,
665  const char* name,
667  ibool mark_space,
673  ibool print_error_if_does_not_exist,
678  bool adjust_space,
680  mem_heap_t* heap,
681  table_id_t table_id);
682 #else /* !UNIV_HOTBACKUP */
683 /********************************************************************/
688 UNIV_INTERN
689 void
690 fil_extend_tablespaces_to_stored_len(void);
691 /*======================================*/
692 #endif /* !UNIV_HOTBACKUP */
693 /**********************************************************************/
698 UNIV_INTERN
699 ibool
701 /*=============================*/
702  ulint* actual_size,
705  ulint space_id,
706  ulint size_after_extend);
709 /*******************************************************************/
712 UNIV_INTERN
713 ibool
715 /*===========================*/
716  ulint id,
717  ulint n_free_now,
718  ulint n_to_reserve);
719 /*******************************************************************/
721 UNIV_INTERN
722 void
724 /*===========================*/
725  ulint id,
726  ulint n_reserved);
727 /*******************************************************************/
730 UNIV_INTERN
731 ulint
733 /*=============================*/
734  ulint id);
735 /********************************************************************/
739 UNIV_INTERN
740 dberr_t
741 fil_io(
742 /*===*/
743  ulint type,
752  bool sync,
753  ulint space_id,
754  ulint zip_size,
756  ulint block_offset,
757  ulint byte_offset,
760  ulint len,
763  void* buf,
766  void* message)
768  __attribute__((nonnull(8)));
769 /**********************************************************************/
774 UNIV_INTERN
775 void
777 /*=========*/
778  ulint segment);
780 /**********************************************************************/
783 UNIV_INTERN
784 void
785 fil_flush(
786 /*======*/
787  ulint space_id);
789 /**********************************************************************/
792 UNIV_INTERN
793 void
795 /*==================*/
796  ulint purpose);
797 /******************************************************************/
800 UNIV_INTERN
801 ibool
802 fil_validate(void);
803 /*==============*/
804 /********************************************************************/
807 UNIV_INTERN
808 ibool
810 /*=============*/
811  fil_addr_t addr);
812 /********************************************************************/
815 UNIV_INTERN
816 ulint
818 /*==============*/
819  const byte* page);
820 /********************************************************************/
823 UNIV_INTERN
824 ulint
826 /*==============*/
827  const byte* page);
828 /*********************************************************************/
830 UNIV_INTERN
831 void
833 /*==============*/
834  byte* page,
835  ulint type);
836 /*********************************************************************/
840 UNIV_INTERN
841 ulint
843 /*==============*/
844  const byte* page);
846 /*******************************************************************/
849 UNIV_INTERN
850 ibool
852 /*============================*/
853  ulint id);
855 /********************************************************************/
858 UNIV_INTERN
859 void
861 /*============*/
862  const char* path);
865 struct PageCallback {
866 
870  :
871  m_zip_size(),
872  m_page_size(),
873  m_filepath() UNIV_NOTHROW {}
874 
875  virtual ~PageCallback() UNIV_NOTHROW {}
876 
882  virtual dberr_t init(
883  os_offset_t file_size,
884  const buf_block_t* block) UNIV_NOTHROW = 0;
885 
894  virtual dberr_t operator()(
895  os_offset_t offset,
896  buf_block_t* block) UNIV_NOTHROW = 0;
897 
903  void set_file(const char* filename, os_file_t file) UNIV_NOTHROW
904  {
905  m_file = file;
906  m_filepath = filename;
907  }
908 
911  virtual ulint get_space_id() const UNIV_NOTHROW = 0;
912 
915  ulint get_zip_size() const
916  {
917  return(m_zip_size);
918  }
919 
923  dberr_t set_zip_size(const buf_frame_t* page) UNIV_NOTHROW;
924 
927  ulint get_page_size() const
928  {
929  return(m_page_size);
930  }
931 
933  ulint m_zip_size;
934 
936  ulint m_page_size;
937 
940 
942  const char* m_filepath;
943 
944 protected:
945  // Disable copying
946  PageCallback(const PageCallback&);
947  PageCallback& operator=(const PageCallback&);
948 };
949 
950 /********************************************************************/
956 UNIV_INTERN
957 dberr_t
959 /*===================*/
960  dict_table_t* table,
961  ulint n_io_buffers,
962  PageCallback& callback)
963  __attribute__((nonnull, warn_unused_result));
964 
965 /*******************************************************************/
969 UNIV_INTERN
970 ulint
972 /*=======================*/
973  const char* name);
981 UNIV_INTERN
982 dberr_t
984 /*================*/
985  space_name_list_t& space_name_list)
987  __attribute__((warn_unused_result));
988 
989 /****************************************************************/
991 UNIV_INTERN
992 void
994 /*===============*/
995  ulint old_space_id,
997  const char* old_name,
998  ulint new_space_id,
1000  const char* new_name,
1001  const char* tmp_name,
1003  mtr_t* mtr)
1004  __attribute__((nonnull));
1005 
1006 /*******************************************************************/
1010 bool
1012 /*==============================*/
1013  fsp_open_info* fsp, /* in: contains space id and .ibd
1014  file information */
1015  ulint page_no); /* in: page_no to obtain from double
1016  write buffer */
1017 
1018 #endif /* !UNIV_INNOCHECKSUM */
1019 #endif /* fil0fil_h */