#include <treewalk.h>


Definition at line 109 of file treewalk.h.
Public Member Functions | |
| TreeWalk (const string &a_strPartName, ui_MsgWriter &a_msgWrite, Int32_t a_numFilesPerBatch, Int32_t a_sysLoadPct, bool &a_abort) | |
| virtual | ~TreeWalk () |
| void | Report () |
| TreeWalk (const cmn_Path &a_path) | |
| virtual | ~TreeWalk () |
| bool | IsIgnorable (ivd_FileType_e a_type, const string &a_name) |
| void | Walk () |
Public Attributes | |
| log_CLASSID_m | |
Protected Member Functions | |
| void | create_subdirs (UInt32_t beg, UInt32_t end) |
| virtual void | PreprocessDir (const cmn_Path &a_dir, UInt32_t a_depth) |
| virtual void | ProcessEntry (const cmn_Path &a_dir, const string &a_name, ivd_FileType_e a_type) |
| virtual bool | HandleError (const cmn_Path &a_dir, const ivd_SysError &a_error) |
Private Types | |
| typedef vector< DirectoryEntry > | DirectoryVec_t |
Private Member Functions | |
| virtual void | CheckDir (bool a_mountpoint, const cmn_Path &a_dirPath, ivd_GenInode_t a_fileInode) |
| When check dir is called then process current dir is checked directory. | |
| void | GenerateDirTree () |
Private Attributes | |
| const string | m_strPartName |
| ui_MsgWriter & | m_msgWrite |
| cmn_Time | m_startTime |
| Int32_t | m_sysLoadPct |
| Check ivdfs with FSC, prepare package every m_numFilesPerBatch number of files read. | |
| UInt64_t | m_simLinkCounter |
| UInt64_t | m_filesCounter |
| UInt64_t | m_missingCount |
| UInt64_t | m_ownerMismatchCount |
| UInt64_t | m_suspectCount |
| UInt64_t | m_prolongedCount |
| UInt64_t | m_notRelCandidate |
| UInt64_t | m_missingCopyCount |
| FileInfoCache | m_fic |
| DirectoryVec_t | m_dirStack |
Classes | |
| class | DirectoryEntry |
typedef vector<DirectoryEntry> TreeWalk::DirectoryVec_t [private] |
Definition at line 56 of file TreeWalk.h.
| TreeWalk::TreeWalk | ( | const string & | a_strPartName, | |
| ui_MsgWriter & | a_msgWrite, | |||
| Int32_t | a_numFilesPerBatch, | |||
| Int32_t | a_sysLoadPct, | |||
| bool & | a_abort | |||
| ) |
Definition at line 156 of file treewalk.cpp.
References dbg_DETAIL, ui_MsgWriter::DisplayMessage(), cmn_TreeWalk::GetStackSize(), log_DBG_m, log_FUNC_A_m, log_WriteEvent(), m_msgWrite, m_startTime, m_strPartName, and cmn_Time::Refresh().
00161 : 00162 cmn_TreeWalk(g_cmn.dirs.tmp + ( a_strPartName + "_hsmfs-fsc_stack"), a_abort), 00163 m_strPartName(a_strPartName), 00164 m_msgWrite(a_msgWrite), 00165 m_sysLoadPct(a_sysLoadPct), 00166 m_simLinkCounter(0), 00167 m_filesCounter(0), 00168 m_missingCount(0), 00169 m_ownerMismatchCount(0), 00170 m_suspectCount(0), 00171 m_prolongedCount(0), 00172 m_notRelCandidate(0), 00173 m_missingCopyCount(0), 00174 m_fic(a_msgWrite, a_numFilesPerBatch, a_sysLoadPct, m_missingCount, m_missingCopyCount, m_ownerMismatchCount) 00175 { 00176 log_FUNC_A_m(TreeWalk, "partName: " << a_strPartName); 00177 00178 log_DBG_m(dbg_DETAIL, 00179 "Task is allowed to occupy " << a_sysLoadPct << "% of system." 00180 << " Package holds " << a_numFilesPerBatch << " entries."); 00181 00182 if (GetStackSize() == 0) { 00183 ostringstream sstrs; 00184 sstrs << "Started FSC vs. HSMFS check. Partition " << m_strPartName; 00185 m_msgWrite.DisplayMessage(sstrs.str()); 00186 log_WriteEvent(sstrs.str()); 00187 } 00188 else { 00189 ostringstream sstrs; 00190 sstrs << "Started FSC vs. HSMFS check (continue from previous run). Partition " << m_strPartName; 00191 m_msgWrite.DisplayMessage(sstrs.str()); 00192 log_WriteEvent(sstrs.str()); 00193 } 00194 00195 m_startTime.Refresh(); 00196 } //============================================================================//

