fio_Transaction Class Reference
[Classes for large file i/o, relative file, and DataBase]

#include <fio_Transaction.h>

Inheritance diagram for fio_Transaction:

Inheritance graph
[legend]
Collaboration diagram for fio_Transaction:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 135 of file fio_Transaction.h.


Public Member Functions

 fio_Transaction (fio_DataBase *a_database_p, const fio_TransactionID_t a_transactionID)
 This constructore create new transaction object on new log file.
virtual ~fio_Transaction ()
void VectorIsFreed (const ivd_RelFileID_t a_fileID, const ivd_VectorSize_t a_vectorSize, const ivd_RecordIDX_t a_idx)
 VectorIsFreed method take care about vectors that were released from DB.
void VectorIsFreed (const fio_UV_t &a_uv)
void VectorIsUsed (const ivd_RelFileID_t a_fileID, const ivd_VectorSize_t a_vectorSize, const ivd_RecordIDX_t a_idx)
 VectorIsUsed method take care about vectors that are got from UVbuffer and used in DB.
void VectorIsUsed (const fio_UV_t &a_uv)
void StartTransaction (fio_TransType_e a_transType)
void StartTransaction ()
void StartTransAnyType ()
void EndTransaction ()
void EndTransIfStarted ()
void AbortTransaction ()
void InsertAlteration (fio_JourHandle *a_jourHnd_p)
 alteration object MUST be created on heap, cause transaction take care about it.
void InsertAlteration (UInt16_t a_fileID, ivd_FilePosition_t a_filePosition, ivd_FileBufSize_t a_bufSize, const UInt8_t *a_data)
int GetStartCount () const
ivd_TransNumber_t GetTransNumber () const
fio_TransactionID_t GetTransID () const
bool IsExclStartTrans ()
void ReadTransactionFromLog (fio_JourHandle *a_jourHnd_p)
 mathod that read transactin start header and reply UVbuffer first and after transaction number >= a_jourhnd_p->GetTransNumb then updateDB is perform too.
void SetMiniTransaction (bool a_set)

Public Attributes

 log_CLASSID_m

Private Member Functions

void CleanUp ()
void ClearAlterVector ()
void WriteAlterationToLog ()
void ExclusiveStartTransaction ()
void FinishTransaction ()
void UpdateDB ()
void PutVectorToBuffer ()
void ReplyAddVectorToBuffer ()
void ReplyRemoveVectorFromBuffer ()
void WriteEndHeader ()
void WriteStartHeader ()
void WriteUVListToJour ()
void ReadUVListFromJour (UInt32_t a_numOfFreedUV, UInt32_t a_numOfUsedUV)

Private Attributes

fio_DataBasem_database_p
 The transaction object is constructed by database and holds pointer to it.
const fio_TransactionID_t m_transactionID
 Is obtained by database. It is used to concurrently access to list of list of unused vectors.
fio_JourHandlem_jourHnd_p
 Jounal handle is used to store start, end transaction header, and DB alterations between them into journal file.
fio_AlterJour m_alteration
 journal of alterations
bool m_valid
 Transaction is valid if is started and then ended.
int m_startCount
 This member is set to 0 by constructor and is increment by each StartTransaction method and is decremented by each EndTransaction method.
ivd_TransNumber_t m_transNumber
 transaction number is set by journal manager through journal handle and it is stored in start and end transaction header.
ivd_FileBufSize_t m_transSize
ivd_AlterNumber_t m_alterNumber
 nujmber of alteration inside transaction, each InsertAlteration() increment this number by 1
bool m_exclStartTrans
 Allow start transaction no mather of DB lock status.
fio_UV_v_t m_freedVec_m
 In this map are UV that DB don't need any more.
fio_UV_v_t m_usedVec_m
 In this map are UV that are got from UVbuffer.
bool m_miniTransaction
 when transaction is use for get or put to UV then is mini prevent that mini trans not trig another mini transaction
fio_TransType_e m_transType
 now only ftt_CIRC_VECT is used

Friends

class fio_DataBase
class fio_uvListMgr

Constructor & Destructor Documentation

fio_Transaction::fio_Transaction ( fio_DataBase a_database_p,
const fio_TransactionID_t  a_transactionID 
)

This constructore create new transaction object on new log file.

Definition at line 233 of file fio_Transaction.cpp.

References log_FUNC_m.

00236         :   
00237         m_database_p(a_database_p),
00238         m_transactionID(a_transactionID),
00239         m_jourHnd_p(NULL),
00240         m_alteration(a_database_p->GetRelFileTransLstMgrRef()),
00241         m_valid(false),
00242         m_startCount(0),
00243         m_transNumber(0),
00244         m_transSize(0),
00245         m_alterNumber(0),
00246         m_exclStartTrans(false),
00247         m_miniTransaction(false),
00248         m_transType(ftt_NONE)
00249 {
00250     log_FUNC_m(fio_Transaction);
00251     // Empty
00252 }

fio_Transaction::~fio_Transaction (  )  [virtual]

Definition at line 256 of file fio_Transaction.cpp.

References ClearAlterVector(), and log_FUNC_m.

00256                                   {
00257     log_FUNC_m(~fio_Transaction);
00258 
00259     ClearAlterVector();
00260 }

Here is the call graph for this function:


Member Function Documentation

void fio_Transaction::VectorIsFreed ( const ivd_RelFileID_t  a_fileID,
const ivd_VectorSize_t  a_vectorSize,
const ivd_RecordIDX_t  a_idx 
)

VectorIsFreed method take care about vectors that were released from DB.

When transaction is finished then this released vectors are put to proper UV buffer.

Referenced by fio_uvListMgr::ReadUV(), ReadUVListFromJour(), and fio_RelFileTrans::ReleaseVectorIdx().

Here is the caller graph for this function:

void fio_Transaction::VectorIsFreed ( const fio_UV_t a_uv  )  [inline]

Definition at line 247 of file fio_Transaction.h.

00247                                              {
00248         m_freedVec_m.push_back(a_uv);
00249     };

