00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifndef __NDB_DISKPAGE_HPP 00018 #define __NDB_DISKPAGE_HPP 00019 00020 #include <ndb_types.h> 00021 00022 struct File_formats 00023 { 00024 STATIC_CONST( NDB_PAGE_SIZE = 32768 ); 00025 STATIC_CONST( NDB_PAGE_SIZE_WORDS = NDB_PAGE_SIZE >> 2); 00026 00027 enum File_type 00028 { 00029 FT_Datafile = 0x1, 00030 FT_Undofile = 0x2 00031 }; 00032 00033 struct Page_header 00034 { 00035 Uint32 m_page_lsn_hi; 00036 Uint32 m_page_lsn_lo; 00037 Uint32 m_page_type; 00038 }; 00039 00040 enum Page_type 00041 { 00042 PT_Unallocated = 0x0, 00043 PT_Extent_page = 0x1, 00044 PT_Tup_fixsize_page = 0x2, 00045 PT_Tup_varsize_page = 0x3, 00046 PT_Undopage = 0x4 00047 }; 00048 00049 struct Zero_page_header 00050 { 00051 char m_magic[8]; 00052 Uint32 m_byte_order; 00053 Uint32 m_page_size; 00054 Uint32 m_ndb_version; 00055 Uint32 m_node_id; 00056 Uint32 m_file_type; 00057 Uint32 m_time; // time(0) 00058 void init(File_type ft, Uint32 node_id, Uint32 version, Uint32 now); 00059 int validate(File_type ft, Uint32 node_id, Uint32 version, Uint32 now); 00060 }; 00061 00062 STATIC_CONST( NDB_PAGE_HEADER_WORDS = sizeof(Page_header) >> 2); 00063 00064 struct Datafile 00065 { 00066 struct Zero_page 00067 { 00068 struct Zero_page_header m_page_header; 00069 Uint32 m_file_no; // Local_key 00070 Uint32 m_file_id; // DICT id 00071 Uint32 m_tablespace_id; 00072 Uint32 m_tablespace_version; 00073 Uint32 m_data_pages; 00074 Uint32 m_extent_pages; 00075 Uint32 m_extent_size; 00076 Uint32 m_extent_count; 00077 Uint32 m_extent_headers_per_page; 00078 Uint32 m_extent_header_words; 00079 Uint32 m_extent_header_bits_per_page; 00080 }; 00081 00082 struct Extent_header 00083 { 00084 Uint32 m_table; 00085 union 00086 { 00087 Uint32 m_fragment_id; 00088 Uint32 m_next_free_extent; 00089 }; 00090 Uint32 m_page_bitmask[1]; // (BitsPerPage*ExtentSize)/(32*PageSize) 00091 Uint32 get_free_bits(Uint32 page) const; 00092 Uint32 get_free_word_offset(Uint32 page) const; 00093 void update_free_bits(Uint32 page, Uint32 bit); 00094 bool check_free(Uint32 extent_size) const ; 00095 }; 00096 00097 STATIC_CONST( EXTENT_HEADER_BITMASK_BITS_PER_PAGE = 4 ); 00098 STATIC_CONST( EXTENT_HEADER_FIXED_WORDS = (sizeof(Extent_header)>>2) - 1); 00099 static Uint32 extent_header_words(Uint32 extent_size_in_pages); 00100 00101 struct Extent_page 00102 { 00103 struct Page_header m_page_header; 00104 Extent_header m_extents[1]; 00105 00106 Extent_header* get_header(Uint32 extent_no, Uint32 extent_size); 00107 }; 00108 00109 STATIC_CONST( EXTENT_PAGE_WORDS = NDB_PAGE_SIZE_WORDS - NDB_PAGE_HEADER_WORDS ); 00110 00111 struct Data_page 00112 { 00113 struct Page_header m_page_header; 00114 }; 00115 }; 00116 00117 struct Undofile 00118 { 00119 struct Zero_page 00120 { 00121 struct Zero_page_header m_page_header; 00122 Uint32 m_file_id; 00123 Uint32 m_logfile_group_id; 00124 Uint32 m_logfile_group_version; 00125 Uint32 m_undo_pages; 00126 }; 00127 struct Undo_page 00128 { 00129 struct Page_header m_page_header; 00130 Uint32 m_words_used; 00131 Uint32 m_data[1]; 00132 }; 00133 00134 struct Undo_entry 00135 { 00136 Uint32 m_file_no; 00137 Uint32 m_page_no; 00138 struct 00139 { 00140 Uint32 m_len_offset; 00141 Uint32 m_data[1]; 00142 } m_changes[1]; 00143 Uint32 m_length; // [ 16-bit type | 16 bit length of entry ] 00144 }; 00145 00146 enum Undo_type { 00147 UNDO_LCP_FIRST = 1 // First LCP record with specific lcp id 00148 ,UNDO_LCP = 2 // LCP Start 00149 00153 ,UNDO_TUP_ALLOC = 3 00154 ,UNDO_TUP_UPDATE = 4 00155 ,UNDO_TUP_FREE = 5 00156 ,UNDO_TUP_CREATE = 6 00157 00158 ,UNDO_END = 0x7FFF 00159 ,UNDO_NEXT_LSN = 0x8000 00160 }; 00161 00162 struct Undo_lcp 00163 { 00164 Uint32 m_lcp_id; 00165 Uint32 m_type_length; // 16 bit type, 16 bit length 00166 }; 00167 }; 00168 STATIC_CONST( UNDO_PAGE_WORDS = NDB_PAGE_SIZE_WORDS - NDB_PAGE_HEADER_WORDS - 1); 00169 }; 00170 00171 00175 inline Uint32 00176 File_formats::Datafile::extent_header_words(Uint32 extent_size_in_pages) 00177 { 00178 return EXTENT_HEADER_FIXED_WORDS + 00179 ((extent_size_in_pages * EXTENT_HEADER_BITMASK_BITS_PER_PAGE + 31) >> 5); 00180 } 00181 00182 inline 00183 File_formats::Datafile::Extent_header* 00184 File_formats::Datafile::Extent_page::get_header(Uint32 no, Uint32 extent_size) 00185 { 00186 Uint32 * tmp = (Uint32*)m_extents; 00187 tmp += no*File_formats::Datafile::extent_header_words(extent_size); 00188 return (Extent_header*)tmp; 00189 } 00190 00191 inline 00192 Uint32 00193 File_formats::Datafile::Extent_header::get_free_bits(Uint32 page) const 00194 { 00195 return ((m_page_bitmask[page >> 3] >> ((page & 7) << 2))) & 15; 00196 } 00197 00198 inline 00199 Uint32 00200 File_formats::Datafile::Extent_header::get_free_word_offset(Uint32 page) const 00201 { 00202 return page >> 3; 00203 } 00204 00205 inline 00206 void 00207 File_formats::Datafile::Extent_header::update_free_bits(Uint32 page, 00208 Uint32 bit) 00209 { 00210 Uint32 shift = (page & 7) << 2; 00211 Uint32 mask = (15 << shift); 00212 Uint32 org = m_page_bitmask[page >> 3]; 00213 m_page_bitmask[page >> 3] = (org & ~mask) | (bit << shift); 00214 } 00215 00216 inline 00217 bool 00218 File_formats::Datafile::Extent_header::check_free(Uint32 extent_size) const 00219 { 00220 Uint32 words = (extent_size * EXTENT_HEADER_BITMASK_BITS_PER_PAGE + 31) >> 5; 00221 Uint32 sum = 0; 00222 for(; words; words--) 00223 sum |= m_page_bitmask[words-1]; 00224 00225 if(sum & 0x3333) 00226 return false; 00227 00228 return true; 00229 } 00230 00231 #include <NdbOut.hpp> 00232 NdbOut& operator<<(NdbOut& out, const File_formats::Zero_page_header&); 00233 NdbOut& operator<<(NdbOut& out, const File_formats::Datafile::Zero_page&); 00234 NdbOut& operator<<(NdbOut& out, const File_formats::Undofile::Zero_page&); 00235 00236 #endif
1.4.7

