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

#include <fio_DataBase.h>

Collaboration diagram for fio_DataBase:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 91 of file fio_DataBase.h.


Public Member Functions

 fio_DataBase (const fio_DataBaseID_t a_dataBaseID, const cmn_Path a_path, fio_RelFileTransLstMgr *a_RelFileTransLstMgr_p)
 Default constructor.
 ~fio_DataBase ()
fio_RelFileTransGetRelFileTrans (ivd_FileID_t a_fileID) const
 Return pointer to relative file object that match its file ID.
fio_RelFileTransLstMgrGetRelFileTransLstMgrRef () const
const cmn_PathGetPath () const
fio_DataBaseID_t GetDataBaseID () const
void Commit ()
 Commit all files from DB;.
void Flush ()
 Commit all files from DB;.
fio_TransactionGetTransObj ()
 Maybe will DB check each transaction instance in future.
void ReleaseTransObj (fio_Transaction **a_trans_p)
 just interface to trans list mgr to release transaction
void ReleaseTransObj (fio_Transaction &a_trans)
unsigned int GetSizeOfLoUTID ()
UInt16_t GetStartTransCount ()
 Used in unit test only is not thread safe.
int LockDB ()
 Excliusive DB lock.
int UnlockDB ()
 Release exclusive DB lock.
void Synchronize (bool a_forced)
 Before shut down and return from LockDB, the DB must be synchronized All unsaved data should be flushed to disk, for example: unused vectors in lists in relative files.
void Suspend ()
 Lock DB and Sync data Stay locked until Continue() method is invoked return 0 if command succeed.
void RegularSuspend (bool a_forced)
void Continue (long status)
 UnLock previously Suspend DB.

Public Attributes

fio_JourMgrm_jourMgr_p
 journaling manager
 log_CLASSID_m
 permanent DB information manager

Private Member Functions

void CleanUp ()
 Unfinished transactions should be cecked before database is in operation.
bool StartTransaction (fio_Transaction *a_transaction_p)
 Destroj all relative file objects and clear the vector.
void EndTransaction ()
 Transaction must notify DB about end transaction;.

Private Attributes

const fio_DataBaseID_t m_dataBaseID
 database identification it is stored
const cmn_Path m_path
 The path where relative files are placed.
fio_RelFileTransLstMgrm_RelFileTransLstMgr_p
 In vectore are storen pointers to relative file objects.
fio_TransLstMgr m_transLstMgr
 Manage list of transaction.
UInt16_t m_startTransCount
 Counter of current active (started) transaction on databse Should be accessed through m_startTrans_x mutex.
bool m_exclusiveLock
 if set DB is locked for start transaction and other that try to lock it
cmn_Mutex m_exclusiveLock_x
 For exclusive access to m_exclusiveLock member.
cmn_Condition m_releaseExclusiveLock_c
 DB is no more locked.
bool m_disableStartTrans
 If this member is true, than no transaction could be started, but should wait until UnlockDB is called;.
cmn_Mutex m_startTrans_x
 Protects access to m_disableStartTrans, m_startTransCount.
cmn_Condition m_noTransactionRun_c
 no one transaction is running
cmn_Condition m_enabledStartTrans_c
 start transaction is enabled again
bool m_suspendInProgress
bool m_suspendded
cmn_Mutex m_suspendInProgress_x
cmn_Condition m_endSuspendInProgress_c

Friends

class fio_Transaction

Constructor & Destructor Documentation

fio_DataBase::fio_DataBase ( const fio_DataBaseID_t  a_dataBaseID,
const cmn_Path  a_path,
fio_RelFileTransLstMgr a_RelFileTransLstMgr_p 
)

Default constructor.

Author:
Dejan Volk Lupo, Hermes SoftLab
If path does'n exist then constructore create it. Database open each file from a_dbfiles array.

Definition at line 45 of file fio_DataBase.cpp.

References cmn_CreatePath(), fio_TransLstMgr::Init(), ivd_NULLCHK_m, log_FUNC_m, m_jourMgr_p, m_path, m_RelFileTransLstMgr_p, m_transLstMgr, s_className, fio_RelFileTransLstMgr::SetDataBase(), Synchronize(), and fio_RelFileTransLstMgr::SyncRelFileObj().