void fio_Transaction::VectorIsUsed ( const ivd_RelFileID_t  a_fileID,
const ivd_VectorSize_t  a_vectorSize,
const ivd_RecordIDX_t  a_idx 
) [inline]

VectorIsUsed method take care about vectors that are got from UVbuffer and used in DB.

It is possible that such a vectors are released in next actions in the same transaction. This is not a problem, because they are going to released list.

Definition at line 256 of file fio_Transaction.h.

Referenced by fio_uvListMgr::GetBunchOfVectorIDXes(), fio_RelFileTrans::GetVectorIDX(), ReadUVListFromJour(), and fio_uvListMgr::WriteUV().

00259                                           {
00260         m_usedVec_m.push_back(fio_UV_t(a_fileID, a_vectorSize, a_idx));
00261     };

Here is the caller graph for this function:

void fio_Transaction::VectorIsUsed ( const fio_UV_t a_uv  )  [inline]

Definition at line 263 of file fio_Transaction.h.

00263                                             {
00264         m_usedVec_m.push_back(a_uv);
00265     };

void fio_Transaction::StartTransaction ( fio_TransType_e  a_transType  ) 

Definition at line 311 of file fio_Transaction.cpp.

References cmn_Num2Str(), ftt_CIRC_VECT, ftt_FLUSH_UV, ftt_HANDLE_UV, ftt_NORMAL, ie_NOTYPE, log_FUNC_m, m_exclStartTrans, m_transType, StartTransaction(), and StartTransAnyType().

Referenced by hsm_FileHeader::AddToReleaseCanList(), i_FSC_i::ChkLastFileID(), hsm_FileHeader::CompleteMigIsDone(), hsm_FileHeader::Event(), hsm_FileHeader::EventOffline(), fsc_DataLMgr::FlushChangesAndCleanCache(), fsc_DataLMgr::GetBunchOfFileIDs(), hsm_FHmigc::GetFileIDs(), fio_CirFileTrans::GetRFIdxFromNextBlock(), hdb_RemoveName(), hsm_FileHeader::InitActive(), fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn(), hsm_FileHeader::MigrationIsDone(), fio_CirFileTrans::NewWriteBackBlock(), hsm_ActiveFH::OrphanedToMigList(), hsm_FileHeader::Recalled(), hsm_FileHeader::StoreDirTreeRec(), hsm_FileHeader::StoreNameOwnRec(), hsm_FileHeader::StoreOldNameOwnRec(), and hsm_FHrelc::Truncate().

