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.


Detailed Description

Definition at line 39 of file hsm_FHADPRecall.h.


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

Constructor & Destructor Documentation

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

Definition at line 42 of file hsm_FHADPRecall.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, and m_alternateDataPath.

00045         :
00046         m_running(a_running),
00047         m_goDown(false),
00048         m_thread_c(&m_thread_x),
00049         m_alternateDataPath(a_alternateDataPath)
00050 {
00051     // empty
00052     log_FUNC_m(hsm_FHADPRecall);
00053 
00054     log_DBG_m(dbg_LOW, "Create ADP Recall list." << endl <<
00055         "-----------------------------------------------------------------------" << endl <<
00056         "Alt Data Path " << m_alternateDataPath << 
00057         "-----------------------------------------------------------------------");
00058 }
//============================================================================//

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

Definition at line 45 of file hsm_FHADPRecall.h.

00045 {};


Member Function Documentation

bool hsm_FHADPRecall::IsAlternateDataPathSet (  )  [inline]

Definition at line 62 of file hsm_FHADPRecall.h.

References m_alternateDataPath.

Referenced by hsm_FileHeader::EventOffline().

00062 { return !m_alternateDataPath.empty(); };

Here is the caller graph for this function:

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

Reimplemented from hsm_FHlist.

Definition at line 61 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().

00061                                                           {
00062     log_FUNC_m(Append);
00063     a_fh_p->IncrRef();    
00064     cmn_MutexLock l(m_FHlist_x);
00065 
00066     hsm_FH_p_li iter = insert(end(), a_fh_p);
00067     a_fh_p->SetRecallFromADPPos(iter);
00068 
00069     WakeUp();
00070 
00071     return iter;
00072 }

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 75 of file hsm_FHADPRecall.cpp.

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

Referenced by RecallFilesFromList().

00075                                                    { // hsm_FH_p_li &a_pos
00076     log_FUNC_m(Remove);
00077     cmn_MutexLock l(m_FHlist_x);
00078     
00079     a_fh_p->DecrRef();    
00080     erase(a_fh_p->GetRecallFromADPPos());
00081 }

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 98 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().

00098                                   {
00099     log_FUNC_m(Run);
00100     m_running = true;
00101 
00102     log_DBG_m(dbg_DETAIL, "Recall from Alternate Data Path thread is starting up");
00103 
00104     while (!m_goDown) {
00105 
00106         try {
00107             m_thread_x.Lock();
00109             m_thread_c.Wait();
00110             m_thread_x.Unlock();
00111 
00112             if (m_goDown) {
00113                 break;
00114             }
00115 
00116             m_FHlist_x.Lock();
00117             UInt32_t numFile = size();
00118 
00119             if (numFile == 0) {
00120                 m_FHlist_x.Unlock();
00121                 log_DBG_m(dbg_DETAIL, "NO files to Recall from ADP.");
00122                 continue;
00123             }
00124             m_FHlist_x.Unlock();
00125 
00126             RecallFilesFromList();
00127 
00128         }
00129         catch (ivd_Error &ie) {
00130             log_DBG_m(dbg_DETAIL, "RecalFromADPThread return ERROR " << ie);
00131         }
00132         catch (ivd_SysError &ise) {
00133             log_DBG_m(dbg_DETAIL, "RecalFromADPThread WILL GO_DOWN on ERROR " << ise);
00134             break;
00135         }
00136         catch (...) {
00137             log_DBG_m(dbg_DETAIL, "RecalFromADPThread WILL GO_DOWN after thrown ERROR.");
00138             break;
00139         }
00140     } // while (!m_goDown)
00141     log_DBG_m(dbg_DETAIL, "Recall from Alternate Data Path thread IS_DOWN.");
00142     m_running = false;
00143 }

Here is the call graph for this function:

void hsm_FHADPRecall::Shutdown (  ) 

Definition at line 84 of file hsm_FHADPRecall.cpp.

References log_FUNC_m, m_goDown, and WakeUp().

