1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,84 +34,88 @@ namespace WriteEngine
{
/** Class FreeMgr */
class FreeMgr : public DbFileOp
class FreeMgr : public DbFileOp
{
public:
/**
* @brief Constructor
*/
FreeMgr();
/**
* @brief Default Destructor
*/
~FreeMgr();
/**
* @brief init free chains in a new index file
*/
const int init( CommBlock &cb, const int freemgrType );
/**
* @brief Init free chains in a new file or an existing file
* The start block is an FBO or an LBID depending on whether we are using BRM
**/
const int init( CommBlock &cb, DataBlock* blockZero, const int freemgrType , const IdxTreeGroupType chainType, const int startBlock, const int numberBlocks );
/**
* @brief find a free segment and return ptr
*/
const int assignSegment( CommBlock &cb, DataBlock* blockZero, const int freemgr_type, const IdxTreeGroupType segmentType, IdxEmptyListEntry* assignPtr ) ;
/**
* @brief put a free segment back into chain
*/
const int releaseSegment( CommBlock &cb, DataBlock* blockZero, const int freemgr_type, const IdxTreeGroupType segmentType, IdxEmptyListEntry* assignPtr ) ;
/**
* @brief Map an FBO to LBID
/**
* @brief Constructor
*/
const uint64_t mapLBID( CommBlock &cb, const uint64_t fbo, int &rc );
/**
* extendFreespace - ran out of space in one of the chains?
* Add blocks via calls to BRM extent mgr and fseek the file to the end
FreeMgr();
/**
* @brief Default Destructor
*/
~FreeMgr();
/**
* @brief init free chains in a new index file
*/
const int init( CommBlock& cb, const int freemgrType );
/**
* @brief Init free chains in a new file or an existing file
* The start block is an FBO or an LBID depending on whether we are using BRM
**/
const int extendFreespace( CommBlock &cb, DataBlock* blockZero, const int freemgr_type );
const int init( CommBlock& cb, DataBlock* blockZero, const int freemgrType, const IdxTreeGroupType chainType, const int startBlock, const int numberBlocks );
/**
* @brief find a free segment and return ptr
*/
const int assignSegment( CommBlock& cb, DataBlock* blockZero, const int freemgr_type, const IdxTreeGroupType segmentType, IdxEmptyListEntry* assignPtr ) ;
/**
* @brief put a free segment back into chain
*/
const int releaseSegment( CommBlock& cb, DataBlock* blockZero, const int freemgr_type, const IdxTreeGroupType segmentType, IdxEmptyListEntry* assignPtr ) ;
/**
* @brief Map an FBO to LBID
*/
const uint64_t mapLBID( CommBlock& cb, const uint64_t fbo, int& rc );
/**
* extendFreespace - ran out of space in one of the chains?
* Add blocks via calls to BRM extent mgr and fseek the file to the end
**/
const int extendFreespace( CommBlock& cb, DataBlock* blockZero, const int freemgr_type );
//private:
/**
* @brief Create sub block zero for use by free manager
*/
const int initBlockzero( DataBlock* blockZero);
/**
* @brief Handle release of sub-blocks separately - sometimes a sub-block contains list entries and sometimes it is a list entry
*/
const int releaseSubblock( CommBlock &cb, WriteEngine::DataBlock*, int, WriteEngine::IdxEmptyListEntry*) ;
const int releaseSubblock( CommBlock& cb, WriteEngine::DataBlock*, int, WriteEngine::IdxEmptyListEntry*) ;
/**
* @brief Handle assignment of sub-blocks separately - sometimes a sub-block contains list entries and sometimes it is a list entry
*/
const int assignSubblock( CommBlock &cb, WriteEngine::DataBlock*, int, WriteEngine::IdxEmptyListEntry*);
const int assignSubblock( CommBlock& cb, WriteEngine::DataBlock*, int, WriteEngine::IdxEmptyListEntry*);
/**
* Blank out the entries in the structure
**/
const void nullPtr( WriteEngine::IdxEmptyListEntry* assignPtr ) const;
const void printMemSubBlock( DataBlock* curBlock, const int sbid );
inline const int calcPtrOffset( const int position ) const
{ return 1+position; }
{
return 1 + position;
}
inline const int calcStatOffset( const int position ) const
{ return 8+position; }
{
return 8 + position;
}
int initType;// decide which algorithm to use to init the chains
int allowExtend; // allow file to be extended
};

View File

@ -32,301 +32,323 @@
using namespace std;
namespace WriteEngine
{
/**
* Constructor
{
/**
* Constructor
*/
IndexList::IndexList()
: m_oid((OID) INVALID_NUM), m_useNarray(true),
m_curLevel(INVALID_NUM), m_curBlkPos(0),
m_curLevelPos(INVALID_NUM)
{
m_freemgr.setDebugLevel(DEBUG_0);
init();
};
/****************************************************************
* DESCRIPTION:
* Public Function for adding a header
* (1) Given a key value and a row ID,
* (2) Return a pointer for insertion into the correct position
* in the Index Tree List Pointer group
* (3) A return code should indicate success or failur
* PARAMETERS:
* input
* pFile - File Handler
* rid - Input row ID
* key - Input key value
* output
* listHdrPtr - Output a pointer to the index list header
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
*
*******************************************************************/
const int IndexList::addIndexListHdr( FILE* pFile, const RID& rowId,
const uint64_t& key,
IdxEmptyListEntry* newEmptyListPtr)
{
int rc;
CommBlock cb;
m_pFile = pFile;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
//Set up the header structure
//Initialize header blokcs
rc = resetBlk(&m_hdrBlock);
m_hdrLbid = INVALID_LBID;
m_hdrSbid = INVALID_NUM;
m_hdrEntry = INVALID_NUM;
//Initialize the new Index List header to null
memset( &m_curIdxRidListHdr, 0, LIST_HDR_SIZE );
//Assign the bit fields for the first entry in the Index List Header
m_curIdxRidListHdr.idxRidListSize.type = LIST_SIZE_TYPE;
m_curIdxRidListHdr.idxRidListSize.spare = 0x0;
m_curIdxRidListHdr.idxRidListSize.size = 1;
//Assign the bit fields for the second entry of the Index List Header
m_curIdxRidListHdr.key = key;
//Assign bit fields for the third entry of the Index List Header
m_curIdxRidListHdr.firstIdxRidListEntry.type = LIST_RID_TYPE;
m_curIdxRidListHdr.firstIdxRidListEntry.spare = 0x0;
m_curIdxRidListHdr.firstIdxRidListEntry.rid = rowId ;
//Assign bit fields for the fourth entry of the Index List Header
m_curIdxRidListHdr.nextIdxRidListPtr.type = LIST_NOT_USED_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.spare = 0x0;
m_curIdxRidListHdr.nextIdxRidListPtr.llp = 0x0;
/* Get assigned space for the header from free manager
* Get the new block for the new idx list header
* The header needs LIST_HDR_SIZE bytes
*/
IndexList::IndexList()
:m_oid((OID) INVALID_NUM), m_useNarray(true),
m_curLevel(INVALID_NUM),m_curBlkPos(0),
m_curLevelPos(INVALID_NUM)
{
m_freemgr.setDebugLevel(DEBUG_0);
init();
};
/****************************************************************
* DESCRIPTION:
* Public Function for adding a header
* (1) Given a key value and a row ID,
* (2) Return a pointer for insertion into the correct position
* in the Index Tree List Pointer group
* (3) A return code should indicate success or failur
* PARAMETERS:
* input
* pFile - File Handler
* rid - Input row ID
* key - Input key value
* output
* listHdrPtr - Output a pointer to the index list header
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
*
*******************************************************************/
const int IndexList::addIndexListHdr( FILE* pFile, const RID& rowId,
const uint64_t& key,
IdxEmptyListEntry* newEmptyListPtr)
{
int rc;
CommBlock cb;
m_pFile = pFile;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
//Set up the header structure
//Initialize header blokcs
rc = resetBlk(&m_hdrBlock);
m_hdrLbid = INVALID_LBID;
m_hdrSbid = INVALID_NUM;
m_hdrEntry = INVALID_NUM;
rc = getSegment(pFile, ENTRY_4, newEmptyListPtr);
//Initialize the new Index List header to null
memset( &m_curIdxRidListHdr, 0, LIST_HDR_SIZE );
//Assign the bit fields for the first entry in the Index List Header
m_curIdxRidListHdr.idxRidListSize.type = LIST_SIZE_TYPE;
m_curIdxRidListHdr.idxRidListSize.spare = 0x0;
m_curIdxRidListHdr.idxRidListSize.size = 1;
//Assign the bit fields for the second entry of the Index List Header
m_curIdxRidListHdr.key = key;
//Assign bit fields for the third entry of the Index List Header
m_curIdxRidListHdr.firstIdxRidListEntry.type =LIST_RID_TYPE;
m_curIdxRidListHdr.firstIdxRidListEntry.spare =0x0;
m_curIdxRidListHdr.firstIdxRidListEntry.rid =rowId ;
//Assign bit fields for the fourth entry of the Index List Header
m_curIdxRidListHdr.nextIdxRidListPtr.type = LIST_NOT_USED_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.spare =0x0;
m_curIdxRidListHdr.nextIdxRidListPtr.llp =0x0;
/* Get assigned space for the header from free manager
* Get the new block for the new idx list header
* The header needs LIST_HDR_SIZE bytes
*/
rc = getSegment(pFile, ENTRY_4, newEmptyListPtr);
if (rc != NO_ERROR)
return rc;
m_hdrLbid = newEmptyListPtr->fbo;
m_hdrSbid = newEmptyListPtr->sbid;
m_hdrEntry = newEmptyListPtr->entry;
//Write Index List Header to the file block
//Write LIST_HDR_SIZE bytes in one time.
rc = readDBFile( cb, m_hdrBlock.data, m_hdrLbid );
rc = writeSubBlockEntry( cb, &m_hdrBlock, m_hdrLbid, m_hdrSbid,
m_hdrEntry,LIST_HDR_SIZE, &m_curIdxRidListHdr );
if (rc!= NO_ERROR)
{
return rc;
}
//Wrote Header Block Out already, Start Over next time
//Update the flags to indicate there is data on the header block
m_hdrBlock.dirty = true;
m_hdrBlock.lbid = m_hdrLbid;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
//DONE
return rc;
};
/****************************************************************
* DESCRIPTION:
*
*
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateIndexList(FILE* pFile, const RID& newRid,
const uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr)
{
int rc;
m_pFile = pFile;
//Initialization
if ( (key!= m_curIdxRidListHdr.key) || (m_hdrBlock.state==BLK_INIT))
{
rc = initGetHdr(key, curIdxRidListHdrPtr);
if (key!= m_curIdxRidListHdr.key)
return ERR_IDX_LIST_INVALID_KEY;
}
rc = updateIndexList(newRid, key);
if (rc!=NO_ERROR)
{
return rc;
}
//Write everything out
rc = updateIndexListWrite();
return rc;
};
/****************************************************************
* DESCRIPTION:
* (0) THIS FUNCIION CAN ONLY BE CALLED WITH THE PUBLIC
*
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateIndexList(const RID& newRid, const uint64_t& key)
{
int rc = NO_ERROR;
if (rc != NO_ERROR)
return rc;
//m_lastLbid==0 or not determines if we can skip from the header,the first
//subblock or go to the last inserted block
if (m_lastLbid ==(uint64_t)INVALID_LBID)
{
rc = updateHdrSub(newRid, key);
}
else // get the lastLbid info from header
{//m_lastLbid > 0, space is in some block now
m_lbid = m_lastLbid;
m_sbid = 0;
m_entry = 0;
m_segType = LIST_BLOCK_TYPE;
m_curType = LIST_BLOCK_TYPE;
rc = addRidInBlk(newRid);
}
return rc;
};
/************************************************
* Description:
* Find a entry for the given rowId and Key
* Then Delete it from the list
* Move the rest of the row id up in the same
* sub block an decrement the count in that subblock
* decrement the header size
* Converted
* input
* pFile -- File Handler
* rowId -- row id
* key -- value
* curIdxRidListHdrPtr - point to the header
*
* return value
* Success -- 0
* Fail -- ERR_IDX_LIST_INVALID_DELETE
************************************************/
const int IndexList::deleteIndexList( FILE* pFile, const RID& rowId,
const uint64_t& key, IdxEmptyListEntry* curIdxRidListHdrPtr)
m_hdrLbid = newEmptyListPtr->fbo;
m_hdrSbid = newEmptyListPtr->sbid;
m_hdrEntry = newEmptyListPtr->entry;
//Write Index List Header to the file block
//Write LIST_HDR_SIZE bytes in one time.
rc = readDBFile( cb, m_hdrBlock.data, m_hdrLbid );
rc = writeSubBlockEntry( cb, &m_hdrBlock, m_hdrLbid, m_hdrSbid,
m_hdrEntry, LIST_HDR_SIZE, &m_curIdxRidListHdr );
if (rc != NO_ERROR)
{
return rc;
}
//Wrote Header Block Out already, Start Over next time
//Update the flags to indicate there is data on the header block
m_hdrBlock.dirty = true;
m_hdrBlock.lbid = m_hdrLbid;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
//DONE
return rc;
};
/****************************************************************
* DESCRIPTION:
*
*
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateIndexList(FILE* pFile, const RID& newRid,
const uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr)
{
int rc;
m_pFile = pFile;
//Initialization
if ( (key != m_curIdxRidListHdr.key) || (m_hdrBlock.state == BLK_INIT))
{
rc = initGetHdr(key, curIdxRidListHdrPtr);
if (key != m_curIdxRidListHdr.key)
return ERR_IDX_LIST_INVALID_KEY;
}
rc = updateIndexList(newRid, key);
if (rc != NO_ERROR)
{
return rc;
}
//Write everything out
rc = updateIndexListWrite();
return rc;
};
/****************************************************************
* DESCRIPTION:
* (0) THIS FUNCIION CAN ONLY BE CALLED WITH THE PUBLIC
*
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateIndexList(const RID& newRid, const uint64_t& key)
{
int rc = NO_ERROR;
//m_lastLbid==0 or not determines if we can skip from the header,the first
//subblock or go to the last inserted block
if (m_lastLbid == (uint64_t)INVALID_LBID)
{
rc = updateHdrSub(newRid, key);
}
else // get the lastLbid info from header
{
//m_lastLbid > 0, space is in some block now
m_lbid = m_lastLbid;
m_sbid = 0;
m_entry = 0;
m_segType = LIST_BLOCK_TYPE;
m_curType = LIST_BLOCK_TYPE;
rc = addRidInBlk(newRid);
}
return rc;
};
/************************************************
* Description:
* Find a entry for the given rowId and Key
* Then Delete it from the list
* Move the rest of the row id up in the same
* sub block an decrement the count in that subblock
* decrement the header size
* Converted
* input
* pFile -- File Handler
* rowId -- row id
* key -- value
* curIdxRidListHdrPtr - point to the header
*
* return value
* Success -- 0
* Fail -- ERR_IDX_LIST_INVALID_DELETE
************************************************/
const int IndexList::deleteIndexList( FILE* pFile, const RID& rowId,
const uint64_t& key, IdxEmptyListEntry* curIdxRidListHdrPtr)
{
int rc = ERR_IDX_LIST_INVALID_DELETE;
m_pFile = pFile;
getHdrInfo(curIdxRidListHdrPtr);
if (key != m_curIdxRidListHdr.key)
{
int rc =ERR_IDX_LIST_INVALID_DELETE;
m_pFile = pFile;
getHdrInfo(curIdxRidListHdrPtr);
if (key!= m_curIdxRidListHdr.key)
{
memset( m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_hdrBlock.dirty = false;
m_hdrBlock.state = BLK_INIT;
return ERR_IDX_LIST_INVALID_KEY;
}
rc = deleteIndexList(rowId,key);
return rc;
}
/************************************************
* Description:
* Converted - keep the first sub block
* Find a entry for the given rowId and Key
* Then Delete it from the list
* Move the rest of the row id up in the same
* sub block an decrement the count in that subblock
* decrement the header size
* input
* pFile -- File Handler
* rowId -- row id
* key -- value
* curIdxRidListHdrPtr - point to the header
*
* return value
* Success -- 0
* Fail -- ERR_IDX_LIST_INVALID_DELETE
************************************************/
const int IndexList::deleteIndexList( const RID& rowId,const uint64_t& key)
rc = deleteIndexList(rowId, key);
return rc;
}
/************************************************
* Description:
* Converted - keep the first sub block
* Find a entry for the given rowId and Key
* Then Delete it from the list
* Move the rest of the row id up in the same
* sub block an decrement the count in that subblock
* decrement the header size
* input
* pFile -- File Handler
* rowId -- row id
* key -- value
* curIdxRidListHdrPtr - point to the header
*
* return value
* Success -- 0
* Fail -- ERR_IDX_LIST_INVALID_DELETE
************************************************/
const int IndexList::deleteIndexList( const RID& rowId, const uint64_t& key)
{
int rc = ERR_IDX_LIST_INVALID_DELETE;
RID savedRid ;
DataBlock prevDataBlock;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
//Check the first row location, 3rd entry
//Because it may be deleted from the delete action
//The header size cannot tell us the rowid size on header
if (m_curIdxRidListHdr.firstIdxRidListEntry.type
== (int)LIST_RID_TYPE)
{
int rc =ERR_IDX_LIST_INVALID_DELETE;
RID savedRid ;
DataBlock prevDataBlock;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
//Check the first row location, 3rd entry
//Because it may be deleted from the delete action
//The header size cannot tell us the rowid size on header
if (m_curIdxRidListHdr.firstIdxRidListEntry.type
==(int)LIST_RID_TYPE)
{
if (m_curIdxRidListHdr.firstIdxRidListEntry.rid
== rowId)
{
m_curIdxRidListHdr.firstIdxRidListEntry.type
=LIST_NOT_USED_TYPE; //not used type
m_curIdxRidListHdr.firstIdxRidListEntry.rid = 0;
m_curIdxRidListHdr.idxRidListSize.size--;
rc = writeSubBlockEntry(cb,&m_hdrBlock,m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_hdrBlock.dirty = false;
m_dLbid = m_hdrLbid;
m_dSbid = m_hdrSbid;
m_dEntry = m_hdrEntry+2;
return rc;
}
};
//Check Header last entry's type
int type = m_curIdxRidListHdr.nextIdxRidListPtr.type;
switch (type)
{
case LIST_NOT_USED_TYPE://Header is not full, no sub-block linked
//No RowId here
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_hdrBlock.dirty = false;
m_dLbid = -1LL;
m_dSbid = -1;
m_dEntry = -1;
return ERR_IDX_LIST_INVALID_DELETE; //not found, failed
case LIST_RID_TYPE:// There is a row id here, Check!
savedRid = m_curIdxRidListHdr.nextIdxRidListPtr.llp;
if (savedRid == rowId)
{
m_curIdxRidListHdr.nextIdxRidListPtr.type
=LIST_NOT_USED_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.llp = 0;
m_curIdxRidListHdr.idxRidListSize.size--;
rc = writeSubBlockEntry(cb, &m_hdrBlock,m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
m_hdrBlock.dirty = false;
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_dLbid = m_hdrLbid;
m_dSbid = m_hdrSbid;
m_dEntry = 3;
return rc;
}
else
{
m_hdrBlock.dirty = false;
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_dLbid = -1LL;
m_dSbid = -1;
m_dEntry = -1;
return ERR_IDX_LIST_INVALID_DELETE;
}
case LIST_SUBBLOCK_TYPE://Not found in header,
rc = deleteInSub(rowId);
if (rc == NO_ERROR)
if (m_curIdxRidListHdr.firstIdxRidListEntry.rid
== rowId)
{
m_curIdxRidListHdr.firstIdxRidListEntry.type
= LIST_NOT_USED_TYPE; //not used type
m_curIdxRidListHdr.firstIdxRidListEntry.rid = 0;
m_curIdxRidListHdr.idxRidListSize.size--;
rc = writeSubBlockEntry(cb, &m_hdrBlock, m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_hdrBlock.dirty = false;
m_dLbid = m_hdrLbid;
m_dSbid = m_hdrSbid;
m_dEntry = m_hdrEntry + 2;
return rc;
}
};
//Check Header last entry's type
int type = m_curIdxRidListHdr.nextIdxRidListPtr.type;
switch (type)
{
case LIST_NOT_USED_TYPE://Header is not full, no sub-block linked
//No RowId here
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_hdrBlock.dirty = false;
m_dLbid = -1LL;
m_dSbid = -1;
m_dEntry = -1;
return ERR_IDX_LIST_INVALID_DELETE; //not found, failed
case LIST_RID_TYPE:// There is a row id here, Check!
savedRid = m_curIdxRidListHdr.nextIdxRidListPtr.llp;
if (savedRid == rowId)
{
m_curIdxRidListHdr.nextIdxRidListPtr.type
= LIST_NOT_USED_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.llp = 0;
m_curIdxRidListHdr.idxRidListSize.size--;
rc = writeSubBlockEntry(cb, &m_hdrBlock, m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
m_hdrBlock.dirty = false;
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_dLbid = m_hdrLbid;
m_dSbid = m_hdrSbid;
m_dEntry = 3;
return rc;
rc = deleteInBlock(rowId);
return rc;
break;
default:
break;
};//end of switch
return ERR_IDX_LIST_INVALID_DELETE;
}
}
}
else
{
m_hdrBlock.dirty = false;
memset(m_hdrBlock.data, 0, sizeof(m_hdrBlock.data));
m_dLbid = -1LL;
m_dSbid = -1;
m_dEntry = -1;
return ERR_IDX_LIST_INVALID_DELETE;
}
case LIST_SUBBLOCK_TYPE://Not found in header,
rc = deleteInSub(rowId);
if (rc == NO_ERROR)
return rc;
rc = deleteInBlock(rowId);
return rc;
break;
default:
break;
};//end of switch
return ERR_IDX_LIST_INVALID_DELETE;
}
}

View File

@ -40,322 +40,386 @@ namespace WriteEngine
class IndexList : public DbFileOp
{
public:
/**
* @brief Constructor
*/
IndexList();
//IndexList(FILE* pFile, IdxEmptyListEntry* newHeaderListPtr);
/**
* @brief Default Destructor
*/
~IndexList(){};
/**
* @brief Constructor
*/
IndexList();
//IndexList(FILE* pFile, IdxEmptyListEntry* newHeaderListPtr);
/**
* @brief Default Destructor
*/
~IndexList() {};
/**
* @brief Public index List related functions
*/
/**
* @brief Add a 4 bytes header for a rowid, key in the index list
*/
const int addIndexListHdr( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr );
const int addIndexListHdr( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr )
{
m_oid = cbList.file.oid; m_pFile = cbList.file.pFile;
int rc = addIndexListHdr( m_pFile, listRid, key, newHeaderListPtr);
return rc;
}
const int addIndexListHdr( FILE* pFile, const RID* ridList, const int size, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr );
const int addIndexListHdr( CommBlock& cbList, RID* ridList, int& size, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr )
{
m_oid = cbList.file.oid; m_pFile = cbList.file.pFile;
int rc = addIndexListHdr( m_pFile, ridList, size, key, newHeaderListPtr);
return rc;
/**
* @brief Public index List related functions
*/
/**
* @brief Add a 4 bytes header for a rowid, key in the index list
*/
const int addIndexListHdr( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr );
const int addIndexListHdr( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr )
{
m_oid = cbList.file.oid;
m_pFile = cbList.file.pFile;
int rc = addIndexListHdr( m_pFile, listRid, key, newHeaderListPtr);
return rc;
}
const int addIndexListHdr( FILE* pFile, const RID* ridList, const int size, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr );
const int addIndexListHdr( CommBlock& cbList, RID* ridList, int& size, const uint64_t& key,
IdxEmptyListEntry* newHeaderListPtr )
{
m_oid = cbList.file.oid;
m_pFile = cbList.file.pFile;
int rc = addIndexListHdr( m_pFile, ridList, size, key, newHeaderListPtr);
return rc;
}
const int addIndexListHdr( CommBlock& cbList, const IdxMultiRid& multiRids,
const uint64_t& key, IdxEmptyListEntry* newHeaderListPtr)
{
m_oid = cbList.file.oid; m_pFile = cbList.file.pFile;
int size = multiRids.totalRid;
return addIndexListHdr( m_pFile, multiRids.ridArray, size,
key, newHeaderListPtr );
m_oid = cbList.file.oid;
m_pFile = cbList.file.pFile;
int size = multiRids.totalRid;
return addIndexListHdr( m_pFile, multiRids.ridArray, size,
key, newHeaderListPtr );
}
/**
* @brief Update the indexlist when a new rowid an key inserted
*/
const int updateIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
const int updateIndexList( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid; m_pFile = cbList.file.pFile;
int rc = updateIndexList( m_pFile, listRid, key, oldHeaderListPtr);
return rc;
};
const int updateIndexList( FILE* pFile, const RID* ridList, const int size,const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
const int updateIndexList( CommBlock& cbList, const RID* ridList, const int size,const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid; m_pFile = cbList.file.pFile;
int rc = updateIndexList( m_pFile, ridList, size,key, oldHeaderListPtr);
return rc;
}
const int updateIndexList( CommBlock& cbList, const IdxMultiRid& multiRids,
const uint64_t& key, IdxEmptyListEntry* oldHeaderListPtr)
{
return updateIndexList( cbList, multiRids.ridArray, multiRids.totalRid,
key, oldHeaderListPtr );
}
/**
* @brief Update the indexlist when a new rowid an key inserted
*/
const int updateIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
/**
* @brief Delete the rowid in the key indexlist
*/
const int deleteIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
const int deleteIndexList( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
int rc = deleteIndexList( m_pFile, listRid, key, oldHeaderListPtr );
return rc;
};
/**
* @brief delete a row id from the key index list and return the location
*/
const int deleteIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
uint64_t& lbid, int& sbid, int& entry );
const int deleteIndexList( CommBlock& cbList, const RID& listRid,
const uint64_t& key,
const int updateIndexList( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid;
m_pFile = cbList.file.pFile;
int rc = updateIndexList( m_pFile, listRid, key, oldHeaderListPtr);
return rc;
};
const int updateIndexList( FILE* pFile, const RID* ridList, const int size, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
const int updateIndexList( CommBlock& cbList, const RID* ridList, const int size, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid;
m_pFile = cbList.file.pFile;
int rc = updateIndexList( m_pFile, ridList, size, key, oldHeaderListPtr);
return rc;
}
const int updateIndexList( CommBlock& cbList, const IdxMultiRid& multiRids,
const uint64_t& key, IdxEmptyListEntry* oldHeaderListPtr)
{
return updateIndexList( cbList, multiRids.ridArray, multiRids.totalRid,
key, oldHeaderListPtr );
}
/**
* @brief Delete the rowid in the key indexlist
*/
const int deleteIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr );
const int deleteIndexList( CommBlock& cbList, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr )
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
int rc = deleteIndexList( m_pFile, listRid, key, oldHeaderListPtr );
return rc;
};
/**
* @brief delete a row id from the key index list and return the location
*/
const int deleteIndexList( FILE* pFile, const RID& listRid, const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
uint64_t& lbid, int& sbid, int& entry );
const int deleteIndexList( CommBlock& cbList, const RID& listRid,
const uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
uint64_t& lbid, int& sbid, int& entry )
{
m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
int rc = deleteIndexList( m_pFile, listRid, key,
oldHeaderListPtr,
lbid, sbid, entry);
return rc;
};
/**
* @brief find a row id from the key index list and return the location
*/
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
int rc = deleteIndexList( m_pFile, listRid, key,
oldHeaderListPtr,
lbid, sbid, entry);
return rc;
};
/**
* @brief find a row id from the key index list and return the location
*/
bool findRowId(FILE* pFile, const RID& rid, const uint64_t& key,
IdxEmptyListEntry* oldIdxRidListHdrPtr,
uint64_t& lbid, int& sbid, int& entry);
bool findRowId(CommBlock& cbList, const RID& rid, const uint64_t& key,
IdxEmptyListEntry* oldIdxRidListHdrPtr,
uint64_t& lbid, int& sbid, int& entry)
{ m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
bool found =findRowId(m_pFile, rid, key,
oldIdxRidListHdrPtr,lbid,
sbid, entry);
return found;
};
/**
* @brief get the total row ids or tokens from the index list header
*/
const int getRIDArrayFromListHdr(FILE* pFile, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size);
const int getRIDArrayFromListHdr(CommBlock& cbList, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size)
{ m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
int rc = getRIDArrayFromListHdr(m_pFile, key,
oldHeaderListPtr,
ridArrary, size);
return rc;
};
const int getRIDArrayFromListHdrNarray(FILE* pFile, uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr,
RID* ridArray, int& size, bool flag);
const int getRIDArrayFromListHdrNarray(CommBlock& cbList, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size, bool flag)
{ m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
int rc = getRIDArrayFromListHdrNarray(m_pFile, key,
oldHeaderListPtr,
ridArrary, size, flag);
return rc;
};
const int init (CommBlock& cbList, const int& freemgr_type)
{
m_oid = cbList.file.oid ; m_pFile = cbList.file.pFile;
int rc = m_freemgr.init(cbList,freemgr_type);
return rc;
};
const int closeList(){int rc = updateIndexListWrite(); return rc;}
void setTransId( const TxnID txnId ) {FileOp::setTransId( txnId );m_freemgr.setTransId(txnId);}
IdxRidListHdr m_curIdxRidListHdr; /**@brief current list header */
const int getHdrInfo(IdxEmptyListEntry* curIdxRidListHdrPtr);
const int getHdrInfo(IdxEmptyListEntry* curIdxRidListHdrPtr, IdxRidListHdr* idxRidListHdr)
{ int rc= 0; rc =getHdrInfo(curIdxRidListHdrPtr);
memcpy(idxRidListHdr, &m_curIdxRidListHdr, LIST_HDR_SIZE);
return rc;
}
/**
* @brief Timer functions
*/
void startTimer() { time( &m_startTime ); }
void stopTimer() { time( &m_endTime ); m_totalTime = difftime( m_endTime, m_startTime); }
double getTotalRunTime() const { return m_totalTime; }
void setDebugLevel(const DebugLevel level){m_freemgr.setDebugLevel(level);}
void setUseSortFlag(const bool flag){m_useSortFlag = flag;}
void startfTimer(){ftime(&t_start);};
void stopfTimer(){ftime(&t_current);};
int getTotalfRunTime()
{int t_diff;
t_diff= (int) (1000.0 * (t_current.time - t_start.time)+ (t_current.millitm - t_start.millitm));
return t_diff;}
/**
* @brief Private index List member functions
*/
const int updateIndexListWrite();
const int init();
const int initBlksGetHdrBlk();
const int initGetHdr(const uint64_t &key, IdxEmptyListEntry* curIdxRidListHdrPtr);
const int resetBlk(DataBlock* dataBlk) ;
const int resetBlkZero(uint64_t& lbid0);
const int writeBlkZero(uint64_t& lbid0);
IdxEmptyListEntry* oldIdxRidListHdrPtr,
uint64_t& lbid, int& sbid, int& entry)
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
bool found = findRowId(m_pFile, rid, key,
oldIdxRidListHdrPtr, lbid,
sbid, entry);
return found;
};
/**
* @brief get the total row ids or tokens from the index list header
*/
const int getRIDArrayFromListHdr(FILE* pFile, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size);
const int getRIDArrayFromListHdr(CommBlock& cbList, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size)
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
int rc = getRIDArrayFromListHdr(m_pFile, key,
oldHeaderListPtr,
ridArrary, size);
return rc;
};
const int getRIDArrayFromListHdrNarray(FILE* pFile, uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr,
RID* ridArray, int& size, bool flag);
const int getRIDArrayFromListHdrNarray(CommBlock& cbList, uint64_t& key,
IdxEmptyListEntry* oldHeaderListPtr,
RID* ridArrary, int& size, bool flag)
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
int rc = getRIDArrayFromListHdrNarray(m_pFile, key,
oldHeaderListPtr,
ridArrary, size, flag);
return rc;
};
const int init (CommBlock& cbList, const int& freemgr_type)
{
m_oid = cbList.file.oid ;
m_pFile = cbList.file.pFile;
int rc = m_freemgr.init(cbList, freemgr_type);
return rc;
};
const int closeList()
{
int rc = updateIndexListWrite();
return rc;
}
void setTransId( const TxnID txnId )
{
FileOp::setTransId( txnId );
m_freemgr.setTransId(txnId);
}
IdxRidListHdr m_curIdxRidListHdr; /**@brief current list header */
const int getHdrInfo(IdxEmptyListEntry* curIdxRidListHdrPtr);
const int getHdrInfo(IdxEmptyListEntry* curIdxRidListHdrPtr, IdxRidListHdr* idxRidListHdr)
{
int rc = 0;
rc = getHdrInfo(curIdxRidListHdrPtr);
memcpy(idxRidListHdr, &m_curIdxRidListHdr, LIST_HDR_SIZE);
return rc;
}
/**
* @brief Timer functions
*/
void startTimer()
{
time( &m_startTime );
}
void stopTimer()
{
time( &m_endTime );
m_totalTime = difftime( m_endTime, m_startTime);
}
double getTotalRunTime() const
{
return m_totalTime;
}
void setDebugLevel(const DebugLevel level)
{
m_freemgr.setDebugLevel(level);
}
void setUseSortFlag(const bool flag)
{
m_useSortFlag = flag;
}
void startfTimer()
{
ftime(&t_start);
};
void stopfTimer()
{
ftime(&t_current);
};
int getTotalfRunTime()
{
int t_diff;
t_diff = (int) (1000.0 * (t_current.time - t_start.time) + (t_current.millitm - t_start.millitm));
return t_diff;
}
/**
* @brief Private index List member functions
*/
const int updateIndexListWrite();
const int init();
const int initBlksGetHdrBlk();
const int initGetHdr(const uint64_t& key, IdxEmptyListEntry* curIdxRidListHdrPtr);
const int resetBlk(DataBlock* dataBlk) ;
const int resetBlkZero(uint64_t& lbid0);
const int writeBlkZero(uint64_t& lbid0);
const int setLastLbid( uint64_t& lastLbid);
const int getLastLbid();
const int findLastBlk(int& count);
const int readCurBlk();
const int writeCurBlk();
const int addRidInBlk( const RID& newRid);
const int insertRid(const RID& newRid, int& pos);
const int updateCurCount(int frequency = 1);
const int getNextInfo(int& count);
const int getNextInfoFromBlk( IdxRidListPtr& idxRidListPtr);
const int getNextInfoFromBlk()
{
return getNextInfoFromBlk(m_lastIdxRidListPtr);
};
const int getLastFboPtr(uint64_t& lbid, int& sbid, IdxRidListPtr& lastFboListPtr);
const int setLastFboPtr(uint64_t& lbid, int& sbid, IdxRidListPtr& lastFboListPtr);
const int setNextInfoFromBlk( IdxRidListPtr& idxRidListPtr);
const int setNarray(bool flag)
{
m_useNarray = flag;
return NO_ERROR;
};
const int findFirstBlk(FILE* pFile, const uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr,
uint64_t& lbid);
bool getUseNarray()
{
return m_useNarray;
};
const int printBlocks(uint64_t& lbid);
const int getBlk(uint64_t& lbid);
const int getSubBlk();
const int getSubBlk(uint64_t& lbid, int& sbid, int& entry);
const int setLastLbid( uint64_t& lastLbid);
const int getLastLbid();
const int findLastBlk(int& count);
const int readCurBlk();
const int writeCurBlk();
const int addRidInBlk( const RID& newRid);
const int insertRid(const RID& newRid, int& pos);
const int updateCurCount(int frequency =1);
const int getNextInfo(int& count);
const int getNextInfoFromBlk( IdxRidListPtr& idxRidListPtr);
const int getNextInfoFromBlk(){return getNextInfoFromBlk(m_lastIdxRidListPtr); };
const int getLastFboPtr(uint64_t& lbid, int& sbid, IdxRidListPtr& lastFboListPtr);
const int setLastFboPtr(uint64_t& lbid, int& sbid, IdxRidListPtr& lastFboListPtr);
const int setNextInfoFromBlk( IdxRidListPtr& idxRidListPtr);
const int setNarray(bool flag){m_useNarray= flag; return NO_ERROR;};
const int findFirstBlk(FILE* pFile, const uint64_t& key,
IdxEmptyListEntry* curIdxRidListHdrPtr,
uint64_t& lbid);
bool getUseNarray(){return m_useNarray;};
const int printBlocks(uint64_t& lbid);
const int getBlk(uint64_t& lbid);
const int getSubBlk();
const int getSubBlk(uint64_t& lbid, int& sbid, int& entry);
private:
struct timeb t_start, t_current;
const int getLastFbo();
struct timeb t_start, t_current;
const int getLastFbo();
const int setLastFbo(int* fbo);
//const int addRidList(RID* ridList, int & size);
/**
* @brief get a segment from freemanager
*/
const int getSegment( FILE* pfile, const IdxTreeGroupType segmentType,
IdxEmptyListEntry* assignPtr );
/**
* @brief insert a rowid into the key index list
*/
const int updateIndexList( const RID& listRid, const uint64_t& key,
/**
* @brief get a segment from freemanager
*/
const int getSegment( FILE* pfile, const IdxTreeGroupType segmentType,
IdxEmptyListEntry* assignPtr );
/**
* @brief insert a rowid into the key index list
*/
const int updateIndexList( const RID& listRid, const uint64_t& key,
uint64_t& startLbid, int& startSbid, int& startEntry,
uint64_t& endLbid, int& endSbid, int& endEntry
);
/**
* @brief insert a rowid into the key index list
*/
const int updateIndexList( const RID& listRid, const uint64_t& key);
);
/**
* @brief insert a rowid into the key index list
*/
const int updateIndexList( const RID& listRid, const uint64_t& key);
const int updateIndexList( const RID* ridList, const int size, int& startPos);
const int addRid(const RID& newRid, IdxRidListPtr& lastIdxRidListPtr);
const int addRidList(const RID* ridList, const int size, int& startPos);
/**
* @brief write all of the blocks in the same time at the end
*/
/**
* @brief add a new subblock segment to the linked list
*/
const int addNextIdxRidList(FILE* pFile, const RID& rowId,
IdxEmptyListEntry* newIdxListEntryPtr);
/**
* @brief find a row id from the key index list and return the location
*/
bool findRowId( const RID& rowId,const uint64_t& key, uint64_t& lbid, int& sbid, int& entry);
/**
* @brief delete a row id from the key index list
*/
/**
* @brief write all of the blocks in the same time at the end
*/
/**
* @brief add a new subblock segment to the linked list
*/
const int addNextIdxRidList(FILE* pFile, const RID& rowId,
IdxEmptyListEntry* newIdxListEntryPtr);
/**
* @brief find a row id from the key index list and return the location
*/
bool findRowId( const RID& rowId, const uint64_t& key, uint64_t& lbid, int& sbid, int& entry);
/**
* @brief delete a row id from the key index list
*/
const int deleteIndexList( const RID& rowId, const uint64_t& key);
/**
* @brief delete a row id from the key index list and return a location
*/
const int deleteIndexList(const RID& rowId,
const uint64_t& key,
uint64_t& lbid, int&sbid, int& entry);
/**
* @brief insert a new row id to the key index list
*/
const int updateIdxRidList(const RID& rid, DataBlock* dataBlock,
const int& sbid, const int& entry,
IdxRidListPtr* idxRidListPtr);
const int deleteInSub( const RID& rowId) ;
const int deleteInBlock(const RID& newRid);
const int releaseSegment() ;
void setListOid(const OID& listOid){m_oid = listOid;}
const OID getListOid(){return m_oid;}
const int insertRowId( uint64_t& curLbid, int& pos, uint64_t& parentLbid);
const int setupBlock ( uint64_t& curLbid, int& pos, uint64_t& parentLbid);
/**
* @brief delete a row id from the key index list and return a location
*/
const int updateHdrSub(const RID& newRid, const uint64_t &key);
const int addRidInSub(const RID& newRid,
IdxRidListPtr& lastIdxRidListPtr);
const int moveRidsToNewSub(FILE* pFile, const RID& oldRid,
const RID& newRid,
IdxEmptyListEntry* newIdxListEntryPtr);
const int updateHdrCount();
const int deleteIndexList(const RID& rowId,
const uint64_t& key,
uint64_t& lbid, int& sbid, int& entry);
/**
* @brief insert a new row id to the key index list
*/
const int updateIdxRidList(const RID& rid, DataBlock* dataBlock,
const int& sbid, const int& entry,
IdxRidListPtr* idxRidListPtr);
const int setParentStatus(uint64_t& pLbid);
const int setCurBlkNextPtr(uint64_t& nextLbid, int count);
const int initNewBlock(int64_t& lbid, DataBlock* dataBlock, uint64_t& pLbid);
const int initNewBlock(DataBlock* dataBlock, uint64_t& pLbid);
const int initCurBlock();
const int getNextInfoFromArray(IdxRidNextListPtr& nextIdxListPtr);
const int getParentInfoFromArray(IdxRidParentListPtr& parentIdxListPtr);
const int updateCurCountInArray(int insCnt=1);
const int updateParentStatus(uint64_t& childLbid);
const int deleteInSub( const RID& rowId) ;
const int deleteInBlock(const RID& newRid);
const int releaseSegment() ;
void setListOid(const OID& listOid)
{
m_oid = listOid;
}
const OID getListOid()
{
return m_oid;
}
const int insertRowId( uint64_t& curLbid, int& pos, uint64_t& parentLbid);
const int setupBlock ( uint64_t& curLbid, int& pos, uint64_t& parentLbid);
const int updateLastPtrAndParent(const int lastCount);
const int updateLastPtr(const int lastCount);
const int updateParent();
/**
* @brief private member data
*/
const int updateHdrSub(const RID& newRid, const uint64_t& key);
const int addRidInSub(const RID& newRid,
IdxRidListPtr& lastIdxRidListPtr);
const int moveRidsToNewSub(FILE* pFile, const RID& oldRid,
const RID& newRid,
IdxEmptyListEntry* newIdxListEntryPtr);
const int updateHdrCount();
const int setParentStatus(uint64_t& pLbid);
const int setCurBlkNextPtr(uint64_t& nextLbid, int count);
const int initNewBlock(int64_t& lbid, DataBlock* dataBlock, uint64_t& pLbid);
const int initNewBlock(DataBlock* dataBlock, uint64_t& pLbid);
const int initCurBlock();
const int getNextInfoFromArray(IdxRidNextListPtr& nextIdxListPtr);
const int getParentInfoFromArray(IdxRidParentListPtr& parentIdxListPtr);
const int updateCurCountInArray(int insCnt = 1);
const int updateParentStatus(uint64_t& childLbid);
const int updateLastPtrAndParent(const int lastCount);
const int updateLastPtr(const int lastCount);
const int updateParent();
/**
* @brief private member data
*/
DataBlock m_curBlock; /**@brief the current block buffer */
DataBlock m_hdrBlock; /**@brief the header block buffer*/
DataBlock m_blockZero; /**@brief 0,0,0 for free manager*/
@ -365,39 +429,39 @@ private:
uint64_t m_hdrLbid; /**@brief the header block number */
int m_hdrSbid; /**@brief the header subblock number */
int m_hdrEntry; /**@brief the header entry number */
uint64_t m_lbid; /**@brief the current block number */
int m_sbid; /**@brief the current subblock number */
int m_entry; /**@brief the current entry number */
uint64_t m_newLbid;
int m_newSbid;
int m_newEntry;
uint64_t m_parentLbid;
int m_parentSbid;
int m_parentEntry;
uint64_t m_nextLbid; /**@brief the next block number */
int m_nextSbid; /**@brief the next subblock number */
int m_nextEntry; /**@brief the next entry number */
uint64_t m_dLbid; /**@brief the next block number */
int m_dSbid; /**@brief the next subblock number */
int m_dEntry; /**@brief the next entry number */
int m_dEntry; /**@brief the next entry number */
FILE* m_pFile; /**@brief file handle for index list */
OID m_oid;
OID m_oid;
int m_llpPos;
bool m_useBlock;
int m_entryGroup;
int m_type;
int m_type;
int m_segType;
int m_curType;
int m_nextType;
int m_totalbytes;
int m_lastFbo;
uint64_t m_lastLbid;
int m_lastFbo;
uint64_t m_lastLbid;
FreeMgr m_freemgr;
time_t m_startTime; // start time
time_t m_endTime; // end time
@ -411,7 +475,7 @@ private:
IdxRidListArrayPtr m_idxRidListArrayPtr;
IdxRidLastListPtr m_lastBLKIdxListPtr;
IdxRidListPtr m_lastIdxRidListPtr;
int m_curLevel;
int m_curBlkPos;
int m_curLevelPos;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,321 +15,347 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/* ========================================================================== */
/* */
/* we_indexlist_narray.cpp */
/* */
/* */
/* Description */
/* */
/* ========================================================================== */
#include <stdio.h>
//#include <pthread.h>
#include <string.h>
#ifndef _MSC_VER
#include <inttypes.h>
#endif
#include <math.h>
#include "we_indextree.h"
#include "we_indexlist.h"
using namespace std;
namespace WriteEngine
{
/****************************************************************
* DESCRIPTION:
* Private Function for print the block trees
*
***************************************************************/
const int IndexList::printBlocks(uint64_t& lbid)
{
int rc;
IdxRidListArrayPtr idxRidListArrayPtr;
int curLevel = 0, curCount=0;
memset(&idxRidListArrayPtr, 0, sizeof(idxRidListArrayPtr));
m_lbid = lbid;
rc = readCurBlk();
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
curLevel = idxRidListArrayPtr.nextIdxListPtr.curLevel;
curCount = idxRidListArrayPtr.nextIdxListPtr.count;
for (int i=0; i< curLevel ; i++)
{
cout << " ";
}
cout << " Lbid->" << lbid << " curLevel->" << curLevel
<< " curCount->" << curCount << endl;
for (int i=0; i<TOTAL_NUM_ARRAY_PTR; i++)
{
uint64_t lbid;
lbid = idxRidListArrayPtr.childIdxRidListPtr[i].childLbid;
if (lbid != (uint64_t)INVALID_LBID)
printBlocks(lbid);
}
return rc;
}
/****************************************************************
* DESCRIPTION:
* Private Function for getting the last Fbo on header
*
***************************************************************/
const int IndexList::setCurBlkNextPtr(uint64_t& nextLbid, int count)
{
int rc ;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if (nextLbid== (uint64_t)INVALID_LBID)
return ERR_IDX_LIST_SET_NEXT_LBID;
m_idxRidListArrayPtr.nextIdxListPtr.type = (int)LIST_BLOCK_TYPE;
m_idxRidListArrayPtr.nextIdxListPtr.curLevel = m_curLevel;
m_idxRidListArrayPtr.nextIdxListPtr.count = count;
m_idxRidListArrayPtr.nextIdxListPtr.nextLbid = nextLbid;
m_idxRidListArrayPtr.nextIdxListPtr.spare = 0;
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state>= BLK_READ))
{
rc = writeSubBlockEntry( cb, &m_curBlock, m_lbid, 0,
BEGIN_LIST_BLK_LLP_POS+ NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH,
&m_idxRidListArrayPtr.nextIdxListPtr );
m_curBlock.state = BLK_READ;
if (rc!= NO_ERROR)
return rc;
}
else
return ERR_IDX_LIST_SET_NEXT_LBID;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::initCurBlock()
{
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state>= BLK_READ))
{
memset(&m_idxRidListArrayPtr, 0, sizeof(m_idxRidListArrayPtr));
for (int i=0; i<TOTAL_NUM_ARRAY_PTR; i++)
{
m_idxRidListArrayPtr.childIdxRidListPtr[i].type = LIST_NOT_USED_TYPE;
m_idxRidListArrayPtr.childIdxRidListPtr[i].llpStat = LLP_NOT_FULL;
m_idxRidListArrayPtr.childIdxRidListPtr[i].spare =0;
m_idxRidListArrayPtr.childIdxRidListPtr[i].childLbid= INVALID_LBID;
}
m_idxRidListArrayPtr.nextIdxListPtr.type = LIST_SIZE_TYPE;
m_idxRidListArrayPtr.nextIdxListPtr.spare = 0;
m_idxRidListArrayPtr.nextIdxListPtr.curLevel = m_curLevel;
m_idxRidListArrayPtr.nextIdxListPtr.count = 0;
m_idxRidListArrayPtr.nextIdxListPtr.nextLbid = INVALID_LBID;
m_idxRidListArrayPtr.parentIdxListPtr.type = LIST_LLP_TYPE;
m_idxRidListArrayPtr.parentIdxListPtr.spare = 0;
m_idxRidListArrayPtr.parentIdxListPtr.curLevelPos = m_curLevelPos;
m_idxRidListArrayPtr.parentIdxListPtr.curBlkPos = m_curBlkPos;
m_idxRidListArrayPtr.parentIdxListPtr.parentLbid = m_parentLbid;
setSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH, &m_idxRidListArrayPtr);
}
else
return ERR_IDX_LIST_INIT_LINK_BLKS;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::getNextInfoFromArray(IdxRidNextListPtr& nextIdxListPtr)
{
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state>= BLK_READ))
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS+ NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
else
return ERR_IDX_LIST_GET_NEXT;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::getParentInfoFromArray(IdxRidParentListPtr& parentIdxListPtr)
{
int rc;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state>= BLK_READ))
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS+ PARENT_PTR_OFFSET,
LIST_ENTRY_WIDTH, &parentIdxListPtr);
else
return ERR_IDX_LIST_GET_PARENT;
m_curLevelPos = parentIdxListPtr.curLevelPos;
m_curBlkPos = parentIdxListPtr.curBlkPos;
m_parentLbid = parentIdxListPtr.parentLbid;
if (m_parentLbid == (uint64_t)INVALID_LBID)
return NO_ERROR;
memset( m_parentBlock.data, 0, sizeof(m_parentBlock.data));
rc = readDBFile(cb, &m_parentBlock, m_parentLbid );
m_parentBlock.lbid = m_parentLbid;
m_parentBlock.state = BLK_READ;
m_parentBlock.dirty = true;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::updateCurCountInArray(int insCnt)
{
int rc = NO_ERROR;
IdxRidNextListPtr nextIdxListPtr;
memset(&nextIdxListPtr, 0, sizeof(IdxRidNextListPtr));
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state>= BLK_READ))
{
getSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS+ NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
nextIdxListPtr.count = nextIdxListPtr.count + insCnt;
setSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS+ NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
m_curBlock.state = BLK_WRITE;
}
else
return ERR_IDX_LIST_GET_COUNT;
return rc;
}
/****************************************************************
* DESCRIPTION:
* childLbid is the new child block and need to register it in
* the correct parent and assigned level
* Private Function for getting the header
*
***************************************************************/
const int IndexList::updateParentStatus(uint64_t& childLbid)
{
int rc;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
IdxRidListArrayPtr idxRidListArrayPtr;
//Get the parent block read out or get the 4 children pointers out
if ((m_parentBlock.state== BLK_INIT)||(m_parentBlock.lbid !=m_parentLbid))
{
rc = readSubBlockEntry(cb, &m_parentBlock, m_parentLbid,
0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
m_parentBlock.dirty = true;
m_parentBlock.state = BLK_READ;
m_parentBlock.lbid = m_parentLbid;
}
else
getSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
//update current Child Block to full
// The reason to update parent is becuse CURRENT child link is full
// The CURRENT child lbid is m_lbid, m_curBlkPos is where it was registered
if (m_lbid != m_parentLbid)//The fulled child is not the parent itself
{ //normal case found the child block is full and set it full
if (idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type == (int)LIST_BLOCK_TYPE)
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_FULL;
//else if ((m_curBlkPos==0) && (m_flag)) //Next level parent, a new parent, no child
else if (m_curBlkPos==0)//get here only when a brand new parent given,
//it went up one level and the go back down to the same level,
{
if (!m_flag) //it is NOT the first block, this flag is useless, cannot be FALSE!
return ERR_IDX_LIST_WRONG_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type = LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_NOT_FULL;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].spare =0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].childLbid= childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS+m_curBlkPos,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curLevelPos ++;
return rc;
}
else //m_flag cannot be false since it is not the first block
return ERR_IDX_LIST_WRONG_TYPE;
}
else//This is the first block-> the current block's parent is itself
{//only done once when first block was full
m_curBlkPos = 0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type = (int)LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_FULL;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].spare =0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].childLbid= childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS+m_curBlkPos,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curLevel=1;
m_curLevelPos = 0;
return rc;
}
int i;
for (i=0; i<TOTAL_NUM_ARRAY_PTR; i++)
{
if(idxRidListArrayPtr.childIdxRidListPtr[i].type != (int)LIST_BLOCK_TYPE)
{
idxRidListArrayPtr.childIdxRidListPtr[i].type = LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[i].llpStat = LLP_NOT_FULL;
idxRidListArrayPtr.childIdxRidListPtr[i].spare =0;
idxRidListArrayPtr.childIdxRidListPtr[i].childLbid= childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS+ i,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[i]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curBlkPos = i; //Need to figure out this where to put it
m_curLevelPos ++;
return rc;
}
}
//Parent is full and all children are full Not found any child pointer is available to add
//then go to sibling in the same level or down
//Need to look for the next block on parent block, on level down
//The level will be increment by 1 HERE
//Change parent lbid go to next link
if (m_curLevelPos == (pow(4.0, m_curLevel)-1))//if the last node of this level
{
m_curLevel++;
m_curLevelPos = -1;
}
m_flag = true; // this need to go
// A new parent
m_curBlkPos = 0;
m_parentLbid = idxRidListArrayPtr.nextIdxListPtr.nextLbid;
memset( m_parentBlock.data, 0, sizeof(m_parentBlock.data));
m_parentBlock.state = BLK_INIT;
m_parentBlock.dirty = false;
rc = updateParentStatus(childLbid);
return rc;
}
}
/* ========================================================================== */
/* */
/* we_indexlist_narray.cpp */
/* */
/* */
/* Description */
/* */
/* ========================================================================== */
#include <stdio.h>
//#include <pthread.h>
#include <string.h>
#ifndef _MSC_VER
#include <inttypes.h>
#endif
#include <math.h>
#include "we_indextree.h"
#include "we_indexlist.h"
using namespace std;
namespace WriteEngine
{
/****************************************************************
* DESCRIPTION:
* Private Function for print the block trees
*
***************************************************************/
const int IndexList::printBlocks(uint64_t& lbid)
{
int rc;
IdxRidListArrayPtr idxRidListArrayPtr;
int curLevel = 0, curCount = 0;
memset(&idxRidListArrayPtr, 0, sizeof(idxRidListArrayPtr));
m_lbid = lbid;
rc = readCurBlk();
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
curLevel = idxRidListArrayPtr.nextIdxListPtr.curLevel;
curCount = idxRidListArrayPtr.nextIdxListPtr.count;
for (int i = 0; i < curLevel ; i++)
{
cout << " ";
}
cout << " Lbid->" << lbid << " curLevel->" << curLevel
<< " curCount->" << curCount << endl;
for (int i = 0; i < TOTAL_NUM_ARRAY_PTR; i++)
{
uint64_t lbid;
lbid = idxRidListArrayPtr.childIdxRidListPtr[i].childLbid;
if (lbid != (uint64_t)INVALID_LBID)
printBlocks(lbid);
}
return rc;
}
/****************************************************************
* DESCRIPTION:
* Private Function for getting the last Fbo on header
*
***************************************************************/
const int IndexList::setCurBlkNextPtr(uint64_t& nextLbid, int count)
{
int rc ;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if (nextLbid == (uint64_t)INVALID_LBID)
return ERR_IDX_LIST_SET_NEXT_LBID;
m_idxRidListArrayPtr.nextIdxListPtr.type = (int)LIST_BLOCK_TYPE;
m_idxRidListArrayPtr.nextIdxListPtr.curLevel = m_curLevel;
m_idxRidListArrayPtr.nextIdxListPtr.count = count;
m_idxRidListArrayPtr.nextIdxListPtr.nextLbid = nextLbid;
m_idxRidListArrayPtr.nextIdxListPtr.spare = 0;
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state >= BLK_READ))
{
rc = writeSubBlockEntry( cb, &m_curBlock, m_lbid, 0,
BEGIN_LIST_BLK_LLP_POS + NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH,
&m_idxRidListArrayPtr.nextIdxListPtr );
m_curBlock.state = BLK_READ;
if (rc != NO_ERROR)
return rc;
}
else
return ERR_IDX_LIST_SET_NEXT_LBID;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::initCurBlock()
{
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state >= BLK_READ))
{
memset(&m_idxRidListArrayPtr, 0, sizeof(m_idxRidListArrayPtr));
for (int i = 0; i < TOTAL_NUM_ARRAY_PTR; i++)
{
m_idxRidListArrayPtr.childIdxRidListPtr[i].type = LIST_NOT_USED_TYPE;
m_idxRidListArrayPtr.childIdxRidListPtr[i].llpStat = LLP_NOT_FULL;
m_idxRidListArrayPtr.childIdxRidListPtr[i].spare = 0;
m_idxRidListArrayPtr.childIdxRidListPtr[i].childLbid = INVALID_LBID;
}
m_idxRidListArrayPtr.nextIdxListPtr.type = LIST_SIZE_TYPE;
m_idxRidListArrayPtr.nextIdxListPtr.spare = 0;
m_idxRidListArrayPtr.nextIdxListPtr.curLevel = m_curLevel;
m_idxRidListArrayPtr.nextIdxListPtr.count = 0;
m_idxRidListArrayPtr.nextIdxListPtr.nextLbid = INVALID_LBID;
m_idxRidListArrayPtr.parentIdxListPtr.type = LIST_LLP_TYPE;
m_idxRidListArrayPtr.parentIdxListPtr.spare = 0;
m_idxRidListArrayPtr.parentIdxListPtr.curLevelPos = m_curLevelPos;
m_idxRidListArrayPtr.parentIdxListPtr.curBlkPos = m_curBlkPos;
m_idxRidListArrayPtr.parentIdxListPtr.parentLbid = m_parentLbid;
setSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH, &m_idxRidListArrayPtr);
}
else
return ERR_IDX_LIST_INIT_LINK_BLKS;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::getNextInfoFromArray(IdxRidNextListPtr& nextIdxListPtr)
{
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state >= BLK_READ))
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS + NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
else
return ERR_IDX_LIST_GET_NEXT;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::getParentInfoFromArray(IdxRidParentListPtr& parentIdxListPtr)
{
int rc;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state >= BLK_READ))
getSubBlockEntry(m_curBlock.data, 0,
BEGIN_LIST_BLK_LLP_POS + PARENT_PTR_OFFSET,
LIST_ENTRY_WIDTH, &parentIdxListPtr);
else
return ERR_IDX_LIST_GET_PARENT;
m_curLevelPos = parentIdxListPtr.curLevelPos;
m_curBlkPos = parentIdxListPtr.curBlkPos;
m_parentLbid = parentIdxListPtr.parentLbid;
if (m_parentLbid == (uint64_t)INVALID_LBID)
return NO_ERROR;
memset( m_parentBlock.data, 0, sizeof(m_parentBlock.data));
rc = readDBFile(cb, &m_parentBlock, m_parentLbid );
m_parentBlock.lbid = m_parentLbid;
m_parentBlock.state = BLK_READ;
m_parentBlock.dirty = true;
return NO_ERROR;
}
/****************************************************************
* DESCRIPTION:
* Private Function for setting the last Fbo on header
*
***************************************************************/
const int IndexList::updateCurCountInArray(int insCnt)
{
int rc = NO_ERROR;
IdxRidNextListPtr nextIdxListPtr;
memset(&nextIdxListPtr, 0, sizeof(IdxRidNextListPtr));
if ((m_curBlock.lbid == m_lbid) && (m_curBlock.state >= BLK_READ))
{
getSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS + NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
nextIdxListPtr.count = nextIdxListPtr.count + insCnt;
setSubBlockEntry(m_curBlock.data, 0, BEGIN_LIST_BLK_LLP_POS + NEXT_BLK_PTR_OFFSET,
LIST_ENTRY_WIDTH, &nextIdxListPtr);
m_curBlock.state = BLK_WRITE;
}
else
return ERR_IDX_LIST_GET_COUNT;
return rc;
}
/****************************************************************
* DESCRIPTION:
* childLbid is the new child block and need to register it in
* the correct parent and assigned level
* Private Function for getting the header
*
***************************************************************/
const int IndexList::updateParentStatus(uint64_t& childLbid)
{
int rc;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
IdxRidListArrayPtr idxRidListArrayPtr;
//Get the parent block read out or get the 4 children pointers out
if ((m_parentBlock.state == BLK_INIT) || (m_parentBlock.lbid != m_parentLbid))
{
rc = readSubBlockEntry(cb, &m_parentBlock, m_parentLbid,
0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
m_parentBlock.dirty = true;
m_parentBlock.state = BLK_READ;
m_parentBlock.lbid = m_parentLbid;
}
else
getSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS,
LIST_BLK_LLP_ENTRY_WIDTH,
&idxRidListArrayPtr);
//update current Child Block to full
// The reason to update parent is becuse CURRENT child link is full
// The CURRENT child lbid is m_lbid, m_curBlkPos is where it was registered
if (m_lbid != m_parentLbid)//The fulled child is not the parent itself
{
//normal case found the child block is full and set it full
if (idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type == (int)LIST_BLOCK_TYPE)
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_FULL;
//else if ((m_curBlkPos==0) && (m_flag)) //Next level parent, a new parent, no child
else if (m_curBlkPos == 0) //get here only when a brand new parent given,
//it went up one level and the go back down to the same level,
{
if (!m_flag) //it is NOT the first block, this flag is useless, cannot be FALSE!
return ERR_IDX_LIST_WRONG_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type = LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_NOT_FULL;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].spare = 0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].childLbid = childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS + m_curBlkPos,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curLevelPos ++;
return rc;
}
else //m_flag cannot be false since it is not the first block
return ERR_IDX_LIST_WRONG_TYPE;
}
else//This is the first block-> the current block's parent is itself
{
//only done once when first block was full
m_curBlkPos = 0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].type = (int)LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].llpStat = LLP_FULL;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].spare = 0;
idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos].childLbid = childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS + m_curBlkPos,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[m_curBlkPos]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curLevel = 1;
m_curLevelPos = 0;
return rc;
}
int i;
for (i = 0; i < TOTAL_NUM_ARRAY_PTR; i++)
{
if (idxRidListArrayPtr.childIdxRidListPtr[i].type != (int)LIST_BLOCK_TYPE)
{
idxRidListArrayPtr.childIdxRidListPtr[i].type = LIST_BLOCK_TYPE;
idxRidListArrayPtr.childIdxRidListPtr[i].llpStat = LLP_NOT_FULL;
idxRidListArrayPtr.childIdxRidListPtr[i].spare = 0;
idxRidListArrayPtr.childIdxRidListPtr[i].childLbid = childLbid;
setSubBlockEntry(m_parentBlock.data, 0, BEGIN_LIST_BLK_LLP_POS + i,
LIST_ENTRY_WIDTH, &idxRidListArrayPtr.childIdxRidListPtr[i]);
rc = writeDBFile( cb, m_parentBlock.data, m_parentLbid );
m_parentBlock.state = BLK_READ;
m_curBlkPos = i; //Need to figure out this where to put it
m_curLevelPos ++;
return rc;
}
}
//Parent is full and all children are full Not found any child pointer is available to add
//then go to sibling in the same level or down
//Need to look for the next block on parent block, on level down
//The level will be increment by 1 HERE
//Change parent lbid go to next link
if (m_curLevelPos == (pow(4.0, m_curLevel) - 1)) //if the last node of this level
{
m_curLevel++;
m_curLevelPos = -1;
}
m_flag = true; // this need to go
// A new parent
m_curBlkPos = 0;
m_parentLbid = idxRidListArrayPtr.nextIdxListPtr.nextLbid;
memset( m_parentBlock.data, 0, sizeof(m_parentBlock.data));
m_parentBlock.state = BLK_INIT;
m_parentBlock.dirty = false;
rc = updateParentStatus(childLbid);
return rc;
}
}