00311                                                                   {
00312     log_FUNC_m(StartTransaction(fio_TransType_e));
00313     m_transType = a_transType;
00314     switch (m_transType) {
00315         case ftt_NORMAL :
00316             m_exclStartTrans = false;
00317             break;
00318             
00319         case ftt_HANDLE_UV :
00320         case ftt_FLUSH_UV  :
00321         case ftt_CIRC_VECT :
00322             m_exclStartTrans = true;
00323             break;
00324             
00325         default :
00326             throw ivd_InternalError(ie_NOTYPE, 
00327                 "Wrong transaction type : " + cmn_Num2Str(m_transType) , true);
00328             break;
00329     }    
00330     StartTransAnyType();
00331 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::StartTransaction (  ) 

Definition at line 334 of file fio_Transaction.cpp.

References ftt_NORMAL, log_FUNC_m, m_exclStartTrans, m_miniTransaction, m_transType, and StartTransAnyType().

Referenced by StartTransaction().

00334                                        {
00335     log_FUNC_m(StartTransaction);
00336     
00337     m_transType       = ftt_NORMAL;
00338     m_exclStartTrans  = false;
00339     m_miniTransaction = false;
00340     
00341     StartTransAnyType();
00342 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::StartTransAnyType (  ) 

Definition at line 345 of file fio_Transaction.cpp.

References CleanUp(), dbg_NORM, log_DBG_m, log_FUNC_m, m_database_p, cmn_LockOwn::m_groupID, m_startCount, m_transactionID, m_transType, and fio_DataBase::StartTransaction().

Referenced by ExclusiveStartTransaction(), and StartTransaction().

00345                                         {
00346     log_FUNC_m(StartTransAnyType);
00347     if (m_startCount == 0) {
00348         log_DBG_m(dbg_NORM, "START transaction. ID : " << m_transactionID
00349             << "  type " << m_transType 
00350             << "  groupID" << m_groupID
00351             << "  startCount " << m_startCount);
00352 
00353         m_database_p->StartTransaction(this); //notify DB, and wait if it's necessary
00354 
00355         CleanUp();
00356     }
00357     m_startCount++;
00358 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::EndTransaction (  ) 

Definition at line 362 of file fio_Transaction.cpp.

References CleanUp(), fio_DataBase::Continue(), dbg_NORM, fio_DataBase::EndTransaction(), fio_regularFlushUV_c, ftt_NONE, ftt_NORMAL, fio_JourHandle::GetFileID(), fio_JourMgr::GetJourWriteHandle(), fio_JourHandle::GetStartPosition(), fio_JourHandle::GetTransNumber(), fio_JourHandle::JourSync(), log_DBG_m, log_FUNC_m, m_alteration, m_alterNumber, m_database_p, m_exclStartTrans, m_freedVec_m, cmn_LockOwn::m_groupID, m_jourHnd_p, fio_DataBase::m_jourMgr_p, m_miniTransaction, m_startCount, m_transactionID, m_transNumber, m_transSize, m_transType, m_usedVec_m, m_valid, NULL, PutVectorToBuffer(), fio_DataBase::RegularSuspend(), fio_JourMgr::ReleaseJourHandle(), ReplyAddVectorToBuffer(), fio_AlterJour::Size(), UpdateDB(), WriteAlterationToLog(), WriteEndHeader(), and WriteStartHeader().

Referenced by hsm_FileHeader::AddToReleaseCanList(), hsm_FileHeader::CompleteMigIsDone(), hsm_FileHeader::Event(), hsm_FileHeader::EventOffline(), fsc_DataLMgr::FlushChangesAndCleanCache(), fsc_DataLMgr::GetBunchOfFileIDs(), hsm_FHmigc::GetFileIDs(), fio_CirFileTrans::GetRFIdxFromNextBlock(), hdb_RemoveName(), hsm_FileHeader::InitActive(), fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn(), hsm_FileHeader::MigrationIsDone(), fio_CirFileTrans::NewWriteBackBlock(), hsm_ActiveFH::OrphanedToMigList(), fio_uvListMgr::PutVector(), fio_uvListMgr::ReadUV(), hsm_FileHeader::Recalled(), hsm_FileHeader::StoreDirTreeRec(), hsm_FileHeader::StoreNameOwnRec(), hsm_FileHeader::StoreOldNameOwnRec(), fio_DataBase::Synchronize(), hsm_FHrelc::Truncate(), and fio_TransGroupLock< _T, _defTransEl >::UnLockAndFlush().

00362                                      {
00363     log_FUNC_m(EndTransaction);
00364 
00365     if (m_startCount == 0) {
00366 //        throw ivd_Error(ie_TRANSACTION_NOT_STARTED, 
00367         log_DBG_m(dbg_NORM, "Transaction level is already 0. Maybe the transaction was aborted.");
00368         return;
00369     }
00370 
00371     m_startCount--;
00372     if (m_startCount == 0) {
00373 
00374         bool newJournalFile = false;
00375 
00376         log_DBG_m(dbg_NORM, "END   transaction. ID : " << m_transactionID
00377             << "  type " << m_transType 
00378             << "  groupID" << m_groupID
00379             << "  startCount " << m_startCount);
00380 
00381         // if something change
00382         if (  m_alteration.Size() > 0
00383            || m_freedVec_m.size()   > 0
00384            || m_usedVec_m.size()    > 0) {
00385 
00386             m_transSize +=   (sizeof(fio_StartTransaction_t) 
00387                             + sizeof(fio_EndTransaction_t))
00388                             + m_freedVec_m.size() * sizeof(fio_UV_t)
00389                             + m_usedVec_m.size()  * sizeof(fio_UV_t);
00390 
00391             // get journal header
00392             m_jourHnd_p   = m_database_p->m_jourMgr_p->GetJourWriteHandle(m_transSize, newJournalFile);
00393             m_transNumber = m_jourHnd_p->GetTransNumber();
00394 
00395             log_DBG_m(dbg_NORM, "INFO  transaction. ID : " << m_transactionID
00396              << "  type " << m_transType 
00397              << "  Size " << m_transSize << 
00398                 "  freedVec " << m_freedVec_m.size() <<
00399                 "  usedVec " << m_usedVec_m.size() <<
00400                 "  alter number " << m_alterNumber <<
00401                 "  jour file 0x" << hex << m_jourHnd_p->GetFileID() << dec <<
00402                 "  jour pos " << m_jourHnd_p->GetStartPosition());
00403 
00404             WriteStartHeader();
00405             WriteAlterationToLog();
00406             WriteEndHeader();
00407             m_jourHnd_p->JourSync();  // flush all changes to journal file
00408 
00409             m_valid = true;
00410 
00411             UpdateDB(); // database must be update before UV from transaction bug 1029;
00412 
00413             // release journal header and commit changes
00414             m_database_p->m_jourMgr_p->ReleaseJourHandle(m_jourHnd_p);
00415             m_jourHnd_p = NULL;
00416 
00417             if (m_miniTransaction) {   // do not trig another mini transaction
00418                 ReplyAddVectorToBuffer();
00419             }
00420             else {
00421                 // put released vector to UVlist
00422                 PutVectorToBuffer();
00423             }
00424 
00425         } //  if (m_alteration_v.size() > 0) 
00426 
00427         // notify DB about end transaction event
00428         m_database_p->EndTransaction();
00429 
00430         CleanUp();
00431 
00432         if (    newJournalFile 
00433             && !m_miniTransaction
00434             && !m_exclStartTrans
00435             && (m_transType == ftt_NORMAL)) { // mini, exclusive and circ-vect transactions can't be initiators
00436             log_DBG_m(dbg_NORM, "Flush UV." );
00437             m_database_p->RegularSuspend(false);
00438             m_database_p->Continue(fio_regularFlushUV_c); // do not delete journal files
00439         }
00440         else {
00441             log_DBG_m(dbg_NORM, "UV not flushed. " 
00442                     << "newJournalFile : " << boolalpha << newJournalFile
00443                     << ", m_miniTransaction : " << boolalpha << m_miniTransaction
00444                     << ", m_exclStartTrans : " << boolalpha << m_exclStartTrans
00445                     << ", m_transType : " << m_transType);
00446         }
00447         m_exclStartTrans  = false;
00448         // if new journal file then suspend=, continue DB.
00449         
00450         m_transType = ftt_NONE;
00451     }
00452 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::EndTransIfStarted (  )  [inline]

Definition at line 277 of file fio_Transaction.h.

Referenced by fio_TransGroupLock< _T, _defTransEl >::ReleaseGroup().

00277                              {
00278         if (m_startCount > 0) {
00279             EndTransaction();
00280         }
00281     };

Here is the caller graph for this function:

void fio_Transaction::AbortTransaction (  ) 

Definition at line 456 of file fio_Transaction.cpp.

References CleanUp(), dbg_NORM, fio_DataBase::EndTransaction(), log_DBG_m, log_FUNC_m, m_alterNumber, m_database_p, m_exclStartTrans, m_miniTransaction, m_startCount, m_transNumber, and m_transSize.

Referenced by fsc_DataLMgr::GetBunchOfFileIDs().

00456                                        {
00457     log_FUNC_m(AbortTransaction);
00458     log_DBG_m(dbg_NORM, "ABORT TRANSACTION " << m_transNumber << 
00459                 " alter number = " << m_alterNumber <<
00460                 " alter size = " << m_transSize);
00461     if (m_startCount > 0) {
00462         m_database_p->EndTransaction();
00463     }
00464     m_startCount      = 0;
00465     m_exclStartTrans  = false;
00466     m_miniTransaction = false;
00467     CleanUp();
00468 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::InsertAlteration ( fio_JourHandle a_jourHnd_p  ) 

alteration object MUST be created on heap, cause transaction take care about it.

void fio_Transaction::InsertAlteration(fio_Alteration *a_alter_p) { log_FUNC_m(InsertAlteration);

if (m_startCount > 0) { m_transSize += a_alter_p->AlterSize(); m_alterNumber++; m_alteration_v.push_back(a_alter_p); log_DBG_m(dbg_DETAIL, " alt num " << m_alterNumber << " alter size " << a_alter_p->AlterSize() << " trans size" << m_transSize); } else { log_FUNC_m(InsertAlteration); throw ivd_Error(ie_TRANSACTION_NOT_STARTED, "Can't InsertAlteration() before StartTransaction().", true); } }

Definition at line 515 of file fio_Transaction.cpp.

References fio_Alter_t::bufSize, fio_AlterJour::Insert(), m_alteration, m_alterNumber, and m_transSize.

Referenced by InsertAlteration(), fio_RelFileTrans::PosWrite(), and ReadTransactionFromLog().

00515                                                                   {
00516 //    log_FUNC_m(InsertAlteration(jour_p))
00517     fio_Alter_t alter(a_jourHnd_p);
00518     m_transSize += sizeof(fio_Alter_t) + alter.bufSize;
00519     m_alterNumber++;
00520     m_alteration.Insert(alter, a_jourHnd_p);
00521 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::InsertAlteration ( UInt16_t  a_fileID,
ivd_FilePosition_t  a_filePosition,
ivd_FileBufSize_t  a_bufSize,
const UInt8_t a_data 
)

Definition at line 525 of file fio_Transaction.cpp.

References ie_TRANSACTION_NOT_STARTED, fio_AlterJour::Insert(), InsertAlteration(), ivd_Error, log_FUNC_m, m_alteration, m_alterNumber, m_startCount, and m_transSize.

00528                                                                    {
00529 //    log_FUNC_m(InsertAlteration)
00530     if (m_startCount > 0) {
00531         m_transSize += sizeof(fio_Alter_t) + a_bufSize;
00532         m_alterNumber++;
00533         m_alteration.Insert(a_fileID, a_filePosition, a_bufSize);
00534         m_alteration.Insert(a_data, a_bufSize);
00535         //log_DBG_m(dbg_DETAIL, " alt num "  << m_alterNumber
00536         //                    << " RelFileID " <<  a_fileID
00537         //                    << " alter size " <<  a_bufSize
00538         //                    << " trans size"  << m_transSize);
00539         //log_DBG_m(dbg_DETAIL, "W alteration : " <<  endl <<
00540         //    cmn_HexDump(a_data, a_bufSize, 16, false) );
00541     }
00542     else {
00543         log_FUNC_m(InsertAlteration);
00544         throw ivd_Error(ie_TRANSACTION_NOT_STARTED, 
00545             "Can't InsertAlteration() before StartTransaction().", true);
00546     }
00547 }

Here is the call graph for this function:

int fio_Transaction::GetStartCount (  )  const [inline]

Definition at line 291 of file fio_Transaction.h.

00291 { return m_startCount; };

ivd_TransNumber_t fio_Transaction::GetTransNumber (  )  const [inline]

Definition at line 292 of file fio_Transaction.h.

00292 { return (m_startCount > 0) ? m_transNumber : 0; };

fio_TransactionID_t fio_Transaction::GetTransID (  )  const [inline]

Definition at line 294 of file fio_Transaction.h.

Referenced by fio_TransLstMgr::isTransRegistered(), and fio_TransLstMgr::ReleaseTransObj().

00294 { return m_transactionID; };

Here is the caller graph for this function:

bool fio_Transaction::IsExclStartTrans (  )  [inline]

Definition at line 296 of file fio_Transaction.h.

Referenced by fio_DataBase::StartTransaction().

00296 {return m_exclStartTrans;};

Here is the caller graph for this function:

void fio_Transaction::ReadTransactionFromLog ( fio_JourHandle a_jourHnd_p  ) 

mathod that read transactin start header and reply UVbuffer first and after transaction number >= a_jourhnd_p->GetTransNumb then updateDB is perform too.

before return the method must set file startPosition of a_jourHnd_p soon after transaction for next call

Definition at line 591 of file fio_Transaction.cpp.

References fio_JourHandle::AddStartPosition(), fio_StartTransaction_t::AlterNumber, CleanUp(), dbg_DETAIL, fio_JourHandle::FindNextTransHdr(), fio_StartTransaction_t::FreedVector, ivd_BaseException::GetError(), fio_JourHandle::GetLastDBTransNum(), fio_JourHandle::GetStartPosition(), fio_JourHandle::GetTransNumber(), ie_NOT_ALTER_T, ie_NOT_ENDTRANS_T, ie_NOT_STARTTRANS_T, ie_UV_NOT_IN_BUFFER, fio_EndTransaction_t::Init(), fio_StartTransaction_t::Init(), InsertAlteration(), log_DBG_m, log_FUNC_m, log_WRN_m, m_alterNumber, m_jourHnd_p, m_startCount, m_transNumber, m_valid, ReadUVListFromJour(), ReplyAddVectorToBuffer(), ReplyRemoveVectorFromBuffer(), fio_JourHandle::ResetPosition(), fio_JourHandle::SetStartPositionIsCurrent(), fio_JourHandle::SetTransNumber(), fio_JourHandle::SetTransSize(), fio_StartTransaction_t::TransNumber, fio_StartTransaction_t::TransSize, UpdateDB(), and fio_StartTransaction_t::UsedVector.

Referenced by fio_JourMgr::Replay().

00593 {
00594     log_FUNC_m(ReadTransactionFromLog);
00595 
00596     m_jourHnd_p = a_jourHnd_p;
00597     log_DBG_m(dbg_DETAIL, "Read jour at position " << a_jourHnd_p->GetStartPosition()
00598                         << ", transNumber " << m_jourHnd_p->GetTransNumber()
00599                         << ", lastDBTransNum " << m_jourHnd_p->GetLastDBTransNum());
00600 
00601     CleanUp();
00602 
00603     ivd_AlterNumber_t jourAlterNum = 0; // will be checked after all alteration are insert
00604 
00605     fio_StartTransaction_t startTrans;
00606     fio_EndTransaction_t   endTrans;
00607 
00608     try {
00609 
00610         startTrans.Init(*m_jourHnd_p);
00611         if (startTrans.TransNumber == 0) { // transaction is damaged and signed as invalid
00612             if (startTrans.TransSize >= sizeof(fio_StartTransaction_t)) {
00613                 m_jourHnd_p->AddStartPosition(startTrans.TransSize);  
00614                 return;
00615             } else {
00616                 m_valid = false;
00617                 goto endofread;
00618             }
00619         }
00620 
00621         m_jourHnd_p->SetTransSize(startTrans.TransSize);
00622 
00623         m_startCount++; // cause start transaction header is going to read.
00624 
00625         ReadUVListFromJour(startTrans.FreedVector, startTrans.UsedVector);
00626        
00627         m_transNumber = startTrans.TransNumber; 
00628 
00629         if (m_transNumber < m_jourHnd_p->GetLastDBTransNum()) {
00630             log_DBG_m(dbg_DETAIL, "DB is up to date, but UV are not.")
00631             // just update UV buffers
00632             //get again all vectors from UV buffer, to rebuild UV buffer
00633             try {
00634                 ReplyRemoveVectorFromBuffer();
00635             }
00636             catch (ivd_InternalError &err) {
00637                 if (err.GetError() == ie_UV_NOT_IN_BUFFER) {
00638                     log_WRN_m(startTrans << endl << *m_jourHnd_p);
00639                 }
00640             }
00641             // put released vector to UVlist, to rebuild UV buffer
00642             ReplyAddVectorToBuffer();
00643             // set next file position
00644             m_jourHnd_p->AddStartPosition(startTrans.TransSize);  
00645             m_startCount--;
00646             return;
00647         }
00648         jourAlterNum  = startTrans.AlterNumber; // need to match number of alterations
00649 
00650     }
00651     catch (ivd_Error &err) {
00652         if (err.GetError() == ie_NOT_STARTTRANS_T) { 
00653             m_valid = false;
00654             goto endofread;
00655         }
00656         else {
00657             throw(err);
00658         }
00659     }
00660 
00661     while (m_alterNumber < jourAlterNum) {  // read all alteration
00662         try {
00663             InsertAlteration(a_jourHnd_p); // increase m_alterNumber too
00664         }
00665         catch (ivd_Error &err) {
00666             if (err.GetError() == ie_NOT_ALTER_T) { 
00667                 // TODO  repair
00668                 m_jourHnd_p->ResetPosition();
00669                 m_valid = false;
00670                 goto endofread;
00671             }
00672             else {
00673                 throw(err);
00674             }
00675         }
00676      }  // while (m_alterNumber <= jourAlterNum)  // loop until all alteration is read
00677 
00678     try {
00679         endTrans.Init(*m_jourHnd_p);
00680         m_startCount--; // because end transaction header is read.
00681         m_valid = (  startTrans == endTrans );
00682     }                    
00683     catch (ivd_Error &err) {
00684         if (err.GetError() == ie_NOT_ENDTRANS_T) { 
00685             // TODO  repair
00686             m_valid = false;
00687             goto endofread;
00688         }
00689         else {
00690             throw(err);
00691         }
00692     }
00693 
00694 endofread:
00695 
00696     if (m_valid) {
00697         log_DBG_m(dbg_DETAIL, "Transaction is valid. Update DB.")
00698 
00699         //get again all vectors from UV buffer, to rebuild UV buffer
00700         ReplyRemoveVectorFromBuffer();
00701         // put released vector to UVlist, to rebuild UV buffer
00702         ReplyAddVectorToBuffer();
00703 
00704         // update journal to know that transaction is successfuly finished
00705         m_jourHnd_p->SetTransNumber(m_transNumber); 
00706         UpdateDB();
00707 
00708         m_jourHnd_p->SetStartPositionIsCurrent();    
00709     }
00710     else {
00711         log_WRN_m( "Transaction is not valid. JourHandle = " << endl << *m_jourHnd_p << startTrans);
00712         // find next header and repaire current
00713         m_jourHnd_p->FindNextTransHdr(true);
00714 
00715         m_startCount = 0; // same as at abort transaction, but not anounce DB
00716     }
00717     CleanUp();
00718 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::SetMiniTransaction ( bool  a_set  )  [inline]

Definition at line 304 of file fio_Transaction.h.

Referenced by fio_uvListMgr::ReadUV().

00304                                                {
00305         m_miniTransaction = a_set;
00306     }

Here is the caller graph for this function:

void fio_Transaction::CleanUp (  )  [private]

Definition at line 264 of file fio_Transaction.cpp.

References ClearAlterVector(), cmn_Num2Str(), log_ERR_m, log_FUNC_m, m_alterNumber, m_freedVec_m, m_startCount, m_transNumber, m_transSize, m_usedVec_m, and m_valid.

Referenced by AbortTransaction(), EndTransaction(), ReadTransactionFromLog(), and StartTransAnyType().

00264                               {
00265     m_valid       = false;
00266     if (m_startCount > 0) {
00267         log_FUNC_m(CleanUp);
00268         log_ERR_m( string("Transaction ") + cmn_Num2Str(m_transNumber) 
00269                  + string(" is going to clean up, but it is not Aborted. Start trans count is ")
00270                  + cmn_Num2Str(m_startCount));
00271     }
00272     m_startCount  = 0;  // cause start transaction header is read.
00273     m_transNumber = 0;  // trans number is got from jour file
00274     m_transSize   = 0;  // reset transaction counters
00275     m_alterNumber = 0;
00276 
00277     m_freedVec_m.clear();
00278     m_usedVec_m.clear();
00279     ClearAlterVector();
00280 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::ClearAlterVector (  )  [private]

Definition at line 284 of file fio_Transaction.cpp.

References fio_AlterJour::Clear(), and m_alteration.

Referenced by CleanUp(), and ~fio_Transaction().

00284                                        {
00285 //    log_FUNC_m(ClearAlterVector);
00286     m_alteration.Clear();
00287 
00288     //fio_Alteration* *ip = &(*m_alteration_v.begin());
00289     //fio_Alteration* *ep = &(*m_alteration_v.end()); // addres of past the end
00290     //for (; ip < ep; ++ip) {
00291     //    if (*ip != NULL) {
00292     //       delete (*ip);
00293     //    }
00294     //}
00295     //m_alteration_v.clear();
00296 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::WriteAlterationToLog (  )  [private]

Definition at line 551 of file fio_Transaction.cpp.

References m_alteration, m_jourHnd_p, and fio_AlterJour::WriteToLog().

Referenced by EndTransaction().

00551                                            {
00552 //    log_FUNC_m(WriteAlterationToLog);
00553 
00554     //fio_Alteration* *ip = &(*m_alteration_v.begin());
00555     //fio_Alteration* *ep = &(*m_alteration_v.end()); // addres of past the end
00556     //for (; ip < ep; ++ip) {
00557     //    if (*ip != NULL) {
00558     //       (*ip)->WriteToLog(m_jourHnd_p);
00559     //    }
00560     //}
00561     m_alteration.WriteToLog(m_jourHnd_p);
00562 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::ExclusiveStartTransaction (  )  [private]

Definition at line 300 of file fio_Transaction.cpp.

References ftt_FLUSH_UV, ftt_HANDLE_UV, log_FUNC_m, m_exclStartTrans, m_miniTransaction, m_transType, and StartTransAnyType().

Referenced by fio_uvListMgr::PutVector(), fio_uvListMgr::ReadUV(), and fio_DataBase::Synchronize().

00300                                                 {
00301     log_FUNC_m(ExclusiveStartTransaction);
00302 
00303     m_exclStartTrans = true;
00304     m_transType = m_miniTransaction 
00305                  ? ftt_HANDLE_UV
00306                  : ftt_FLUSH_UV;
00307     StartTransAnyType();
00308 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::FinishTransaction (  )  [private]

void fio_Transaction::UpdateDB (  )  [private]

Definition at line 472 of file fio_Transaction.cpp.

References fio_AlterJour::Clear(), fio_DataBase::Flush(), m_alteration, m_database_p, and fio_AlterJour::UpdateDB().

Referenced by EndTransaction(), and ReadTransactionFromLog().

00472                                {
00473 //    log_FUNC_m(UpdateDB);
00474 
00475     //fio_Alteration* *ip = &(*m_alteration_v.begin());
00476     //fio_Alteration* *ep = &(*m_alteration_v.end()); // addres of past the end
00477     //for (; ip < ep; ++ip) {
00478     //    if (*ip != NULL) {
00479     //       (*ip)->UpdateRelFile();
00480     //       delete (*ip);
00481     //    }
00482     //}
00483     //m_alteration_v.clear();
00484     m_alteration.UpdateDB();
00485     m_alteration.Clear();
00486     m_database_p->Flush();
00487 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::PutVectorToBuffer (  )  [private]

Definition at line 804 of file fio_Transaction.cpp.

References dbg_DETAIL, fio_DataBase::GetRelFileTrans(), log_DBG_m, log_FUNC_m, m_database_p, fio_UV_t::m_fileID, m_freedVec_m, fio_UV_t::m_idx, and fio_UV_t::m_vectorSize.

Referenced by EndTransaction().

00804                                         {
00805     log_FUNC_m(PutVectorToBuffer);
00806     
00807     //fio_RelFileTrans *rft_p = NULL;
00808     //ivd_RelFileID_t      prevFileID = 0;
00809 //    ivd_RelFileID_t      currFileID;
00810 
00811     register fio_UV_t *ip = &(*m_freedVec_m.begin());
00812     register fio_UV_t *ep = &(*m_freedVec_m.end()); // addres of past the end
00813     for(; ip < ep; ++ip) {
00814         //ivd_RelFileID_t currFileID = iter->m_fileID;
00815         //if (currFileID == 0) {
00816         //    throw ivd_InternalError(ie_REL_FILE_INDEX_INV, "Idx " + cmn_Num2Str(currFileID), true);
00817         //}
00818         //if (prevFileID != currFileID) {  // get new relfiletrans pointer
00819         //    prevFileID  = currFileID;
00820         //    rft_p = m_database_p->GetRelFileTrans(currFileID);
00821         //}
00822 //        rft_p->PutVectorToBufferAndFlush(iter->m_idx, iter->m_vectorSize);
00823     log_DBG_m(dbg_DETAIL, "Freed UV RelFileID " << (int)ip->m_fileID << "  idx " << ip->m_idx 
00824                      << "  size " << ip->m_vectorSize);
00825         m_database_p->GetRelFileTrans(ip->m_fileID)->
00826             PutVectorToBufferAndFlush(ip->m_idx, ip->m_vectorSize);
00827     }
00828     m_freedVec_m.clear();
00829 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::ReplyAddVectorToBuffer (  )  [private]

Definition at line 833 of file fio_Transaction.cpp.

References fio_DataBase::GetRelFileTrans(), m_database_p, fio_UV_t::m_fileID, m_freedVec_m, fio_UV_t::m_idx, and fio_UV_t::m_vectorSize.

Referenced by EndTransaction(), and ReadTransactionFromLog().

00833                                              {
00834     
00835     //fio_RelFileTrans *rft_p = NULL;
00836     //ivd_RelFileID_t      prevFileID = 0;
00837 //    ivd_RelFileID_t      currFileID;
00838 
00839     register fio_UV_t *ip = &(*m_freedVec_m.begin());
00840     register fio_UV_t *ep = &(*m_freedVec_m.end()); // addres of past the end
00841     for(; ip < ep; ++ip) {
00842         //ivd_RelFileID_t currFileID = ip->m_fileID;
00843         //if (currFileID == 0) {
00844         //    log_FUNC_m(ReplyAddVectorToBuffer);
00845         //    throw ivd_InternalError(ie_REL_FILE_INDEX_INV, "Idx " + cmn_Num2Str(currFileID), true);
00846         //    
00847         //}
00848         //if (prevFileID != currFileID) {  // get new relfiletrans pointer
00849         //    prevFileID  = currFileID;
00850         //    rft_p = m_database_p->GetRelFileTrans(currFileID);
00851         //}
00852 //        rft_p->AddVectorToBuffer(iter->m_idx, iter->m_vectorSize);
00853         m_database_p->GetRelFileTrans(ip->m_fileID)->
00854             AddVectorToBuffer(ip->m_idx, ip->m_vectorSize);
00855     }
00856     m_freedVec_m.clear();
00857 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::ReplyRemoveVectorFromBuffer (  )  [private]

Definition at line 861 of file fio_Transaction.cpp.

References fio_DataBase::GetRelFileTrans(), log_FUNC_m, m_database_p, fio_UV_t::m_fileID, fio_UV_t::m_idx, m_usedVec_m, and fio_UV_t::m_vectorSize.

Referenced by ReadTransactionFromLog().

00861                                                   {
00862     log_FUNC_m(ReplyRemoveVectorFromBuffer);
00863 
00864     //fio_RelFileTrans *rft_p = NULL;
00865     //ivd_RelFileID_t      prevFileID = 0;
00866     //ivd_RelFileID_t      currFileID;
00867 //    fio_UV_v_i iter;
00868 
00869     register fio_UV_t *ip = &(*m_usedVec_m.begin());
00870     register fio_UV_t *ep = &(*m_usedVec_m.end()); // addres of past the end
00871     for(; ip < ep; ++ip) {
00872         //currFileID = iter->m_fileID;
00873         //if (  prevFileID != currFileID 
00874         //   || rft_p      == NULL) {  // get new relfiletrans pointer
00875         //    prevFileID  = currFileID;
00876         //    rft_p = m_database_p->GetRelFileTrans(currFileID);
00877         //}
00878         m_database_p->GetRelFileTrans(ip->m_fileID)->
00879             RemoveVectorFromBuffer(ip->m_idx, ip->m_vectorSize);
00880 //        rft_p->RemoveVectorFromBuffer(iter->m_idx, iter->m_vectorSize);
00881     }
00882     m_usedVec_m.clear();
00883 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::WriteEndHeader (  )  [private]

Definition at line 582 of file fio_Transaction.cpp.

References fio_JourHandle::JourWrite(), log_FUNC_m, m_jourHnd_p, and m_transNumber.

Referenced by EndTransaction().

00582                                      {
00583     log_FUNC_m(WriteEndHeader);
00584 
00585     fio_EndTransaction_t end(m_transNumber);
00586     m_jourHnd_p->JourWrite(&end, sizeof(end));
00587 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::WriteStartHeader (  )  [private]

Definition at line 566 of file fio_Transaction.cpp.

References fio_JourHandle::JourWrite(), log_FUNC_m, m_alterNumber, m_freedVec_m, m_jourHnd_p, m_transNumber, m_transSize, m_usedVec_m, and WriteUVListToJour().

Referenced by EndTransaction().

00566                                        {
00567     log_FUNC_m(WriteStartHeader);
00568 
00569     fio_StartTransaction_t start(m_transNumber, 
00570                                  m_transSize, 
00571                                  m_alterNumber, 
00572                                  m_freedVec_m.size(),
00573                                  m_usedVec_m.size());
00574 
00575     m_jourHnd_p->JourWrite(&start, sizeof(start));
00576     WriteUVListToJour();
00577     // TODO write freed and used vector 
00578 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::WriteUVListToJour (  )  [private]

Definition at line 887 of file fio_Transaction.cpp.

References fio_JourHandle::JourWrite(), m_freedVec_m, m_jourHnd_p, m_usedVec_m, and size.

Referenced by WriteStartHeader().

00887                                         {
00888     int size;
00889     if (0 < (size = m_freedVec_m.size())) {
00890         m_jourHnd_p->JourWrite(&*m_freedVec_m.begin(), 
00891                                sizeof(fio_UV_t) * size);
00892     }
00893 
00894     if (0 < (size = m_usedVec_m.size())) {
00895         m_jourHnd_p->JourWrite(&*m_usedVec_m.begin(), 
00896                                sizeof(fio_UV_t) * size);
00897     }
00898 /*    fio_UV_v_i iter;
00899     for(iter  = m_freedVec_m.begin();
00900         iter != m_freedVec_m.end();
00901         iter++) 
00902     {
00903         if (iter->m_idx == 0) {
00904             log_FUNC_m(WriteUVListToJour);
00905             log_ERR_m("Free UV is going to write to jour. Idx = 0  RelFileID = " << iter->m_fileID
00906                    << "  vectorSize = " << iter->m_vectorSize);
00907         }
00908 //        fio_UV_t uv(iter->first.fileID, iter->m_vectorSize, iter->m_idx);
00909         m_jourHnd_p->JourWrite(&(*iter), sizeof(fio_UV_t));
00910     }
00911 */
00912 /*
00913     for(iter  = m_usedVec_m.begin();
00914         iter != m_usedVec_m.end();
00915         iter++) 
00916     {
00917         if (iter->m_idx == 0) {
00918             log_FUNC_m(WriteUVListToJour);
00919             log_ERR_m("Used UV is going to write to jour. Idx = 0  RelFileID = " << iter->m_fileID
00920                    << "  vectorSize = " << iter->m_vectorSize);
00921         }
00922 //        fio_UV_t uv(iter->first.fileID, iter->first.vectorSize, iter->second);
00923         m_jourHnd_p->JourWrite(&(*iter), sizeof(fio_UV_t));
00924     }
00925 */
00926 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_Transaction::ReadUVListFromJour ( UInt32_t  a_numOfFreedUV,
UInt32_t  a_numOfUsedUV 
) [private]

Definition at line 930 of file fio_Transaction.cpp.

References fio_JourHandle::JourRead(), log_ERR_m, log_FUNC_m, fio_UV_t::m_fileID, fio_UV_t::m_idx, m_jourHnd_p, fio_UV_t::m_vectorSize, VectorIsFreed(), and VectorIsUsed().

Referenced by ReadTransactionFromLog().

00930                                                                                         {
00931 //            log_FUNC_m(ReadUVListFromJour);
00932 
00933     fio_UV_t uv;
00934     unsigned int i;
00935 //    log_DBG_m(dbg_DETAIL, "Num of freed UV " << a_numOfFreedUV 
00936 //                     << "  num of used UV " << a_numOfUsedUV);
00937     for (i = 0; i < a_numOfFreedUV; i++) {
00938         m_jourHnd_p->JourRead(&uv, sizeof(uv));
00939         if (uv.m_idx == 0) {
00940             log_FUNC_m(ReadUVListFromJour);
00941             log_ERR_m("Skip freed UV that is read from jour. Idx = 0  RelFileID = " << (int)uv.m_fileID
00942                    << "  vectorSize = " << uv.m_vectorSize);
00943         }
00944         else {
00945             VectorIsFreed(uv);
00946         }
00947     }
00948     for (i = 0; i < a_numOfUsedUV; i++) {
00949         m_jourHnd_p->JourRead(&uv, sizeof(uv));
00950         if (uv.m_idx == 0) {
00951             log_FUNC_m(ReadUVListFromJour);
00952             log_ERR_m("Skip used UV that is read from jour. Idx = 0  RelFileID = " << (int)uv.m_fileID
00953                    << "  vectorSize = " << uv.m_vectorSize);
00954         }
00955         else {
00956             VectorIsUsed(uv);
00957         }
00958     }
00959 }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class fio_DataBase [friend]

Definition at line 136 of file fio_Transaction.h.

friend class fio_uvListMgr [friend]

Definition at line 137 of file fio_Transaction.h.


Member Data Documentation

The transaction object is constructed by database and holds pointer to it.

The transaction is not responsible to destruct databse.

Definition at line 160 of file fio_Transaction.h.

Referenced by AbortTransaction(), EndTransaction(), PutVectorToBuffer(), ReplyAddVectorToBuffer(), ReplyRemoveVectorFromBuffer(), StartTransAnyType(), and UpdateDB().

Is obtained by database. It is used to concurrently access to list of list of unused vectors.

Definition at line 163 of file fio_Transaction.h.

Referenced by EndTransaction(), and StartTransAnyType().

Jounal handle is used to store start, end transaction header, and DB alterations between them into journal file.

Definition at line 169 of file fio_Transaction.h.

Referenced by EndTransaction(), ReadTransactionFromLog(), ReadUVListFromJour(), WriteAlterationToLog(), WriteEndHeader(), WriteStartHeader(), and WriteUVListToJour().

journal of alterations

Definition at line 172 of file fio_Transaction.h.

Referenced by ClearAlterVector(), EndTransaction(), InsertAlteration(), UpdateDB(), and WriteAlterationToLog().

bool fio_Transaction::m_valid [private]

Transaction is valid if is started and then ended.

In log file have to be stored strat and end header.

Definition at line 178 of file fio_Transaction.h.

Referenced by CleanUp(), EndTransaction(), and ReadTransactionFromLog().

This member is set to 0 by constructor and is increment by each StartTransaction method and is decremented by each EndTransaction method.

The first StratTransaction call realy write start header to log file and last EndTransaction call write end header and upade changes to DB.

Definition at line 188 of file fio_Transaction.h.

Referenced by AbortTransaction(), CleanUp(), EndTransaction(), InsertAlteration(), ReadTransactionFromLog(), and StartTransAnyType().

transaction number is set by journal manager through journal handle and it is stored in start and end transaction header.

Definition at line 194 of file fio_Transaction.h.

Referenced by AbortTransaction(), CleanUp(), EndTransaction(), ReadTransactionFromLog(), WriteEndHeader(), and WriteStartHeader().

nujmber of alteration inside transaction, each InsertAlteration() increment this number by 1

Definition at line 201 of file fio_Transaction.h.

Referenced by AbortTransaction(), CleanUp(), EndTransaction(), InsertAlteration(), ReadTransactionFromLog(), and WriteStartHeader().

Allow start transaction no mather of DB lock status.

Each start transaction event should ask DB to increase number of active transaction In case that DB is locked than DB stop StartTransaction() until unlock of DB. But lock database need to synchronize it and need a transaction for that.

Definition at line 207 of file fio_Transaction.h.

Referenced by AbortTransaction(), EndTransaction(), ExclusiveStartTransaction(), and StartTransaction().

In this map are UV that DB don't need any more.

All these freed vectors are available for DB to use them.

Definition at line 219 of file fio_Transaction.h.

Referenced by CleanUp(), EndTransaction(), PutVectorToBuffer(), ReplyAddVectorToBuffer(), WriteStartHeader(), and WriteUVListToJour().

In this map are UV that are got from UVbuffer.

Both maps will be released to proper UVbuffers after transaction commit.

Definition at line 225 of file fio_Transaction.h.

Referenced by CleanUp(), EndTransaction(), ReplyRemoveVectorFromBuffer(), WriteStartHeader(), and WriteUVListToJour().

when transaction is use for get or put to UV then is mini prevent that mini trans not trig another mini transaction

Definition at line 229 of file fio_Transaction.h.

Referenced by AbortTransaction(), EndTransaction(), ExclusiveStartTransaction(), and StartTransaction().

now only ftt_CIRC_VECT is used

Definition at line 232 of file fio_Transaction.h.

Referenced by EndTransaction(), ExclusiveStartTransaction(), StartTransaction(), and StartTransAnyType().

Reimplemented from cmn_LockOwn.

Definition at line 235 of file fio_Transaction.h.


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

Generated on Mon Feb 27 19:18:08 2012 for OPENARCHIVE by  doxygen 1.5.6