Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends

fio_RelFile Class Reference
[Classes for large file i/o, relative file, and DataBase]

#include <fio_RelFile.h>

Inheritance diagram for fio_RelFile:
Inheritance graph
[legend]
Collaboration diagram for fio_RelFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 fio_RelFile (bool a_readOnly, const int a_fileID, cmn_Path a_path, string a_fileName, const int a_recordSize, const Int16_t a_recordStructVersion, const UInt16_t a_numOfDifVector=ivd_MAX_NUM_OF_DIF_VECTOR_IN_REL_FILES_d, const UInt16_t a_smallestVectorSize=1, const bool a_accessToIdx0=false)
virtual ~fio_RelFile ()
fio_RelFileHeader_t GetRelFileHeader ()
virtual void SyncRelFileObj ()
 Sync relative file object with data on disk after transaction reply.
ivd_RecordIDX_t FirstNewIDX ()
void SetFirstNewIDX ()
 calculate with FirstNewIDX methos and set m_firstNewIDX member
ivd_RecordIDX_t GetFirstNewIDX ()
ivd_FilePosition_t Idx2Pos (ivd_RecordIDX_t a_idx)
 pass index and return position in file
int WriteRec (const fio_RecordIDX_t a_index, const void *a_buffer, const unsigned int a_numOfRec=1, fio_Transaction *a_transaction=NULL)
 Write one or more records (vector) from a_buffer to a_index place in file.
int ReadRec (const fio_RecordIDX_t, void *, const unsigned int=1)
 Read one or more records (vector) from a_buffer to a_index place in file.
void ReleaseVector (const fio_RecordIDX_t a_index, unsigned int a_numOfRec, fio_Transaction *a_transaction=NULL)
 Release one or more records (vector) from a_index place in file.
ivd_RecordIDX_t GetNewVectorIDX (unsigned int)
 Reserve one or more records (vector) in file and return index to it.
unsigned int GetFirstRecordOffset ()
unsigned int GetRecordSize ()
unsigned int GetNumOfRecord ()
void Flush ()
virtual void DumpHdr (ostream &os)
 dump header to stream

Public Attributes

 log_CLASSID_m
 Macro for class name member.

Protected Member Functions

ivd_RecordIDX_t GetFirstNewIDX (unsigned int)
ivd_RecordIDX_t GetUnusedVectorIDX (const unsigned int, fio_Transaction *a_transacton_p=NULL)
int UpdateListOfUnusedVector (const unsigned int, fio_Transaction *a_transaction_p=NULL)
virtual int PosWrite (ivd_FilePosition_t a_position, const void *a_buffer_p, ivd_FileBufSize_t a_size, fio_Transaction *a_transaction) const
 PosWrite with transaction method is virtual.
void CreateFile ()
 when file has not yet created then this method is called
void WriteHeader ()
void WriteListOfUnusedVector ()
void ReadListOfUnusedVector ()
ivd_RecordIDX_t ReadNextUnusedVectorIDX (fio_RecordIDX_t a_index, UInt16_t a_vecSize)
 read record at index and return the index to next record;

Protected Attributes

const unsigned int m_recordSize
const unsigned int m_loUVHeaderLen
const unsigned int m_numOfDifVector
const UInt16_t m_smallestVectorSize
const ivd_FileBufSize_t m_sizeOfListOfUnusedVector
const unsigned int m_firstRecordOffset
const Int16_t m_recordStructVersion
const bool m_accessToIdx0
struct fio_RelFileHeader_t m_fileHeader
struct fio_RelFileHeader_t m_currFileHeader
fio_LoUV_v_t m_listOfUV_v
 vector of list of unused vectors
ivd_RecordIDX_t m_firstNewIDX
cmn_Mutex m_RelativeFile_x
 Exclusive access to Relative file.
cmn_Mutex m_listOfLoUV_x
 Exclusive access to list of list of unused vectors.
cmn_Mutex m_firstNewIDX_x
 Exclusive access m_firstNewIDX.

Friends

class fio_uvListMgr
class fsc_RawUpdate

Detailed Description

Definition at line 216 of file fio_RelFile.h.


Constructor & Destructor Documentation

fio_RelFile::fio_RelFile ( bool  a_readOnly,
const int  a_fileID,
cmn_Path  a_path,
string  a_fileName,
const int  a_recordSize,
const Int16_t  a_recordStructVersion,
const UInt16_t  a_numOfDifVector = ivd_MAX_NUM_OF_DIF_VECTOR_IN_REL_FILES_d,
const UInt16_t  a_smallestVectorSize = 1,
const bool  a_accessToIdx0 = false 
)

