Public Member Functions | Public Attributes | Private Attributes | Friends

fsc_CopyMgr Class Reference
[File System Catalog]

<Description:> A more elaborate class description that describes all aspects of class usage etc. More...

#include <fsc_CopyMgr.h>

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

List of all members.

Public Member Functions

 fsc_CopyMgr (fsc_MedPosMgr *a_medPosMgr_p, df_SplitInfo &a_splitInfo)
 fsc_CopyMgr (fsc_dlcType_e a_dlcType, fsc_EntryMgr *a_entryMgr_p, ivd_DataType_t a_dataType)
 fsc_CopyMgr (df_SplitInfo &a_splitInfo)
 fsc_CopyMgr (Int16_t a_numOfElement, ivd_RecordIDX_t a_copyIdx, ivd_DataType_t a_dataType)
virtual ~fsc_CopyMgr ()
void AddSplit (fsc_Split *a_split_p)
void Remove (ivd_MediaKey_t a_mediumKey, ivd_MedVolNum_t a_medVolNum)
 remove all entries from particular volume.
bool Remove (ivd_MediaKey_t a_mediumKey, ivd_MedVolNum_t a_medVolNum, UInt32_t a_blockOffs)
 Remove one particular entry.
void GetCopiesPos (ivd_CopiesPos_v_t &a_copiesPos_v, fsc_MigInfo_t &migInfo)
bool Write2DB (fsc_NextEntity_t &a_nextEntry, fio_Transaction &a_trans)
 Write all changes to DB, update nextEntry structure to proper index and size return true if nextEntry structure is changed.
void Dump (ostream &os)
bool TreeWalk (fsc_Collector &a_collector)

Public Attributes

fsc_Copy_p_l_t m_copy_p_l
 log_CLASSID_m
 Macro to add class name member s_className.

Private Attributes

fio_RelFileTransm_relFile
 this is pointer to relative file "fsc_xxxx.lrf" object.

Friends

class ut_fsc_CopyMgr

Detailed Description

<Description:> A more elaborate class description that describes all aspects of class usage etc.

Author:
Dejan Volk Lupo, HERMES SoftLab
See also:
<reference>

Definition at line 62 of file fsc_CopyMgr.h.


Constructor & Destructor Documentation

fsc_CopyMgr::fsc_CopyMgr ( fsc_MedPosMgr a_medPosMgr_p,
df_SplitInfo a_splitInfo 
)

Referenced by fsc_CopyMgr().

Here is the caller graph for this function:

fsc_CopyMgr::fsc_CopyMgr ( fsc_dlcType_e  a_dlcType,
fsc_EntryMgr a_entryMgr_p,
ivd_DataType_t  a_dataType 
)

Definition at line 58 of file fsc_CopyMgr.cpp.

References fsc_CopyMgr(), log_FUNC_m, and m_copy_p_l.

            :
            m_relFile(*g_copyRF_p)
{
    log_FUNC_m(fsc_CopyMgr(fsc_dlcType_e, fsc_EntryMgr, df_SplitInfo));

    // first copy is got from higher level
    fsc_Copy* copy_p = new fsc_Copy(a_dlcType, a_entryMgr_p, a_dataType);

    m_copy_p_l.push_front(copy_p);
}

Here is the call graph for this function:

fsc_CopyMgr::fsc_CopyMgr ( df_SplitInfo a_splitInfo  ) 

Definition at line 74 of file fsc_CopyMgr.cpp.

