The world's most popular open source database
#include <tuppage.hpp>
Collaboration diagram for Tup_varsize_page:

Definition at line 103 of file tuppage.hpp.
| Uint32 Tup_varsize_page::alloc_record | ( | Uint32 | page_idx, | |
| Uint32 | size, | |||
| Tup_varsize_page * | temp | |||
| ) |
Alloc page_idx from page, return page_idx temp is used when having to reorg page before allocating
We need to expand directory
Definition at line 138 of file tuppage.cpp.
References assert, FREE, free, free_list(), free_space, get_index_ptr(), high_index, insert_pos, m_data, next_free_index, reorg(), and unlikely.
00140 { 00141 assert(page_idx); // 0 is not allowed 00142 Uint32 free = free_space; 00143 Uint32 largest_size= DATA_WORDS - (insert_pos + high_index); 00144 Uint32 free_list = next_free_index; 00145 00146 if (page_idx < high_index) 00147 { 00148 Uint32 *ptr = get_index_ptr(page_idx); 00149 Uint32 word = *ptr; 00150 00151 if (unlikely((free < alloc_size) || ! (word & FREE))) 00152 { 00153 return ~0; 00154 } 00155 00156 if (alloc_size >= largest_size) 00157 { 00158 /* 00159 We can't fit this segment between the insert position and the end of 00160 the index entries. We will pack the page so that all free space 00161 exists between the insert position and the end of the index entries. 00162 */ 00163 reorg(temp); 00164 } 00165 00166 Uint32 next = (word & NEXT_MASK) >> NEXT_SHIFT; 00167 Uint32 prev = (word & PREV_MASK) >> PREV_SHIFT; 00168 00169 if (next != END_OF_FREE_LIST) 00170 { 00171 Uint32 * next_ptr = get_index_ptr(next); 00172 Uint32 next_word = * next_ptr; 00173 * next_ptr = (next_word & ~PREV_MASK) | (prev << PREV_SHIFT); 00174 } 00175 00176 if (prev != END_OF_FREE_LIST) 00177 { 00178 Uint32 * prev_ptr = get_index_ptr(prev); 00179 Uint32 prev_word = * prev_ptr; 00180 * prev_ptr = (prev_word & ~NEXT_MASK) | (next << NEXT_SHIFT); 00181 } 00182 else 00183 { 00184 assert(next_free_index == page_idx); 00185 next_free_index = next; 00186 } 00187 00188 * ptr = insert_pos + (alloc_size << LEN_SHIFT); 00189 free -= alloc_size; 00190 } 00191 else 00192 { 00196 Uint32 hi = high_index; 00197 Uint32 expand = (page_idx + 1 - hi); 00198 Uint32 size = alloc_size + expand; 00199 if (unlikely(size > free)) 00200 { 00201 return ~0; 00202 } 00203 00204 if (size >= largest_size) 00205 { 00206 /* 00207 We can't fit this segment between the insert position and the end of 00208 the index entries. We will pack the page so that all free space 00209 exists between the insert position and the end of the index entries. 00210 */ 00211 reorg(temp); 00212 } 00213 00214 Uint32 *ptr = m_data + DATA_WORDS - hi; 00215 if (page_idx == hi) 00216 { 00217 * ptr = insert_pos + (alloc_size << LEN_SHIFT); 00218 } 00219 else 00220 { 00221 if (free_list != END_OF_FREE_LIST) 00222 { 00223 Uint32 * prev_ptr = get_index_ptr(free_list); 00224 Uint32 prev_word = * prev_ptr; 00225 * prev_ptr = (prev_word & ~PREV_MASK) | (hi << PREV_SHIFT); 00226 } 00227 00228 for (; hi < page_idx;) 00229 { 00230 * ptr-- = FREE | (free_list << NEXT_SHIFT) | ((hi+1) << PREV_SHIFT); 00231 free_list = hi++; 00232 } 00233 00234 * ptr++ = insert_pos + (alloc_size << LEN_SHIFT); 00235 * ptr = ((* ptr) & ~PREV_MASK) | (END_OF_FREE_LIST << PREV_SHIFT); 00236 00237 next_free_index = hi - 1; 00238 } 00239 high_index = hi + 1; 00240 free -= size; 00241 } 00242 00243 free_space = free; 00244 insert_pos += alloc_size; 00245 00246 return page_idx; 00247 }
Here is the call graph for this function:

| Uint32 Tup_varsize_page::alloc_record | ( | Uint32 | size, | |
| Tup_varsize_page * | temp, | |||
| Uint32 | chain | |||
| ) |
Alloc record from page, return page_idx temp is used when having to reorg page before allocating
Definition at line 250 of file tuppage.cpp.
References assert, FREE, free_space, get_index_ptr(), get_index_word(), high_index, insert_pos, next_free_index, and reorg().
00252 { 00253 assert(free_space >= alloc_size); 00254 Uint32 largest_size= DATA_WORDS - (insert_pos + high_index); 00255 if (alloc_size >= largest_size) { 00256 /* 00257 We can't fit this segment between the insert position and the end of 00258 the index entries. We will pack the page so that all free space 00259 exists between the insert position and the end of the index entries. 00260 */ 00261 reorg(temp); 00262 largest_size= DATA_WORDS - (insert_pos + high_index); 00263 } 00264 assert(largest_size > alloc_size); 00265 00266 Uint32 page_idx; 00267 if (next_free_index == END_OF_FREE_LIST) { 00268 /* 00269 We are out of free index slots. We will extend the array of free 00270 slots 00271 */ 00272 page_idx= high_index++; 00273 free_space--; 00274 } else { 00275 // Pick an empty slot among the index entries 00276 page_idx= next_free_index; 00277 assert((get_index_word(page_idx) & FREE) == FREE); 00278 assert(((get_index_word(page_idx) & PREV_MASK) >> PREV_SHIFT) == 00279 END_OF_FREE_LIST); 00280 next_free_index= (get_index_word(page_idx) & NEXT_MASK) >> NEXT_SHIFT; 00281 assert(next_free_index); 00282 if (next_free_index != END_OF_FREE_LIST) 00283 { 00284 Uint32 *ptr = get_index_ptr(next_free_index); 00285 Uint32 word = *ptr; 00286 * ptr = (word & ~PREV_MASK) | (END_OF_FREE_LIST << PREV_SHIFT); 00287 } 00288 } 00289 00290 assert(chain == 0 || chain == CHAIN); 00291 * get_index_ptr(page_idx) = insert_pos + chain + (alloc_size << LEN_SHIFT); 00292 00293 insert_pos += alloc_size; 00294 free_space -= alloc_size; 00295 //ndbout_c("%p->alloc_record(%d%s) -> %d", this,alloc_size, (chain ? " CHAIN" : ""),page_idx); 00296 return page_idx; 00297 }
Here is the call graph for this function:

Free record from page
Definition at line 300 of file tuppage.cpp.
References assert, FREE, free_space, get_index_ptr(), high_index, insert_pos, m_data, memset, next_free_index, and rebuild_index().
Referenced by Dbtup::realloc_var_part().
00301 { 00302 //ndbout_c("%p->free_record(%d%s)", this, page_idx, (chain ? " CHAIN": "")); 00303 Uint32 *index_ptr= get_index_ptr(page_idx); 00304 Uint32 index_word= * index_ptr; 00305 Uint32 entry_pos= (index_word & POS_MASK) >> POS_SHIFT; 00306 Uint32 entry_len= (index_word & LEN_MASK) >> LEN_SHIFT; 00307 assert(chain == 0 || chain == CHAIN); 00308 assert((index_word & CHAIN) == chain); 00309 #ifdef VM_TRACE 00310 memset(m_data + entry_pos, 0xF2, 4*entry_len); 00311 #endif 00312 if (page_idx + 1 == high_index) { 00313 /* 00314 We are removing the last in the entry list. We could potentially 00315 have several free entries also before this. To take that into account 00316 we will rebuild the free list and thus compress it and update the 00317 free space accordingly. 00318 */ 00319 rebuild_index(index_ptr); 00320 } else { 00321 if (next_free_index != END_OF_FREE_LIST) 00322 { 00323 Uint32 *ptr = get_index_ptr(next_free_index); 00324 Uint32 word = *ptr; 00325 assert(((word & PREV_MASK) >> PREV_SHIFT) == END_OF_FREE_LIST); 00326 * ptr = (word & ~PREV_MASK) | (page_idx << PREV_SHIFT); 00327 } 00328 * index_ptr= FREE | next_free_index | (END_OF_FREE_LIST << PREV_SHIFT); 00329 next_free_index= page_idx; 00330 assert(next_free_index); 00331 } 00332 00333 free_space+= entry_len; 00334 // If we're the "last" entry, decrease insert_pos 00335 insert_pos -= (entry_pos + entry_len == insert_pos ? entry_len : 0); 00336 00337 return free_space; 00338 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 256 of file tuppage.hpp.
Referenced by Dbtup::handle_size_change_after_update().
00256 { 00257 return get_index_word(page_idx) & CHAIN; 00258 }
Here is the caller graph for this function:

Definition at line 252 of file tuppage.hpp.
Referenced by Dbtup::commit_operation(), Dbtup::do_tup_abortreq(), Dbtup::handle_size_change_after_update(), and Dbtup::realloc_var_part().
00252 { 00253 return (get_index_word(page_idx) & LEN_MASK) >> LEN_SHIFT; 00254 }
Here is the caller graph for this function:

| Uint32* Tup_varsize_page::get_free_space_ptr | ( | ) | [inline] |
Definition at line 154 of file tuppage.hpp.
References Tup_page::m_data.
Referenced by Dbtup::realloc_var_part().
00154 { 00155 return m_data+insert_pos; 00156 }
Here is the caller graph for this function:

Definition at line 162 of file tuppage.hpp.
References assert, and Tup_page::m_data.
Referenced by alloc_record(), free_record(), and reorg().
00162 { 00163 assert(page_idx < high_index); 00164 return (m_data + (DATA_WORDS - page_idx)); 00165 }
Here is the caller graph for this function:

Definition at line 167 of file tuppage.hpp.
References assert, and Tup_page::m_data.
Referenced by alloc_record().
00167 { 00168 assert(page_idx < high_index); 00169 return * (m_data + (DATA_WORDS - page_idx)); 00170 }
Here is the caller graph for this function:

Definition at line 238 of file tuppage.hpp.
References Tup_page::m_data.
Referenced by Dbtup::realloc_var_part().
00238 { 00239 return m_data + ((get_index_word(page_idx) & POS_MASK) >> POS_SHIFT); 00240 }
Here is the caller graph for this function:

Definition at line 205 of file tuppage.hpp.
References assert, FREE, Tup_page::free_space, and pos().
Referenced by Dbtup::realloc_var_part().
00205 { 00206 assert(free_space >= growth_len); 00207 00208 Uint32 *pos= get_index_ptr(page_index); 00209 Uint32 idx= *pos; 00210 assert(! (idx & FREE)); 00211 assert((((idx & POS_MASK) >> POS_SHIFT) + ((idx & LEN_MASK) >> LEN_SHIFT)) 00212 == insert_pos); 00213 00214 * pos= idx + (growth_len << LEN_SHIFT); 00215 insert_pos+= growth_len; 00216 free_space-= growth_len; 00217 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void Tup_varsize_page::init | ( | ) |
Definition at line 128 of file tuppage.cpp.
References free_space, high_index, insert_pos, m_page_header, File_formats::Page_header::m_page_type, next_free_index, and File_formats::PT_Tup_varsize_page.
00129 { 00130 free_space= DATA_WORDS - 1; 00131 high_index= 1; 00132 insert_pos= 0; 00133 next_free_index= END_OF_FREE_LIST; 00134 m_page_header.m_page_type = File_formats::PT_Tup_varsize_page; 00135 }
| bool Tup_varsize_page::is_space_behind_entry | ( | Uint32 | page_index, | |
| Uint32 | growth_len | |||
| ) | const [inline] |
Check if one can grow tuple wo/ reorg
Definition at line 195 of file tuppage.hpp.
References pos().
Referenced by Dbtup::realloc_var_part().
00195 { 00196 Uint32 idx= get_index_word(page_index); 00197 Uint32 pos= (idx & POS_MASK) >> POS_SHIFT; 00198 Uint32 len= (idx & LEN_MASK) >> LEN_SHIFT; 00199 if ((pos + len == insert_pos) && 00200 (insert_pos + growth_len < DATA_WORDS - high_index)) 00201 return true; 00202 return false; 00203 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Uint32 Tup_varsize_page::largest_frag_size | ( | ) | const [inline] |
Definition at line 158 of file tuppage.hpp.
00158 { 00159 return DATA_WORDS - (high_index + insert_pos); 00160 }
| void Tup_varsize_page::rebuild_index | ( | Uint32 * | ptr | ) |
Definition at line 341 of file tuppage.cpp.
References assert, empty, FREE, free_space, high_index, m_data, and next_free_index.
Referenced by free_record().
00342 { 00343 Uint32 empty= 1; 00344 Uint32 *end= m_data + DATA_WORDS; 00345 00349 for(index_ptr++; index_ptr < end; index_ptr++) 00350 if((* index_ptr) & FREE) 00351 empty++; 00352 else 00353 break; 00354 00355 if(index_ptr == end) 00356 { 00357 // Totally free page 00358 high_index = 1; 00359 free_space += empty; 00360 next_free_index = END_OF_FREE_LIST; 00361 return; 00362 } 00363 00364 Uint32 next= END_OF_FREE_LIST; 00365 Uint32 dummy; 00366 Uint32 *prev_ptr = &dummy; 00367 for(index_ptr++; index_ptr < end; index_ptr++) 00368 { 00369 if ((* index_ptr) & FREE) 00370 { 00371 * index_ptr= FREE | next; 00372 next= (end - index_ptr); 00373 * prev_ptr |= (next << PREV_SHIFT); 00374 prev_ptr = index_ptr; 00375 } 00376 } 00377 00378 * prev_ptr |= (END_OF_FREE_LIST << PREV_SHIFT); 00379 00380 high_index -= empty; 00381 free_space += empty; 00382 next_free_index= next; 00383 assert(next_free_index); 00384 }
Here is the caller graph for this function:

| void Tup_varsize_page::reorg | ( | Tup_varsize_page * | temp | ) |
Definition at line 387 of file tuppage.cpp.
References assert, FREE, get_index_ptr(), high_index, insert_pos, m_data, and memcpy.
Referenced by alloc_record(), and Dbtup::realloc_var_part().
00388 { 00389 Uint32 new_insert_pos= 0; 00390 Uint32 old_insert_pos= insert_pos; 00391 00392 // Copy key data part of page to a temporary page. 00393 memcpy(copy_page->m_data, m_data, 4*old_insert_pos); 00394 assert(high_index > 0); 00395 Uint32* index_ptr= get_index_ptr(high_index-1); 00396 Uint32 *end_of_page= m_data + DATA_WORDS; 00397 for (; index_ptr < end_of_page; index_ptr++) 00398 { 00399 Uint32 index_word= * index_ptr; 00400 Uint32 entry_len= (index_word & LEN_MASK) >> LEN_SHIFT; 00401 if (!(index_word & FREE) && entry_len) 00402 { 00403 /* 00404 We found an index item that needs to be packed. 00405 We will update the index entry and copy the data to the page. 00406 */ 00407 Uint32 entry_pos= (index_word & POS_MASK) >> POS_SHIFT; 00408 assert(entry_pos + entry_len <= old_insert_pos); 00409 assert(new_insert_pos + entry_len <= old_insert_pos); 00410 * index_ptr= (new_insert_pos << POS_SHIFT) + (index_word & ~POS_MASK); 00411 memcpy(m_data+new_insert_pos, copy_page->m_data+entry_pos, 4*entry_len); 00412 00413 new_insert_pos += entry_len; 00414 } 00415 } 00416 insert_pos= new_insert_pos; 00417 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file tuppage.hpp.
References pos().
Referenced by Dbtup::realloc_var_part().
00247 { 00248 Uint32 *pos= get_index_ptr(page_idx); 00249 * pos = (*pos & ~LEN_MASK) + (len << LEN_SHIFT); 00250 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 242 of file tuppage.hpp.
References pos().
Referenced by Dbtup::realloc_var_part().
00242 { 00243 Uint32 *pos= get_index_ptr(page_idx); 00244 * pos = (* pos & ~POS_MASK) + (offset << POS_SHIFT); 00245 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 219 of file tuppage.hpp.
References assert, FREE, Tup_page::free_space, Tup_page::m_data, memset, and pos().
Referenced by Dbtup::commit_operation(), and Dbtup::do_tup_abortreq().
00219 { 00220 Uint32 *pos= get_index_ptr(page_index); 00221 Uint32 idx= *pos; 00222 Uint32 old_pos = (idx & POS_MASK) >> POS_SHIFT; 00223 Uint32 old_size = (idx & LEN_MASK) >> LEN_SHIFT; 00224 00225 assert( ! (idx & FREE)); 00226 assert(old_size >= new_size); 00227 00228 * pos= (idx & ~LEN_MASK) + (new_size << LEN_SHIFT); 00229 Uint32 shrink = old_size - new_size; 00230 #ifdef VM_TRACE 00231 memset(m_data + old_pos + new_size, 0xF1, 4 * shrink); 00232 #endif 00233 free_space+= shrink; 00234 if(insert_pos == (old_pos + old_size)) 00235 insert_pos -= shrink; 00236 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Tup_varsize_page::STATIC_CONST | ( | PREV_SHIFT | = LEN_SHIFT |
) |
| Tup_varsize_page::STATIC_CONST | ( | PREV_MASK | = LEN_MASK |
) |
| Tup_varsize_page::STATIC_CONST | ( | NEXT_SHIFT | = POS_SHIFT |
) |
| Tup_varsize_page::STATIC_CONST | ( | NEXT_MASK | = POS_MASK |
) |
| Tup_varsize_page::STATIC_CONST | ( | END_OF_FREE_LIST | = POS_MASK |
) |
| Tup_varsize_page::STATIC_CONST | ( | POS_SHIFT | = 0 |
) |
| Tup_varsize_page::STATIC_CONST | ( | LEN_SHIFT | = 15 |
) |
| Tup_varsize_page::STATIC_CONST | ( | POS_MASK | = 0x00007FFF |
) |
| Tup_varsize_page::STATIC_CONST | ( | LEN_MASK | = 0x3FFF8000 |
) |
| Tup_varsize_page::STATIC_CONST | ( | FREE | = 0x40000000 |
) |
| Tup_varsize_page::STATIC_CONST | ( | CHAIN | = 0x80000000 |
) |
| Tup_varsize_page::STATIC_CONST | ( | DATA_WORDS | = File_formats::NDB_PAGE_SIZE_WORDS-32 |
) |
| union { ... } |
| union { ... } |
Definition at line 112 of file tuppage.hpp.
Definition at line 111 of file tuppage.hpp.
Definition at line 120 of file tuppage.hpp.
Definition at line 122 of file tuppage.hpp.
Referenced by alloc_record(), free_record(), init(), Dbtup::realloc_var_part(), and rebuild_index().
Definition at line 132 of file tuppage.hpp.
Referenced by alloc_record(), free_record(), init(), rebuild_index(), and reorg().
Definition at line 133 of file tuppage.hpp.
Referenced by alloc_record(), free_record(), init(), Dbtup::realloc_var_part(), and reorg().
Definition at line 115 of file tuppage.hpp.
Definition at line 124 of file tuppage.hpp.
| Uint32 Tup_varsize_page::m_data[DATA_WORDS] |
Definition at line 150 of file tuppage.hpp.
Referenced by alloc_record(), free_record(), rebuild_index(), and reorg().
Definition at line 131 of file tuppage.hpp.
Definition at line 130 of file tuppage.hpp.
Definition at line 127 of file tuppage.hpp.
Definition at line 129 of file tuppage.hpp.
Definition at line 126 of file tuppage.hpp.
Definition at line 106 of file tuppage.hpp.
Definition at line 128 of file tuppage.hpp.
Definition at line 116 of file tuppage.hpp.
Definition at line 118 of file tuppage.hpp.
Definition at line 123 of file tuppage.hpp.
Referenced by alloc_record(), free_record(), init(), and rebuild_index().
Definition at line 108 of file tuppage.hpp.
Definition at line 107 of file tuppage.hpp.
Definition at line 121 of file tuppage.hpp.
Definition at line 119 of file tuppage.hpp.
Definition at line 109 of file tuppage.hpp.
Definition at line 125 of file tuppage.hpp.
Definition at line 134 of file tuppage.hpp.
1.4.7

