#include <fio_JourFile.h>


Definition at line 143 of file fio_JourFile.h.
Public Member Functions | |
| fio_JourFile (fio_permDBinfo_t *a_permDBinfo_p, bool a_readOnly, ivd_FileID_t a_fileID, cmn_Path a_path, string a_name="") | |
| fio_JourHandle * | GetJourWriteHandle (ivd_FileBufSize_t a_transSize) |
| get journal handle for write from JourFile instance | |
| fio_PermJourInfo_t & | GetJourInfo () |
| void | DecRefCount () |
| decrement reference counter, if counter is zero then jourFile obj is removed | |
| void | IncRefCount () |
| increment reference counter | |
| fio_JourHandle * | GetJourReadHandle (ivd_FilePosition_t a_position) |
| get journal handle for read from JourFile instance | |
| ivd_FilePosition_t | GetFreeTransPosition () |
| void | ResetFreeTransPosition (ivd_FilePosition_t a_freeTransPosition) |
| Used to set new file size after reaply of transactions. | |
| void | DumpDamagedTrans (ostream &os, char *data, ivd_FilePosition_t transFilePos, fio_JourHandle *jourHnd) |
| void | Dump (ostream &os, fio_SizeOff_v &a_sizeOff_v, fio_jourDumpArguments_t &a_jda) |
Static Public Member Functions | |
| static string | JourFileName (ivd_FileID_t a_jourFileNum) |
| Return a name for journal file, it's fileID represent in hex number compound "j" + "xxxxxxxx" + c_fio_JourFileExt where xxxxxxxx is ascii hex presentation of a_jourFileNum. | |
| static ivd_FileID_t | JourFileNumber (const string &a_fileName) |
| Convert jour file name to jour file number as fileID. | |
Public Attributes | |
| log_CLASSID_m | |
| Description of a class member. | |
Private Member Functions | |
| void | TestFreedVector (ostream &os, fio_UV_t &uv) |
| void | TestUsedVector (ostream &os, fio_UV_t &uv) |
Private Attributes | |
| ivd_FilePosition_t | m_freeTransPosition |
| where next transaction could to be storen inside jour file | |
| cmn_Mutex | m_freeTransPosition_x |
| exclusive lock for m_freeTransPosition | |
| fio_PermJourInfo_t | m_permJourInfo |
| journal permanent information | |
| int | m_refCount |
| number of active journal handle | |
| cmn_Mutex | m_refCount_x |
| mutex for reference counter | |
Static Private Attributes | |
| static fsc_RecordIDX_vv_t | m_uvChkDeposit |
| fio_JourFile::fio_JourFile | ( | fio_permDBinfo_t * | a_permDBinfo_p, | |
| bool | a_readOnly, | |||
| ivd_FileID_t | a_fileID, | |||
| cmn_Path | a_path, | |||
| string | a_name = "" | |||
| ) |
Definition at line 141 of file fio_JourFile.cpp.
References c_fio_maxJourFileHeadLen, dbg_DETAIL, fio_PermJourInfo_t::Init(), ivd_NULLCHK_m, log_DBG_m, log_FUNC_m, m_freeTransPosition, m_permJourInfo, m_uvChkDeposit, s_className, cmn_File::SeekEndF(), and fio_PermJourInfo_t::WriteInfo().
00147 : 00148 fio_File(a_readOnly, 00149 a_fileID, 00150 a_path, 00151 a_name.length() == 0 00152 ? JourFileName(a_fileID) 00153 : a_name), 00154 // fix bug 507 00155 m_refCount(0) 00156 // end 00157 { 00158 log_FUNC_m(fio_JourFile); 00159 00160 m_freeTransPosition = SeekEndF(); // check if file is new 00161 if (m_freeTransPosition < c_fio_maxJourFileHeadLen) { 00162 m_freeTransPosition = c_fio_maxJourFileHeadLen; 00163 00164 ivd_NULLCHK_m(a_permDBinfo_p, fio_PermDBinfoMgr::s_className); 00165 m_permJourInfo.Init(a_permDBinfo_p); 00166 m_permJourInfo.WriteInfo(this); // write header on this file 00167 } 00168 else { 00169 // get header from this file 00170 m_permJourInfo.Init(this); 00171 } 00172 log_DBG_m(dbg_DETAIL, "Create journal file " << hex << a_fileID << dec ); 00173 m_uvChkDeposit.resize(20); // per 20 relative files 00174 } //============================================================================//