Referenced by hsm_Containers::Stop().

00084                                {
00085     log_FUNC_m(Shutdown);
00086     m_goDown = true;
00087     WakeUp();
00088 }

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_FHADPRecall::WakeUp ( void   ) 

Definition at line 91 of file hsm_FHADPRecall.cpp.

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

Referenced by Append(), and Shutdown().

00091                                  {
00092     log_FUNC_m(WakeUp);
00093     cmn_MutexLock l(m_thread_x);
00094     m_thread_c.Broadcast();
00095 }

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 146 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().

00146                                           {
00147     log_FUNC_m(RecallFilesFromList);
00148 
00149     log_DBG_m(dbg_DETAIL, "Recall from Alternate Data");
00150     m_FHlist_x.Lock();
00151     hsm_FH_p_li iter = begin();
00152     while (  iter  != end()) {
00153         if (m_goDown) {
00154             m_FHlist_x.Unlock();
00155             return;
00156         }
00157 
00158         hsm_FileHeader &fh = (**iter);
00159         if (&fh == NULL) {
00160             log_FUNC_m(MngDirty);
00161             throw ivd_InternalError(ie_NULLPTR, "Recall from ADP list contain NULL pointer.", true);
00162         }
00163 
00164         //  try to lock FH by inode
00165         ivd_GenInode_t inode = fh.GetInode();
00166         if (!g_hsm_fhLock.CanLockByID(inode)) {
00167             SpliceToEndNoLock(iter);
00168             if (size() == 1) {
00169                 ivd_USleep(10000); 
00170             }
00171             continue;  // can't use this FH already locked, so skip it
00172         }
00173         // now FH is locked, so list can be unlock
00174         m_FHlist_x.Unlock();
00175 
00176 
00177         RecallFileFromADP(fh);
00178         Remove(&fh);
00179 
00180         g_hsm_fhLock.UnLockByID(inode);
00181 
00182         m_FHlist_x.Lock();
00183         iter = begin();
00184     }
00185     m_FHlist_x.Unlock();
00186 }

Here is the call graph for this function:

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 189 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().