| TreeWalk::~TreeWalk | ( | ) | [virtual] |
Definition at line 200 of file treewalk.cpp.
References FileInfoCache::CheckFiles(), dbg_DETAIL, log_DBG_m, log_FUNC_m, m_fic, and Report().
00200 { 00201 log_FUNC_m(~TreeWalk); 00202 log_DBG_m(dbg_DETAIL, "Check remaining files."); 00203 m_fic.CheckFiles(); 00204 Report(); 00205 }

| TreeWalk::TreeWalk | ( | const cmn_Path & | a_path | ) |
Definition at line 50 of file TreeWalk.cpp.
References log_FUNC_A_m, and m_dirStack.
00050 { 00051 00052 log_FUNC_A_m(TreeWalk, "a_path=" << a_path); 00053 00054 m_dirStack.push_back(DirectoryEntry(a_path, 1)); 00055 }
| virtual TreeWalk::~TreeWalk | ( | ) | [inline, virtual] |
| void TreeWalk::Report | ( | ) |
Definition at line 394 of file treewalk.cpp.
References dbg_DETAIL, ui_MsgWriter::DisplayMessage(), log_DBG_m, log_FUNC_m, log_WriteEvent(), cmn_TreeWalk::m_abort, m_filesCounter, m_missingCopyCount, m_missingCount, m_msgWrite, m_notRelCandidate, m_ownerMismatchCount, m_prolongedCount, m_simLinkCounter, and m_suspectCount.
Referenced by ~TreeWalk().
00394 { 00395 log_FUNC_m(Report); 00396 ostringstream sstrs; 00397 sstrs << (m_abort ? "Aborted" : "Finished" ) 00398 << " (symlink: " << m_simLinkCounter 00399 << ", checked: " << m_filesCounter 00400 << ", missing: " << m_missingCount 00401 << ", owner mismatch: " << m_ownerMismatchCount 00402 << ", num. of copies mismatch: " << m_missingCopyCount 00403 << ", suspicious: " << m_suspectCount 00404 << ", partially recalled: " << m_prolongedCount 00405 << ", not release candidate: " << m_notRelCandidate 00406 << ")." << endl; 00407 log_DBG_m(dbg_DETAIL, sstrs.str()); 00408 log_WriteEvent(sstrs.str()); 00409 m_msgWrite.DisplayMessage(sstrs.str()); 00410 }


