Public Member Functions | Public Attributes | Private Attributes

hsm_ActiveFH Class Reference
[Classes for managing object list]

#include <hsm_ActiveFH.h>

Collaboration diagram for hsm_ActiveFH:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 hsm_ActiveFH (fio_CirFileTrans &a_cirFile)
 ~hsm_ActiveFH ()
void FindNextClearCurrRec (fio_Transaction &a_trans)
void FindNextRec ()
ivd_RecordIDX_t Append (hsm_FileHeader *a_fh_p, fio_Transaction &a_trans)
ivd_RecordIDX_t Update (hsm_FileHeader *a_fh_p, fio_Transaction &a_trans)
void Release (hsm_FileHeader *a_fh_p, fio_Transaction &a_trans)
ivd_RecordIDX_t MoveToEnd (hsm_FileHeader *a_fh_p, fio_Transaction &a_trans)
hdb_Active_tGetRefRleaseCandRec ()
void ActiveToList (string &a_fsID)
void OrphanedToMigList ()

Public Attributes

 log_CLASSID_m

Private Attributes

fio_CirFileTransm_cirFile
ivd_RecordIDX_t m_idx
 index of first element in active list
hdb_Active_t m_activeFH
cmn_Mutex m_activeFH_x

Detailed Description

Definition at line 50 of file hsm_ActiveFH.h.


Constructor & Destructor Documentation

hsm_ActiveFH::hsm_ActiveFH ( fio_CirFileTrans a_cirFile  ) 

Definition at line 56 of file hsm_ActiveFH.cpp.

References log_FUNC_m.

        :
        m_cirFile(a_cirFile),
        m_idx(0)
{
    log_FUNC_m(hsm_ActiveFH);
    // dont need transaction cause m_idx is zerro
//    FindNextRec();
}

hsm_ActiveFH::~hsm_ActiveFH (  ) 

Definition at line 68 of file hsm_ActiveFH.cpp.

References dbg_LOW, log_DBG_m, and log_FUNC_m.

                            {
    log_FUNC_m(~hsm_ActiveFH);
    log_DBG_m(dbg_LOW, "      ~hsm_ActiveFH destructor");
}


Member Function Documentation

void hsm_ActiveFH::ActiveToList ( string &  a_fsID  ) 

Simulate delete evvent

Definition at line 200 of file hsm_ActiveFH.cpp.

References CHG_DELETED_d, hdb_Active_t::chgFlags, ivd_FS_File::Close(), dbg_DETAIL, dbg_NORM, hsm_FileHeader::DecrRef(), ivd_FS_File::e_Cache, file, hdb_Active_t::fileID, g_fs_api_p, g_hsm_FHCache_p, g_hsmDB_p, hdb_Active_t::generalInode, ivd_BaseException::GetError(), hsm_FHcache::GetFH(), ivd_BaseException::GetFriendly(), ivd_FS_File::GetProperties(), ivd_FileSystemAPI::GetRootPath(), fio_DataBase::GetTransObj(), hdb_RemoveName(), hdbReadNameOwnRec(), hsmdbGetPath(), hsm_FileHeader::InitActive(), hsm_FHcache::Insert(), IVD_PRINT_ID_FS, log_DBG_m, log_FUNC_m, log_WRN_m, m_cirFile, ivd_FS_FileProperty_t::m_Inode, hsm_FileHeader::MakePath(), hdb_Active_t::nameOwnIdx, NULL, hdb_Active_t::oldNameOwnIdx, ivd_FS_File::Open(), fio_CirFileTrans::ReadNext(), fio_CirFileTrans::ReadNextReset(), fio_DataBase::ReleaseTransObj(), and fio_CirFileTrans::WriteRec().