Definition at line 171 of file fio_RelFile.cpp.

References assert, fio_RelFileHeader_t::byteOrder, CreateFile(), dbg_DETAIL, fio_RelFileHeader_t::fileID, fio_FH_IDENTIFICATION_LEN_d, g_notCheckRFHeader, fio_File::GetFileName(), fio_RelFileHeader_t::headerStructVersion, fio_RelFileHeader_t::identification, ie_RECORD_TOO_SMALL, ie_REL_FILE_HEADER_INV, ivd_Error, log_DBG_m, log_ERR_m, log_FUNC_m, fio_RelFileHeader_t::loUVHeaderLen, m_currFileHeader, m_fileHeader, m_firstRecordOffset, m_listOfUV_v, m_numOfDifVector, m_recordSize, fio_RelFileHeader_t::numOfDifVector, fio_RelFileHeader_t::recordSize, fio_RelFileHeader_t::recordStructVersion, fio_RelFileHeader_t::relFileHeaderLen, cmn_File::SeekEndF(), fio_RelFileHeader_t::smallestVectorSize, and str.

        :
        fio_File(a_readOnly, a_fileID, a_path, a_fileName),
        m_recordSize(a_recordSize),
        m_loUVHeaderLen(sizeof(fio_uvListHeader_t)),
        m_numOfDifVector(a_numOfDifVector),
        m_smallestVectorSize(a_smallestVectorSize),
        m_sizeOfListOfUnusedVector(m_numOfDifVector * m_loUVHeaderLen),
        m_firstRecordOffset(m_sizeOfListOfUnusedVector + c_fio_maxRelFileHeadLen),
        m_recordStructVersion(a_recordStructVersion),
        m_accessToIdx0(a_accessToIdx0),
        m_fileHeader(       // create file header
            GetFileName(),
            GetFileID(),
            m_recordStructVersion,
            m_recordSize,
            m_loUVHeaderLen,
            m_numOfDifVector,
            m_smallestVectorSize)
{
    log_FUNC_m(fio_RelFile);

    assert(sizeof(fio_UnusedRec_t) > m_recordSize);
    if (m_recordSize < sizeof(ivd_RecordIDX_t)) {
        throw ivd_Error(ie_RECORD_TOO_SMALL, "There is no space for index to bind unused vector (record).", true);
    }

    m_listOfUV_v.resize(m_numOfDifVector, fio_uvListHeader_t());

    // Check if file is new (empty)
    ivd_FilePosition_t fileSize = SeekEndF();
    if (fileSize <= m_firstRecordOffset) { // new or empty file
        CreateFile();       // write file header, filler, and list of unused vector to file
    }
    else {
        struct fio_RelFileHeader_t currentFileHeader(*this);// get file header from file
        m_currFileHeader = currentFileHeader;
        // check if currentFileHeader match with instantiated fileHeader by constructor
        log_DBG_m(dbg_DETAIL,"Check relative file header structure." << currentFileHeader << endl
                          << " Expected header : " << m_fileHeader);
        int pos = strncmp(m_fileHeader.identification, currentFileHeader.identification, fio_FH_IDENTIFICATION_LEN_d);
        if (   (pos != 0)
            || (m_fileHeader.fileID               != currentFileHeader.fileID)
            || (m_fileHeader.recordStructVersion  != currentFileHeader.recordStructVersion)
            || (m_fileHeader.recordSize           != currentFileHeader.recordSize)
            || (m_fileHeader.loUVHeaderLen        != currentFileHeader.loUVHeaderLen)
            || (m_fileHeader.numOfDifVector       != currentFileHeader.numOfDifVector)
            || (m_fileHeader.smallestVectorSize   != currentFileHeader.smallestVectorSize)
            || (m_fileHeader.relFileHeaderLen     != currentFileHeader.relFileHeaderLen)
            || (m_fileHeader.byteOrder            != currentFileHeader.byteOrder)
           ) {
               ostringstream str;
               str << "\nEXPECTED HEADER: \n" << m_fileHeader
                   << "\nDB HEADER :\n" << currentFileHeader;

               if (g_notCheckRFHeader) {
                    m_fileHeader.recordSize = currentFileHeader.recordSize;
                    if (pos != 0) {
                        strncpy(m_fileHeader.identification, currentFileHeader.identification, fio_FH_IDENTIFICATION_LEN_d);
                    }
                    log_ERR_m("Header is damaged. The FSC may be corrupted."
                        + str.str() );
               }
               else {
                    throw ivd_Error(ie_REL_FILE_HEADER_INV,
                        "Relative file header of " + GetFileName()
                        + " doesn't match."
                        + str.str(), true);
               }
        }
        if (m_fileHeader.headerStructVersion  != currentFileHeader.headerStructVersion) {
               if (g_notCheckRFHeader) {
                    log_ERR_m("Header is damaged. The FSC may be corrupted.");
               }
               else {
                    throw ivd_Error(ie_REL_FILE_HEADER_INV,
                        "Structure version of relative file header of " + GetFileName() + " doesn't match.", true);
               }
        }
    }
}