| void TreeWalk::CheckDir | ( | bool | a_mountpoint, | |
| const cmn_Path & | a_dirPath, | |||
| ivd_GenInode_t | a_fileInode | |||
| ) | [private, virtual] |
When check dir is called then process current dir is checked directory.
Implements cmn_TreeWalk.
Definition at line 207 of file treewalk.cpp.
References FileInfoCache::AddFile(), FileInfoCache::CheckFiles(), dbg_DETAIL, dbg_LOW, dbg_NORM, hsm_FileHeader::DecrRef(), ui_MsgWriter::DisplayMessage(), cmn_TreeWalk::DoWalk(), ivd_FS_File::e_Cache, g_File2hdbID_p, g_fs_api_p, g_hsm_FHCache_p, hsm_FHcache::GetFH(), cmn_TreeWalk::GetLastVector(), cmn_Time::GetTimeInMicroSec(), ie_ABORT, ift_DIR, ift_SYMLINK, ivd_Error, IVD_PRINT_ID_FS, ivd_USleep, log_DBG_m, log_FUNC_m, cmn_TreeWalk::m_abort, ivd_FS_FileProperty_t::m_dirtyFlag, m_fic, ivd_FS_FileProperty_t::m_fileID, m_filesCounter, ivd_FS_FileProperty_t::m_fileSize, fname_inode_t::m_fileType, ivd_FS_FileProperty_t::m_Inode, fname_inode_t::m_iNode, m_msgWrite, fname_inode_t::m_name, m_notRelCandidate, ivd_FS_FileProperty_t::m_offlineFlag, m_prolongedCount, m_simLinkCounter, m_startTime, m_suspectCount, m_sysLoadPct, ivd_FS_FileProperty_t::m_type, NULL, fio_RelFile::ReadRec(), cmn_Time::Refresh(), cmn_TreeWalk::SaveStack(), and cmn_Time::Time2hmsm().
00209 { 00210 log_FUNC_m(CheckDir); 00211 00212 if (m_abort) { 00213 m_fic.CheckFiles(); 00214 SaveStack(); 00215 throw ivd_Error(ie_ABORT, " FSC Check"); 00216 } 00217 00218 log_DBG_m(dbg_DETAIL, "Check in directory " << a_dirPath << endl << 00219 "a_fileInode" << a_fileInode); 00220 00221 ivd_FileID_t ownerFID = 0; 00222 00223 log_DBG_m(dbg_LOW, "*** @owner: " << &(ownerFID) ); 00224 00225 // if not mountpoint (inode == 0), get FileID of parent (owner) 00226 if ( !a_mountpoint) { 00227 auto_ptr<ivd_FS_File> owner_ap; 00228 owner_ap.reset(new ivd_FS_File(*g_fs_api_p, a_dirPath )); 00229 try { 00230 //HPUX - The file needs to be opened ( to be in the kernel cache ) 00231 owner_ap->Open(ivd_FS_File::e_Cache, a_dirPath); 00232 ivd_FS_FileProperty_t ownerProp; 00233 owner_ap->GetProperties(ownerProp); 00234 ownerFID = ownerProp.m_fileID; 00235 log_DBG_m(dbg_LOW, "ownerFID:" << ownerFID); 00236 } 00237 catch (ivd_SysError &se) { // can't get ownerInfo, end of dir scan 00238 log_DBG_m(dbg_LOW, "Syserror:" << se); 00239 return; 00240 } 00241 } 00242 00243 while (!GetLastVector().empty()) { 00244 00245 fname_inode_t &f = GetLastVector().back(); 00246 00247 log_DBG_m(dbg_NORM, "File to check: " << f.m_name 00248 << ", m_iNode:" << f.m_iNode 00249 << ", m_fileType: "<< f.m_fileType); 00250 00251 if (f.m_fileType == ift_SYMLINK) { // sym link are not migratted so skip it. 00252 log_DBG_m(dbg_DETAIL, "SymLink, skip it. " << f.m_name); 00253 GetLastVector().pop_back(); 00254 ++m_simLinkCounter; 00255 continue; 00256 } 00257 00258 ivd_FS_FileProperty_t fileProp; 00259 00260 { // Start of separate block to decrease stack usage 00261 auto_ptr<ivd_FS_File> file_ap; 00262 file_ap.reset(new ivd_FS_File(*g_fs_api_p, f.m_iNode)); 00263 00264 try { 00265 //The file needs to be opened ( to be in the kernel cache ) 00266 file_ap->Open(ivd_FS_File::e_Cache,( a_dirPath + f.m_name)); 00267 file_ap->GetProperties(fileProp); 00268 file_ap->Close(); 00269 } 00270 catch (ivd_SysError ) { // can't get fileInfo, skip it 00271 GetLastVector().pop_back(); 00272 continue; 00273 } 00274 00275 m_filesCounter++; 00276 00277 // Check if file is active in HSM, otherwise check it in FSC 00278 hsm_FileHeader *hsmFH = g_hsm_FHCache_p->GetFH(fileProp.m_Inode); 00279 00280 log_DBG_m(dbg_DETAIL, "file info: inode " 00281 << IVD_PRINT_ID_FS(fileProp.m_Inode) 00282 << " fileId " << fileProp.m_fileID 00283 << " fileProp.m_type: " << fileProp.m_type 00284 << " fileType from dirlist " << f.m_fileType); 00285 00286 if (hsmFH == NULL) { 00287 string fullName; 00288 fullName = a_dirPath + f.m_name; 00289 //m_msgWrite.DisplayMessage("checking: "+fullName); 00290 00291 if ( fileProp.m_dirtyFlag 00292 || (fileProp.m_fileID == 0)) { // when EA are not set yet. 00293 ostringstream sstr; 00294 sstr << fileProp.m_fileID << " 0 " // migID=0 00295 << fullName << endl; 00296 if (f.m_fileType == ift_DIR) { 00297 sstr << " Directory is not migrated. (It is not in HSM lists. Maybe it is in event queue.)"; 00298 } 00299 else { 00300 sstr << " File is dirty. (It is not in HSM lists. Maybe it is in event queue.)"; 00301 } 00302 m_msgWrite.DisplayMessage(sstr.str()); 00303 m_suspectCount++; 00304 } 00305 else { 00306 // file_ap->SetFullPath(fullName); 00307 if ( fileProp.m_type == 1 // it is file 00308 && file_ap->IsOfflineProlonged()) { 00309 ostringstream sstr; 00310 sstr << fileProp.m_fileID << " 0 " // migID=0 00311 << fullName << endl 00312 << "Offline file not fully released/recalled."; 00313 m_msgWrite.DisplayMessage(sstr.str()); 00314 m_prolongedCount++; 00315 } 00316 else if ( fileProp.m_type == 1 // it is file 00317 && fileProp.m_fileID > 0) { 00318 00319 log_DBG_m(dbg_DETAIL, "Check if file is online and size > 0. " 00320 << ", dirty: " << boolalpha << fileProp.m_dirtyFlag 00321 << ", offline: " << boolalpha << fileProp.m_offlineFlag 00322 << ", size: " << fileProp.m_fileSize); 00323 if ( !fileProp.m_dirtyFlag 00324 && !fileProp.m_offlineFlag // file is online 00325 && fileProp.m_fileSize > 0) { 00326 00327 auto_ptr<hdb_file2hdbID_t> file2hdbID_ap; 00328 file2hdbID_ap.reset(new hdb_file2hdbID_t()); 00329 00330 g_File2hdbID_p->ReadRec(fileProp.m_fileID, file2hdbID_ap.get() ); 00331 00332 log_DBG_m(dbg_DETAIL, "Check if file is on release list. " 00333 << *file2hdbID_ap); 00334 if (file2hdbID_ap->relCandIdx == 0) { // not on release candidte list 00335 ostringstream sstr; 00336 sstr << fileProp.m_fileID << " 0 " // migID=0 00337 << fullName << endl 00338 << "Online file not on release candidate list."; 00339 m_msgWrite.DisplayMessage(sstr.str()); 00340 m_notRelCandidate++; 00341 } 00342 } 00343 } 00344 00345 auto_ptr<FileInfo> fileInfo_ap; 00346 fileInfo_ap.reset(new FileInfo(a_dirPath, "", 0, 0, ownerFID)); 00347 00348 fileInfo_ap->m_name = f.m_name; 00349 fileInfo_ap->m_size = fileProp.m_fileSize; 00350 fileInfo_ap->m_fileID = fileProp.m_fileID; 00351 // TODO get Stat of file 00352 if (m_fic.AddFile(*fileInfo_ap)) { 00353 SaveStack(); 00354 cmn_Time now; 00355 // log_DBG_m(dbg_DETAIL, "Current time " << now.Time2YMDhmsm() ); 00356 // log_DBG_m(dbg_DETAIL, "Start time " << m_startTime.Time2YMDhmsm() ); 00357 now -= m_startTime; 00358 log_DBG_m(dbg_DETAIL, "To check last package of entries take " << now.Time2hmsm()); 00359 if (m_sysLoadPct > 0 && m_sysLoadPct < 100) { 00360 UInt64_t microSec = now.GetTimeInMicroSec(); 00361 if (microSec > 600000000) { // do not wait more than 10min 00362 microSec = 600000000; 00363 } 00364 log_DBG_m(dbg_DETAIL, "Wait for " << microSec << " micro sec to continue."); 00365 ivd_USleep(microSec / m_sysLoadPct * 100 - microSec); 00366 } 00367 m_startTime.Refresh(); 00368 } 00369 } 00370 } 00371 else { // dereference, cause cache Increment it 00372 log_DBG_m(dbg_DETAIL, "File found in HSM cache " << a_dirPath + f.m_name); 00373 hsmFH->DecrRef(); 00374 } 00375 } // End of block to decrease stack usage 00376 00377 if (f.m_fileType == ift_DIR) { 00378 log_DBG_m(dbg_DETAIL, "file is a directory. Call DoWalk():" << 00379 a_dirPath + f.m_name << ", inode: " << IVD_PRINT_ID_FS(fileProp.m_Inode)); 00380 00381 if (!DoWalk(a_dirPath + f.m_name, fileProp.m_Inode, false)) { 00382 // DoWalk was unable to cnage to this directory 00383 // so skip all other entries. 00384 // !!!! Why skip other entries? !!!! 00385 return; 00386 }; 00387 } 00388 GetLastVector().pop_back(); 00389 } 00390 }

| bool TreeWalk::IsIgnorable | ( | ivd_FileType_e | a_type, | |
| const string & | a_name | |||
| ) |
Definition at line 58 of file TreeWalk.cpp.
References ift_DIR.
Referenced by GenerateDirTree(), and Walk().
00058 { 00059 00060 if (a_type == ift_DIR && (a_name == "." || a_name == "..")) { 00061 return true; 00062 } 00063 00064 return false; 00065 }

| void TreeWalk::Walk | ( | ) |
Definition at line 121 of file TreeWalk.cpp.
References dbg_LOW, GenerateDirTree(), ivd_BaseException::GetFriendly(), cmn_FastDirLst::GetNextName(), HandleError(), ift_DIR, IsIgnorable(), log_DBG_m, log_FUNC_m, m_dirStack, TreeWalk::DirectoryEntry::m_path, and ProcessEntry().
Referenced by _tmain().
00121 { 00122 00123 log_FUNC_m(Walk); 00124 00125 DirectoryEntry dir; 00126 string fName; 00127 ivd_GenInode_t inodeInfo; 00128 ivd_FileType_e fType; 00129 00130 /* First let's get the directories */ 00131 GenerateDirTree(); 00132 00133 /* Now it's all about looping the dirs and list their content */ 00134 while (m_dirStack.empty() != true) { 00135 00136 dir = m_dirStack.back(); 00137 m_dirStack.pop_back(); 00138 cmn_FastDirLst dirDes(dir.m_path); 00139 00140 while (true) { 00141 try { 00142 fName = dirDes.GetNextName(inodeInfo, fType); 00143 } 00144 catch (const ivd_SysError &a_error) { 00145 00146 log_DBG_m(dbg_LOW, 00147 "Can't read entry in directory " << dir.m_path 00148 << ". Error: " << a_error.GetFriendly()); 00149 00150 if (HandleError(dir.m_path, a_error) != true) { 00151 throw; 00152 } 00153 } 00154 00155 if (fName == "") { 00156 break; 00157 } 00158 00159 if (! IsIgnorable(fType,fName) ) { 00160 ProcessEntry(dir.m_path, fName, fType); 00161 } 00162 } 00163 /* 00164 We've just finished supplying ProcessEntry() with files, 00165 now we pass the directory in which the files resided, so in case 00166 ProcessEntry unlinked the files, the dir is now empty 00167 */ 00168 ProcessEntry(dir.m_path, "", ift_DIR); 00169 } 00170 }


| virtual void TreeWalk::PreprocessDir | ( | const cmn_Path & | a_dir, | |
| UInt32_t | a_depth | |||
| ) | [inline, protected, virtual] |
Reimplemented in CreateTree.
Definition at line 39 of file TreeWalk.h.
Referenced by GenerateDirTree().

| virtual void TreeWalk::ProcessEntry | ( | const cmn_Path & | a_dir, | |
| const string & | a_name, | |||
| ivd_FileType_e | a_type | |||
| ) | [inline, protected, virtual] |
| virtual bool TreeWalk::HandleError | ( | const cmn_Path & | a_dir, | |
| const ivd_SysError & | a_error | |||
| ) | [inline, protected, virtual] |
Definition at line 41 of file TreeWalk.h.
Referenced by GenerateDirTree(), and Walk().

| void TreeWalk::GenerateDirTree | ( | ) | [private] |
Definition at line 67 of file TreeWalk.cpp.
References dbg_LOW, ivd_BaseException::GetFriendly(), cmn_FastDirLst::GetNextName(), HandleError(), ift_DIR, IsIgnorable(), log_DBG_m, log_FUNC_m, TreeWalk::DirectoryEntry::m_depth, m_dirStack, TreeWalk::DirectoryEntry::m_path, PreprocessDir(), and predicate::type.
Referenced by Walk().
00067 { 00068 00069 log_FUNC_m(GenerateDirTree); 00070 00071 unsigned long i; 00072 unsigned long dirCount = m_dirStack.size(); 00073 /* 00074 This is used to indicate the stack size before the for loop starts, we 00075 couldn't use m_dirStack.size() as the stack size changes in every iteration 00076 */ 00077 unsigned long stSize; 00078 00079 DirectoryEntry dir; 00080 string fName; 00081 ivd_GenInode_t inode; 00082 ivd_FileType_e type; 00083 00084 while (dirCount != 0){ 00085 for (stSize = m_dirStack.size(),i = stSize - dirCount, 00086 dirCount = 0; i < stSize; i++) { 00087 00088 dir = m_dirStack.at(i); 00089 cmn_FastDirLst cmnDir(dir.m_path); 00090 00091 PreprocessDir(dir.m_path, dir.m_depth); 00092 while (true) { 00093 00094 try { 00095 fName = cmnDir.GetNextName(inode, type); 00096 } 00097 catch (const ivd_SysError &a_error) { 00098 log_DBG_m(dbg_LOW, 00099 "Can't read entry in directory " << dir.m_path 00100 << ". Error: " << a_error.GetFriendly()); 00101 00102 if (HandleError(dir.m_path, a_error) != true) { 00103 throw; 00104 } 00105 } 00106 00107 if (fName == "") { 00108 break; 00109 } 00110 00111 if( ! IsIgnorable(type, fName) && type == ift_DIR ) { 00112 ++dirCount; 00113 m_dirStack.push_back( 00114 DirectoryEntry(dir.m_path + fName, dir.m_depth+1) ); 00115 } 00116 } 00117 } 00118 } 00119 }


Reimplemented from cmn_TreeWalk.
Reimplemented in CreateTree, RecAccess, RecOpen, and RecRemove.
Definition at line 122 of file treewalk.h.
const string TreeWalk::m_strPartName [private] |
ui_MsgWriter& TreeWalk::m_msgWrite [private] |
cmn_Time TreeWalk::m_startTime [private] |
Int32_t TreeWalk::m_sysLoadPct [private] |
Check ivdfs with FSC, prepare package every m_numFilesPerBatch number of files read.
After each package is checked slep so much that chack process will have only m_sysLoadPct system percetage impact. Hint: sleep for (time for last package) * (100 div a_sysLoadPct - 1) To work with int arithmetic: (time for last package) div a_sysLoadPct * 100 - (time for last package) (time for last package) must bee in proper units to fit integer in seconds if task take more than 10 s othervice in miliseconds
table: % faktor to multiply last package time 100 0 full speed 80 0.25 50 0.5 40 1.5 25 3.0 10 9.0 5 19.0 0 0 full speed
Definition at line 150 of file treewalk.h.
Referenced by CheckDir().
UInt64_t TreeWalk::m_simLinkCounter [private] |
UInt64_t TreeWalk::m_filesCounter [private] |
UInt64_t TreeWalk::m_missingCount [private] |
UInt64_t TreeWalk::m_ownerMismatchCount [private] |
UInt64_t TreeWalk::m_suspectCount [private] |
UInt64_t TreeWalk::m_prolongedCount [private] |
UInt64_t TreeWalk::m_notRelCandidate [private] |
UInt64_t TreeWalk::m_missingCopyCount [private] |
FileInfoCache TreeWalk::m_fic [private] |
DirectoryVec_t TreeWalk::m_dirStack [private] |
1.5.6