00189                                                             {
00190     log_FUNC_m(RecallFileFromADP);
00191     cmn_Path filePath(a_fh.MakePath());
00192     cmn_Path sourPath(m_alternateDataPath + filePath);
00193     cmn_Path destPath(g_fs_api_p->GetRootPath() + filePath);
00194 
00195     ivd_GenInode_t inode = a_fh.GetInode();
00196     log_DBG_m(dbg_NORM, "Recall from ADP. INO " << IVD_PRINT_ID_FS(inode) << endl
00197                         << "  from path " << sourPath << endl
00198                         << "         to " << destPath);
00199 
00200     // unlock to prevent main thread to stop when new event for this file ocure
00201     g_hsm_fhLock.UnLockByID(inode);
00202 
00203     string errMsg;
00204 
00205     bool recalled = false;
00206     cmn_File source(sourPath);
00207     ivd_FS_File recallFile(*g_fs_api_p, destPath, inode);
00208         
00209     try {
00210         source.OpenF(fom_OPEN_EXISTING | fom_READ);
00211     }
00212     catch (ivd_SysError &ie) {
00213         ostringstream sstr;
00214         sstr << "Can't open file on ADP. Error: " << ie.GetFriendly();
00215         errMsg = sstr.str();
00216         log_DBG_m (dbg_DETAIL, errMsg);
00217         goto end;
00218     }
00219 
00220     try {
00221         recallFile.Open(ivd_FS_File::e_Recall, destPath);
00222         recallFile.SetStreamHeader(stt_DATA);
00223     }
00224     catch (ivd_SysError &ie) {
00225         ostringstream sstr;
00226         sstr << "Can't open file on HSMFS. Error: " << ie.GetFriendly();
00227         errMsg = sstr.str();
00228         log_DBG_m (dbg_DETAIL, errMsg);
00229         goto end;
00230     }
00231 
00232     try {
00233         
00234         ivd_FileInfo_t sourceFileInfo;
00235         ivd_FileInfo_t recallFileInfo;
00236         source.StatF(sourceFileInfo);
00237         recallFile.StatF(recallFileInfo);
00238         if (sourceFileInfo.size != recallFileInfo.size) {
00239             ostringstream sstr;
00240             sstr << "Source and destination file has different sizes. "
00241                  << " Source file size = " << sourceFileInfo.size
00242                  << " Destination file size = " << recallFileInfo.size << ".";
00243             errMsg = sstr.str();
00244             goto end;
00245         }
00246         
00247         int read = source.ReadF(m_buf, recallBufSize_d);
00248         
00249         log_DBG_m(dbg_DETAIL, "Recall from ADP. ReadSize " << read
00250             << " SFCookie " << c_ivd_StubFileCookie
00251             << " buf value " << string(m_buf, c_ivd_StubFileCookieSize));
00252 
00253         if (  (read >= c_ivd_StubFileCookieSize)
00254             && (memcmp(m_buf, c_ivd_StubFileCookie, c_ivd_StubFileCookieSize) == 0) ) {
00255             errMsg = "Got stub file.";
00256             log_DBG_m (dbg_DETAIL, errMsg);
00257             goto end;
00258         }
00259 
00260         int written;
00261         while (read > 0) {
00262             written = recallFile.WriteStream(m_buf, read);
00263             if (written != read) {
00264                 errMsg = "Can't write as many data as read. Is HSMFS full?";
00265                 log_DBG_m (dbg_DETAIL, errMsg);
00266                 goto end;
00267             }
00268             read    = source.ReadF(m_buf, recallBufSize_d);
00269         }
00270         recallFile.Close();
00271     }
00272     catch (ivd_SysError &ie) {
00273         ostringstream sstr;
00274         sstr << "Can't recall from ADS. Error: " << ie.GetFriendly();
00275         errMsg = sstr.str();
00276         log_DBG_m (dbg_DETAIL, errMsg);
00277         goto end;
00278     }
00279     recalled = true;
00280 end:
00281     g_hsm_fhLock.LockByID(inode);
00282     if (recalled) {
00283 //        a_fh.SetOffline(false);
00284         recallFile.SetDataOnline();
00285         a_fh.SendReply(ivd_FS_OK_Reply);            
00286         try {
00287             recallFile.TriggerEvent(ivd_FS_File::e_MigrateEvt);
00288         }
00289         catch (...) {
00290             log_DBG_m(dbg_NORM, "trig migrate failed: " << 
00291                         destPath);
00292         }
00293     }
00294     else {
00295         a_fh.SendReply(ivd_FS_ERR_Reply);    
00296 
00297         ostringstream sstr;
00298         sstr << "Recall from ADP '" << m_alternateDataPath
00299             << "' failed. File: '" << filePath << "'. "
00300              << errMsg;
00301         log_WriteEvent(evt_ERROR, sstr.str());
00302         // truncate wont work and it is not so important.
00303     }
00304 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool& hsm_FHADPRecall::m_running [private]

outside variable that set when thread is down

Definition at line 45 of file hsm_FHADPRecall.h.

Referenced by Run().

bool hsm_FHADPRecall::m_goDown [private]

Definition at line 50 of file hsm_FHADPRecall.h.

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

Definition at line 52 of file hsm_FHADPRecall.h.

Referenced by Run(), and WakeUp().

Definition at line 53 of file hsm_FHADPRecall.h.

Referenced by Run(), and WakeUp().

access filea via mountpoint.

Definition at line 56 of file hsm_FHADPRecall.h.

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

char hsm_FHADPRecall::m_buf[recallBufSize_d] [private]

Definition at line 58 of file hsm_FHADPRecall.h.

Referenced by RecallFileFromADP().

Reimplemented from hsm_FHlist.

Definition at line 60 of file hsm_FHADPRecall.h.


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

Generated on Mon Feb 27 19:25:55 2012 for OPENARCHIVE by  doxygen 1.5.6