| string fio_JourFile::JourFileName | ( | ivd_FileID_t | a_jourFileNum | ) | [static] |
Return a name for journal file, it's fileID represent in hex number compound "j" + "xxxxxxxx" + c_fio_JourFileExt where xxxxxxxx is ascii hex presentation of a_jourFileNum.
Definition at line 258 of file fio_JourFile.cpp.
References c_fio_JourFileExt, log_FUNC_m, and snprintf.
Referenced by fio_JourMgr::fio_JourMgr().
00258 { 00259 log_FUNC_m(JourFileName); 00260 00261 char sNum[10]; 00262 snprintf(sNum, 10, "%08x", a_jourFileNum); 00263 string seqNumber(sNum); 00264 return "j" + seqNumber + c_fio_JourFileExt; 00265 }

| ivd_FileID_t fio_JourFile::JourFileNumber | ( | const string & | a_fileName | ) | [static] |
Convert jour file name to jour file number as fileID.
Definition at line 243 of file fio_JourFile.cpp.
References ie_INV_FILE_NAME, and ivd_Error.
Referenced by fio_JourMgr::fio_JourMgr(), JournalDump(), and fio_JourMgr::RemoveArhivedJourFile().
00243 { 00244 00245 char *p; 00246 // journal file name format is jxxxxxxxx.ljr 00247 // skip the 'j' 00248 ivd_FileID_t fileID = strtoul(a_fileName.data() + 1, &p, 16); 00249 if (*p != '.') { 00250 throw ivd_Error(ie_INV_FILE_NAME, "Missing '.' in journal file name.", true); 00251 }; 00252 00253 return fileID; 00254 }

| fio_JourHandle * fio_JourFile::GetJourWriteHandle | ( | ivd_FileBufSize_t | a_transSize | ) |
get journal handle for write from JourFile instance
Definition at line 207 of file fio_JourFile.cpp.
References m_freeTransPosition, and m_freeTransPosition_x.
Referenced by fio_JourMgr::GetJourWriteHandle().
00207 { 00208 // log_FUNC_m(GetJourWriteHandle); 00209 00210 ivd_FilePosition_t pos; 00211 { 00212 cmn_MutexLock l(m_freeTransPosition_x); 00213 pos = m_freeTransPosition; // get current possition 00214 m_freeTransPosition += a_transSize; // increment it 00215 } 00216 fio_JourHandle* jourHnd_p = new fio_JourHandle(this, pos, a_transSize); 00217 00218 return jourHnd_p; 00219 }

| fio_PermJourInfo_t& fio_JourFile::GetJourInfo | ( | ) | [inline] |
| void fio_JourFile::DecRefCount | ( | ) |
decrement reference counter, if counter is zero then jourFile obj is removed
Definition at line 179 of file fio_JourFile.cpp.
References cmn_File::GetFullPathRef(), ie_FATAL_ERROR, cmn_Mutex::Lock(), log_FUNC_m, m_refCount, m_refCount_x, and cmn_Mutex::Unlock().
Referenced by fio_JourMgr::AddNewJourFile(), fio_JourHandle::~fio_JourHandle(), and fio_JourMgr::~fio_JourMgr().
00179 { 00180 m_refCount_x.Lock(); 00181 if (m_refCount == 0) { 00182 log_FUNC_m(DecRefCount); 00183 m_refCount_x.Unlock(); 00184 throw ivd_InternalError(ie_FATAL_ERROR, 00185 "Reference counter went negative." + GetFullPathRef()); 00186 } 00187 m_refCount--; 00188 if (m_refCount == 0) { 00189 m_refCount_x.Unlock(); 00190 delete this; 00191 return; 00192 } 00193 m_refCount_x.Unlock(); 00194 }


| void fio_JourFile::IncRefCount | ( | ) |
increment reference counter
Definition at line 198 of file fio_JourFile.cpp.
References log_FUNC_m, m_refCount, and m_refCount_x.
Referenced by fio_JourMgr::AddNewJourFile(), fio_JourHandle::fio_JourHandle(), and fio_JourMgr::fio_JourMgr().
00198 { 00199 log_FUNC_m(IncRefCount); 00200 cmn_MutexLock l(m_refCount_x); 00201 m_refCount++; 00202 }

| fio_JourHandle * fio_JourFile::GetJourReadHandle | ( | ivd_FilePosition_t | a_position | ) |
get journal handle for read from JourFile instance
Definition at line 223 of file fio_JourFile.cpp.
References c_fio_maxJourFileHeadLen.
Referenced by Dump(), and fio_JourMgr::GetJourReadHandle().
00223 { 00224 // log_FUNC_m(GetJourReadHandle); 00225 00226 ivd_FilePosition_t pos = a_position; 00227 if (pos == 0) { 00228 pos = c_fio_maxJourFileHeadLen; 00229 } 00230 fio_JourHandle* jourHnd_p = new fio_JourHandle(this, pos, 0); 00231 00232 return jourHnd_p; 00233 }

| ivd_FilePosition_t fio_JourFile::GetFreeTransPosition | ( | ) | [inline] |
Definition at line 216 of file fio_JourFile.h.
Referenced by Dump(), fio_JourMgr::GetJourWriteHandle(), fio_JourMgr::Replay(), and fio_JourMgr::SetLastSyncPosition().
00216 { return m_freeTransPosition; };

| void fio_JourFile::ResetFreeTransPosition | ( | ivd_FilePosition_t | a_freeTransPosition | ) |
Used to set new file size after reaply of transactions.
Definition at line 236 of file fio_JourFile.cpp.
References log_FUNC_m, m_freeTransPosition, and m_freeTransPosition_x.
Referenced by fio_JourHandle::FindNextTransHdr().
00236 { 00237 log_FUNC_m(SetFreeTransPosition); 00238 cmn_MutexLock l(m_freeTransPosition_x); 00239 m_freeTransPosition = a_freeTransPosition; 00240 }

| void fio_JourFile::DumpDamagedTrans | ( | ostream & | os, | |
| char * | data, | |||
| ivd_FilePosition_t | transFilePos, | |||
| fio_JourHandle * | jourHnd | |||
| ) |
Definition at line 269 of file fio_JourFile.cpp.
References c_fio_MaxAlterDataBufSize, cmn_HexDump(), fio_JourHandle::FindNextTransHdr(), and fio_JourHandle::JourRead().
Referenced by Dump().
00272 { 00273 // find next transaction header 00274 ivd_FilePosition_t pos = jourHnd->FindNextTransHdr(false); 00275 00276 ivd_FileBufSize_t dataSize = pos - transFilePos; 00277 os << " Data size = " << dataSize << " nex positon = " << pos << endl; 00278 int blockCount = 0; 00279 while (dataSize > 0) { 00280 ivd_FileBufSize_t dataToRead = dataSize > c_fio_MaxAlterDataBufSize 00281 ? c_fio_MaxAlterDataBufSize 00282 : dataSize; 00283 00284 jourHnd->JourRead(data, dataToRead); 00285 blockCount++; 00286 os << cmn_HexDump(data, dataToRead, 16, true); 00287 dataSize -= dataToRead; 00288 } 00289 }


| void fio_JourFile::Dump | ( | ostream & | os, | |
| fio_SizeOff_v & | a_sizeOff_v, | |||
| fio_jourDumpArguments_t & | a_jda | |||
| ) |
Definition at line 293 of file fio_JourFile.cpp.
References alloca(), fio_Alter_t::bufSize, c_fio_MaxAlterDataBufSize, cmn_HexDump(), fio_Alter_t::Dump(), fio_UV_t::Dump(), DumpDamagedTrans(), fio_jourDumpArguments_t::fileID, fio_Alter_t::fileID, fio_Alter_t::filePosition, fio_JourHandle::GetCurrentPosition(), ivd_BaseException::GetError(), fio_File::GetFileName(), GetFreeTransPosition(), GetJourReadHandle(), fio_jourDumpArguments_t::idx, ie_NOT_ALTER_T, ie_NOT_ENDTRANS_T, ie_NOT_STARTTRANS_T, fio_EndTransaction_t::Init(), fio_StartTransaction_t::Init(), fio_JourHandle::JourRead(), fio_JourHandle::JourSkip(), log_FUNC_m, m_freeTransPosition, recIdx, fio_JourHandle::ResetPosition(), fio_JourHandle::SetStartPositionIsCurrent(), fio_JourHandle::SetTransNumber(), fio_JourHandle::SetTransSize(), fio_jourDumpArguments_t::showData, fio_jourDumpArguments_t::showVector, TestFreedVector(), TestUsedVector(), fio_jourDumpArguments_t::testUVIdx, fio_StartTransaction_t::TransNumber, and fio_StartTransaction_t::TransSize.
Referenced by JournalDump().
00295 { 00296 log_FUNC_m(Dump); 00297 os << "Journal file " << GetFileName() << 00298 "\n free transaction position" << m_freeTransPosition << '\n'; 00299 fio_JourHandle *jourHnd = GetJourReadHandle(0); 00300 jourHnd->SetTransNumber(0); 00301 00302 fio_StartTransaction_t startTrans; 00303 fio_EndTransaction_t endTrans; 00304 00305 // reserved data buffer on stact of size c_fio_MaxAlterDataBufSize 00306 // !!! DO NOT reserve stack in loops cause allocate only per function. 00307 char *data = (char*)(alloca(c_fio_MaxAlterDataBufSize)); 00308 // ivd_NULLCHK_m(data, "alloca(c_fio_MaxAlterDataBufSize)"); 00309 00310 ivd_FilePosition_t fileSize = GetFreeTransPosition(); 00311 while (jourHnd->GetCurrentPosition() < fileSize) { 00312 ivd_FilePosition_t transFilePos = jourHnd->GetCurrentPosition(); 00313 jourHnd->SetStartPositionIsCurrent(); 00314 try { 00315 startTrans.Init(*jourHnd); 00316 jourHnd->SetTransNumber(startTrans.TransNumber); 00317 } 00318 catch (ivd_Error &err) { 00319 if (err.GetError() == ie_NOT_STARTTRANS_T) { 00320 // when read start trans failed then jourHeader file pos is reset. 00321 os << "Pos = " << transFilePos 00322 << " damaged start trans:\n" << startTrans; 00323 DumpDamagedTrans(os, data, transFilePos, jourHnd); 00324 continue; 00325 } 00326 else { 00327 throw(err); 00328 } 00329 } 00330 00331 jourHnd->SetTransSize(startTrans.TransSize); 00332 00333 os << "Pos = " << transFilePos << " " << startTrans; 00334 00335 fio_UV_t uv; 00336 unsigned int i; 00337 00338 if (a_jda.showVector) { 00339 os << " File ID VectorSize Index\n" << 00340 "------------------------------------\n"; 00341 } 00342 00343 for (i = 0; i < startTrans.FreedVector; i++) { 00344 jourHnd->JourRead(&uv, sizeof(uv)); 00345 if (a_jda.testUVIdx) { 00346 TestFreedVector(os, uv); 00347 } 00348 if (a_jda.showVector) { 00349 uv.Dump(os, a_jda.idx); 00350 } 00351 } 00352 00353 if (a_jda.showVector) { 00354 os << " File ID VectorSize Index\n" << 00355 "------------------------------------\n"; 00356 } 00357 for (i = 0; i < startTrans.UsedVector; i++) { 00358 jourHnd->JourRead(&uv, sizeof(uv)); 00359 if (a_jda.testUVIdx) { 00360 TestUsedVector(os, uv); 00361 } 00362 if (a_jda.showVector) { 00363 uv.Dump(os, a_jda.idx); 00364 } 00365 } 00366 00367 os << "Alt.numb" << " Jour pos" 00368 << " RFID"<< " IDX" << " File pos" << " Buf size" << '\n'; 00369 ivd_AlterNumber_t jourAlterNum = 0; // will be checked after all alteration are insert 00370 while (jourAlterNum < startTrans.AlterNumber) { // read all alteration 00371 try { 00372 fio_Alter_t alter(jourHnd); 00373 jourAlterNum++; 00374 00375 int recSize = 0; 00376 if (alter.fileID <= a_sizeOff_v.size() ) { 00377 recSize = a_sizeOff_v[alter.fileID].recSize; 00378 } 00379 int offset = a_sizeOff_v[alter.fileID].relFileOffset; 00380 ivd_RecordIDX_t recIdx = (alter.filePosition - offset) / recSize; 00381 00382 if ( ( (alter.filePosition < offset) 00383 || (a_jda.idx == 0) 00384 || (a_jda.idx == recIdx) ) 00385 &&( (a_jda.fileID == 0) 00386 || (a_jda.fileID == alter.fileID) ) ) { 00387 os << setw(8) << jourAlterNum << setw(10) << jourHnd->GetCurrentPosition(); 00388 00389 alter.Dump(os, recSize, offset); 00390 if (a_jda.showData) { 00391 ivd_FileBufSize_t dataSize = alter.bufSize; 00392 ivd_FileBufSize_t maxFitBuff = (c_fio_MaxAlterDataBufSize / recSize) * recSize; 00393 int blockCount = 0; 00394 00395 while (dataSize > 0) { 00396 ivd_FileBufSize_t dataToRead = dataSize > maxFitBuff 00397 ? maxFitBuff 00398 : dataSize; 00399 00400 jourHnd->JourRead(data, dataToRead); 00401 blockCount++; 00402 os << cmn_HexDump(data, dataToRead, recSize, false); 00403 dataSize -= dataToRead; 00404 } 00405 } 00406 else { 00407 jourHnd->JourSkip(alter.bufSize); 00408 } 00409 } 00410 else { 00411 // skip data 00412 jourHnd->JourSkip(alter.bufSize); 00413 } 00414 } 00415 catch (ivd_Error &err) { 00416 if (err.GetError() == ie_NOT_ALTER_T) { 00417 os << " Alteration damaged " << endl; 00418 jourHnd->ResetPosition(); 00419 DumpDamagedTrans(os, data, transFilePos, jourHnd); 00420 goto nextTransaction; 00421 } 00422 else { 00423 throw(err); 00424 } 00425 } 00426 } // while (m_alterNumber <= jourAlterNum) // loop until all alteration is read 00427 // read end thransaction header 00428 try { 00429 endTrans.Init(*jourHnd); 00430 if ( startTrans == endTrans ) { 00431 os << startTrans.TransNumber << " OK.\n" << endl; 00432 } 00433 else { 00434 os << "Transaction is NOT valid start and end transaction header are different.\n\n"; 00435 } 00436 } 00437 catch (ivd_Error &err) { 00438 if (err.GetError() == ie_NOT_ENDTRANS_T) { 00439 os << " EndTrans header damaged" << endl << endTrans; 00440 DumpDamagedTrans(os, data, transFilePos, jourHnd); 00441 goto nextTransaction; 00442 } 00443 else { 00444 throw(err); 00445 } 00446 } 00447 nextTransaction: ; 00448 00449 // when transactionis succesfuly finished then 00450 // transaciton number in jourHnd must be updated 00451 } 00452 }


| void fio_JourFile::TestFreedVector | ( | ostream & | os, | |
| fio_UV_t & | uv | |||
| ) | [private] |
Definition at line 455 of file fio_JourFile.cpp.
References fio_UV_t::m_fileID, fio_UV_t::m_idx, m_uvChkDeposit, and fio_UV_t::m_vectorSize.
Referenced by Dump().
00455 { 00456 vector<ivd_RecordIDX_t> &uvPerRelFile = m_uvChkDeposit[uv.m_fileID]; 00457 00458 ivd_RecordIDX_t *ip = &(*uvPerRelFile.begin()); 00459 ivd_RecordIDX_t *ep = &(*uvPerRelFile.end()); 00460 ivd_RecordIDX_t toIdx = uv.m_idx + uv.m_vectorSize; 00461 for(; ip != ep; ++ip) { 00462 if (*ip == uv.m_idx) { 00463 os << "FATAL ERROR at freed UV with idx " << uv.m_idx 00464 << ", with size " << uv.m_vectorSize 00465 << " already exist in free list." 00466 << " Relative file ID " << (int)uv.m_fileID 00467 << endl; 00468 } 00469 else { // check cross linked index 00470 for (ivd_RecordIDX_t idx = uv.m_idx; idx < toIdx; ++idx) { 00471 if (*ip == idx) { 00472 os << "FATAL ERROR at freed UV with idx " << uv.m_idx 00473 << ", with size " << uv.m_vectorSize 00474 << " Freed vector is cross linked with vector on index " << idx 00475 << " Relative file ID " << (int)uv.m_fileID 00476 << endl; 00477 } 00478 } 00479 } 00480 } 00481 uvPerRelFile.push_back(uv.m_idx); 00482 }

| void fio_JourFile::TestUsedVector | ( | ostream & | os, | |
| fio_UV_t & | uv | |||
| ) | [private] |
Definition at line 485 of file fio_JourFile.cpp.
References fio_UV_t::m_fileID, fio_UV_t::m_idx, m_uvChkDeposit, and fio_UV_t::m_vectorSize.
Referenced by Dump().
00485 { 00486 vector<ivd_RecordIDX_t> &uvPerRelFile = m_uvChkDeposit[uv.m_fileID]; 00487 00488 ivd_RecordIDX_t *ip = &(*uvPerRelFile.begin()); 00489 ivd_RecordIDX_t *ep = &(*uvPerRelFile.end()); 00490 for(; ip != ep; ++ip) { 00491 if (*ip == uv.m_idx) { 00492 if (ip != --ep) { // endel become last 00493 //os << "idx " << *ip << " is used " 00494 // << " overwritten by idx " << *ep << endl; 00495 *ip = *ep; 00496 } 00497 // os << " removed idx " << uvPerRelFile.back() << endl; 00498 uvPerRelFile.pop_back(); 00499 return; 00500 } 00501 } 00502 os << "FATAL ERROR at used UV with idx " << uv.m_idx 00503 << ", with size " << uv.m_vectorSize 00504 << " not found in free list." 00505 << " Relative file ID " << (int)uv.m_fileID 00506 << endl; 00507 }

where next transaction could to be storen inside jour file
Definition at line 156 of file fio_JourFile.h.
Referenced by Dump(), fio_JourFile(), GetJourWriteHandle(), and ResetFreeTransPosition().
cmn_Mutex fio_JourFile::m_freeTransPosition_x [private] |
exclusive lock for m_freeTransPosition
Definition at line 159 of file fio_JourFile.h.
Referenced by GetJourWriteHandle(), and ResetFreeTransPosition().
journal permanent information
Definition at line 162 of file fio_JourFile.h.
Referenced by fio_JourFile().
int fio_JourFile::m_refCount [private] |
number of active journal handle
Definition at line 166 of file fio_JourFile.h.
Referenced by DecRefCount(), and IncRefCount().
cmn_Mutex fio_JourFile::m_refCount_x [private] |
mutex for reference counter
Definition at line 168 of file fio_JourFile.h.
Referenced by DecRefCount(), and IncRefCount().
fsc_RecordIDX_vv_t fio_JourFile::m_uvChkDeposit [static, private] |
Definition at line 176 of file fio_JourFile.h.
Referenced by fio_JourFile(), TestFreedVector(), and TestUsedVector().
Description of a class member.
<reference> Macro to add class name member s_className.
Reimplemented from fio_File.
Definition at line 189 of file fio_JourFile.h.
1.5.6