00049         :
00050         m_dataBaseID(a_dataBaseID),
00051         m_path(a_path + string("journal")),
00052         m_RelFileTransLstMgr_p(a_RelFileTransLstMgr_p),
00053         m_startTransCount(0),
00054         m_exclusiveLock(false),
00055         m_releaseExclusiveLock_c(&m_exclusiveLock_x),
00056         m_disableStartTrans(false),
00057         m_noTransactionRun_c(&m_startTrans_x),
00058         m_enabledStartTrans_c(&m_startTrans_x),
00059         m_suspendInProgress(false),
00060         m_suspendded(false),
00061         m_endSuspendInProgress_c(&m_suspendInProgress_x)
00062 {
00063     log_FUNC_m(fio_DataBase);
00064 
00065     m_RelFileTransLstMgr_p->SetDataBase(this);
00066 
00067     // any number of reserved transaction, could be used, 
00068     m_transLstMgr.Init(this, 10);
00069 
00070     cmn_CreatePath(m_path);
00071     m_jourMgr_p =  new fio_JourMgr(this);
00072     // JourMgr may update relative files, so
00073     // sync relative file objects with DB on disk
00074     m_RelFileTransLstMgr_p->SyncRelFileObj();
00075     
00076     // just in case that DB not proper went down
00077     Synchronize(false);
00078 
00079     ivd_NULLCHK_m(m_jourMgr_p, fio_JourMgr::s_className);
00080 }
//============================================================================//

Here is the call graph for this function:

fio_DataBase::~fio_DataBase (  ) 

Definition at line 84 of file fio_DataBase.cpp.

References CleanUp(), dbg_NORM, cmn_Mutex::Lock(), LockDB(), log_DBG_m, log_FUNC_m, m_endSuspendInProgress_c, m_suspendded, m_suspendInProgress, m_suspendInProgress_x, Synchronize(), cmn_Mutex::Unlock(), UnlockDB(), and cmn_Condition::Wait().

00084                             {
00085     log_FUNC_m(~fio_DataBase);
00086 
00087 //    LockDB(); // Lock, prevent start transaction and Synchronize DB before shut down
00090     m_suspendInProgress_x.Lock();
00091     while (m_suspendInProgress) {
00092         log_DBG_m(dbg_NORM, "WAIT! DB IS SUSPEND SYNC in progress.");
00093         m_endSuspendInProgress_c.Wait();
00094     }
00095     m_suspendInProgress_x.Unlock();
00096 
00097     cmn_MutexLock l(m_suspendInProgress_x);
00098     if (!m_suspendded) {
00099         LockDB();
00100     }
00101     else {
00102        log_DBG_m(dbg_NORM, "DB IS IN SUSPEND MODE.");
00103        m_suspendded = false;
00104     }
00105     Synchronize(false);
00108     UnlockDB();
00109     CleanUp();
00110 }

Here is the call graph for this function:


Member Function Documentation

void fio_DataBase::CleanUp (  )  [inline, private]

Unfinished transactions should be cecked before database is in operation.

So this method is called inside constructor to finish them. CleanUp is invoked by destructor or constructor if something goes wrong.

Definition at line 114 of file fio_DataBase.cpp.

References Destroy(), log_FUNC_m, m_jourMgr_p, and m_RelFileTransLstMgr_p.

Referenced by ~fio_DataBase().