View File

@ -15,254 +15,278 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/****************************************************************************/
/* */
/* we_indexlist_add_hdr.cpp */
/* (c) 2001 Author */
/* */
/* Description */
/* */
/************************************************************************** */
#include <stdio.h>
#include <string.h>
#ifndef _MSC_VER
#include <inttypes.h>
#endif
#include "we_indexlist.h"
using namespace std;
namespace WriteEngine
{
/****************************************************************
* DESCRIPTION:
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateHdrSub(const RID& newRid, const uint64_t &key)
{
int rc = ERR_IDX_LIST_INVALID_UP_HDR;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if (m_curIdxRidListHdr.firstIdxRidListEntry.type
== (int)LIST_NOT_USED_TYPE)
{
m_curIdxRidListHdr.firstIdxRidListEntry.type =LIST_RID_TYPE;
m_curIdxRidListHdr.firstIdxRidListEntry.rid = newRid;
m_curIdxRidListHdr.idxRidListSize.size++;
if (m_hdrBlock.lbid == m_hdrLbid)
rc = writeSubBlockEntry( cb, &m_hdrBlock, m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
else
return ERR_IDX_LIST_WRONG_LBID_WRITE;
m_hdrBlock.state = BLK_READ;
return rc;
};//Done
//Check Header last entry's type and go to different next step
m_nextType = m_curIdxRidListHdr.nextIdxRidListPtr.type;
switch (m_nextType)
{
case LIST_NOT_USED_TYPE://Header is not full
//insert row id into header last enty
m_curIdxRidListHdr.nextIdxRidListPtr.type=LIST_RID_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.llp= newRid;
m_curIdxRidListHdr.idxRidListSize.size++;
if (m_hdrBlock.lbid == m_hdrLbid)
rc =writeSubBlockEntry( cb, &m_hdrBlock,m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE, &m_curIdxRidListHdr);
else
return ERR_IDX_LIST_WRONG_LBID_WRITE;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
break;
case LIST_RID_TYPE://Header is full, need a new sub-block
RID oldRid ;
IdxEmptyListEntry newIdxListEntry;
oldRid = m_curIdxRidListHdr.nextIdxRidListPtr.llp;
//need a sub block
m_segType = LIST_SUBBLOCK_TYPE;
rc= moveRidsToNewSub(m_pFile, oldRid,newRid,&newIdxListEntry);
if (rc!=NO_ERROR)
return rc;
//update header count twice
m_curIdxRidListHdr.nextIdxRidListPtr.type = m_segType;
m_curIdxRidListHdr.nextIdxRidListPtr.llp =
((IdxRidListHdrPtr*)&newIdxListEntry)->llp;
m_curIdxRidListHdr.nextIdxRidListPtr.spare= 0;
m_curIdxRidListHdr.idxRidListSize.size++;
setSubBlockEntry(m_hdrBlock.data, m_hdrSbid,
m_hdrEntry, LIST_HDR_SIZE,
&m_curIdxRidListHdr );
rc = writeDBFile( cb, m_hdrBlock.data, m_hdrLbid );
if (rc!=NO_ERROR)
return rc;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
if (m_curBlock.state==BLK_WRITE)
{
rc = writeDBFile( cb, m_curBlock.data, m_lbid );
m_curBlock.state = BLK_READ;
}
break;
case LIST_SUBBLOCK_TYPE: //first one is a sub block
m_lbid= ((IdxEmptyListEntry*)
&(m_curIdxRidListHdr.nextIdxRidListPtr))->fbo;
m_sbid=((IdxEmptyListEntry*)
&(m_curIdxRidListHdr.nextIdxRidListPtr))->sbid;
m_entry=((IdxEmptyListEntry*)
&(m_curIdxRidListHdr.nextIdxRidListPtr))->entry;
m_curType = m_nextType;
m_segType = LIST_BLOCK_TYPE;
rc =readCurBlk();
rc = getNextInfoFromBlk(m_lastIdxRidListPtr);
rc = addRidInSub(newRid, m_lastIdxRidListPtr);
break;
default:
rc=ERR_IDX_LIST_INVALID_UP_HDR;
break;
} //end of switch
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;
}
/***********************************************************
* DESCRIPTION:
* RETURN:
* success NO_ERROR
* fail
***********************************************************/
const int IndexList::moveRidsToNewSub(FILE* pFile, const RID& oldRid,
const RID& newRid,
IdxEmptyListEntry* newIdxListEntryPtr)
{
int rc;
//Write everything out in getSegment
m_segType = LIST_SUBBLOCK_TYPE;
rc =getSegment( m_pFile, ENTRY_32, newIdxListEntryPtr );
if (rc != NO_ERROR)
return rc;
//This is the new segment
m_curType = LIST_SUBBLOCK_TYPE;
m_lbid = newIdxListEntryPtr->fbo;
m_sbid = newIdxListEntryPtr->sbid;
m_entry = newIdxListEntryPtr->entry;
if (m_lbid !=m_hdrLbid)
rc = readCurBlk();
rc = insertRid(oldRid, m_entry);
m_entry++;
rc = insertRid(newRid, m_entry);
rc = updateCurCount(2);
return rc;
}
/****************************************************************************
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***************************************************************************/
const int IndexList::updateHdrCount()
{
int rc=NO_ERROR;
if (m_hdrBlock.state == BLK_INIT)
return ERR_IDX_LIST_UPDATE_HDR_COUNT;
m_curIdxRidListHdr.idxRidListSize.size++;
setSubBlockEntry( m_hdrBlock.data, m_hdrSbid,
m_hdrEntry, LIST_HDR_SIZE,
&m_curIdxRidListHdr );
m_hdrBlock.state = BLK_WRITE;
return rc;
}
}
/****************************************************************************/
/* */
/* we_indexlist_add_hdr.cpp */
/* (c) 2001 Author */
/* */
/* Description */
/* */
/************************************************************************** */
#include <stdio.h>
#include <string.h>
#ifndef _MSC_VER
#include <inttypes.h>
#endif
#include "we_indexlist.h"
using namespace std;
namespace WriteEngine
{
/****************************************************************
* DESCRIPTION:
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***********************************************************/
const int IndexList::updateHdrSub(const RID& newRid, const uint64_t& key)
{
int rc = ERR_IDX_LIST_INVALID_UP_HDR;
CommBlock cb;
cb.file.oid = m_oid;
cb.file.pFile = m_pFile;
if (m_curIdxRidListHdr.firstIdxRidListEntry.type
== (int)LIST_NOT_USED_TYPE)
{
m_curIdxRidListHdr.firstIdxRidListEntry.type = LIST_RID_TYPE;
m_curIdxRidListHdr.firstIdxRidListEntry.rid = newRid;
m_curIdxRidListHdr.idxRidListSize.size++;
if (m_hdrBlock.lbid == m_hdrLbid)
rc = writeSubBlockEntry( cb, &m_hdrBlock, m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE,
&m_curIdxRidListHdr );
else
return ERR_IDX_LIST_WRONG_LBID_WRITE;
m_hdrBlock.state = BLK_READ;
return rc;
};//Done
//Check Header last entry's type and go to different next step
m_nextType = m_curIdxRidListHdr.nextIdxRidListPtr.type;
switch (m_nextType)
{
case LIST_NOT_USED_TYPE://Header is not full
//insert row id into header last enty
m_curIdxRidListHdr.nextIdxRidListPtr.type = LIST_RID_TYPE;
m_curIdxRidListHdr.nextIdxRidListPtr.llp = newRid;
m_curIdxRidListHdr.idxRidListSize.size++;
if (m_hdrBlock.lbid == m_hdrLbid)
rc = writeSubBlockEntry( cb, &m_hdrBlock, m_hdrLbid,
m_hdrSbid, m_hdrEntry,
LIST_HDR_SIZE, &m_curIdxRidListHdr);
else
return ERR_IDX_LIST_WRONG_LBID_WRITE;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
break;
case LIST_RID_TYPE://Header is full, need a new sub-block
RID oldRid ;
IdxEmptyListEntry newIdxListEntry;
oldRid = m_curIdxRidListHdr.nextIdxRidListPtr.llp;
//need a sub block
m_segType = LIST_SUBBLOCK_TYPE;
rc = moveRidsToNewSub(m_pFile, oldRid, newRid, &newIdxListEntry);
if (rc != NO_ERROR)
return rc;
//update header count twice
m_curIdxRidListHdr.nextIdxRidListPtr.type = m_segType;
m_curIdxRidListHdr.nextIdxRidListPtr.llp =
((IdxRidListHdrPtr*)&newIdxListEntry)->llp;
m_curIdxRidListHdr.nextIdxRidListPtr.spare = 0;
m_curIdxRidListHdr.idxRidListSize.size++;
setSubBlockEntry(m_hdrBlock.data, m_hdrSbid,
m_hdrEntry, LIST_HDR_SIZE,
&m_curIdxRidListHdr );
rc = writeDBFile( cb, m_hdrBlock.data, m_hdrLbid );
if (rc != NO_ERROR)
return rc;
m_hdrBlock.state = BLK_READ;
m_lastLbid = INVALID_LBID;
if (m_curBlock.state == BLK_WRITE)
{
rc = writeDBFile( cb, m_curBlock.data, m_lbid );
m_curBlock.state = BLK_READ;
}
break;
case LIST_SUBBLOCK_TYPE: //first one is a sub block
m_lbid = ((IdxEmptyListEntry*)
& (m_curIdxRidListHdr.nextIdxRidListPtr))->fbo;
m_sbid = ((IdxEmptyListEntry*)
& (m_curIdxRidListHdr.nextIdxRidListPtr))->sbid;
m_entry = ((IdxEmptyListEntry*)
& (m_curIdxRidListHdr.nextIdxRidListPtr))->entry;
m_curType = m_nextType;
m_segType = LIST_BLOCK_TYPE;
rc = readCurBlk();
rc = getNextInfoFromBlk(m_lastIdxRidListPtr);
rc = addRidInSub(newRid, m_lastIdxRidListPtr);
break;
default:
rc = ERR_IDX_LIST_INVALID_UP_HDR;
break;
} //end of switch
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;
}
/***********************************************************
* DESCRIPTION:
* RETURN:
* success NO_ERROR
* fail
***********************************************************/
const int IndexList::moveRidsToNewSub(FILE* pFile, const RID& oldRid,
const RID& newRid,
IdxEmptyListEntry* newIdxListEntryPtr)
{
int rc;
//Write everything out in getSegment
m_segType = LIST_SUBBLOCK_TYPE;
rc = getSegment( m_pFile, ENTRY_32, newIdxListEntryPtr );
if (rc != NO_ERROR)
return rc;
//This is the new segment
m_curType = LIST_SUBBLOCK_TYPE;
m_lbid = newIdxListEntryPtr->fbo;
m_sbid = newIdxListEntryPtr->sbid;
m_entry = newIdxListEntryPtr->entry;
if (m_lbid != m_hdrLbid)
rc = readCurBlk();
rc = insertRid(oldRid, m_entry);
m_entry++;
rc = insertRid(newRid, m_entry);
rc = updateCurCount(2);
return rc;
}
/****************************************************************************
* RETURN:
* success - successfully created the index list header
* failure - it did not create the index list header
***************************************************************************/
const int IndexList::updateHdrCount()
{
int rc = NO_ERROR;
if (m_hdrBlock.state == BLK_INIT)
return ERR_IDX_LIST_UPDATE_HDR_COUNT;
m_curIdxRidListHdr.idxRidListSize.size++;
setSubBlockEntry( m_hdrBlock.data, m_hdrSbid,
m_hdrEntry, LIST_HDR_SIZE,
&m_curIdxRidListHdr );
m_hdrBlock.state = BLK_WRITE;
return rc;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -45,226 +45,286 @@ namespace WriteEngine
class IndexTree : public DbFileOp
{
public:
/**
* @brief Constructor
*/
EXPORT IndexTree();
/**
* @brief Constructor
*/
EXPORT IndexTree();
/**
* @brief Default Destructor
*/
EXPORT ~IndexTree();
/**
* @brief Default Destructor
*/
EXPORT ~IndexTree();
/**
* @brief A wrapper for the call to free manager
*/
EXPORT const int assignSegment( int segmentType, IdxEmptyListEntry* assignPtr, int no );
/**
* @brief A wrapper for the call to free manager
*/
EXPORT const int assignSegment( int segmentType, IdxEmptyListEntry* assignPtr, int no );
/**
* @brief Build empty index tree part
*/
EXPORT const int buildEmptyTreePart( const uint64_t key, const int width, const RID rid, const int startBitTestNo, const int offset = 0 );
/**
* @brief Build empty index tree part
*/
EXPORT const int buildEmptyTreePart( const uint64_t key, const int width, const RID rid, const int startBitTestNo, const int offset = 0 );
/**
* @brief Build empty index branch
*/
EXPORT const int buildEmptyIndexTreeBranch( const uint64_t key, const int width, const RID rid, const int rootTestbitVal );
/**
* @brief Build empty index branch
*/
EXPORT const int buildEmptyIndexTreeBranch( const uint64_t key, const int width, const RID rid, const int rootTestbitVal );
/**
* @brief Build exist index branch
*/
EXPORT const int buildExistIndexTreeBranch( const uint64_t key, const int width, const RID rid, const int rootTestbitVal, IdxBitmapPointerEntry bitmapEntry );
/**
* @brief Build exist index branch
*/
EXPORT const int buildExistIndexTreeBranch( const uint64_t key, const int width, const RID rid, const int rootTestbitVal, IdxBitmapPointerEntry bitmapEntry );
/**
* @brief Calculate bit test array
*/
EXPORT const int calculateBittestArray();
/**
* @brief Calculate bit test array
*/
EXPORT const int calculateBittestArray();
/**
* @brief Close index
*/
EXPORT void closeIndex();
/**
* @brief Close index
*/
EXPORT void closeIndex();
/**
* @brief Clear index tree member variables
*/
void clear() { clearBlock( &m_rootBlock ); }
/**
* @brief Clear index tree member variables
*/
void clear()
{
clearBlock( &m_rootBlock );
}
/**
* @brief Create index related files
*/
EXPORT const int createIndex( const FID treeFid, const FID listFid, const bool useFreeMgrFlag = true );
/**
* @brief Create index related files
*/
EXPORT const int createIndex( const FID treeFid, const FID listFid, const bool useFreeMgrFlag = true );
/**
* @brief Delete a value from an index
*/
EXPORT const int deleteIndex( const uint64_t key, const int width, const RID rid );
/**
* @brief Delete a value from an index
*/
EXPORT const int deleteIndex( const uint64_t key, const int width, const RID rid );
/**
* @brief Drop index related files
*/
const int dropIndex( const FID treeFid, const FID listFid )
/**
* @brief Drop index related files
*/
const int dropIndex( const FID treeFid, const FID listFid )
#ifdef BROKEN_BY_MULTIPLE_FILES_PER_OID
{ m_cbTree.file.pFile = m_fileopTree.openFile(treeFid);
m_cbList.file.pFile = m_fileopList.openFile(listFid);
closeIndex(); m_useMultiCol = false; deleteFile( treeFid ); deleteFile( listFid ); return NO_ERROR; }
{
m_cbTree.file.pFile = m_fileopTree.openFile(treeFid);
m_cbList.file.pFile = m_fileopList.openFile(listFid);
closeIndex();
m_useMultiCol = false;
deleteFile( treeFid );
deleteFile( listFid );
return NO_ERROR;
}
#endif
{ std::string segFile;
m_cbTree.file.pFile = m_fileopTree.openFile(
treeFid,0,0,0, segFile);
m_cbList.file.pFile = m_fileopList.openFile(
listFid,0,0,0, segFile);
closeIndex(); m_useMultiCol = false; deleteFile( treeFid ); deleteFile( listFid ); return NO_ERROR; }
{
std::string segFile;
m_cbTree.file.pFile = m_fileopTree.openFile(
treeFid, 0, 0, 0, segFile);
m_cbList.file.pFile = m_fileopList.openFile(
listFid, 0, 0, 0, segFile);
closeIndex();
m_useMultiCol = false;
deleteFile( treeFid );
deleteFile( listFid );
return NO_ERROR;
}
/**
* @brief Get the test bit value
*/
EXPORT const bool getTestbitValue( const uint64_t key, const int width, const int curTestNo, int* bittestVal );
/**
* @brief Get the test bit value
*/
EXPORT const bool getTestbitValue( const uint64_t key, const int width, const int curTestNo, int* bittestVal );
/**
* @brief Get the match entry in the tree
*/
EXPORT const bool getTreeMatchEntry( DataBlock* block, const uint64_t sbid, const uint64_t entry, const int width,
const int allocCount, const bool* entryMap, int* matchEntry, IdxBitTestEntry* checkEntry );
/**
* @brief Get the match entry in the tree
*/
EXPORT const bool getTreeMatchEntry( DataBlock* block, const uint64_t sbid, const uint64_t entry, const int width,
const int allocCount, const bool* entryMap, int* matchEntry, IdxBitTestEntry* checkEntry );
/**
* @brief Get the tree node summary information
*/
EXPORT const int getTreeNodeInfo( DataBlock* block, const uint64_t sbid, const uint64_t entry, const int width,
const IdxTreeGroupType group, int* allocCount, int* realCount, bool* entryMap );
/**
* @brief Get the tree node summary information
*/
EXPORT const int getTreeNodeInfo( DataBlock* block, const uint64_t sbid, const uint64_t entry, const int width,
const IdxTreeGroupType group, int* allocCount, int* realCount, bool* entryMap );
/**
* @brief Check index address pointer is empty or not
*/
EXPORT const bool isAddrPtrEmpty( void* pStruct, const IdxTreeEntryType entryType ) const;
/**
* @brief Check index address pointer is empty or not
*/
EXPORT const bool isAddrPtrEmpty( void* pStruct, const IdxTreeEntryType entryType ) const;
/**
* @brief Check whether the tree is empty
*/
EXPORT const bool isTreeEmpty();
/**
* @brief Check whether the tree is empty
*/
EXPORT const bool isTreeEmpty();
/**
* @brief Init index
*/
EXPORT const int initIndex( const FID treeFid, const FID listFid );
/**
* @brief Init index
*/
EXPORT const int initIndex( const FID treeFid, const FID listFid );
/**
* @brief Move tree entries
*/
EXPORT const int moveEntry( const uint64_t oldFbo, const uint64_t oldSbid, const uint64_t oldEntry, const int width, const uint64_t newFbo,
const uint64_t newSbid, const uint64_t newEntry, const int newGroup, const int allocCount, bool* entryMap, int* moveCount, const int newAllocCount = 0 );
/**
* @brief Move tree entries
*/
EXPORT const int moveEntry( const uint64_t oldFbo, const uint64_t oldSbid, const uint64_t oldEntry, const int width, const uint64_t newFbo,
const uint64_t newSbid, const uint64_t newEntry, const int newGroup, const int allocCount, bool* entryMap, int* moveCount, const int newAllocCount = 0 );
/**
* @brief Open index related files
*/
EXPORT const int openIndex( const FID treeFid, const FID listFid );
/**
* @brief Open index related files
*/
EXPORT const int openIndex( const FID treeFid, const FID listFid );
/**
* @brief Process index, including delete and search
*/
EXPORT const int processIndex( const uint64_t key, const int width, const RID rid, IdxEmptyListEntry& listHdrAddr, const bool bDelete = true );
/**
* @brief Process index, including delete and search
*/
EXPORT const int processIndex( const uint64_t key, const int width, const RID rid, IdxEmptyListEntry& listHdrAddr, const bool bDelete = true );
/**
* @brief A wrapper for the call to free manager
*/
EXPORT const int releaseSegment( int segmentType, IdxEmptyListEntry* myPtr );
/**
* @brief A wrapper for the call to free manager
*/
EXPORT const int releaseSegment( int segmentType, IdxEmptyListEntry* myPtr );
/**
* @brief Clean up index file
*/
EXPORT const int resetIndexFile( const FID treeFid, const FID listFid );
/**
* @brief Clean up index file
*/
EXPORT const int resetIndexFile( const FID treeFid, const FID listFid );
/**
* @brief Setup bitset by column
*/
EXPORT const int setBitsetColumn( void* val, const int pos, const int width, const ColType colType );
/**
* @brief Setup bitset by column
*/
EXPORT const int setBitsetColumn( void* val, const int pos, const int width, const ColType colType );
/**
* @brief Set bit test entry
*/
EXPORT void setBittestEntry( IdxBitTestEntry* bittestEntry, const uint64_t testbitVal, const uint64_t group, const uint64_t fbo, const uint64_t sbid, const uint64_t entry, constu int64_t entryType = BIT_TEST ) const;
/**
* @brief Set bit test entry
*/
EXPORT void setBittestEntry( IdxBitTestEntry* bittestEntry, const uint64_t testbitVal, const uint64_t group, const uint64_t fbo, const uint64_t sbid, const uint64_t entry, constu int64_t entryType = BIT_TEST ) const;
/**
* @brief Set blank entry
*/
void setBlankEntry( void* pStruct ) const { memset( pStruct, 0, 8 ); }
/**
* @brief Set blank entry
*/
void setBlankEntry( void* pStruct ) const
{
memset( pStruct, 0, 8 );
}
/**
* @brief Set empty list ptr entry
*/
EXPORT void setEmptyListEntry( IdxEmptyListEntry* myEntry, const uint64_t group, const uint64_t fbo, const uint64_t sbid, const uint64_t entry ) const;
/**
* @brief Set empty list ptr entry
*/
EXPORT void setEmptyListEntry( IdxEmptyListEntry* myEntry, const uint64_t group, const uint64_t fbo, const uint64_t sbid, const uint64_t entry ) const;
/**
* @brief Set transaction Id
*/
EXPORT void setTransId( const TxnID txnId ) { FileOp::setTransId( txnId ); m_cbTree.session.txnid = m_cbList.session.txnid = txnId; m_freeMgr.setTransId(txnId); m_listMgr.setTransId(txnId);}
/**
* @brief Set transaction Id
*/
EXPORT void setTransId( const TxnID txnId )
{
FileOp::setTransId( txnId );
m_cbTree.session.txnid = m_cbList.session.txnid = txnId;
m_freeMgr.setTransId(txnId);
m_listMgr.setTransId(txnId);
}
/**
* @brief Set use brm flag
*/
/**
* @brief Set use brm flag
*/
/**
* @brief Update a value in an index
*/
EXPORT const int updateIndex( const uint64_t key, const int width, const RID rid );
/**
* @brief Update a value in an index
*/
EXPORT const int updateIndex( const uint64_t key, const int width, const RID rid );
EXPORT const int updateListFile( const uint64_t key, const int width, const RID rid, const int curLevel, const uint64_t group, const int allocCount, const int useCount, const int offset, const bool addFlag = false );
EXPORT const int updateListFile( const uint64_t key, const int width, const RID rid, const int curLevel, const uint64_t group, const int allocCount, const int useCount, const int offset, const bool addFlag = false );
// internal use functions
EXPORT void clearTree( IdxTree* myTree );
EXPORT void clearTreeNode( IdxTreeNode* myNode );
const IdxTree& getTree() { return m_tree; }
const DataBlock& getRootBlock() { return m_rootBlock; }
const bool getUseMultiRid() { return m_useMultiRid; }
// internal use functions
EXPORT void clearTree( IdxTree* myTree );
EXPORT void clearTreeNode( IdxTreeNode* myNode );
const IdxTree& getTree()
{
return m_tree;
}
const DataBlock& getRootBlock()
{
return m_rootBlock;
}
const bool getUseMultiRid()
{
return m_useMultiRid;
}
EXPORT void setTreeHeader( IdxTree* myTree, const uint64_t key, const RID rid, const int width,
const int testbitVal, const IdxBitmapPointerEntry bitmapEntry );
EXPORT void setTreeNode( IdxTreeNode* myNode, const int level, const int allocCount, const int useCount,
const int offset, const IdxBitTestEntry nextEntry, const IdxBitTestEntry curEntry );
EXPORT void setTreeHeader( IdxTree* myTree, const uint64_t key, const RID rid, const int width,
const int testbitVal, const IdxBitmapPointerEntry bitmapEntry );
EXPORT void setTreeNode( IdxTreeNode* myNode, const int level, const int allocCount, const int useCount,
const int offset, const IdxBitTestEntry nextEntry, const IdxBitTestEntry curEntry );
EXPORT const int updateIndexList( const uint64_t key, const int width, const RID rid, IdxEmptyListEntry* myEntry, const int no, const bool addFlag = false);
EXPORT const int updateIndexList( const uint64_t key, const int width, const RID rid, IdxEmptyListEntry* myEntry, const int no, const bool addFlag = false);
EXPORT void printMemSubBlock( DataBlock* curBlock, const int sbid, const bool bNoZero = false );
EXPORT void printSubBlock( const int fbo, const int sbid, const bool bNoZero = false );
EXPORT void printMemSubBlock( DataBlock* curBlock, const int sbid, const bool bNoZero = false );
EXPORT void printSubBlock( const int fbo, const int sbid, const bool bNoZero = false );
void setAssignFbo( const int fbo ) { m_assignFbo = fbo; } // internal testing purpose only
void setUseFreeMgr( const bool val ) { m_useFreeMgr = val; }
void setUseListMgr( const bool val ) { m_useListMgr = val; }
void setUseMultiCol( const bool val ) { m_useMultiCol = val; }
void setUseMultiRid( const bool val ) { m_useMultiRid = val; }
void setCbTree(CommBlock& cb){ memcpy(&m_cbTree.session, &cb.session,
sizeof(cb.session));
memcpy(&m_cbTree.file, &cb.file,
sizeof(cb.file)); }
const CommBlock& getCbTree() const {return m_cbTree;}
void setAssignFbo( const int fbo )
{
m_assignFbo = fbo; // internal testing purpose only
}
void setUseFreeMgr( const bool val )
{
m_useFreeMgr = val;
}
void setUseListMgr( const bool val )
{
m_useListMgr = val;
}
void setUseMultiCol( const bool val )
{
m_useMultiCol = val;
}
void setUseMultiRid( const bool val )
{
m_useMultiRid = val;
}
void setCbList(CommBlock& cb){memcpy(&m_cbList.session, &cb.session,
sizeof(cb.session));
memcpy(&m_cbList.file, &cb.file,
sizeof(cb.file)); }
const CommBlock& getCbList() const {return m_cbList;}
void setCbTree(CommBlock& cb)
{
memcpy(&m_cbTree.session, &cb.session,
sizeof(cb.session));
memcpy(&m_cbTree.file, &cb.file,
sizeof(cb.file));
}
const CommBlock& getCbTree() const
{
return m_cbTree;
}
DataBlock m_rootBlock; /** @brief This block contains sub block 0 and sub block 1 */
CommBlock m_cbTree; /** @brief index tree */
CommBlock m_cbList; /** @brief index list */
void setCbList(CommBlock& cb)
{
memcpy(&m_cbList.session, &cb.session,
sizeof(cb.session));
memcpy(&m_cbList.file, &cb.file,
sizeof(cb.file));
}
const CommBlock& getCbList() const
{
return m_cbList;
}
IdxTree m_tree; /** @brief index tree node */
FreeMgr m_freeMgr; /** @brief index free mgr */
IndexList m_listMgr; /** @brief index list mgr */
DataBlock m_rootBlock; /** @brief This block contains sub block 0 and sub block 1 */
CommBlock m_cbTree; /** @brief index tree */
CommBlock m_cbList; /** @brief index list */
IdxMultiColKey m_multiColKey; /** @brief index multi-column key */
IdxMultiRid m_multiRid; /** @brief index multi rids */
FileOp m_fileopTree;
FileOp m_fileopList;
IdxTree m_tree; /** @brief index tree node */
FreeMgr m_freeMgr; /** @brief index free mgr */
IndexList m_listMgr; /** @brief index list mgr */
IdxMultiColKey m_multiColKey; /** @brief index multi-column key */
IdxMultiRid m_multiRid; /** @brief index multi rids */
FileOp m_fileopTree;
FileOp m_fileopList;
private:
// internal testing flags
bool m_useFreeMgr;
bool m_useListMgr;
bool m_useMultiCol;
bool m_useMultiRid;
int m_assignFbo;
// internal testing flags
bool m_useFreeMgr;
bool m_useListMgr;
bool m_useMultiCol;
bool m_useMultiRid;
int m_assignFbo;
};
} //end of namespace