MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diskpage.hpp
1 /*
2  Copyright (C) 2005-2007 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef __NDB_DISKPAGE_HPP
20 #define __NDB_DISKPAGE_HPP
21 
22 #include <ndb_types.h>
23 
24 struct File_formats
25 {
26  STATIC_CONST( NDB_PAGE_SIZE = 32768 );
27  STATIC_CONST( NDB_PAGE_SIZE_WORDS = NDB_PAGE_SIZE >> 2);
28 
29  enum File_type
30  {
31  FT_Datafile = 0x1,
32  FT_Undofile = 0x2
33  };
34 
35  struct Page_header
36  {
37  Uint32 m_page_lsn_hi;
38  Uint32 m_page_lsn_lo;
39  Uint32 m_page_type;
40  };
41 
42  enum Page_type
43  {
44  PT_Unallocated = 0x0,
45  PT_Extent_page = 0x1,
46  PT_Tup_fixsize_page = 0x2,
47  PT_Tup_varsize_page = 0x3,
48  PT_Undopage = 0x4
49  };
50 
52  {
53  char m_magic[8];
54  Uint32 m_byte_order;
55  Uint32 m_page_size;
56  Uint32 m_ndb_version;
57  Uint32 m_node_id;
58  Uint32 m_file_type;
59  Uint32 m_time; // time(0)
60  Zero_page_header() {}
61  void init(File_type ft, Uint32 node_id, Uint32 version, Uint32 now);
62  int validate(File_type ft, Uint32 node_id, Uint32 version, Uint32 now);
63  };
64 
65  STATIC_CONST( NDB_PAGE_HEADER_WORDS = sizeof(Page_header) >> 2);
66 
67  struct Datafile
68  {
69  struct Zero_page
70  {
71  struct Zero_page_header m_page_header;
72  Uint32 m_file_no; // Local_key
73  Uint32 m_file_id; // DICT id
74  Uint32 m_tablespace_id;
75  Uint32 m_tablespace_version;
76  Uint32 m_data_pages;
77  Uint32 m_extent_pages;
78  Uint32 m_extent_size;
79  Uint32 m_extent_count;
80  Uint32 m_extent_headers_per_page;
81  Uint32 m_extent_header_words;
82  Uint32 m_extent_header_bits_per_page;
83  };
84 
85  struct Extent_header
86  {
87  Uint32 m_table;
88  union
89  {
90  Uint32 m_fragment_id;
91  Uint32 m_next_free_extent;
92  };
93  Extent_header() {}
94  Uint32 m_page_bitmask[1]; // (BitsPerPage*ExtentSize)/(32*PageSize)
95  Uint32 get_free_bits(Uint32 page) const;
96  Uint32 get_free_word_offset(Uint32 page) const;
97  void update_free_bits(Uint32 page, Uint32 bit);
98  bool check_free(Uint32 extent_size) const ;
99  };
100 
101  STATIC_CONST( EXTENT_HEADER_BITMASK_BITS_PER_PAGE = 4 );
102  STATIC_CONST( EXTENT_HEADER_FIXED_WORDS = (sizeof(Extent_header)>>2) - 1);
103  static Uint32 extent_header_words(Uint32 extent_size_in_pages);
104 
105  struct Extent_page
106  {
107  struct Page_header m_page_header;
108  Extent_header m_extents[1];
109 
110  Extent_page() {}
111  Extent_header* get_header(Uint32 extent_no, Uint32 extent_size);
112  };
113 
114  STATIC_CONST( EXTENT_PAGE_WORDS = NDB_PAGE_SIZE_WORDS - NDB_PAGE_HEADER_WORDS );
115 
116  struct Data_page
117  {
118  struct Page_header m_page_header;
119  };
120  };
121 
122  struct Undofile
123  {
124  struct Zero_page
125  {
126  struct Zero_page_header m_page_header;
127  Uint32 m_file_id;
128  Uint32 m_logfile_group_id;
129  Uint32 m_logfile_group_version;
130  Uint32 m_undo_pages;
131  };
132  struct Undo_page
133  {
134  struct Page_header m_page_header;
135  Uint32 m_words_used;
136  Uint32 m_data[1];
137  };
138 
139  struct Undo_entry
140  {
141  Uint32 m_file_no;
142  Uint32 m_page_no;
143  struct
144  {
145  Uint32 m_len_offset;
146  Uint32 m_data[1];
147  } m_changes[1];
148  Uint32 m_length; // [ 16-bit type | 16 bit length of entry ]
149  };
150 
151  enum Undo_type {
152  UNDO_LCP_FIRST = 1 // First LCP record with specific lcp id
153  ,UNDO_LCP = 2 // LCP Start
154 
158  ,UNDO_TUP_ALLOC = 3
159  ,UNDO_TUP_UPDATE = 4
160  ,UNDO_TUP_FREE = 5
161  ,UNDO_TUP_CREATE = 6
162  ,UNDO_TUP_DROP = 7
163  ,UNDO_TUP_ALLOC_EXTENT = 8
164  ,UNDO_TUP_FREE_EXTENT = 9
165 
166  ,UNDO_END = 0x7FFF
167  ,UNDO_NEXT_LSN = 0x8000
168  };
169 
170  struct Undo_lcp
171  {
172  Uint32 m_lcp_id;
173  Uint32 m_type_length; // 16 bit type, 16 bit length
174  };
175  };
176  STATIC_CONST( UNDO_PAGE_WORDS = NDB_PAGE_SIZE_WORDS - NDB_PAGE_HEADER_WORDS - 1);
177 };
178 
179 
183 inline Uint32
185 {
186  return EXTENT_HEADER_FIXED_WORDS +
187  ((extent_size_in_pages * EXTENT_HEADER_BITMASK_BITS_PER_PAGE + 31) >> 5);
188 }
189 
190 inline
192 File_formats::Datafile::Extent_page::get_header(Uint32 no, Uint32 extent_size)
193 {
194  Uint32 * tmp = (Uint32*)m_extents;
195  tmp += no*File_formats::Datafile::extent_header_words(extent_size);
196  return (Extent_header*)tmp;
197 }
198 
199 inline
200 Uint32
201 File_formats::Datafile::Extent_header::get_free_bits(Uint32 page) const
202 {
203  return ((m_page_bitmask[page >> 3] >> ((page & 7) << 2))) & 15;
204 }
205 
206 inline
207 Uint32
208 File_formats::Datafile::Extent_header::get_free_word_offset(Uint32 page) const
209 {
210  return page >> 3;
211 }
212 
213 inline
214 void
215 File_formats::Datafile::Extent_header::update_free_bits(Uint32 page,
216  Uint32 bit)
217 {
218  Uint32 shift = (page & 7) << 2;
219  Uint32 mask = (15 << shift);
220  Uint32 org = m_page_bitmask[page >> 3];
221  m_page_bitmask[page >> 3] = (org & ~mask) | (bit << shift);
222 }
223 
224 inline
225 bool
226 File_formats::Datafile::Extent_header::check_free(Uint32 extent_size) const
227 {
228  Uint32 words = (extent_size * EXTENT_HEADER_BITMASK_BITS_PER_PAGE + 31) >> 5;
229  Uint32 sum = 0;
230  for(; words; words--)
231  sum |= m_page_bitmask[words-1];
232 
233  if(sum & 0x3333)
234  return false;
235 
236  return true;
237 }
238 
239 #include <NdbOut.hpp>
240 NdbOut& operator<<(NdbOut& out, const File_formats::Zero_page_header&);
241 NdbOut& operator<<(NdbOut& out, const File_formats::Datafile::Zero_page&);
242 NdbOut& operator<<(NdbOut& out, const File_formats::Undofile::Zero_page&);
243 
244 #endif