Public Member Functions | Private Member Functions | Private Attributes

hsm_FHADPRecall Class Reference
[G_new_group]

#include <hsm_FHADPRecall.h>

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

List of all members.

Public Member Functions

 hsm_FHADPRecall (bool &a_running, const cmn_Path &a_alternateDataPath)
virtual ~hsm_FHADPRecall (void)
bool IsAlternateDataPathSet ()
virtual hsm_FH_p_li Append (hsm_FileHeader *a_fh_p)
void Remove (hsm_FileHeader *a_fh_p)
virtual void Run (void *arg)
 wait until a broadcast event occure Append method send a broadcast after add new file on list.
void Shutdown ()
void WakeUp (void)

Private Member Functions

void RecallFilesFromList ()
 recall files one by one
void RecallFileFromADP (hsm_FileHeader &a_fh)
 when file is locked and list unlocked then a recall is performed.

Private Attributes

bool & m_running
 outside variable that set when thread is down
bool m_goDown
cmn_Mutex m_thread_x
cmn_Condition m_thread_c
const cmn_Path m_alternateDataPath
 access filea via mountpoint.
char m_buf [recallBufSize_d]
 log_CLASSID_m

Detailed Description

Definition at line 53 of file hsm_FHADPRecall.h.


Constructor & Destructor Documentation

hsm_FHADPRecall::hsm_FHADPRecall ( bool &  a_running,
const cmn_Path a_alternateDataPath 
)

Definition at line 56 of file hsm_FHADPRecall.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, and m_alternateDataPath.

        :
        m_running(a_running),
        m_goDown(false),
        m_thread_c(&m_thread_x),
        m_alternateDataPath(a_alternateDataPath)
{
    // empty
    log_FUNC_m(hsm_FHADPRecall);

    log_DBG_m(dbg_LOW, "Create ADP Recall list." << endl <<
        "-----------------------------------------------------------------------" << endl <<
        "Alt Data Path " << m_alternateDataPath << 
        "-----------------------------------------------------------------------");
}

virtual hsm_FHADPRecall::~hsm_FHADPRecall ( void   )  [inline, virtual]

Definition at line 59 of file hsm_FHADPRecall.h.

{};


Member Function Documentation

hsm_FH_p_li hsm_FHADPRecall::Append ( hsm_FileHeader a_fh_p  )  [virtual]

Definition at line 75 of file hsm_FHADPRecall.cpp.

References hsm_FileHeader::IncrRef(), log_FUNC_m, hsm_FHlist::m_FHlist_x, hsm_ListPos::SetRecallFromADPPos(), and WakeUp().

