/************************************************ * No Change * RETURN: * success - successfully created the index list header * failure - it did not create the index list header ***********************************************************/ const int IndexList::addRidInBlk( const RID& newRid) { int maxCount, count=0; int rc = NO_ERROR; CommBlock cb; cb.file.oid = m_oid; cb.file.pFile = m_pFile; if (m_useNarray) maxCount = MAX_BLK_NARRAY_RID_CNT; else maxCount = MAX_BLK_RID_CNT; //Find the last block that has a space or //No next block linked rc = findLastBlk(count); if ((count ==maxCount) && (m_nextType==LIST_SIZE_TYPE)) {//Full, also need a new segment IdxEmptyListEntry newIdxListEntryPtr; m_segType = LIST_BLOCK_TYPE; rc = getSegment( m_pFile, ENTRY_BLK, &newIdxListEntryPtr); m_nextLbid = ((IdxEmptyListEntry*)&newIdxListEntryPtr)->fbo; m_nextType = m_segType; m_lastIdxRidListPtr.llp=((IdxRidListPtr*)&newIdxListEntryPtr)->llp; rc = updateLastPtrAndParent(count); //the new block for insertion and count record m_lbid = m_nextLbid; m_sbid = 0; m_entry = 0; m_curType = m_nextType; rc = readCurBlk(); //free manager puts bad entry type at the last entry for new block //clean it up! IdxRidListPtr idxRidListPtr; memset(&idxRidListPtr, 0, sizeof(idxRidListPtr)); rc = setNextInfoFromBlk( idxRidListPtr); if (m_useNarray) { rc = initCurBlock(); } //Set the count to the beginning count = 0; }//end if FULL get new segment // insert in the current block at the location if (m_lastLbid != m_lbid) { rc = setLastLbid(m_lbid); } rc = insertRid(newRid, count); rc = updateCurCount(); rc = updateHdrCount(); return rc; }
/************************************************ * No Change * RETURN: * success - successfully created the index list header * failure - it did not create the index list header ***********************************************************/ const int IndexList::addRidInSub(const RID& newRid, IdxRidListPtr& lastIdxRidListPtr) { int rc = NO_ERROR; int maxCount; int count; CommBlock cb; cb.file.oid = m_oid; cb.file.pFile = m_pFile; m_curType = LIST_SUBBLOCK_TYPE; m_segType = LIST_BLOCK_TYPE; m_nextType = lastIdxRidListPtr.type; maxCount = MAX_SUB_RID_CNT; count = lastIdxRidListPtr.count; //For n-array m_curLevel =0; m_curLevelPos = 0; m_curBlkPos = 0; m_parentLbid = INVALID_LBID; if ((count ==maxCount) && (m_nextType==LIST_SIZE_TYPE)) {//Full, need a new segment IdxEmptyListEntry newIdxListEntryPtr; memset(&newIdxListEntryPtr, 0, sizeof(newIdxListEntryPtr)); rc = getSegment( m_pFile, ENTRY_BLK, &newIdxListEntryPtr); if (rc!=NO_ERROR) return rc; lastIdxRidListPtr.type = LIST_BLOCK_TYPE; lastIdxRidListPtr.llp=((IdxRidListPtr*)&newIdxListEntryPtr)->llp; lastIdxRidListPtr.spare=0x0; rc = setNextInfoFromBlk( lastIdxRidListPtr); //New Block initialization m_lbid = newIdxListEntryPtr.fbo; m_sbid = 0; m_entry = 0; m_curType = m_segType; rc = readCurBlk(); //make sure no garbage in the new block last entry IdxRidListPtr idxRidListPtr; memset(&idxRidListPtr, 0, sizeof(idxRidListPtr)); rc = setNextInfoFromBlk( idxRidListPtr); count = 0; if (m_useNarray) rc = initCurBlock(); if (m_lastLbid != m_lbid) { rc = setLastLbid(m_lbid); } }//end if FULL else if (count <maxCount)// if less than maxCount either type =7 or 0 { if (m_lastLbid != INVALID_LBID) { uint64_t zlbid = INVALID_LBID; rc = setLastLbid(zlbid); } } //endif count else if ((count ==maxCount) && (m_nextType==LIST_BLOCK_TYPE)) { m_lbid = ((IdxEmptyListEntry*)&lastIdxRidListPtr)->fbo; m_sbid = 0; m_entry = 0; m_curType = LIST_BLOCK_TYPE; rc = addRidInBlk(newRid); return rc; } rc = insertRid(newRid, count);// count is the position rc = updateCurCount(); rc = updateHdrCount(); return rc; }