Referenced by fs_api::EventMounted().

                                              {
    log_FUNC_m(ActiveToList);

    cmn_File mountPoint(g_fs_api_p->GetRootPath() + ".");
        
    fio_Transaction &trans = *g_hsmDB_p->GetTransObj(); 

    hdb_Active_t  actRec;
    ivd_RecordIDX_t idx;
    // reset circular list for read
    m_cirFile.ReadNextReset();
    while ((idx = m_cirFile.ReadNext(&actRec)) > 0) {
        if (actRec.generalInode > 0) {
            log_DBG_m(dbg_DETAIL, "Find active FH rec in HSMDB Idx = "
                << idx << endl << actRec);
            if (!(actRec.chgFlags & CHG_DELETED_d)) {
                hdb_DirNode_t dir; // default const. it filled with zeroes
                ivd_RecordIDX_t dirTreeIdx = 0;
                hdb_String name;
                hdbReadNameOwnRec(actRec.nameOwnIdx, dirTreeIdx, name, dir);
                ivd_FS_File file(*g_fs_api_p, actRec.generalInode, actRec.fileID);
                try {
                    //HPUX - The file needs to be opened ( to be in the kernel cache ).
                    file.Open(ivd_FS_File::e_Cache,
                        (g_fs_api_p->GetRootPath() + hsmdbGetPath(dir) + name));
                    ivd_FS_FileProperty_t fileProp;
                    file.GetProperties(fileProp);
                    //Close file
                    file.Close();

                    // got current inode from FS
                    if (actRec.generalInode != fileProp.m_Inode) {
                        log_DBG_m(dbg_NORM, "Inode changed. from DB "
                            << IVD_PRINT_ID_FS(actRec.generalInode)
                            <<  " from FS "
                            << IVD_PRINT_ID_FS(fileProp.m_Inode));
                        actRec.generalInode = fileProp.m_Inode;
                    }
                }
                catch (ivd_SysError &se) {
                    // if GetProperties not found inode or it has not proper general number throw ENXIO
                    // TODO renamed file ENOENT has to be resolved on different way.
                    if (  se.GetError() ==  ENXIO   // inode not exist 
                       && a_fsID == mountPoint.GetFileSystemID()) { // FS is still mounted
                        log_DBG_m(dbg_DETAIL, "FS mounted, but file is not found.");
                        trans.StartTransaction();
                        if (actRec.oldNameOwnIdx) { // remove old name first 
                            hdb_RemoveName(actRec.oldNameOwnIdx, trans);
                        }
                        if (actRec.fileID == 0) { // fileID is not migratted yet so remove it
                            log_DBG_m(dbg_NORM, "Skip it and remove from DB. INO " << IVD_PRINT_ID_FS(actRec.generalInode));
                            hdb_Active_t act; // record with zerroes
                            m_cirFile.WriteRec(idx, &act, 1, trans);
                            // remove nameOwnIdx
                            hdb_RemoveName(actRec.nameOwnIdx, trans);
                            trans.EndTransaction();
                            continue;
                        }
                        else {
                            log_DBG_m(dbg_NORM, "Set in HSMDB as deleted. INO " << IVD_PRINT_ID_FS(actRec.generalInode));
                            actRec.chgFlags      = CHG_DELETED_d;
                            actRec.oldNameOwnIdx = actRec.nameOwnIdx;
                            actRec.nameOwnIdx    = 0;
                            // update active record
                            m_cirFile.WriteRec(idx, &actRec, 1, trans);
                        }
                        trans.EndTransaction();
                    }
                    else {
                        log_WRN_m(se.GetFriendly()
                                << " Can't get general inode of fileID " << actRec.fileID
                                << " File probably not exist or IVDFS is unmounted.");
                    }
                }
            }
            // directory can be already in cache
            hsm_FileHeader *fh_p = g_hsm_FHCache_p->GetFH(actRec.generalInode);
            if (fh_p != NULL) { // must be directory
//DEL                if (fh_p->GetfType() != ift_DIR) {
//                    throw ivd_InternalError(ie_HSM_INVTYPE, 
//                        "Expect directory, but got " + cmn_Num2Str(fh_p->GetfType()), true);
//                }
                log_DBG_m(dbg_DETAIL, "Update FH " << fh_p->MakePath());
                fh_p->InitActive(idx, actRec);
            }
            else{ 
                fh_p = new hsm_FileHeader(idx, actRec);
                log_DBG_m(dbg_DETAIL, "New FH " << fh_p->MakePath() << " add to cache.");
                g_hsm_FHCache_p->Insert(fh_p);                       
            }
            // GetFH and constructor increase ref automaticaly,
            // to prevent others to dereference FH before is handled in Event method
            fh_p->DecrRef(); 
        }
    }
    g_hsmDB_p->ReleaseTransObj(trans);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ivd_RecordIDX_t hsm_ActiveFH::Append ( hsm_FileHeader a_fh_p,
fio_Transaction a_trans 
)

Definition at line 107 of file hsm_ActiveFH.cpp.

References dbg_DETAIL, hdb_Active_t::generalInode, hsm_FileHeader::GetChgFlag(), hsm_FileHeader::GetFileID(), fio_File::GetFileName(), hsm_FileHeader::GetFileSize(), hsm_FileHeader::GetFName(), hsm_FileHeader::GetfType(), hsm_FileHeader::GetInode(), hsm_FileHeader::GetNameOwnIdx(), hsm_FileHeader::GetOldNameOwnIdx(), log_DBG_m, log_FUNC_m, m_activeFH, m_activeFH_x, m_cirFile, m_idx, and fio_CirFileTrans::WriteBack().

Referenced by MoveToEnd(), and hsm_FileHeader::StoreActiveRec().

                                      {
    log_FUNC_m(Append);
    hdb_Active_t act(    a_fh_p->GetNameOwnIdx(),  
                         a_fh_p->GetOldNameOwnIdx(),
                         a_fh_p->GetInode(),
                         a_fh_p->GetChgFlag(),
                         a_fh_p->GetFileID(),
                         a_fh_p->GetfType()
                         );

    log_DBG_m(dbg_DETAIL, act);

    ivd_RecordIDX_t idx = m_cirFile.WriteBack(&act, a_trans);
    log_DBG_m(dbg_DETAIL, "Added file " << a_fh_p->GetFName() 
                          << " size " << a_fh_p->GetFileSize()
                          << " to " << m_cirFile.GetFileName()
                          << " idx " << idx);


    cmn_MutexLock l(m_activeFH_x);
    if (m_activeFH.generalInode == 0) {
        m_activeFH = act; // first record is set immediately
        m_idx = idx;           // and is skipped by FindNexRec
    }        
    return idx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_ActiveFH::FindNextClearCurrRec ( fio_Transaction a_trans  ) 

Definition at line 76 of file hsm_ActiveFH.cpp.

References FindNextRec(), log_FUNC_m, m_activeFH_x, m_cirFile, m_idx, and fio_CirFileTrans::WriteRec().

                                                                {
    log_FUNC_m(FindNextClearCurrRec);
    cmn_MutexLock l(m_activeFH_x);
    if (m_idx != 0) {
        hdb_ReleaseCand_t rc; // release previous cand record with zeroes
        m_cirFile.WriteRec(m_idx, &rc, 1, a_trans);
    }
    FindNextRec();
}

Here is the call graph for this function:

void hsm_ActiveFH::FindNextRec (  ) 

Definition at line 88 of file hsm_ActiveFH.cpp.

References hdb_Active_t::Clear(), dbg_DETAIL, hdb_Active_t::generalInode, log_DBG_m, log_FUNC_m, m_activeFH, m_cirFile, m_idx, and fio_CirFileTrans::ReadFront().

Referenced by FindNextClearCurrRec(), and Release().

                               {
    log_FUNC_m(FindNextRec);
    ivd_RecordIDX_t idx = 0;
    log_DBG_m(dbg_DETAIL, "Current index is " << m_idx);
    do { // read util no more records or found actual record 
        idx = m_cirFile.ReadFront(&m_activeFH); 
        log_DBG_m(dbg_DETAIL, " ReadFront from idx " << idx);
        // first record is already truncate so skip it (idx == m_idx)
    } while (idx != 0 && (m_activeFH.generalInode == 0 || idx == m_idx));
    if (idx == 0) {
//        log_DBG_m(dbg_DETAIL, "No more records in circ file.");
        m_activeFH.Clear();
    }
    m_idx = idx;
    log_DBG_m(dbg_DETAIL, " New RF idx " << m_idx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

hdb_Active_t& hsm_ActiveFH::GetRefRleaseCandRec (  )  [inline]

Definition at line 86 of file hsm_ActiveFH.h.

References m_activeFH.

{ return m_activeFH;};

ivd_RecordIDX_t hsm_ActiveFH::MoveToEnd ( hsm_FileHeader a_fh_p,
fio_Transaction a_trans 
)

Definition at line 190 of file hsm_ActiveFH.cpp.

References Append(), log_FUNC_m, and Release().

Referenced by hsm_FileHeader::StoreActiveRec().

                                                       {
    log_FUNC_m(MoveToEnd);

    Release(a_fh_p, a_trans);
    return Append(a_fh_p, a_trans);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_ActiveFH::OrphanedToMigList (  ) 

Definition at line 301 of file hsm_ActiveFH.cpp.

References CHG_DELETED_d, hdb_Active_t::chgFlags, ivd_FS_File::Close(), dbg_DETAIL, dbg_NORM, hsm_FileHeader::DecrRef(), ivd_FS_File::e_Cache, eDirWaitList, fio_Transaction::EndTransaction(), eNoList, file, hdb_Active_t::fileID, g_fs_api_p, g_hsm_FHCache_p, g_hsm_fhLock, g_hsmDB_p, hdb_Active_t::generalInode, hsm_FHcache::GetFH(), hsm_FileHeader::GetList(), ivd_FS_File::GetProperties(), ivd_FileSystemAPI::GetRootPath(), fio_DataBase::GetTransObj(), hdb_RemoveName(), hdbReadNameOwnRec(), hsmdbGetPath(), hsm_FHcache::Insert(), IVD_PRINT_ID_FS, log_DBG_m, log_FUNC_m, m_cirFile, ivd_FS_FileProperty_t::m_fileID, ivd_FS_FileProperty_t::m_Inode, hdb_Active_t::nameOwnIdx, NULL, hdb_Active_t::oldNameOwnIdx, ivd_FS_File::Open(), path, fio_CirFileTrans::ReadNext(), fio_CirFileTrans::ReadNextReset(), fio_DataBase::ReleaseTransObj(), fio_Transaction::StartTransaction(), hsm_FileHeader::ToMigCand(), and fio_CirFileTrans::WriteRec().

                                     {
    log_FUNC_m(OrphanedToMigList);

    hdb_Active_t  actRec;
    ivd_RecordIDX_t idx;

    // reset circular list for read
    m_cirFile.ReadNextReset();
    while ((idx = m_cirFile.ReadNext(&actRec)) > 0) {
        if (actRec.generalInode == 0) {
            continue;
        }

        if (!(actRec.chgFlags & CHG_DELETED_d)) {
            hdb_DirNode_t dir; // default const. it filled with zeroes
            ivd_RecordIDX_t dirTreeIdx = 0;
            hdb_String name;
            hdbReadNameOwnRec(actRec.nameOwnIdx, dirTreeIdx, name, dir);
            cmn_Path path = g_fs_api_p->GetRootPath() + hsmdbGetPath(dir) + name;
            ivd_FS_File file(*g_fs_api_p, path);
            try {
                //HPUX - The file needs to be opened ( to be in the kernel cache ).
                file.Open(ivd_FS_File::e_Cache);
                ivd_FS_FileProperty_t fileProp;
                file.GetProperties(fileProp);
                //HPUX close file
                file.Close();
                if (fileProp.m_fileID == actRec.fileID) {
                    // got current inode from FS
                    if (actRec.generalInode != fileProp.m_Inode) {
                        log_DBG_m(dbg_NORM, "Inode changed. from DB " << IVD_PRINT_ID_FS(actRec.generalInode)
                                        <<  " from FS " << IVD_PRINT_ID_FS(fileProp.m_Inode));
                        actRec.generalInode = fileProp.m_Inode;
                    }
                }
                else {
                }
            }
            catch (ivd_SysError) {
                log_DBG_m(dbg_NORM, "Can't get general inode of fileID " << actRec.fileID
                                    << " File probably not exist.");
                //HPUX close file
                file.Close();
                if (actRec.fileID == 0) { // fileID is not migratted yet so remove it
                    log_DBG_m(dbg_NORM, "Removed from DB");
                    fio_Transaction *trans = g_hsmDB_p->GetTransObj();
                    trans->StartTransaction();
                    if (actRec.oldNameOwnIdx) {
                        hdb_RemoveName(actRec.oldNameOwnIdx, *trans);
                    }
                    hdb_Active_t act; // record with zerroes
                    m_cirFile.WriteRec(idx, &act, 1, *trans);
                    // remove nameOwnIdx
                    hdb_RemoveName(actRec.nameOwnIdx, *trans);

                    trans->EndTransaction();
                    g_hsmDB_p->ReleaseTransObj(&trans);
                    continue;
                }
                else { // Set changes to Deletted
                    log_DBG_m(dbg_NORM, "Set as DELETED.");
                    fio_Transaction *trans = g_hsmDB_p->GetTransObj();
                    trans->StartTransaction();

                    if (actRec.oldNameOwnIdx) { //oldName will be replaced, so remove it
                        hdb_RemoveName(actRec.oldNameOwnIdx, *trans);
                    }
                    // update active list
                    actRec.chgFlags = CHG_DELETED_d;
                    actRec.oldNameOwnIdx = actRec.nameOwnIdx;
                    actRec.nameOwnIdx = 0;

                    m_cirFile.WriteRec(idx, &actRec, 1, *trans);

                    trans->EndTransaction();
                    g_hsmDB_p->ReleaseTransObj(&trans);
                }
            }
        }
        g_hsm_fhLock.LockByID(actRec.generalInode);
        // directory can be already in cache
        hsm_FileHeader *fh_p = g_hsm_FHCache_p->GetFH(actRec.generalInode);
        if (fh_p == NULL) {
            fh_p = new hsm_FileHeader(idx, actRec, true); // add direct to migcand list 
            log_DBG_m(dbg_DETAIL, "Active in HSMDB, but not in mig process. Idx = " << idx << endl << actRec);
            g_hsm_FHCache_p->Insert(fh_p);                       
        }
        else { // must be directory
            // check if is in active list
            hsm_List_e list = fh_p->GetList();
            if (   list == eDirWaitList
                || list == eNoList) {
                log_DBG_m(dbg_DETAIL, "Active in HSMDB, but not in mig process. Idx = " << idx << endl << actRec);
                fh_p->ToMigCand();
            }
        }
        // GetFH and constructor increase ref automaticaly,
        // to prevent others to dereference FH before is handled in Event method
        fh_p->DecrRef(); 
        g_hsm_fhLock.UnLockByID(actRec.generalInode);
    }
}

Here is the call graph for this function:

void hsm_ActiveFH::Release ( hsm_FileHeader a_fh_p,
fio_Transaction a_trans 
)

Definition at line 169 of file hsm_ActiveFH.cpp.

References dbg_DETAIL, FindNextRec(), hsm_FileHeader::GetActiveIdx(), fio_File::GetFileName(), hsm_FileHeader::GetFName(), log_DBG_m, log_FUNC_m, m_activeFH_x, m_cirFile, m_idx, and fio_CirFileTrans::WriteRec().

Referenced by hsm_FileHeader::Event(), hsm_FileHeader::InitActive(), MoveToEnd(), hsm_FileHeader::RemoveFromActiveList(), and hsm_FileHeader::RemoveFromHSM().

                                                     {
    log_FUNC_m(Release);

    ivd_RecordIDX_t idx = a_fh_p->GetActiveIdx();

    log_DBG_m(dbg_DETAIL, "remove file: " << a_fh_p->GetFName() 
                          << ", from: " << m_cirFile.GetFileName()
                          << ", idx: " << idx);

    hdb_Active_t act; // record with zerroes
    m_cirFile.WriteRec(idx, &act, 1, a_trans);

    cmn_MutexLock l(m_activeFH_x);
    if (m_idx == idx) { // if current record is released, then read next
        FindNextRec();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ivd_RecordIDX_t hsm_ActiveFH::Update ( hsm_FileHeader a_fh_p,
fio_Transaction a_trans 
)

Definition at line 138 of file hsm_ActiveFH.cpp.

References dbg_DETAIL, hdb_Active_t::generalInode, hsm_FileHeader::GetActiveIdx(), hsm_FileHeader::GetChgFlag(), hsm_FileHeader::GetFileID(), fio_File::GetFileName(), hsm_FileHeader::GetFileSize(), hsm_FileHeader::GetFName(), hsm_FileHeader::GetfType(), hsm_FileHeader::GetInode(), hsm_FileHeader::GetNameOwnIdx(), hsm_FileHeader::GetOldNameOwnIdx(), log_DBG_m, log_FUNC_m, m_activeFH, m_activeFH_x, m_cirFile, m_idx, and fio_CirFileTrans::WriteRec().

Referenced by hsm_FileHeader::InitActive(), and hsm_FileHeader::MigrationIsDone().

                                      {
    log_FUNC_m(Update);
    hdb_Active_t act(    a_fh_p->GetNameOwnIdx(),  
                         a_fh_p->GetOldNameOwnIdx(),
                         a_fh_p->GetInode(),
                         a_fh_p->GetChgFlag(),
                         a_fh_p->GetFileID(),
                         a_fh_p->GetfType()
                         );

    log_DBG_m(dbg_DETAIL, act);
    ivd_RecordIDX_t idx = a_fh_p->GetActiveIdx();
    m_cirFile.WriteRec(idx, &act, 1, a_trans);
    log_DBG_m(dbg_DETAIL, "Update file " << a_fh_p->GetFName() 
                          << " size " << a_fh_p->GetFileSize()
                          << " to " << m_cirFile.GetFileName()
                          << " idx " << idx);


    cmn_MutexLock l(m_activeFH_x);
    if (m_activeFH.generalInode == 0) {
        m_activeFH = act; // first record is set immediately
        m_idx = idx;           // and is skipped by FindNexRec
    }        
    return idx;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 57 of file hsm_ActiveFH.h.

Definition at line 64 of file hsm_ActiveFH.h.

Referenced by Append(), FindNextRec(), GetRefRleaseCandRec(), and Update().

Definition at line 66 of file hsm_ActiveFH.h.

Referenced by Append(), FindNextClearCurrRec(), Release(), and Update().

index of first element in active list

Definition at line 63 of file hsm_ActiveFH.h.

Referenced by Append(), FindNextClearCurrRec(), FindNextRec(), Release(), and Update().


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