References df_SplitInfo::Dump(), fsc_CopyMgr(), ie_FSC_INV_SPLIT_INFO, ie_FSC_TOO_MUCH_COPIES, log_FUNC_m, m_copy_p_l, maxNumOfCopies_c, and df_SplitInfo::noCopies.

            :
            m_relFile(*g_copyRF_p)
{
    log_FUNC_m(fsc_CopyMgr(df_SplitInfo));

    if (  a_splitInfo.noCopies >  0) {
        if (a_splitInfo.noCopies > maxNumOfCopies_c) {
            throw ivd_InternalError(ie_FSC_TOO_MUCH_COPIES,
                "Front end agent created too many copies." + a_splitInfo.Dump(), true);
        }
        fsc_Copy* copy_p = new fsc_Copy(a_splitInfo);

        m_copy_p_l.push_front(copy_p);
        // reserve space for all copies
        for (int i = 1; i < a_splitInfo.noCopies; i++ ) {
            fsc_Copy* copy_p = new fsc_Copy();

            m_copy_p_l.push_front(copy_p);
        }
    }
    else {
        throw ivd_InternalError(ie_FSC_INV_SPLIT_INFO,
            "Number of copies are not specified." + a_splitInfo.Dump(), true);
    }
}

Here is the call graph for this function:

fsc_CopyMgr::fsc_CopyMgr ( Int16_t  a_numOfElement,
ivd_RecordIDX_t  a_copyIdx,
ivd_DataType_t  a_dataType 
)

Definition at line 103 of file fsc_CopyMgr.cpp.

References alloca(), cmn_HexDump(), dbg_DETAIL, fsc_CopyMgr(), log_DBG_m, log_FUNC_m, m_copy_p_l, m_relFile, and fio_RelFile::ReadRec().

            :
            fsc_EntryMgr(a_numOfElement, a_copyIdx),
            m_relFile(*g_copyRF_p)
{
    log_FUNC_m(fsc_CopyMgr(Int16_t..));

//    log_DBG_m(dbg_DETAIL,"Get " << a_numOfElement
//                      << " copies from idx " << a_copyIdx);

    if (a_numOfElement > 0) {
        fsc_Copy_t *copyData_v = reinterpret_cast<fsc_Copy_t*>
                                    (alloca(a_numOfElement * sizeof(fsc_Copy_t)));

        fsc_Copy_t *p    =  copyData_v;
        fsc_Copy_t *endp = &copyData_v[a_numOfElement];

        m_relFile.ReadRec(a_copyIdx, copyData_v, a_numOfElement);

        log_DBG_m(dbg_DETAIL, "R copies from = " << a_copyIdx << endl <<
            cmn_HexDump(copyData_v, a_numOfElement * sizeof(fsc_Copy_t), sizeof(fsc_Copy_t), false) );
//        cout << "Read copy vect to DB" << endl;
//        cout << cmn_HexDump(iter, a_numOfElement * sizeof(fsc_Copy_t) ) << endl;

        for (; p < endp; p++) {
            fsc_Copy* copy_p = new fsc_Copy(*p);
            m_copy_p_l.push_back(copy_p);
        }
    }
}

Here is the call graph for this function:

fsc_CopyMgr::~fsc_CopyMgr (  )  [virtual]

Definition at line 138 of file fsc_CopyMgr.cpp.

References m_copy_p_l.

{
    for (fsc_Copy_p_l_i iter = m_copy_p_l.begin();
         iter != m_copy_p_l.end();
         ++iter) {
        delete *iter;
    }
}


Member Function Documentation

void fsc_CopyMgr::AddSplit ( fsc_Split a_split_p  ) 

Definition at line 148 of file fsc_CopyMgr.cpp.

References cmn_Num2Str(), dbg_DETAIL, dlc_NotUsed, ie_INVALID_ARG, log_DBG_m, log_FUNC_m, m_copy_p_l, sp_ALREADY_ADDED, sp_CHECK_OTHER_COPIES, sp_INSERTTED, sp_NEW_COPY, and sp_REPLACE.