Here is the call graph for this function:

fio_RelFile::~fio_RelFile (  )  [virtual]

Definition at line 264 of file fio_RelFile.cpp.

References log_FUNC_m.


Member Function Documentation

void fio_RelFile::CreateFile (  )  [protected]

when file has not yet created then this method is called

Definition at line 531 of file fio_RelFile.cpp.

References alloca(), c_fio_maxRelFileHeadLen, fio_GuardRecordFiller_c, log_FUNC_m, m_accessToIdx0, m_fileHeader, m_firstRecordOffset, m_recordSize, cmn_File::SeekF(), cmn_File::WriteF(), WriteHeader(), and WriteListOfUnusedVector().

Referenced by fio_RelFile().

                             {
    log_FUNC_m(CreateFile);

    WriteHeader();
    ivd_FileBufSize_t written;
    for (unsigned int i = sizeof(m_fileHeader); i < c_fio_maxRelFileHeadLen; i++) {
        static char c = '\0';
        written = WriteF(&c, 1);
    }
    WriteListOfUnusedVector();

    SeekF(m_firstRecordOffset);
    if (m_accessToIdx0) {
        // write zeroes
        char * zerroBuff = reinterpret_cast<char*>(alloca(m_recordSize));
        memset(zerroBuff, 0, m_recordSize);
        WriteF(zerroBuff, m_recordSize);
    }
    else if (m_recordSize > sizeof(fio_GuardRecordFiller_c)) {
        // write guard record if idx 0 is not used
        int n = m_recordSize / sizeof(fio_GuardRecordFiller_c);
        for (int i = 0; i < n; i++) {
            WriteF( fio_GuardRecordFiller_c, m_recordSize);
        }
        WriteF( fio_GuardRecordFiller_c, m_recordSize);
    }
    else {
        WriteF( fio_GuardRecordFiller_c, m_recordSize % sizeof(fio_GuardRecordFiller_c));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::DumpHdr ( ostream &  os  )  [virtual]

dump header to stream

Reimplemented in fio_CirFileTrans.

Definition at line 631 of file fio_RelFile.cpp.

References GetNumOfRecord(), log_FUNC_m, and m_currFileHeader.

                                     {
    log_FUNC_m(DumpHdr);
    os << m_currFileHeader;
    os << "USED RECORDS   = " << GetNumOfRecord() << endl;
}

Here is the call graph for this function:

fio_RecordIDX_t fio_RelFile::FirstNewIDX (  ) 

Definition at line 277 of file fio_RelFile.cpp.

References assert, log_FUNC_m, m_firstRecordOffset, m_recordSize, and cmn_File::SeekEndF().

Referenced by i_FSC_i::ChkLastFileID(), hdb_Tables::DumpMigratedFiles(), hsm_FHmigc::GetFileIDs(), main(), nsc_ScanForIVDFSRecovery(), fsc_RawUpdate::ScanAllFileID(), and SetFirstNewIDX().

                                         {
    log_FUNC_m(FirstNewIDX);

    assert(0 < m_recordSize);
    // number of current used records is new index, cause index 0 is reserved.
    // STRANGE it must return result + 1 ???
    // maybe method WriteRec(...) solved this problem by updating m_firstNewIDX
    // and method void fio_uvListMgr::ReadUV(), where write a byte in next record
    return (SeekEndF() - m_firstRecordOffset) / m_recordSize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::Flush (  )  [inline]

Definition at line 360 of file fio_RelFile.h.

Referenced by fio_RelFileTransLstMgr::Flush().

{};

Here is the caller graph for this function:

fio_RecordIDX_t fio_RelFile::GetFirstNewIDX ( unsigned int  a_numOfRec  )  [protected]

Definition at line 301 of file fio_RelFile.cpp.

References cmn_Mutex::Lock(), m_firstNewIDX, m_firstNewIDX_x, and cmn_Mutex::Unlock().

Referenced by fio_uvListMgr::ReadUV().

                                                                   {
//    log_FUNC_m(GetFirstNewIDX);

    m_firstNewIDX_x.Lock();
    fio_RecordIDX_t firstNewIDX = m_firstNewIDX;
    m_firstNewIDX += a_numOfRec;
    m_firstNewIDX_x.Unlock();

    return firstNewIDX;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ivd_RecordIDX_t fio_RelFile::GetFirstNewIDX (  )  [inline]

Definition at line 324 of file fio_RelFile.h.

Referenced by GetNewVectorIDX().

{ return m_firstNewIDX; };

Here is the caller graph for this function:

unsigned int fio_RelFile::GetFirstRecordOffset (  )  [inline]

Definition at line 356 of file fio_RelFile.h.

fio_RecordIDX_t fio_RelFile::GetNewVectorIDX ( unsigned int  a_numOfRec  ) 

Reserve one or more records (vector) in file and return index to it.

Definition at line 409 of file fio_RelFile.cpp.

References GetFirstNewIDX(), GetUnusedVectorIDX(), ie_INVALID_ARG, ie_REL_FILE_VEC_SIZE_INV, ivd_Error, log_FUNC_m, m_numOfDifVector, and m_smallestVectorSize.

                                                                    {

    if (a_numOfRec < m_smallestVectorSize) {
        log_FUNC_m(GetNewVectorIDX);
        throw ivd_InternalError(ie_INVALID_ARG, "Too small vector.");
    }
    unsigned int listIDX = a_numOfRec - m_smallestVectorSize;

    if(listIDX >= m_numOfDifVector) {
        log_FUNC_m(GetNewVectorIDX);
        throw ivd_Error(ie_REL_FILE_VEC_SIZE_INV, "Too large vector search", true);
    }

    fio_RecordIDX_t newIndex = GetUnusedVectorIDX(a_numOfRec); // try to find it inside list of list of unused vector
    if (newIndex == 0) {
        return GetFirstNewIDX(a_numOfRec);  // if not get it from the end of the file
    }
    else {
        return newIndex;
    }
}

Here is the call graph for this function:

unsigned int fio_RelFile::GetNumOfRecord (  )  [inline]

Definition at line 358 of file fio_RelFile.h.

Referenced by DumpHdr(), fsc_DataLMgr::GetNumOfUsedFileID(), and main().

{ return m_firstNewIDX - 1;};

Here is the caller graph for this function:

unsigned int fio_RelFile::GetRecordSize (  )  [inline]

Definition at line 357 of file fio_RelFile.h.

Referenced by fio_uvListMgr::WriteUV().

{ return m_recordSize;};

Here is the caller graph for this function:

fio_RelFileHeader_t fio_RelFile::GetRelFileHeader (  )  [inline]

Definition at line 236 of file fio_RelFile.h.

Referenced by RevertUpdate(), and Update().

{ return m_currFileHeader; }; 

Here is the caller graph for this function:

fio_RecordIDX_t fio_RelFile::GetUnusedVectorIDX ( const unsigned int  a_numOfRec,
fio_Transaction a_transacton_p = NULL 
) [protected]

Definition at line 433 of file fio_RelFile.cpp.

References fio_uvListHeader_t::firstUnusedIDX, cmn_Mutex::Lock(), m_listOfLoUV_x, m_listOfUV_v, m_smallestVectorSize, fio_UnusedRec_t::next, fio_uvListHeader_t::numOfElements, ReadRec(), cmn_Mutex::Unlock(), and UpdateListOfUnusedVector().

Referenced by GetNewVectorIDX().

                                                      {
//    log_FUNC_m(GetUnusedVectorIDX);

    unsigned int listIDX = a_numOfRec - m_smallestVectorSize;

    fio_uvListHeader_t &uvlHeader = m_listOfUV_v[listIDX];// get proper header

    m_listOfLoUV_x.Lock();

    fio_RecordIDX_t newIndex = uvlHeader.firstUnusedIDX; // get index of proper size vector

    if (newIndex != 0) {

        fio_UnusedRec_t unusedRec;

        ReadRec( newIndex, &unusedRec );
        uvlHeader.firstUnusedIDX = unusedRec.next; // rebound the unused list
        uvlHeader.numOfElements--;                 // decrement number of list element

        UpdateListOfUnusedVector(listIDX, a_transaction_p);// update unused list at index
    }
    m_listOfLoUV_x.Unlock();

    return newIndex;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ivd_FilePosition_t fio_RelFile::Idx2Pos ( ivd_RecordIDX_t  a_idx  )  [inline]
virtual int fio_RelFile::PosWrite ( ivd_FilePosition_t  a_position,
const void *  a_buffer_p,
ivd_FileBufSize_t  a_size,
fio_Transaction a_transaction 
) const [inline, protected, virtual]

PosWrite with transaction method is virtual.

In this RelFile class write alteration directly to file.

Reimplemented in fio_RelFileTrans.

Definition at line 295 of file fio_RelFile.h.

References fio_File::PosWrite().

Referenced by UpdateListOfUnusedVector(), WriteHeader(), WriteListOfUnusedVector(), and WriteRec().

                                                        { 
        return fio_File::PosWrite(a_position, a_buffer_p, a_size);
    };

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::ReadListOfUnusedVector (  )  [protected]

Definition at line 580 of file fio_RelFile.cpp.

References c_fio_maxRelFileHeadLen, dbg_DETAIL, dbg_GetLevel(), dbg_IsActive(), fio_File::GetFileName(), cmn_File::GetFullPathRef(), ie_FILE_ERROR, ivd_Error, log_DBG_m, log_ERR_m, log_FUNC_m, m_listOfUV_v, m_sizeOfListOfUnusedVector, and fio_File::PosRead().

Referenced by SyncRelFileObj().

                                         {
    log_FUNC_m(ReadListOfUnusedVector);

    ivd_FileBufSize_t read = fio_File::PosRead(
             c_fio_maxRelFileHeadLen, // position after space reserved for file header
             &*m_listOfUV_v.begin(),
             m_sizeOfListOfUnusedVector);

    if (dbg_IsActive() && (dbg_GetLevel() == dbg_DETAIL)) {
        ostringstream sstr;
        log_DBG_m(dbg_DETAIL,"List of list of UV relative file : '" << GetFullPathRef() << "'");
        log_DBG_m(dbg_DETAIL,"Vec size   #ofUV  First index");
        log_DBG_m(dbg_DETAIL,"-----------------------------");

        fio_LoUV_v_i iter = m_listOfUV_v.begin();
        int i = 1;
        for (; iter != m_listOfUV_v.end(); ++iter, ++i) {
            log_DBG_m(dbg_DETAIL, setw(8) << i
                 << setw(8) << (*iter).numOfElements
                 << setw(13) << (*iter).firstUnusedIDX);
        }
    }

    if (read != m_sizeOfListOfUnusedVector) {
        log_ERR_m(
            "Can't read list of UV from relative file " << GetFileName() << endl);
        throw ivd_Error(ie_FILE_ERROR, "Can't read list of UV from relative file.", true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

fio_RecordIDX_t fio_RelFile::ReadNextUnusedVectorIDX ( fio_RecordIDX_t  a_index,
UInt16_t  a_vecSize 
) [protected]

read record at index and return the index to next record;

NOTE a_vecSize is decremented by one.

Definition at line 465 of file fio_RelFile.cpp.

References cmn_HexDump(), fio_MAX_UV_SIZE_TO_COMPARE_d, cmn_File::GetFullPathRef(), ie_INV_UNUSED_VECT_STRUCT, IsUVFillerCorrupted(), ivd_Error, log_FUNC_m, m_recordSize, fio_UnusedRec_t::next, ReadRec(), fio_UnusedRec_t::vecSize, and fio_UnusedRec_t::wordFiller.

Referenced by fio_uvListMgr::ReadUV().

                                                                                                {
    log_FUNC_m(ReadNextUnusedVectorIDX);

    fio_UnusedRec_t unusedRec;
    ReadRec( a_index, &unusedRec );
    bool invalidRecord(false);
    ostringstream sstr;

    //SimulateUVStructureError(&unusedRec);

    if (a_vecSize != unusedRec.vecSize) {
        sstr << "Expected vector size: " << a_vecSize
             << ", but got vector size: " << unusedRec.vecSize << endl
             << "NOTE! stored vector size values are one less then real vector size." << endl;
        invalidRecord = true;
    }
    /*
    If vector is unused everything except next and vecSize members must be set to zero.
    This depends on m_recordSize. e.g:
    if it is set to 8 (bytes, 4(next) + 2(vecSize) + 2(wordFiller)) then
    wordFiller must be set to 0.
    if it is set to 12 (bytes, 4(next) + 2(vecSize) + 2(wordFiller) + 4(longFiller1)) then
    wordFiller and longFiller1 must be set to 0.
    */
    UInt16_t sizeToCompare(m_recordSize - (sizeof(unusedRec.next) + sizeof(unusedRec.vecSize)));
    /*
    Do not test if last filler is set to 0 since it can contain anything.
    */
    if (sizeToCompare > fio_MAX_UV_SIZE_TO_COMPARE_d) {
        sizeToCompare = fio_MAX_UV_SIZE_TO_COMPARE_d;
    }

    char* filler_p = reinterpret_cast<char*>(&unusedRec.wordFiller);
    if (IsUVFillerCorrupted(filler_p, sizeToCompare)) {
        sstr << "Expected zero fillers, but got non-zero fillers." << endl;
        invalidRecord = true;
    }

    if (invalidRecord) {
        ostringstream errStr;
        errStr << "In relative file : '" << GetFullPathRef() << "'"
               << " at index: " << a_index << "." << endl << sstr.str()
               << cmn_HexDump(&unusedRec, m_recordSize, m_recordSize, false);
        throw ivd_Error(ie_INV_UNUSED_VECT_STRUCT, errStr.str(), true);
    }
    return unusedRec.next;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fio_RelFile::ReadRec ( const fio_RecordIDX_t  a_index,
void *  a_buffer,
const unsigned int  a_numOfRec = 1 
)

Read one or more records (vector) from a_buffer to a_index place in file.

number of read records is return

Reimplemented in fio_CirFileTrans.

Definition at line 348 of file fio_RelFile.cpp.

References Idx2Pos(), ie_REL_FILE_INDEX_INV, ivd_Error, log_FUNC_m, m_accessToIdx0, m_recordSize, and fio_File::PosRead().

Referenced by TreeWalk::CheckDir(), hdb_Tables::DumpMigratedFiles(), fsc_CopyMgr::fsc_CopyMgr(), fsc_DataL_t::fsc_DataL_t(), fsc_GenerationMgr::fsc_GenerationMgr(), fsc_nsElement_t::fsc_nsElement_t(), fsc_SplitMgr::fsc_SplitMgr(), GetUnusedVectorIDX(), hdb_RemoveName(), hdbReadNameOwnRec(), hsm_CheckFile2hsmdbRec(), hsm_FileHeader::InitFromDB(), ReadNextUnusedVectorIDX(), fio_CirFileTrans::ReadRec(), fsc_RawUpdate::ScanAllFileID(), and fsc_RawScan::ScanAllFileID().

                                         {

    if(  !m_accessToIdx0
      &&  a_index == 0) {
        log_FUNC_m(ReadRec);
        throw ivd_Error(ie_REL_FILE_INDEX_INV,
                "Can't read on index 0. It's reserved.", true);
    }
    // return the number of record read
    return PosRead( Idx2Pos(a_index),
                    a_buffer,
                    m_recordSize * a_numOfRec) / m_recordSize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::ReleaseVector ( const fio_RecordIDX_t  a_index,
unsigned int  a_numOfRec,
fio_Transaction a_transaction = NULL 
)

Release one or more records (vector) from a_index place in file.

Definition at line 367 of file fio_RelFile.cpp.

References assert, fio_uvListHeader_t::firstUnusedIDX, ie_INVALID_ARG, ie_REL_FILE_INDEX_INV, ie_REL_FILE_VEC_SIZE_INV, ivd_Error, cmn_Mutex::Lock(), log_FUNC_m, m_listOfLoUV_x, m_listOfUV_v, m_numOfDifVector, m_recordSize, m_smallestVectorSize, fio_uvListHeader_t::numOfElements, cmn_Mutex::Unlock(), UpdateListOfUnusedVector(), and WriteRec().

                                                               {

    if(a_index == 0) {
        log_FUNC_m(ReleaseVector);
        throw ivd_Error(ie_REL_FILE_INDEX_INV,
                "Can't release vector on index 0. It's reserved.", true);
    }

    if (a_numOfRec < m_smallestVectorSize) {
        log_FUNC_m(ReleaseVector);
        throw ivd_InternalError(ie_INVALID_ARG, "Too small vector.");
    }
    unsigned int listIDX = a_numOfRec - m_smallestVectorSize;

    if(listIDX >= m_numOfDifVector) {
        log_FUNC_m(ReleaseVector);
        throw ivd_Error(ie_REL_FILE_VEC_SIZE_INV, "Too large vector search", true);
    }

    fio_uvListHeader_t &uvlHeader = m_listOfUV_v[listIDX]; // get proper header

    assert(sizeof(fio_UnusedRec_t) > m_recordSize);


    m_listOfLoUV_x.Lock();

     // released record point to current in list
    fio_UnusedRec_t unusedRec(uvlHeader.firstUnusedIDX, listIDX);

    uvlHeader.firstUnusedIDX = a_index;          // rebound the unused list
    uvlHeader.numOfElements++;                   // increment number of list element
    WriteRec( a_index, &unusedRec, 1);                  // update unused record
    UpdateListOfUnusedVector(listIDX, a_transaction_p); // update unused list at index

    m_listOfLoUV_x.Unlock();
}

Here is the call graph for this function:

void fio_RelFile::SetFirstNewIDX (  ) 

calculate with FirstNewIDX methos and set m_firstNewIDX member

Definition at line 290 of file fio_RelFile.cpp.

References FirstNewIDX(), log_ERR_m, log_FUNC_m, and m_firstNewIDX.

Referenced by fio_CirFileTrans::fio_CirFileTrans(), and SyncRelFileObj().

                                 {
    log_FUNC_m(SetFirstNewIDX);
    m_firstNewIDX = FirstNewIDX();
    if (m_firstNewIDX < 1) {
        log_ERR_m("first unused vector IDX is less than 1. Set it to 1.");
        m_firstNewIDX = 1;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::SyncRelFileObj (  )  [virtual]

Sync relative file object with data on disk after transaction reply.

Reimplemented in fio_CirFileTrans, and fio_RelFileTrans.

Definition at line 270 of file fio_RelFile.cpp.

References log_FUNC_m, ReadListOfUnusedVector(), and SetFirstNewIDX().

Referenced by fio_RelFileTrans::SyncRelFileObj().

Here is the call graph for this function:

Here is the caller graph for this function:

int fio_RelFile::UpdateListOfUnusedVector ( const unsigned int  a_listIdx,
fio_Transaction a_transaction_p = NULL 
) [protected]

Definition at line 612 of file fio_RelFile.cpp.

References c_fio_maxRelFileHeadLen, ie_REL_FILE_VEC_SIZE_INV, ivd_Error, log_FUNC_m, m_listOfUV_v, m_loUVHeaderLen, m_numOfDifVector, and PosWrite().

Referenced by GetUnusedVectorIDX(), and ReleaseVector().

                                                         {

    if(a_listIdx >= m_numOfDifVector) {
        log_FUNC_m(UpdateListOfUnusedVector);
        throw ivd_Error(ie_REL_FILE_VEC_SIZE_INV, "Too large vector (list index)", true);
    }

    ivd_FilePosition_t  position =  a_listIdx * m_loUVHeaderLen + c_fio_maxRelFileHeadLen;

    return PosWrite( position,
                    &m_listOfUV_v[a_listIdx].firstUnusedIDX,
                     m_loUVHeaderLen,
                     a_transaction_p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::WriteHeader (  )  [protected]

Definition at line 516 of file fio_RelFile.cpp.

References fio_File::GetFileName(), ie_FILE_ERROR, ivd_Error, log_ERR_m, log_FUNC_m, m_fileHeader, and PosWrite().

Referenced by CreateFile(), and fsc_RawUpdate::UpdateHeaders().

                              {
    log_FUNC_m(WriteHeader);

    unsigned int fileHeaderSize = sizeof(m_fileHeader);

    ivd_FileBufSize_t written = fio_File::PosWrite(0, &m_fileHeader, fileHeaderSize);

    if (written !=  fileHeaderSize) {
        log_ERR_m("Can't write to relative file " << GetFileName() << endl);
        throw ivd_Error(ie_FILE_ERROR, "Can't write to relative file.", true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_RelFile::WriteListOfUnusedVector (  )  [protected]

Definition at line 564 of file fio_RelFile.cpp.

References c_fio_maxRelFileHeadLen, fio_File::GetFileName(), ie_FILE_ERROR, ivd_Error, log_ERR_m, log_FUNC_m, m_listOfUV_v, m_sizeOfListOfUnusedVector, and PosWrite().

Referenced by CreateFile().

                                          {

    ivd_FileBufSize_t written = fio_File::PosWrite(
             c_fio_maxRelFileHeadLen, // position after space reserved for file header
             &*m_listOfUV_v.begin(),
             m_sizeOfListOfUnusedVector);

    if (written != m_sizeOfListOfUnusedVector) {
        log_FUNC_m(WriteListOfUnusedVector);
        log_ERR_m("Can't write to relative file " << GetFileName() << endl);
        throw ivd_Error(ie_FILE_ERROR, "Can't write to relative file.", true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fio_RelFile::WriteRec ( const fio_RecordIDX_t  a_index,
const void *  a_buffer,
const unsigned int  a_numOfRec = 1,
fio_Transaction a_transaction = NULL 
)

Write one or more records (vector) from a_buffer to a_index place in file.

Definition at line 315 of file fio_RelFile.cpp.

References Idx2Pos(), ie_REL_FILE_INDEX_INV, ie_REL_FILE_VEC_SIZE_INV, ivd_Error, cmn_Mutex::Lock(), log_FUNC_m, m_accessToIdx0, m_firstNewIDX, m_firstNewIDX_x, m_numOfDifVector, m_recordSize, m_smallestVectorSize, PosWrite(), and cmn_Mutex::Unlock().

Referenced by hsm_FHrelc::Append(), i_FSC_i::ChkLastFileID(), hsm_FileHeader::CompleteMigIsDone(), fsc_DataLMgr::GetBunchOfFileIDs(), hsm_FHmigc::GetFileIDs(), hsm_FHrelc::Release(), ReleaseVector(), hsm_FileHeader::RemoveNameFromHSMDB(), hsm_FHrelc::Truncate(), fsc_SplitMgr::Write2DB(), fsc_DataL::Write2DB(), fsc_CopyMgr::Write2DB(), fio_Vector::Write2DB(), and fio_CirFileTrans::WriteRec().

                                                            {

    if(  !m_accessToIdx0
      &&  a_index == 0) {
        log_FUNC_m(WriteRec);
        throw ivd_Error(ie_REL_FILE_INDEX_INV,
                "Can't write on index 0. It's reserved.", true);
    }

    m_firstNewIDX_x.Lock();
    if(a_index >= m_firstNewIDX) {
        m_firstNewIDX = a_index + 1;
    }
    m_firstNewIDX_x.Unlock();

    if (a_numOfRec > m_smallestVectorSize) {
        if((a_numOfRec - m_smallestVectorSize) >= m_numOfDifVector) {
            log_FUNC_m(WriteRec);
            throw ivd_Error(ie_REL_FILE_VEC_SIZE_INV, "Too large vector write", true);
        }
    }

    return PosWrite(Idx2Pos(a_index),
                    a_buffer,
                    a_numOfRec * m_recordSize,
                    a_transaction);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class fio_uvListMgr [friend]

Reimplemented in fio_RelFileTrans.

Definition at line 219 of file fio_RelFile.h.

friend class fsc_RawUpdate [friend]

Definition at line 220 of file fio_RelFile.h.


Member Data Documentation

Macro for class name member.

Reimplemented from fio_File.

Reimplemented in fio_CirFileTrans, fio_RelFileTrans, and fio_VarLenRFT.

Definition at line 320 of file fio_RelFile.h.

const bool fio_RelFile::m_accessToIdx0 [protected]

Definition at line 248 of file fio_RelFile.h.

Referenced by CreateFile(), ReadRec(), and WriteRec().

Definition at line 254 of file fio_RelFile.h.

Referenced by DumpHdr(), and fio_RelFile().

Definition at line 251 of file fio_RelFile.h.

Referenced by CreateFile(), fio_RelFile(), and WriteHeader().

Definition at line 259 of file fio_RelFile.h.

Referenced by GetFirstNewIDX(), SetFirstNewIDX(), and WriteRec().

Exclusive access m_firstNewIDX.

Definition at line 268 of file fio_RelFile.h.

Referenced by GetFirstNewIDX(), and WriteRec().

const unsigned int fio_RelFile::m_firstRecordOffset [protected]

Definition at line 246 of file fio_RelFile.h.

Referenced by CreateFile(), fio_RelFile(), and FirstNewIDX().

cmn_Mutex fio_RelFile::m_listOfLoUV_x [mutable, protected]

Exclusive access to list of list of unused vectors.

Definition at line 265 of file fio_RelFile.h.

Referenced by GetUnusedVectorIDX(), and ReleaseVector().

const unsigned int fio_RelFile::m_loUVHeaderLen [protected]

Definition at line 242 of file fio_RelFile.h.

Referenced by fio_RelFileTrans::fio_RelFileTrans(), and UpdateListOfUnusedVector().

const unsigned int fio_RelFile::m_numOfDifVector [protected]
const unsigned int fio_RelFile::m_recordSize [protected]

Definition at line 247 of file fio_RelFile.h.

Exclusive access to Relative file.

Definition at line 262 of file fio_RelFile.h.

Definition at line 245 of file fio_RelFile.h.

Referenced by ReadListOfUnusedVector(), and WriteListOfUnusedVector().


The documentation for this class was generated from the following files: