Public Member Functions | Public Attributes | Private Attributes | Friends

fsc_GenerationMgr Class Reference
[File System Catalog]

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

#include <fsc_GenerationMgr.h>

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

List of all members.

Public Member Functions

 fsc_GenerationMgr (df_SplitInfo &a_splitInfo)
 Default constructor.
 fsc_GenerationMgr (fsc_DataL_t &a_dataL)
virtual ~fsc_GenerationMgr ()
fsc_GenInsertAct_e GetGenInsertAct ()
void Insert (df_SplitInfo &a_splitInfo)
 Insert a split into Data location tree.
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.
fsc_GenerationFindGen (ivd_MigrationID_t a_migID)
 find Generation object
void GetCopiesPos (ivd_CopiesPos_v_t &a_copiesPos_v, ivd_MigrationID_t &a_migID, fsc_MigInfo_t &a_migInfo)
void CheckLastGen (string &a_status, ivd_MigrationID_t &a_migID)
bool Write2DB (fsc_DataL_t &a_dataL, 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_Generation_p_l_t m_generation_p_l
 log_CLASSID_m

Private Attributes

fsc_GenInsertAct_e m_genInsertAct
 what happened when insert gen? add newest one update last update other used to proper update NSC attributes
ivd_RecordIDX_v_t m_idxOfChainedVec_v

Friends

class ut_fsc_GenerationMgr

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 67 of file fsc_GenerationMgr.h.


Constructor & Destructor Documentation

fsc_GenerationMgr::fsc_GenerationMgr ( df_SplitInfo a_splitInfo  ) 

Default constructor.

Definition at line 67 of file fsc_GenerationMgr.cpp.

References log_FUNC_m, and m_generation_p_l.

fsc_GenerationMgr::fsc_GenerationMgr ( fsc_DataL_t a_dataL  ) 

Definition at line 80 of file fsc_GenerationMgr.cpp.

References alloca(), c_lastVecIdx, c_maxRFVecSize, cmn_HexDump(), cmn_Num2Str(), dbg_DETAIL, g_generationRF_p, fsc_DataL_t::generationIdx, ie_FSC_INV_GENERATION_NUM, log_DBG_m, log_FUNC_m, m_generation_p_l, m_idxOfChainedVec_v, fio_Vector::m_vectorSize, fio_UnusedRec_t::next, fsc_DataL_t::numOfAllGen, fsc_DataL_t::numOfElement, and fio_RelFile::ReadRec().

            :
            fio_Vector(*g_generationRF_p, a_dataL.numOfElement, a_dataL.generationIdx, false),
            m_genInsertAct(giaUNKNOWN_ACT)
{
    log_FUNC_m(fsc_GenerationMgr);

    UInt16_t numOfElement  = a_dataL.numOfElement;

    if (a_dataL.numOfElement == 0) { // correct numOfElement and m_vectorSize
        numOfElement = c_maxRFVecSize;
        m_vectorSize = numOfElement;
    }

    UInt16_t        lastElIdx     = numOfElement - 1;
    ivd_RecordIDX_t generationIdx = a_dataL.generationIdx;
    log_DBG_m(dbg_DETAIL,"Get " << numOfElement
                      << " generations from idx " << generationIdx);

    if (generationIdx > 0) {
        // allocate space for max possible vec 256
        fsc_Generation_t *genData = reinterpret_cast<fsc_Generation_t*>
                                    (alloca(c_maxRFVecSize * sizeof(fsc_Generation_t)));

        g_generationRF_p->ReadRec(generationIdx, genData, numOfElement);

        log_DBG_m(dbg_DETAIL, "R Generations from = " << generationIdx << endl <<
            cmn_HexDump(genData, numOfElement * sizeof(fsc_Generation_t), sizeof(fsc_Generation_t), false) );

        // if more chained vectors exist than last element is index to next vector in chain
        fsc_Generation_t *end_p = &genData[a_dataL.numOfAllGen >= c_maxRFVecSize
                                           ? numOfElement - 1
                                           : numOfElement];
        fsc_Generation_t *p     =  genData;
        for (; p < end_p; ++p) {
            fsc_Generation* gen_p = new fsc_Generation(*p);
            m_generation_p_l.push_back(gen_p);
        }

        if (a_dataL.numOfAllGen >= c_maxRFVecSize) {
            ivd_RecordIDX_t vecIdx = reinterpret_cast<fio_UnusedRec_t*>(&genData[lastElIdx])->next;
            end_p = &genData[c_lastVecIdx];
            fio_UnusedRec_t &lastRec_p = *reinterpret_cast<fio_UnusedRec_t*>(&genData[c_lastVecIdx]);
            while (vecIdx > 0) {
                m_idxOfChainedVec_v.push_back(vecIdx);
                log_DBG_m(dbg_DETAIL,"Linked vector. Get " << c_maxRFVecSize
                                << " generations from idx " << vecIdx);
                g_generationRF_p->ReadRec(vecIdx, genData, c_maxRFVecSize);
                log_DBG_m(dbg_DETAIL, "R Generations from = " << vecIdx << endl <<
                    cmn_HexDump(genData,
                                c_maxRFVecSize * sizeof(fsc_Generation_t),
                                sizeof(fsc_Generation_t),
                                false) );

                fsc_Generation_t *p = genData;
                for (; p < end_p; ++p) {
                    fsc_Generation* gen_p = new fsc_Generation(*p);
                    log_DBG_m(dbg_DETAIL, "gen_p = 0x" << hex << gen_p << dec);
                    m_generation_p_l.push_back(gen_p);
                }
                vecIdx = lastRec_p.next;
            }
            if (a_dataL.numOfAllGen != m_generation_p_l.size()) {
                throw ivd_InternalError(ie_FSC_INV_GENERATION_NUM,
                                         cmn_Num2Str(m_generation_p_l.size())
                                         + " gen num got from generation.lrf != a_dataL.numOfAllGen "
                                         + cmn_Num2Str(a_dataL.numOfAllGen));
            }
        }
    }
}

Here is the call graph for this function:

fsc_GenerationMgr::~fsc_GenerationMgr (  )  [virtual]

Definition at line 153 of file fsc_GenerationMgr.cpp.

References m_generation_p_l.

{
    for (fsc_Generation_p_l_i iter = m_generation_p_l.begin();
         iter != m_generation_p_l.end();
         iter++) {
        delete *iter;
    }
}


Member Function Documentation

void fsc_GenerationMgr::CheckLastGen ( string &  a_status,
ivd_MigrationID_t a_migID 
)

Definition at line 332 of file fsc_GenerationMgr.cpp.

References log_FUNC_m, m_generation_p_l, and fsc_Generation::m_migrationID.

Referenced by fsc_DataL::CheckLastGen().

                                                                                {
    log_FUNC_m(CheckLastGen);

    if (m_generation_p_l.size() == 0) {
        a_status += "    Missing in FSC.\n";
        return;
    }
    fsc_Generation *gen_p = *m_generation_p_l.begin();
    a_migID = gen_p->m_migrationID;
}

Here is the caller graph for this function:

void fsc_GenerationMgr::Dump ( ostream &  os  ) 

Reimplemented from fio_Vector.

Definition at line 463 of file fsc_GenerationMgr.cpp.

References dbg_DETAIL, fio_Vector::GetVectorIndex(), log_DBG_m, log_FUNC_m, and m_generation_p_l.

Referenced by fsc_DataL::Dump(), and GetCopiesPos().

                                        {
    log_FUNC_m(Dump);
//    os << "Gen  vector index  =" << fio_Vector::GetVectorIndex() << endl;
    os << "    Generation number  =" << m_generation_p_l.size() << endl;
    os << "    Next idx = " << fio_Vector::GetVectorIndex() << endl;
//    os << "n  Previous num of gen. =" << m_prevVecSize << endl;

    fsc_Generation_p_l_i iter = m_generation_p_l.begin();
    for (;iter != m_generation_p_l.end(); ++iter) {
        log_DBG_m(dbg_DETAIL, "*iter = 0x" << hex << (*iter) << dec);
        if ((*iter)->m_migrationID == 0) {
            os << "       Reserved space for generation." << endl;
        }
        else {
            (*iter)->Dump(os);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

fsc_Generation * fsc_GenerationMgr::FindGen ( ivd_MigrationID_t  a_migID  ) 

find Generation object

Definition at line 259 of file fsc_GenerationMgr.cpp.

References m_generation_p_l.

                                                                    {

    fsc_Generation_p_l_i iter = m_generation_p_l.begin();
    for (;iter != m_generation_p_l.end(); iter++) {
        if ((*iter)->m_migrationID == a_migID) {
            return *iter;
        }
    }
    return NULL;
}

void fsc_GenerationMgr::GetCopiesPos ( ivd_CopiesPos_v_t a_copiesPos_v,
ivd_MigrationID_t a_migID,
fsc_MigInfo_t a_migInfo 
)

Definition at line 271 of file fsc_GenerationMgr.cpp.

References Dump(), fsc_Generation::GetCopiesPos(), ie_FSC_NOCOPIES, ivd_DATA_d, ivd_Error, log_FUNC_m, fsc_MigInfo_t::m_fileId, m_generation_p_l, and fsc_Generation::m_migrationID.

Referenced by fsc_DataL::GetCopiesPos().

                                                {
    log_FUNC_m(GetCopiesPos);

    fsc_Generation *gen_p;

    if (  a_migID == 0  ) {
        fsc_Generation_p_l_i iter = m_generation_p_l.begin();
        for (;iter != m_generation_p_l.end(); iter++) {
            if ((*iter)->m_dataType & ivd_DATA_d) {
                gen_p = *iter;
                goto GetCopies;
            }
        }
        stringstream dump;
        dump << " Getting copies of fileID " << a_migInfo.m_fileId
             << " and MigID " << a_migID
             << " failed, because none of generations contain data.\n";
        Dump(dump);
        throw ivd_Error(ie_FSC_NOCOPIES, dump.str());
    }
    else {
        fsc_Generation_p_l_i iter = m_generation_p_l.begin();
        for (;iter != m_generation_p_l.end(); iter++) {
            if (   (*iter)->m_migrationID <= a_migID
                && (*iter)->m_dataType & ivd_DATA_d) {
                gen_p = *iter;
                goto GetCopies;
            }
        }
        stringstream dump;
        dump << " Getting copies of fileID " << a_migInfo.m_fileId
             << " and MigID " << a_migID
             << " failed, because none of generations before MigID contain data.\n";
        Dump(dump);
        throw ivd_Error(ie_FSC_NOCOPIES, dump.str());
    }

GetCopies:
    a_migID = gen_p->m_migrationID;
    gen_p->GetCopiesPos(a_copiesPos_v, a_migInfo);
}

Here is the call graph for this function:

Here is the caller graph for this function:

fsc_GenInsertAct_e fsc_GenerationMgr::GetGenInsertAct (  )  [inline]

Definition at line 99 of file fsc_GenerationMgr.h.

References m_genInsertAct.

Referenced by fsc_DataL::Insert().

{ return m_genInsertAct; };

Here is the caller graph for this function:

void fsc_GenerationMgr::Insert ( df_SplitInfo a_splitInfo  ) 

Insert a split into Data location tree.

Definition at line 164 of file fsc_GenerationMgr.cpp.

References dbg_NORM, df_SplitInfo::Dump(), fsc_maxGenerations_c, log_DBG_m, log_FUNC_m, log_WRN_m, fio_Vector::m_changed, m_generation_p_l, m_genInsertAct, and df_SplitInfo::migrationID.

Referenced by fsc_DataL::Insert().

                                                         {
    log_FUNC_m(Insert);

    ivd_MigrationID_t   migID = a_splitInfo.migrationID;
    fsc_Generation_p_l_i iter = m_generation_p_l.begin();

    // take proper sort position, descending sort by migID
    while (iter   != m_generation_p_l.end()
        && (**iter).m_migrationID > migID) {
        ++iter;
    }

    // if generation is not here jet
    if (   iter == m_generation_p_l.end()   // end of the list
       || (**iter ).m_migrationID < migID) {// no element with same migID
        // Empty,  just continue
    }
    else {
        // fix bug 1228, size may change when splits
        //if ((*iter)->m_size != a_splitInfo.fileSize) {
        //    throw ivd_InternalError(ie_FSC_INV_SPLIT_INFO ,
        //        string("Inserted split match with migrationID, but has different file size.") +
        //        " Gen   MigID    = " + cmn_Num2Str(migID) +
        //        " Gen   FileSize = " + cmn_Num2Str((*iter)->m_size)+ a_splitInfo.Dump(),
        //        true);
        //}
        (*iter)->Insert(a_splitInfo);
        if (iter == m_generation_p_l.begin()) {
            m_genInsertAct = giaLAST_GEN_UPDATED;
        }
        else if (iter == ++(m_generation_p_l.begin())) {
            m_genInsertAct = giaONE_BEFORE_LAST_GEN_UPDATED;
        }
        else {
           m_genInsertAct =  giaOTHER_GEN_UPDATED;
        }
        return;
    }
    // now iter must point to end or to elemet with smaller migID

    fsc_Generation* gen_p = new fsc_Generation(a_splitInfo);

    // newest if inserted to first place
    if (iter == m_generation_p_l.begin()) {
        m_genInsertAct = giaNEWEST_GEN;
    }
    else if (iter == ++(m_generation_p_l.begin())) {
        m_genInsertAct = giaINSERT_ONE_BEFORE_LAST_GEN;
    }
    else {
        m_genInsertAct =  giaINSERT_OLD_GEN;
    }

    m_generation_p_l.insert(iter, gen_p);
    m_changed = true;
    if (m_generation_p_l.size() % 256 == 0) {
        log_DBG_m(dbg_NORM,"CONGRATULATION: " << m_generation_p_l.size()
                           << " generations of file: " <<  a_splitInfo.Dump());
    }
    if (m_generation_p_l.size() > fsc_maxGenerations_c) {
        log_WRN_m("Number of generation exceeded " << fsc_maxGenerations_c
               <<". The oldest one will be ignored.");
        fsc_Generation_p_l_i iter = --(m_generation_p_l.end());
        delete *iter;
        m_generation_p_l.erase(iter);
    }
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Remove one particular entry.

Definition at line 244 of file fsc_GenerationMgr.cpp.

References log_FUNC_m, m_generation_p_l, and Remove().

                                                               {
    log_FUNC_m(Remove);

    fsc_Generation_p_l_i iter = m_generation_p_l.begin();
    for (;iter != m_generation_p_l.end(); iter++) {
        if ((**iter).Remove(a_mediumKey, a_medVolNum, a_blockOffs)) {
            return true;
        }
    }
    return false;
}

Here is the call graph for this function:

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

remove all entries from particular volume.

Definition at line 234 of file fsc_GenerationMgr.cpp.

References log_FUNC_m, and m_generation_p_l.

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

                                                                {
    log_FUNC_m(Remove);
    fsc_Generation_p_l_i iter = m_generation_p_l.begin();
    for (;iter != m_generation_p_l.end(); iter++) {
        (**iter).Remove(a_mediumKey, a_medVolNum);
    }
}

Here is the caller graph for this function:

bool fsc_GenerationMgr::TreeWalk ( fsc_Collector a_collector  ) 

Definition at line 316 of file fsc_GenerationMgr.cpp.

References log_FUNC_m, m_generation_p_l, and fsc_Collector::ProcObjGenerationMgr().

Referenced by fsc_DataL::TreeWalk().

                                                             {
    log_FUNC_m(TreeWalk);

    if (!a_collector.ProcObjGenerationMgr(this)) {
        return false;
    }
    fsc_Generation_p_l_i iter = m_generation_p_l.begin();
    for (;iter != m_generation_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_GenerationMgr::Write2DB ( fsc_DataL_t a_dataL,
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 344 of file fsc_GenerationMgr.cpp.

References c_maxNumOfMember, c_maxRFVecSize, cmn_HexDump(), dbg_DETAIL, dlc_NotUsed, fsc_NextEntity_t::dlcType, fsc_Generation::Dump(), fsc_Vector_t::entryIdx, g_generationRF_p, fsc_DataL_t::generationIdx, log_DBG_m, log_FUNC_m, fio_Vector::m_changed, m_generation_p_l, m_genInsertAct, m_idxOfChainedVec_v, fio_Vector::m_relFileTrans, fio_Vector::m_vectorIndex, fio_Vector::m_vectorSize, fio_UnusedRec_t::next, fsc_Generation_t::nextEntity, fsc_DataL_t::numOfAllGen, fsc_DataL_t::numOfElement, fsc_Vector_t::numOfElement, fio_RelFileTrans::ReleaseVectorIdx(), size, fsc_NextEntity_t::vector, fio_Vector::Write2DB(), and fsc_Generation::Write2DB().

Referenced by fsc_DataL::Write2DB().

                                                           {
    log_FUNC_m(Write2DB);

    bool vecDataChanged      = false;
    fsc_Generation_v_st size = m_generation_p_l.size();

    log_DBG_m(dbg_DETAIL, "Generations = " << size);
    if (size) {
        fsc_Generation_p_l_i iter = m_generation_p_l.begin();
        fsc_Generation_t *p  = &g_gensData[0];
        fsc_Generation_t *ep = &g_gensData[size];

        while (p < ep) {  // fulfill the data vector
            fsc_Generation *g = (*iter);
            if (g->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
                    m_changed = true;
                    ostringstream sstr;
                    g->Dump(sstr);
                    log_DBG_m(dbg_DETAIL, "Remove generation " << sstr.str());
                    // release object
                    delete g;
                    size--;
                    ep--;
                    iter = m_generation_p_l.erase(iter);
                    continue;
                }
            }
            iter++;
            p++;
        }
    }
    if (!(m_changed || vecDataChanged)) {
        log_DBG_m(dbg_DETAIL, "No gen changed.");
        a_dataL.numOfAllGen  = size;
        return false;
    }
    // it is possible that size became zero after handle each element
    if (size == 0) {
        if( size != m_vectorSize) {
            //TODO remove all chained vector
            m_relFileTrans.ReleaseVectorIdx(m_vectorIndex, m_vectorSize, &a_trans);
            m_vectorSize  = 0;
            m_vectorIndex = 0;
            vecDataChanged = true;
        }
        a_dataL.numOfAllGen   = 0;
        a_dataL.generationIdx = 0;
        a_dataL.numOfElement  = 0;
        return vecDataChanged;
    }

    UInt32_t genToStore;
    UInt32_t firstVecSize = genToStore = size;

    log_DBG_m(dbg_DETAIL, "size >= c_maxRFVecSize, " << size << " >= " << c_maxRFVecSize);
    if (size >= c_maxRFVecSize) { // save prepared vector to DB
        ivd_RecordIDX_t nextVecIdx = 0; // last vector in chain

        while (genToStore >= c_maxRFVecSize) {
            fsc_Generation_t *ep = &g_gensData[genToStore];
            fio_UnusedRec_t &link = *reinterpret_cast<fio_UnusedRec_t*>(ep);
            ep -= c_maxNumOfMember;

            link.next = nextVecIdx;
            ivd_RecordIDX_t vecIdx = 0;
            if (m_idxOfChainedVec_v.size()) {
                vecIdx = m_idxOfChainedVec_v.back();
                m_idxOfChainedVec_v.pop_back();
            }
            fio_Vector v(*g_generationRF_p,
                         c_maxRFVecSize,
                         vecIdx, true);

            v.Write2DB(ep, c_maxRFVecSize, nextVecIdx, a_trans);
                log_DBG_m(dbg_DETAIL, "W entry vector of " << c_maxRFVecSize << " generations : idx =" << nextVecIdx << endl <<
                    cmn_HexDump(ep,
                                c_maxRFVecSize * sizeof(fsc_Generation_t),
                                sizeof(fsc_Generation_t), false) );
            genToStore -= c_maxNumOfMember;
        }
        firstVecSize = genToStore + 1;
        fio_UnusedRec_t &lastRecfv = *reinterpret_cast<fio_UnusedRec_t*>(&g_gensData[genToStore]);
        lastRecfv.next = nextVecIdx;
    }

    // remove not used c_maxRFVecSize elements size vectors
    ivd_RecordIDX_t *vIdxIp = &(*m_idxOfChainedVec_v.begin()); // reuse vector
    ivd_RecordIDX_t *vIdxEp = &(*m_idxOfChainedVec_v.end());
    log_DBG_m(dbg_DETAIL, "Release vect " << hex << vIdxIp
                       << " " << vIdxEp << dec);
    while (vIdxIp < vIdxEp) {
        log_DBG_m(dbg_DETAIL, "Release vect " << *vIdxIp);
        g_generationRF_p->ReleaseVectorIdx(*vIdxIp, c_maxRFVecSize, &a_trans);
        vIdxIp++;
    }
    m_idxOfChainedVec_v.clear();

    bool change = m_changed;
    if (   m_changed
        || vecDataChanged) {
        m_changed = true; // fio_Vector doesn't know if only vecDataChanged is changed
        fio_Vector::Write2DB(g_gensData, firstVecSize, a_dataL.generationIdx, a_trans);
        a_dataL.numOfElement = firstVecSize;
        log_DBG_m(dbg_DETAIL, "W linked vector of " << firstVecSize << " generations : idx =" << a_dataL.generationIdx << endl <<
            cmn_HexDump(g_gensData, firstVecSize * sizeof(fsc_Generation_t), sizeof(fsc_Generation_t), false) );
    }

    m_genInsertAct = giaUNKNOWN_ACT;
    // tel owner my profile
    a_dataL.numOfAllGen  = size;
    return change;
}

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_GenerationMgr [friend]

Definition at line 68 of file fsc_GenerationMgr.h.


Member Data Documentation

Reimplemented from fio_Vector.

Definition at line 96 of file fsc_GenerationMgr.h.

what happened when insert gen? add newest one update last update other used to proper update NSC attributes

Definition at line 88 of file fsc_GenerationMgr.h.

Referenced by GetGenInsertAct(), Insert(), and Write2DB().

Definition at line 90 of file fsc_GenerationMgr.h.

Referenced by fsc_GenerationMgr(), and Write2DB().


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