19 #define DBTUP_FIXALLOC_CPP
21 #include <RefConvert.hpp>
22 #include <ndb_limits.h>
65 Dbtup::alloc_fix_rec(Uint32 * err,
66 Fragrecord*
const regFragPtr,
67 Tablerec*
const regTabPtr,
69 Uint32 * out_frag_page_id)
76 pagePtr.i = regFragPtr->thFreeFirst.firstItem;
77 if (pagePtr.i == RNIL) {
81 pagePtr.i = allocFragPage(err, regFragPtr);
82 if (pagePtr.i != RNIL) {
88 c_page_pool.
getPtr(pagePtr);
90 convertThPage((Fix_page*)pagePtr.p, regTabPtr, MM);
91 pagePtr.p->page_state = ZTH_MM_FREE;
94 free_pages.addFirst(pagePtr);
108 c_page_pool.
getPtr(pagePtr);
111 Uint32
page_offset= alloc_tuple_from_page(regFragPtr, (Fix_page*)pagePtr.p);
113 *out_frag_page_id= pagePtr.p->frag_page_id;
114 key->m_page_no = pagePtr.i;
119 void Dbtup::convertThPage(Fix_page* regPagePtr,
123 Uint32 nextTuple = regTabPtr->m_offsets[mm].m_fix_header_size;
130 Uint32 prev = 0xFFFF;
132 memset(regPagePtr->m_data, 0xF1, 4*Fix_page::DATA_WORDS);
135 Uint32 gci_val = 0xF1F1F1F1;
136 if (regTabPtr->m_bits & Tablerec::TR_RowGCI)
138 Tuple_header* ptr = 0;
139 gci_pos = Uint32(ptr->get_mm_gci(regTabPtr) - (Uint32*)ptr);
142 while (pos + nextTuple <= Fix_page::DATA_WORDS)
144 regPagePtr->m_data[pos] = (prev << 16) | (pos + nextTuple);
145 regPagePtr->m_data[pos + 1] = Fix_page::FREE_RECORD;
146 regPagePtr->m_data[pos + gci_pos] = gci_val;
152 regPagePtr->m_data[prev] |= 0xFFFF;
153 regPagePtr->next_free_index= 0;
154 regPagePtr->free_space= cnt;
155 regPagePtr->m_page_header.m_page_type = File_formats::PT_Tup_fixsize_page;
159 Dbtup::alloc_tuple_from_page(Fragrecord*
const regFragPtr,
160 Fix_page*
const regPagePtr)
162 ndbassert(regPagePtr->free_space);
163 Uint32 idx= regPagePtr->alloc_record();
164 if(regPagePtr->free_space == 0)
175 ndbrequire(regPagePtr->page_state == ZTH_MM_FREE);
177 free_pages.remove((Page*)regPagePtr);
178 regPagePtr->page_state = ZTH_MM_FULL;
185 void Dbtup::free_fix_rec(Fragrecord* regFragPtr,
188 Fix_page* regPagePtr)
190 Uint32 free= regPagePtr->free_record(key->m_page_idx);
191 PagePtr pagePtr = { (Page*)regPagePtr, key->m_page_no };
197 ndbrequire(regPagePtr->page_state == ZTH_MM_FULL);
198 regPagePtr->page_state = ZTH_MM_FREE;
199 free_pages.addLast(pagePtr);
202 (Fix_page::DATA_WORDS / regTabPtr->m_offsets[MM].m_fix_header_size))
205 Uint32 page_no = pagePtr.p->frag_page_id;
207 free_pages.remove(pagePtr);
208 releaseFragPage(regFragPtr, page_no, pagePtr);
213 Dbtup::alloc_fix_rowid(Uint32 * err,
214 Fragrecord* regFragPtr,
217 Uint32 * out_frag_page_id)
219 Uint32 page_no = key->m_page_no;
220 Uint32 idx= key->m_page_idx;
223 if ((pagePtr.i = allocFragPage(err, regTabPtr, regFragPtr, page_no)) == RNIL)
228 c_page_pool.
getPtr(pagePtr);
229 Uint32 state = pagePtr.p->page_state;
233 if (((Fix_page*)pagePtr.p)->alloc_record(idx) != idx)
235 * err = ZROWID_ALLOCATED;
239 if(pagePtr.p->free_space == 0)
242 pagePtr.p->page_state = ZTH_MM_FULL;
243 free_pages.remove(pagePtr);
246 *out_frag_page_id= page_no;
247 key->m_page_no = pagePtr.i;
248 key->m_page_idx = idx;
249 return pagePtr.p->m_data + idx;
251 * err = ZROWID_ALLOCATED;