Referenced by hsm_FileHeader::EventOffline().

                                                          {
    log_FUNC_m(Append);
    a_fh_p->IncrRef();    
    cmn_MutexLock l(m_FHlist_x);

    hsm_FH_p_li iter = insert(end(), a_fh_p);
    a_fh_p->SetRecallFromADPPos(iter);

    WakeUp();

    return iter;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool hsm_FHADPRecall::IsAlternateDataPathSet (  )  [inline]

Definition at line 76 of file hsm_FHADPRecall.h.

References m_alternateDataPath.

Referenced by hsm_FileHeader::EventOffline().

{ return !m_alternateDataPath.empty(); };

Here is the caller graph for this function:

void hsm_FHADPRecall::RecallFileFromADP ( hsm_FileHeader a_fh  )  [private]

when file is locked and list unlocked then a recall is performed.

Definition at line 203 of file hsm_FHADPRecall.cpp.

References ivd_FS_File::Close(), dbg_DETAIL, dbg_NORM, ivd_FS_File::e_MigrateEvt, ivd_FS_File::e_Recall, evt_ERROR, fom_OPEN_EXISTING, fom_READ, g_fs_api_p, g_hsm_fhLock, ivd_BaseException::GetFriendly(), hsm_FileHeader::GetInode(), ivd_FileSystemAPI::GetRootPath(), ivd_FS_ERR_Reply, ivd_FS_OK_Reply, IVD_PRINT_ID_FS, log_DBG_m, log_FUNC_m, log_WriteEvent(), m_alternateDataPath, m_buf, hsm_FileHeader::MakePath(), ivd_FS_File::Open(), cmn_File::OpenF(), cmn_File::ReadF(), recallBufSize_d, hsm_FileHeader::SendReply(), ivd_FS_File::SetDataOnline(), ivd_FS_File::SetStreamHeader(), ivd_FS_File::StatF(), cmn_File::StatF(), stt_DATA, ivd_FS_File::TriggerEvent(), and ivd_FS_File::WriteStream().

Referenced by RecallFilesFromList().

                                                            {
    log_FUNC_m(RecallFileFromADP);
    cmn_Path filePath(a_fh.MakePath());
    cmn_Path sourPath(m_alternateDataPath + filePath);
    cmn_Path destPath(g_fs_api_p->GetRootPath() + filePath);

    ivd_GenInode_t inode = a_fh.GetInode();
    log_DBG_m(dbg_NORM, "Recall from ADP. INO " << IVD_PRINT_ID_FS(inode) << endl
                        << "  from path " << sourPath << endl
                        << "         to " << destPath);

    // unlock to prevent main thread to stop when new event for this file ocure
    g_hsm_fhLock.UnLockByID(inode);

    string errMsg;

    bool recalled = false;
    cmn_File source(sourPath);
    ivd_FS_File recallFile(*g_fs_api_p, destPath, inode);
        
    try {
        source.OpenF(fom_OPEN_EXISTING | fom_READ);
    }
    catch (ivd_SysError &ie) {
        ostringstream sstr;
        sstr << "Can't open file on ADP. Error: " << ie.GetFriendly();
        errMsg = sstr.str();
        log_DBG_m (dbg_DETAIL, errMsg);
        goto end;
    }

    try {
        recallFile.Open(ivd_FS_File::e_Recall, destPath);
        recallFile.SetStreamHeader(stt_DATA);
    }
    catch (ivd_SysError &ie) {
        ostringstream sstr;
        sstr << "Can't open file on HSMFS. Error: " << ie.GetFriendly();
        errMsg = sstr.str();
        log_DBG_m (dbg_DETAIL, errMsg);
        goto end;
    }

    try {
        
        ivd_FileInfo_t sourceFileInfo;
        ivd_FileInfo_t recallFileInfo;
        source.StatF(sourceFileInfo);
        recallFile.StatF(recallFileInfo);
        if (sourceFileInfo.size != recallFileInfo.size) {
            ostringstream sstr;
            sstr << "Source and destination file has different sizes. "
                 << " Source file size = " << sourceFileInfo.size
                 << " Destination file size = " << recallFileInfo.size << ".";
            errMsg = sstr.str();
            goto end;
        }
        
        int read = source.ReadF(m_buf, recallBufSize_d);
        
        log_DBG_m(dbg_DETAIL, "Recall from ADP. ReadSize " << read
            << " SFCookie " << c_ivd_StubFileCookie
            << " buf value " << string(m_buf, c_ivd_StubFileCookieSize));

        if (  (read >= c_ivd_StubFileCookieSize)
            && (memcmp(m_buf, c_ivd_StubFileCookie, c_ivd_StubFileCookieSize) == 0) ) {
            errMsg = "Got stub file.";
            log_DBG_m (dbg_DETAIL, errMsg);
            goto end;
        }

        int written;
        while (read > 0) {
            written = recallFile.WriteStream(m_buf, read);
            if (written != read) {
                errMsg = "Can't write as many data as read. Is HSMFS full?";
                log_DBG_m (dbg_DETAIL, errMsg);
                goto end;
            }
            read    = source.ReadF(m_buf, recallBufSize_d);
        }
        recallFile.Close();
    }
    catch (ivd_SysError &ie) {
        ostringstream sstr;
        sstr << "Can't recall from ADS. Error: " << ie.GetFriendly();
        errMsg = sstr.str();
        log_DBG_m (dbg_DETAIL, errMsg);
        goto end;
    }
    recalled = true;
end:
    g_hsm_fhLock.LockByID(inode);
    if (recalled) {
//        a_fh.SetOffline(false);
        recallFile.SetDataOnline();
        a_fh.SendReply(ivd_FS_OK_Reply);            
        try {
            recallFile.TriggerEvent(ivd_FS_File::e_MigrateEvt);
        }
        catch (...) {
            log_DBG_m(dbg_NORM, "trig migrate failed: " << 
                        destPath);
        }
    }
    else {
        a_fh.SendReply(ivd_FS_ERR_Reply);    

        ostringstream sstr;
        sstr << "Recall from ADP '" << m_alternateDataPath
            << "' failed. File: '" << filePath << "'. "
             << errMsg;
        log_WriteEvent(evt_ERROR, sstr.str());
        // truncate wont work and it is not so important.
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_FHADPRecall::RecallFilesFromList (  )  [private]

recall files one by one

Definition at line 160 of file hsm_FHADPRecall.cpp.

References dbg_DETAIL, g_hsm_fhLock, hsm_FileHeader::GetInode(), ie_NULLPTR, ivd_USleep, cmn_Mutex::Lock(), log_DBG_m, log_FUNC_m, hsm_FHlist::m_FHlist_x, m_goDown, NULL, RecallFileFromADP(), Remove(), size, hsm_FHlist::SpliceToEndNoLock(), and cmn_Mutex::Unlock().

Referenced by Run().

                                          {
    log_FUNC_m(RecallFilesFromList);

    log_DBG_m(dbg_DETAIL, "Recall from Alternate Data");
    m_FHlist_x.Lock();
    hsm_FH_p_li iter = begin();
    while (  iter  != end()) {
        if (m_goDown) {
            m_FHlist_x.Unlock();
            return;
        }

        hsm_FileHeader &fh = (**iter);
        if (&fh == NULL) {
            log_FUNC_m(MngDirty);
            throw ivd_InternalError(ie_NULLPTR, "Recall from ADP list contain NULL pointer.", true);
        }

        //  try to lock FH by inode
        ivd_GenInode_t inode = fh.GetInode();
        if (!g_hsm_fhLock.CanLockByID(inode)) {
            SpliceToEndNoLock(iter);
            if (size() == 1) {
                ivd_USleep(10000); 
            }
            continue;  // can't use this FH already locked, so skip it
        }
        // now FH is locked, so list can be unlock
        m_FHlist_x.Unlock();


        RecallFileFromADP(fh);
        Remove(&fh);

        g_hsm_fhLock.UnLockByID(inode);

        m_FHlist_x.Lock();
        iter = begin();
    }
    m_FHlist_x.Unlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_FHADPRecall::Remove ( hsm_FileHeader a_fh_p  ) 

Definition at line 89 of file hsm_FHADPRecall.cpp.

References hsm_FileHeader::DecrRef(), hsm_ListPos::GetRecallFromADPPos(), log_FUNC_m, and hsm_FHlist::m_FHlist_x.

Referenced by RecallFilesFromList().

                                                   { // hsm_FH_p_li &a_pos
    log_FUNC_m(Remove);
    cmn_MutexLock l(m_FHlist_x);
    
    a_fh_p->DecrRef();    
    erase(a_fh_p->GetRecallFromADPPos());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_FHADPRecall::Run ( void *  arg  )  [virtual]

wait until a broadcast event occure Append method send a broadcast after add new file on list.

Wait to broadcast

Reimplemented from cmn_Thread.

Definition at line 112 of file hsm_FHADPRecall.cpp.

References dbg_DETAIL, cmn_Mutex::Lock(), log_DBG_m, log_FUNC_m, hsm_FHlist::m_FHlist_x, m_goDown, m_running, m_thread_c, m_thread_x, RecallFilesFromList(), size, cmn_Mutex::Unlock(), and cmn_Condition::Wait().

                                  {
    log_FUNC_m(Run);
    m_running = true;

    log_DBG_m(dbg_DETAIL, "Recall from Alternate Data Path thread is starting up");

    while (!m_goDown) {

        try {
            m_thread_x.Lock();
            m_thread_c.Wait();
            m_thread_x.Unlock();

            if (m_goDown) {
                break;
            }

            m_FHlist_x.Lock();
            UInt32_t numFile = size();

            if (numFile == 0) {
                m_FHlist_x.Unlock();
                log_DBG_m(dbg_DETAIL, "NO files to Recall from ADP.");
                continue;
            }
            m_FHlist_x.Unlock();

            RecallFilesFromList();

        }
        catch (ivd_Error &ie) {
            log_DBG_m(dbg_DETAIL, "RecalFromADPThread return ERROR " << ie);
        }
        catch (ivd_SysError &ise) {
            log_DBG_m(dbg_DETAIL, "RecalFromADPThread WILL GO_DOWN on ERROR " << ise);
            break;
        }
        catch (...) {
            log_DBG_m(dbg_DETAIL, "RecalFromADPThread WILL GO_DOWN after thrown ERROR.");
            break;
        }
    } // while (!m_goDown)
    log_DBG_m(dbg_DETAIL, "Recall from Alternate Data Path thread IS_DOWN.");
    m_running = false;
}

Here is the call graph for this function:

void hsm_FHADPRecall::Shutdown (  ) 

Definition at line 98 of file hsm_FHADPRecall.cpp.

References log_FUNC_m, m_goDown, and WakeUp().

Referenced by hsm_Containers::Stop().

                               {
    log_FUNC_m(Shutdown);
    m_goDown = true;
    WakeUp();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_FHADPRecall::WakeUp ( void   ) 

Definition at line 105 of file hsm_FHADPRecall.cpp.

References cmn_Condition::Broadcast(), log_FUNC_m, m_thread_c, and m_thread_x.

Referenced by Append(), and Shutdown().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from cmn_Thread.

Definition at line 74 of file hsm_FHADPRecall.h.

access filea via mountpoint.

Definition at line 70 of file hsm_FHADPRecall.h.

Referenced by hsm_FHADPRecall(), IsAlternateDataPathSet(), and RecallFileFromADP().

char hsm_FHADPRecall::m_buf[recallBufSize_d] [private]

Definition at line 72 of file hsm_FHADPRecall.h.

Referenced by RecallFileFromADP().

bool hsm_FHADPRecall::m_goDown [private]

Definition at line 64 of file hsm_FHADPRecall.h.

Referenced by RecallFilesFromList(), Run(), and Shutdown().

bool& hsm_FHADPRecall::m_running [private]

outside variable that set when thread is down

Definition at line 59 of file hsm_FHADPRecall.h.

Referenced by Run().

Definition at line 67 of file hsm_FHADPRecall.h.

Referenced by Run(), and WakeUp().

Definition at line 66 of file hsm_FHADPRecall.h.

Referenced by Run(), and WakeUp().


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