18 #ifndef __NDB_TUP_PAGE_HPP
19 #define __NDB_TUP_PAGE_HPP
21 #include <ndb_types.h>
22 #include "../diskpage.hpp"
38 Uint32 first_cluster_page;
39 Uint32 last_cluster_page;
40 Uint32 next_cluster_page;
41 Uint32 prev_cluster_page;
43 Uint32 physical_page_id;
45 Uint32 next_free_index;
47 Uint32 uncommitted_used_space;
53 Uint32 m_extent_info_ptr;
56 STATIC_CONST( DATA_WORDS = File_formats::NDB_PAGE_SIZE_WORDS - 32 );
58 Uint32 m_data[DATA_WORDS];
68 Uint32 first_cluster_page;
69 Uint32 last_cluster_page;
70 Uint32 next_cluster_page;
71 Uint32 prev_cluster_page;
73 Uint32 physical_page_id;
75 Uint32 next_free_index;
77 Uint32 uncommitted_used_space;
83 Uint32 m_extent_info_ptr;
86 STATIC_CONST( FREE_RECORD = ~(Uint32)0 );
87 STATIC_CONST( DATA_WORDS = File_formats::NDB_PAGE_SIZE_WORDS - 32 );
89 Uint32 m_data[DATA_WORDS];
91 Uint32* get_ptr(Uint32 page_idx, Uint32 rec_size){
92 assert(page_idx + rec_size <= DATA_WORDS);
93 return m_data + page_idx;
103 Uint32 free_record(Uint32 page_idx);
109 Uint32 m_restart_seq;
113 Uint32 first_cluster_page;
114 Uint32 last_cluster_page;
115 Uint32 next_cluster_page;
116 Uint32 prev_cluster_page;
118 Uint32 physical_page_id;
120 Uint32 next_free_index;
122 Uint32 uncommitted_used_space;
126 Uint32 m_fragment_id;
128 Uint32 m_extent_info_ptr;
133 STATIC_CONST( DATA_WORDS = File_formats::NDB_PAGE_SIZE_WORDS - 32 );
134 STATIC_CONST( CHAIN = 0x80000000 );
135 STATIC_CONST( FREE = 0x40000000 );
136 STATIC_CONST( LEN_MASK = 0x3FFF8000 );
137 STATIC_CONST( POS_MASK = 0x00007FFF );
138 STATIC_CONST( LEN_SHIFT = 15 );
139 STATIC_CONST( POS_SHIFT = 0 );
140 STATIC_CONST( END_OF_FREE_LIST = POS_MASK );
142 STATIC_CONST( NEXT_MASK = POS_MASK );
143 STATIC_CONST( NEXT_SHIFT = POS_SHIFT );
144 STATIC_CONST( PREV_MASK = LEN_MASK );
145 STATIC_CONST( PREV_SHIFT = LEN_SHIFT );
147 Uint32 m_data[DATA_WORDS];
152 Uint32* get_free_space_ptr() {
153 return m_data+insert_pos;
156 Uint32 largest_frag_size()
const {
157 return DATA_WORDS - (high_index + insert_pos);
160 Uint32 *get_index_ptr(Uint32 page_idx) {
161 assert(page_idx < high_index);
162 return (m_data + (DATA_WORDS - page_idx));
165 Uint32 get_index_word(Uint32 page_idx)
const {
166 assert(page_idx < high_index);
167 return * (m_data + (DATA_WORDS - page_idx));
194 Uint32 idx= get_index_word(page_index);
195 Uint32 pos= (idx & POS_MASK) >> POS_SHIFT;
196 Uint32 len= (idx & LEN_MASK) >> LEN_SHIFT;
197 if ((pos + len == insert_pos) &&
198 (insert_pos + growth_len < DATA_WORDS - high_index))
203 void grow_entry(Uint32 page_index, Uint32 growth_len) {
204 assert(free_space >= growth_len);
206 Uint32 *pos= get_index_ptr(page_index);
208 assert(! (idx & FREE));
209 assert((((idx & POS_MASK) >> POS_SHIFT) + ((idx & LEN_MASK) >> LEN_SHIFT))
212 * pos= idx + (growth_len << LEN_SHIFT);
213 insert_pos+= growth_len;
214 free_space-= growth_len;
217 void shrink_entry(Uint32 page_index, Uint32 new_size){
218 Uint32 *pos= get_index_ptr(page_index);
220 Uint32 old_pos = (idx & POS_MASK) >> POS_SHIFT;
221 Uint32 old_size = (idx & LEN_MASK) >> LEN_SHIFT;
223 assert( ! (idx & FREE));
224 assert(old_size >= new_size);
226 * pos= (idx & ~LEN_MASK) + (new_size << LEN_SHIFT);
227 Uint32 shrink = old_size - new_size;
229 memset(m_data + old_pos + new_size, 0xF1, 4 * shrink);
232 if(insert_pos == (old_pos + old_size))
233 insert_pos -= shrink;
236 Uint32* get_ptr(Uint32 page_idx) {
237 return m_data + ((get_index_word(page_idx) & POS_MASK) >> POS_SHIFT);
240 void set_entry_offset(Uint32 page_idx, Uint32
offset){
241 Uint32 *pos= get_index_ptr(page_idx);
242 * pos = (* pos & ~POS_MASK) + (offset << POS_SHIFT);
245 void set_entry_len(Uint32 page_idx, Uint32 len) {
246 Uint32 *pos= get_index_ptr(page_idx);
247 * pos = (*pos & ~LEN_MASK) + (len << LEN_SHIFT);
250 Uint32 get_entry_len(Uint32 page_idx)
const {
251 return (get_index_word(page_idx) & LEN_MASK) >> LEN_SHIFT;
254 Uint32 get_entry_chain(Uint32 page_idx)
const {
255 return get_index_word(page_idx) & CHAIN;
258 bool is_free(Uint32 page_idx)
const
260 return ((get_index_word(page_idx) & FREE) != 0) ?
true :
false;