Referenced by fsc_Generation::Insert(), and Remove().

                                               {
    log_FUNC_m(AddSplit);

//    stringstream dump;
//    a_split_p->Dump(dump);
//    log_DBG_m(dbg_DETAIL, "AddSplit \n" << dump.str());
    fsc_Split_p_l_i possibleInsertPoint;
    fsc_Split_p_l_t replacedSplit_p_l;

    sp_State_e checkCopyState = sp_SENTINEL;
    sp_State_e addState = sp_NEW_COPY;

    fsc_Copy_p_l_i possibleUsefullCopy;
    fsc_Copy_p_l_i freeCopy = m_copy_p_l.end();
    fsc_Copy_p_l_i it;

    for (it = m_copy_p_l.begin(); it != m_copy_p_l.end(); ++it) {
         if ((**it).isReorganized()) {
            continue;
         }
        //stringstream dump;
        //(**it).Dump(dump);
        //log_DBG_m(dbg_DETAIL, "Copy from copyMgr \n" << dump.str());
        if ((**it).m_nextEntry.dlcType == dlc_NotUsed) {    // free element
            log_DBG_m(dbg_DETAIL, "Found unused copy");
            freeCopy = it;
            continue; // skip it first
        }
        switch (addState = (**it).AddSplit(a_split_p, possibleInsertPoint ,replacedSplit_p_l)) {
        case sp_INSERTTED :
            log_DBG_m(dbg_DETAIL, "INSERTTED");
            return;

        case sp_NEW_COPY :
            log_DBG_m(dbg_DETAIL, "NEW_COPY");
            continue;

        case sp_CHECK_OTHER_COPIES :  // if no other places then use possibleInsertPoint
                                      // this status is return when added split has enought space
                                      // but it is not sure if is proper place.
            log_DBG_m(dbg_DETAIL, "CHECK_OTHER_COPIES");
            checkCopyState      = addState;
            possibleUsefullCopy = it;
            continue;

        case sp_REPLACE : {// expect some splits in replacedSplit_p_l list
            log_DBG_m(dbg_DETAIL, "REPLACE");
            fsc_Split_p_l_i iter = replacedSplit_p_l.begin();
            for ( ; iter != replacedSplit_p_l.end(); ++iter ) {
                // NOTE: recursion, call this method again
                // WARNING: replace only split that does'n fit with
                // split that its offset proper fit to previous split
                AddSplit(*iter); // insert it again
            }
            return;
        }
        case sp_ALREADY_ADDED :
            log_DBG_m(dbg_DETAIL, "ALREADY_ADDED");
            delete a_split_p;
            return;

        default : ;
        }
    }
    if (checkCopyState == sp_CHECK_OTHER_COPIES) {
        log_DBG_m(dbg_DETAIL, "action INSERT after CHECK_OTHER_COPIES");
        // todo direct insert to copy
        (*possibleUsefullCopy)->AddSplit(possibleInsertPoint, a_split_p);
        return;
    }

    if (addState == sp_NEW_COPY) {
        log_DBG_m(dbg_DETAIL, "action NEW_COPY");
        if (freeCopy != m_copy_p_l.end()) {
            // how to know if split is whole or not
            // maybe lastsplit bool will help
            new (*freeCopy) fsc_Copy(a_split_p); // instantiate on willing addres
        }
        else {
            fsc_Copy* copy_p = new fsc_Copy(a_split_p);

            m_copy_p_l.insert(it, copy_p);
        }
        return;
    }
    else {
        throw ivd_InternalError(ie_INVALID_ARG,
            "Can't insert split. State " + cmn_Num2Str((int)addState), true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fsc_CopyMgr::Dump ( ostream &  os  ) 

Definition at line 454 of file fsc_CopyMgr.cpp.

References dlc_NotUsed, log_FUNC_m, m_copy_p_l, and fsc_EntryMgr::m_prevVecIndex.

Referenced by fsc_Generation::Dump().

                                  {
    log_FUNC_m(Dump);
    os << "C      Previous vector idx  =" << m_prevVecIndex << endl;
    os << "p      Number of copies     =" << m_copy_p_l.size() << endl;
//    os << "y      Previous num of cop. =" << m_prevVecSize << endl;

    fsc_Copy_p_l_i iter = m_copy_p_l.begin();
    for (;iter != m_copy_p_l.end(); ++iter) {
        if ((*iter)->m_nextEntry.dlcType == dlc_NotUsed) {
            os << "           Reserved space for copy" << endl;
        }
        else {
            (*iter)->Dump(os);
        }
    }
}

Here is the caller graph for this function:

void fsc_CopyMgr::GetCopiesPos ( ivd_CopiesPos_v_t a_copiesPos_v,
fsc_MigInfo_t migInfo 
)

Definition at line 300 of file fsc_CopyMgr.cpp.

References dbg_DETAIL, dlc_NotUsed, fsc_NextEntity_t::dlcType, fsc_Copy::Dump(), fsc_Copy::GetMediaPos(), ivd_DATA_d, log_DBG_m, log_FUNC_m, log_MSG_m, log_WARNING, m_copy_p_l, fsc_Copy::m_dataType, fsc_MigInfo_t::m_fileId, fsc_MigInfo_t::m_migId, and fsc_Entry::m_nextEntry.

Referenced by fsc_Generation::GetCopiesPos().

                                                                                         {
    log_FUNC_m(GetCopiesPos);
    //FIX bug 690  reserve space not alocate
    a_copiesPos_v.reserve(m_copy_p_l.size());

    int i = 0;
    for (fsc_Copy_p_l_i iter = m_copy_p_l.begin();
         iter != m_copy_p_l.end();
         ++iter, i++) {
        fsc_Copy &c = (**iter);
        log_DBG_m(dbg_DETAIL," Copy's record type " << (int)c.m_nextEntry.dlcType
                            << " data type " << c.m_dataType);
        if ( c.m_nextEntry.dlcType != dlc_NotUsed ) {
            if ((c.m_dataType & ivd_DATA_d) != ivd_DATA_d) {
                ostringstream sstr;
                sstr << "The copy " << (i + 1)
                     << " (FileID: " << a_migInfo.m_fileId
                     << ", MigID: " << a_migInfo.m_migId
                     << ") does not contain the data flag, "
                     << "but the generation contains it. "
                     << "Continuing with the recall...\n";
                c.Dump(sstr);
                // log warning without the stack dump into the error.log
                log_MSG_m(log_WARNING, 0, sstr.str());
                continue;
            }

            //FIX bug 690  add one by one
            a_copiesPos_v.resize(a_copiesPos_v.size() + 1);
            c.GetMediaPos(a_copiesPos_v.back(), a_migInfo);
            if (a_copiesPos_v.back().size() == 0) {
                a_copiesPos_v.pop_back();
            }
        }
    }
    if (a_copiesPos_v.size() != a_copiesPos_v.capacity()) {
        log_DBG_m(dbg_DETAIL,"Missing copy info of fileId " << a_migInfo.m_fileId
            << " migId " << a_migInfo.m_migId);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fsc_CopyMgr::Remove ( ivd_MediaKey_t  a_mediumKey,
ivd_MedVolNum_t  a_medVolNum 
)

remove all entries from particular volume.

Definition at line 240 of file fsc_CopyMgr.cpp.

References AddSplit(), log_FUNC_m, and m_copy_p_l.

Referenced by fsc_Generation::Remove(), and Remove().

                                                          {
    log_FUNC_m(Remove);
    fsc_Split_p_l_t replacedSplit_p_l;

    fsc_Copy_p_l_i iter = m_copy_p_l.begin();
    for (;iter != m_copy_p_l.end(); ++iter) {
        // remove entry from all copies and collect orphaned splits from all copies
        (*iter)->Remove(a_mediumKey, a_medVolNum, replacedSplit_p_l);
    }
    if (replacedSplit_p_l.size()) {
        //log_DbgLevel_t dbgLevel = dbg_GetLevel();
        //UInt32_t       dbgFlags = dbg_GetFlags();
        //bool           dbgActiv = dbg_IsActive();

        //dbg_On(dbg_DETAIL,
        //       dbg_THROW | dbg_INOUT | dbg_COMPACT | dbg_ERRORLOG,
        //       ".");
        // if removed copy contains splits than all
        // remaining splits have to be reinserted.
        fsc_Split_p_l_i iter = replacedSplit_p_l.begin();
        for ( ; iter != replacedSplit_p_l.end(); ++iter ) {
            AddSplit(*iter); // insert it again
        }
        replacedSplit_p_l.clear();

        //dbg_SetLevel(dbgLevel);
        //dbg_SetFlags(dbgFlags);
        //if (!dbgActiv) {
        //    dbg_Off();
        //}
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool fsc_CopyMgr::Remove ( ivd_MediaKey_t  a_mediumKey,
ivd_MedVolNum_t  a_medVolNum,
UInt32_t  a_blockOffs 
)

Remove one particular entry.

Definition at line 275 of file fsc_CopyMgr.cpp.

References AddSplit(), log_FUNC_m, m_copy_p_l, and Remove().

                                                          {
    log_FUNC_m(Remove);
    bool ret = false;
    fsc_Split_p_l_t replacedSplit_p_l;

    fsc_Copy_p_l_i iter = m_copy_p_l.begin();
    for (;(iter != m_copy_p_l.end()) && !ret; ++iter) {
        // remove first match entry and stop
        ret = (*iter)->Remove(a_mediumKey, a_medVolNum, a_blockOffs, replacedSplit_p_l);
    }
    if (replacedSplit_p_l.size()) {
        // if removed copy contains splits than all
        // remaining splits have to be reinserted.
        fsc_Split_p_l_i iter = replacedSplit_p_l.begin();
        for ( ; iter != replacedSplit_p_l.end(); ++iter ) {
            AddSplit(*iter); // insert it again
        }
        replacedSplit_p_l.clear();
    }
    return ret;
}

Here is the call graph for this function:

bool fsc_CopyMgr::TreeWalk ( fsc_Collector a_collector  ) 

Definition at line 342 of file fsc_CopyMgr.cpp.

References log_FUNC_m, m_copy_p_l, and fsc_Collector::ProcObjCopyMgr().

Referenced by fsc_Generation::TreeWalk().

                                                       {
    log_FUNC_m(TreeWalk);

    if (!a_collector.ProcObjCopyMgr(this)){
        return false;
    }
    fsc_Copy_p_l_i iter = m_copy_p_l.begin();
    for (;iter != m_copy_p_l.end(); ++iter) {
        if (!(**iter).TreeWalk(a_collector)) {
            return false;
        }
    }
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool fsc_CopyMgr::Write2DB ( fsc_NextEntity_t a_nextEntry,
fio_Transaction a_trans 
)

Write all changes to DB, update nextEntry structure to proper index and size return true if nextEntry structure is changed.

Definition at line 358 of file fsc_CopyMgr.cpp.

References cmn_HexDump(), dbg_DETAIL, dlc_NotUsed, fsc_NextEntity_t::dlcType, fsc_Vector_t::entryIdx, fio_RelFileTrans::GetVectorIDX(), log_DBG_m, log_FUNC_m, m_copy_p_l, fsc_EntryMgr::m_prevVecIndex, fsc_EntryMgr::m_prevVecSize, m_relFile, fsc_Copy_t::nextEntity, fsc_Vector_t::numOfElement, fio_RelFileTrans::ReleaseVectorIdx(), size, fsc_NextEntity_t::vector, fsc_Copy::Write2DB(), and fio_RelFile::WriteRec().

Referenced by fsc_Generation::Write2DB().

                                                      {
    log_FUNC_m(Write2DB);

    bool vecIdxOrSizeChanged = false;
    bool vecDataChanged      = false;

    fsc_Copy_v_st size = m_copy_p_l.size();
    log_DBG_m(dbg_DETAIL," Num of copies before write = " << size );

    if (size) {
        fsc_Copy_t *p = g_copyData_v;
        fsc_Copy_p_l_i iter = m_copy_p_l.begin();
        while (iter != m_copy_p_l.end()) {  // fulfill the data vector
            fsc_Copy *c = (*iter);
            if ( c->Write2DB(*p, a_trans)) {
                vecDataChanged = true;
                if (   p->nextEntity.dlcType          == dlc_NotUsed
                &&  p->nextEntity.vector.entryIdx     == 0
                &&  p->nextEntity.vector.numOfElement == 0) { // entry was removed
                // release object
                    log_DBG_m(dbg_DETAIL,"Copy released iter =" << hex << *iter << dec);
                    delete c;
                    size--;
                    iter = m_copy_p_l.erase(iter);
                    log_DBG_m(dbg_DETAIL,"iter after erase = " << hex << *iter << dec);
                    continue;
                }
            }
            ++iter;
            p++;
        }
    }
    log_DBG_m(dbg_DETAIL," Num of copies after write = " << size );
    // it is possible that size became zero after handle each element
    if (size == 0) {
       log_DBG_m(dbg_DETAIL,"All Copies released" );
        if( size != m_prevVecSize) {
            m_relFile.ReleaseVectorIdx(m_prevVecIndex, m_prevVecSize, &a_trans);
            m_prevVecSize  = 0;
            m_prevVecIndex = 0;
            vecIdxOrSizeChanged = true;
        }
        a_nextEntry.dlcType              = dlc_NotUsed;
        a_nextEntry.vector.entryIdx      = 0;
        a_nextEntry.vector.numOfElement  = 0;
        return vecIdxOrSizeChanged;
    }
    if (size == 1) {
     // special handling. Delete previous copies and return what last copy contain
        log_DBG_m(dbg_DETAIL,"Only one copy left" );
        a_nextEntry = g_copyData_v[0].nextEntity;
        log_DBG_m(dbg_DETAIL, "a_nextEntry = " <<
            cmn_HexDump(&a_nextEntry, sizeof(fsc_NextEntity_t), sizeof(fsc_NextEntity_t), false) );
        size--;
        if( size != m_prevVecSize) {
            m_relFile.ReleaseVectorIdx(m_prevVecIndex, m_prevVecSize, &a_trans);
            m_prevVecSize  = 0;
            m_prevVecIndex = 0;
        }
        return true;
    }

    ivd_RecordIDX_t idx = m_prevVecIndex;  // curent vector index
    if (idx == 0) {
        idx = m_relFile.GetVectorIDX(size, &a_trans);
        vecIdxOrSizeChanged = true;
    }
    else if (size != m_prevVecSize) {
        idx = m_relFile.GetVectorIDX(size, &a_trans);
        m_relFile.ReleaseVectorIdx(m_prevVecIndex, m_prevVecSize, &a_trans);
        vecIdxOrSizeChanged = true;
    }

    //log_DBG_m(dbg_DETAIL, " vecIdxOrSizeCahnged " << vecIdxOrSizeChanged
    //                   << " vecDataChanged " << vecDataChanged);
    if (  vecIdxOrSizeChanged
       || vecDataChanged) {  // if something change write it t
        log_DBG_m(dbg_DETAIL, "W Copies : idx = " << idx << endl <<
            cmn_HexDump(g_copyData_v, size * sizeof(fsc_Copy_t), sizeof(fsc_Copy_t), false) );
        // write data to relative file
         m_relFile.WriteRec(idx, g_copyData_v, size, &a_trans);
//        cout << cmn_HexDump(g_copyData_v, size * sizeof(fsc_Copy_t) ) << endl;
//        m_vecIndex     = idx;
        m_prevVecSize  = size;
        m_prevVecIndex = idx;
    }
    // tel owner my profile

    a_nextEntry.dlcType              = dlc_Copy;
    a_nextEntry.vector.entryIdx      = idx;
    a_nextEntry.vector.numOfElement  = size;
    return vecIdxOrSizeChanged;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class ut_fsc_CopyMgr [friend]

Definition at line 63 of file fsc_CopyMgr.h.


Member Data Documentation

Macro to add class name member s_className.

Reimplemented from fsc_EntryMgr.

Definition at line 90 of file fsc_CopyMgr.h.

this is pointer to relative file "fsc_xxxx.lrf" object.

It's not need to delete it in destructor

Definition at line 83 of file fsc_CopyMgr.h.

Referenced by fsc_CopyMgr(), and Write2DB().


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