00114                                   {
00115     log_FUNC_m(CleanUp);
00116 
00117     delete m_jourMgr_p;
00118     Destroy(m_RelFileTransLstMgr_p);
00119 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool fio_DataBase::StartTransaction ( fio_Transaction a_transaction_p  )  [private]

Destroj all relative file objects and clear the vector.

Ivoked by CleanUp method. Transaction must ask DB to prove start transaction;

Definition at line 193 of file fio_DataBase.cpp.

References dbg_NORM, fio_Transaction::IsExclStartTrans(), cmn_Mutex::Lock(), log_DBG_m, log_FUNC_m, m_disableStartTrans, m_enabledStartTrans_c, m_startTrans_x, m_startTransCount, cmn_Mutex::Unlock(), and cmn_Condition::Wait().

Referenced by fio_Transaction::StartTransAnyType().

00193                                                                      {
00194 
00195     m_startTrans_x.Lock();
00196     if (!a_transaction_p->IsExclStartTrans()) {
00197         log_FUNC_m(StartTransaction);
00198         while (m_disableStartTrans) {
00199             log_DBG_m(dbg_NORM, "WAIT until transactions are enabled.");
00200             m_enabledStartTrans_c.Wait();
00201         }
00202     }
00203     m_startTransCount++;
00204 //    log_DBG_m(dbg_NORM, "Start transaction. Count =" << m_startTransCount);
00205     m_startTrans_x.Unlock();
00206     return true;
00207 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::EndTransaction (  )  [private]

Transaction must notify DB about end transaction;.

Definition at line 211 of file fio_DataBase.cpp.

References cmn_Condition::Broadcast(), cmn_Mutex::Lock(), m_disableStartTrans, m_noTransactionRun_c, m_startTrans_x, m_startTransCount, and cmn_Mutex::Unlock().

Referenced by fio_Transaction::AbortTransaction(), and fio_Transaction::EndTransaction().

00211                                   {
00212 //    log_FUNC_m(EndTransaction);
00213 
00214     m_startTrans_x.Lock();
00215     m_startTransCount--;
00216     if (   m_disableStartTrans 
00217        && (m_startTransCount == 0))  {
00218         m_noTransactionRun_c.Broadcast();
00219     }
00220 //    log_DBG_m(dbg_NORM, "End   transaction. Count =" << m_startTransCount);
00221     m_startTrans_x.Unlock();
00222 }

Here is the call graph for this function:

Here is the caller graph for this function:

fio_RelFileTrans* fio_DataBase::GetRelFileTrans ( ivd_FileID_t  a_fileID  )  const [inline]

Return pointer to relative file object that match its file ID.

Used for recovery and or to find proper relative files for FSC.

Definition at line 198 of file fio_DataBase.h.

Referenced by fio_Transaction::PutVectorToBuffer(), fio_Transaction::ReplyAddVectorToBuffer(), and fio_Transaction::ReplyRemoveVectorFromBuffer().

00198                                                                           {
00199         return m_RelFileTransLstMgr_p->GetRelFileTrans(a_fileID);
00200     };

Here is the caller graph for this function:

fio_RelFileTransLstMgr& fio_DataBase::GetRelFileTransLstMgrRef (  )  const [inline]

Definition at line 202 of file fio_DataBase.h.

00202                                                                     {
00203         return *m_RelFileTransLstMgr_p;
00204     };

const cmn_Path& fio_DataBase::GetPath (  )  const [inline]

Definition at line 206 of file fio_DataBase.h.

Referenced by fio_JourMgr::AddNewJourFile(), fio_JourMgr::fio_JourMgr(), and fio_JourMgr::RemoveArhivedJourFile().

00206 { return m_path; };

Here is the caller graph for this function:

fio_DataBaseID_t fio_DataBase::GetDataBaseID (  )  const [inline]

Definition at line 208 of file fio_DataBase.h.

00208 { return m_dataBaseID; };

void fio_DataBase::Commit (  )  [inline]

Commit all files from DB;.

Definition at line 211 of file fio_DataBase.h.

Referenced by fio_JourMgr::ReleaseWaiters().

Here is the caller graph for this function:

void fio_DataBase::Flush (  )  [inline]

Commit all files from DB;.

Definition at line 214 of file fio_DataBase.h.

Referenced by fio_Transaction::UpdateDB().

Here is the caller graph for this function:

fio_Transaction* fio_DataBase::GetTransObj (  )  [inline]

void fio_DataBase::ReleaseTransObj ( fio_Transaction **  a_trans_p  )  [inline]

void fio_DataBase::ReleaseTransObj ( fio_Transaction a_trans  )  [inline]

Definition at line 223 of file fio_DataBase.h.

00223 { m_transLstMgr.ReleaseTransObj(a_trans); };

unsigned int fio_DataBase::GetSizeOfLoUTID (  )  [inline]

Definition at line 225 of file fio_DataBase.h.

00225 { return m_transLstMgr.GetSizeOfLoUTID(); };

UInt16_t fio_DataBase::GetStartTransCount (  )  [inline]

Used in unit test only is not thread safe.

Definition at line 228 of file fio_DataBase.h.

00228 {return m_startTransCount;};   

int fio_DataBase::LockDB (  ) 

Excliusive DB lock.

Definition at line 144 of file fio_DataBase.cpp.

References dbg_NORM, cmn_Mutex::Lock(), log_DBG_m, log_FUNC_m, m_disableStartTrans, m_exclusiveLock, m_exclusiveLock_x, m_noTransactionRun_c, m_releaseExclusiveLock_c, m_startTrans_x, m_startTransCount, cmn_Mutex::Unlock(), and cmn_Condition::Wait().

Referenced by RegularSuspend(), and ~fio_DataBase().

00144                          {
00145     log_FUNC_m(LockDB);
00146 
00147     // exclusive DB lock 
00148     m_exclusiveLock_x.Lock();
00149     while (m_exclusiveLock) {
00150         log_DBG_m(dbg_NORM, "WAIT! DB IS LOCKED.");
00151         m_releaseExclusiveLock_c.Wait();
00152     }
00153     m_exclusiveLock = true;
00154     m_exclusiveLock_x.Unlock();
00155 
00156 
00157     m_startTrans_x.Lock();
00158     m_disableStartTrans = true;
00159     log_DBG_m(dbg_NORM, "DISABLE transaction.");
00160     while (m_startTransCount > 0) {
00161         log_DBG_m(dbg_NORM, "WAIT until current transactions are done.");
00162         log_DBG_m(dbg_NORM, "   Num of trans =" << m_startTransCount);
00163         m_noTransactionRun_c.Wait(); //TODO where to set timeout period, use ETIMEDOUT
00164     };
00165     log_DBG_m(dbg_NORM, "LOCK DB!");
00166     m_startTrans_x.Unlock();
00167 //MOVE     Synchronize(); // flush all unsaved changes to disk
00168     return 0;
00169 }

Here is the call graph for this function:

Here is the caller graph for this function:

int fio_DataBase::UnlockDB (  ) 

Release exclusive DB lock.

Definition at line 173 of file fio_DataBase.cpp.

References cmn_Condition::Broadcast(), dbg_NORM, cmn_Mutex::Lock(), log_DBG_m, log_FUNC_m, m_disableStartTrans, m_enabledStartTrans_c, m_exclusiveLock, m_exclusiveLock_x, m_releaseExclusiveLock_c, m_startTrans_x, and cmn_Mutex::Unlock().

Referenced by Continue(), and ~fio_DataBase().

00173                            {
00174     log_FUNC_m(UnlockDB);
00175 
00176     m_startTrans_x.Lock();
00177     log_DBG_m(dbg_NORM, "ENABLE transaction.");
00178     m_disableStartTrans = false;
00179     m_enabledStartTrans_c.Broadcast();
00180     m_startTrans_x.Unlock();
00181 
00182     m_exclusiveLock_x.Lock();
00183     log_DBG_m(dbg_NORM, "UNLOCK DB!");
00184     m_exclusiveLock = false;
00185     m_releaseExclusiveLock_c.Broadcast();
00186     m_exclusiveLock_x.Unlock();
00187 
00188     return 0;
00189 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::Synchronize ( bool  a_forced  ) 

Before shut down and return from LockDB, the DB must be synchronized All unsaved data should be flushed to disk, for example: unused vectors in lists in relative files.

Definition at line 123 of file fio_DataBase.cpp.

References fio_Transaction::EndTransaction(), fio_Transaction::ExclusiveStartTransaction(), GetTransObj(), log_FUNC_m, m_jourMgr_p, m_RelFileTransLstMgr_p, ReleaseTransObj(), fio_JourMgr::SetLastSyncPosition(), and fio_RelFileTransLstMgr::Synchronize().

Referenced by fio_DataBase(), RegularSuspend(), and ~fio_DataBase().

00123                                             {
00124     log_FUNC_m(Synchronize);
00125 
00126     // get transaction object to adopt DB access
00127     fio_Transaction *a_transaction_p = GetTransObj();
00128     // It is possible that starttransactin is not allowed, so use exclusive
00129     a_transaction_p->ExclusiveStartTransaction();
00130 
00131     m_RelFileTransLstMgr_p->Synchronize(a_transaction_p);
00132 
00133     a_transaction_p->EndTransaction();
00134     // release transaction object as not needed
00135     ReleaseTransObj(&a_transaction_p);
00136 
00137     // at this point is no UV in memory buffer
00138     m_jourMgr_p->SetLastSyncPosition(a_forced);
00139 
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::Suspend (  ) 

Lock DB and Sync data Stay locked until Continue() method is invoked return 0 if command succeed.

Definition at line 225 of file fio_DataBase.cpp.

References RegularSuspend().

Referenced by i_HSM_i::Suspend(), and i_FSC_i::Suspend().

00225                            {
00226     RegularSuspend(true);
00227 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::RegularSuspend ( bool  a_forced  ) 

Definition at line 230 of file fio_DataBase.cpp.

References cmn_Condition::Broadcast(), dbg_NORM, cmn_Mutex::Lock(), LockDB(), log_DBG_m, log_FUNC_m, m_endSuspendInProgress_c, m_suspendded, m_suspendInProgress, m_suspendInProgress_x, Synchronize(), cmn_Mutex::Unlock(), and cmn_Condition::Wait().

Referenced by fio_Transaction::EndTransaction(), and Suspend().

00230                                                {
00231     log_FUNC_m(RegularSuspend);
00232     m_suspendInProgress_x.Lock();
00233     while (m_suspendInProgress) {
00234         log_DBG_m(dbg_NORM, "WAIT! DB IS SUSPENDED.");
00235         m_endSuspendInProgress_c.Wait();
00236     }
00237     m_suspendInProgress = true;
00238     m_suspendInProgress_x.Unlock();
00239 
00240     LockDB();
00241     Synchronize(a_forced); // force suspend
00242 
00243     m_suspendInProgress_x.Lock();
00244     m_suspendInProgress = false;
00245     m_suspendded        = true;
00246     m_endSuspendInProgress_c.Broadcast();
00247     m_suspendInProgress_x.Unlock();
00248 }

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::Continue ( long  status  ) 

UnLock previously Suspend DB.

If status is OK then clean journal files.

Definition at line 252 of file fio_DataBase.cpp.

References fio_regularFlushUV_c, log_WriteEvent(), m_jourMgr_p, m_suspendded, m_suspendInProgress_x, fio_JourMgr::RemoveArhivedJourFile(), and UnlockDB().

Referenced by i_HSM_i::Continue(), i_FSC_i::Continue(), and fio_Transaction::EndTransaction().

00252                                        {
00253     cmn_MutexLock l(m_suspendInProgress_x);
00254     if ( status == 0 ) {
00255         m_jourMgr_p->RemoveArhivedJourFile();
00256         if (!m_suspendded) {
00257             log_WriteEvent("Suspend mode already disabled. Old archived journal files are removed.");
00258         }
00259     }
00260     if (  m_suspendded ) { 
00261         if (status == fio_regularFlushUV_c) { // regulary flush of UV
00262             // empty
00263         } else if (status == 0) {
00264             log_WriteEvent("End of suspend mode. Old archived journal files are removed.");
00265         }
00266         else {
00267             ostringstream sstr;
00268             sstr << "End of suspend mode. Old journal files are not deleted. Status " 
00269                                << status;
00270             log_WriteEvent(sstr.str());
00271         }
00272         UnlockDB();
00273         m_suspendded = false;
00274     }
00275 }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class fio_Transaction [friend]

Definition at line 92 of file fio_DataBase.h.


Member Data Documentation

database identification it is stored

Definition at line 111 of file fio_DataBase.h.

const cmn_Path fio_DataBase::m_path [private]

The path where relative files are placed.

Definition at line 114 of file fio_DataBase.h.

Referenced by fio_DataBase().

In vectore are storen pointers to relative file objects.

Definition at line 119 of file fio_DataBase.h.

Referenced by CleanUp(), fio_DataBase(), and Synchronize().

journaling manager

Definition at line 123 of file fio_DataBase.h.

Referenced by CleanUp(), Continue(), fio_Transaction::EndTransaction(), fio_DataBase(), and Synchronize().

Manage list of transaction.

See also:
fio_TransLstMgr class

Definition at line 127 of file fio_DataBase.h.

Referenced by fio_DataBase().

Counter of current active (started) transaction on databse Should be accessed through m_startTrans_x mutex.

Definition at line 131 of file fio_DataBase.h.

Referenced by EndTransaction(), LockDB(), and StartTransaction().

if set DB is locked for start transaction and other that try to lock it

Definition at line 135 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

For exclusive access to m_exclusiveLock member.

Definition at line 138 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

DB is no more locked.

Definition at line 141 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

If this member is true, than no transaction could be started, but should wait until UnlockDB is called;.

Definition at line 146 of file fio_DataBase.h.

Referenced by EndTransaction(), LockDB(), StartTransaction(), and UnlockDB().

Protects access to m_disableStartTrans, m_startTransCount.

Definition at line 149 of file fio_DataBase.h.

Referenced by EndTransaction(), LockDB(), StartTransaction(), and UnlockDB().

no one transaction is running

Definition at line 152 of file fio_DataBase.h.

Referenced by EndTransaction(), and LockDB().

start transaction is enabled again

Definition at line 155 of file fio_DataBase.h.

Referenced by StartTransaction(), and UnlockDB().

Definition at line 157 of file fio_DataBase.h.

Referenced by RegularSuspend(), and ~fio_DataBase().

Definition at line 158 of file fio_DataBase.h.

Referenced by Continue(), RegularSuspend(), and ~fio_DataBase().

Definition at line 160 of file fio_DataBase.h.

Referenced by Continue(), RegularSuspend(), and ~fio_DataBase().

Definition at line 162 of file fio_DataBase.h.

Referenced by RegularSuspend(), and ~fio_DataBase().

permanent DB information manager

Definition at line 168 of file fio_DataBase.h.


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

Generated on Mon Feb 27 19:15:31 2012 for OPENARCHIVE by  doxygen 1.5.6