Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends

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.

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

Detailed Description

Definition at line 105 of file fio_DataBase.h.


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

        :
        m_dataBaseID(a_dataBaseID),
        m_path(a_path + string("journal")),
        m_RelFileTransLstMgr_p(a_RelFileTransLstMgr_p),
        m_startTransCount(0),
        m_exclusiveLock(false),
        m_releaseExclusiveLock_c(&m_exclusiveLock_x),
        m_disableStartTrans(false),
        m_noTransactionRun_c(&m_startTrans_x),
        m_enabledStartTrans_c(&m_startTrans_x),
        m_suspendInProgress(false),
        m_suspendded(false),
        m_endSuspendInProgress_c(&m_suspendInProgress_x)
{
    log_FUNC_m(fio_DataBase);

    m_RelFileTransLstMgr_p->SetDataBase(this);

    // any number of reserved transaction, could be used, 
    m_transLstMgr.Init(this, 10);

    cmn_CreatePath(m_path);
    m_jourMgr_p =  new fio_JourMgr(this);
    // JourMgr may update relative files, so
    // sync relative file objects with DB on disk
    m_RelFileTransLstMgr_p->SyncRelFileObj();
    
    // just in case that DB not proper went down
    Synchronize(false);

    ivd_NULLCHK_m(m_jourMgr_p, fio_JourMgr::s_className);
}

Here is the call graph for this function:

fio_DataBase::~fio_DataBase (  ) 

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

                            {
    log_FUNC_m(~fio_DataBase);

//    LockDB(); // Lock, prevent start transaction and Synchronize DB before shut down
    m_suspendInProgress_x.Lock();
    while (m_suspendInProgress) {
        log_DBG_m(dbg_NORM, "WAIT! DB IS SUSPEND SYNC in progress.");
        m_endSuspendInProgress_c.Wait();
    }
    m_suspendInProgress_x.Unlock();

    cmn_MutexLock l(m_suspendInProgress_x);
    if (!m_suspendded) {
        LockDB();
    }
    else {
       log_DBG_m(dbg_NORM, "DB IS IN SUSPEND MODE.");
       m_suspendded = false;
    }
    Synchronize(false);
    UnlockDB();
    CleanUp();
}

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 128 of file fio_DataBase.cpp.

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

Referenced by ~fio_DataBase().

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::Commit (  )  [inline]

Commit all files from DB;.

Definition at line 225 of file fio_DataBase.h.

Referenced by fio_JourMgr::ReleaseWaiters().

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

                                       {
    cmn_MutexLock l(m_suspendInProgress_x);
    if ( status == 0 ) {
        m_jourMgr_p->RemoveArhivedJourFile();
        if (!m_suspendded) {
            log_WriteEvent("Suspend mode already disabled. Old archived journal files are removed.");
        }
    }
    if (  m_suspendded ) { 
        if (status == fio_regularFlushUV_c) { // regulary flush of UV
            // empty
        } else if (status == 0) {
            log_WriteEvent("End of suspend mode. Old archived journal files are removed.");
        }
        else {
            ostringstream sstr;
            sstr << "End of suspend mode. Old journal files are not deleted. Status " 
                               << status;
            log_WriteEvent(sstr.str());
        }
        UnlockDB();
        m_suspendded = false;
    }
}

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

                                  {
//    log_FUNC_m(EndTransaction);

    m_startTrans_x.Lock();
    m_startTransCount--;
    if (   m_disableStartTrans 
       && (m_startTransCount == 0))  {
        m_noTransactionRun_c.Broadcast();
    }
//    log_DBG_m(dbg_NORM, "End   transaction. Count =" << m_startTransCount);
    m_startTrans_x.Unlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::Flush (  )  [inline]

Commit all files from DB;.

Definition at line 228 of file fio_DataBase.h.

Referenced by fio_Transaction::UpdateDB().

Here is the caller graph for this function:

fio_DataBaseID_t fio_DataBase::GetDataBaseID (  )  const [inline]

Definition at line 222 of file fio_DataBase.h.

{ return m_dataBaseID; };

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

Definition at line 220 of file fio_DataBase.h.

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

{ return m_path; };

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 212 of file fio_DataBase.h.

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

                                                                          {
        return m_RelFileTransLstMgr_p->GetRelFileTrans(a_fileID);
    };

Here is the caller graph for this function:

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

Definition at line 216 of file fio_DataBase.h.

                                                                    {
        return *m_RelFileTransLstMgr_p;
    };

unsigned int fio_DataBase::GetSizeOfLoUTID (  )  [inline]

Definition at line 239 of file fio_DataBase.h.

UInt16_t fio_DataBase::GetStartTransCount (  )  [inline]

Used in unit test only is not thread safe.

Definition at line 242 of file fio_DataBase.h.

{return m_startTransCount;};   

fio_Transaction* fio_DataBase::GetTransObj (  )  [inline]
int fio_DataBase::LockDB (  ) 

Excliusive DB lock.

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

                         {
    log_FUNC_m(LockDB);

    // exclusive DB lock 
    m_exclusiveLock_x.Lock();
    while (m_exclusiveLock) {
        log_DBG_m(dbg_NORM, "WAIT! DB IS LOCKED.");
        m_releaseExclusiveLock_c.Wait();
    }
    m_exclusiveLock = true;
    m_exclusiveLock_x.Unlock();


    m_startTrans_x.Lock();
    m_disableStartTrans = true;
    log_DBG_m(dbg_NORM, "DISABLE transaction.");
    while (m_startTransCount > 0) {
        log_DBG_m(dbg_NORM, "WAIT until current transactions are done.");
        log_DBG_m(dbg_NORM, "   Num of trans =" << m_startTransCount);
        m_noTransactionRun_c.Wait(); //TODO where to set timeout period, use ETIMEDOUT
    };
    log_DBG_m(dbg_NORM, "LOCK DB!");
    m_startTrans_x.Unlock();
//MOVE     Synchronize(); // flush all unsaved changes to disk
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fio_DataBase::RegularSuspend ( bool  a_forced  ) 
void fio_DataBase::ReleaseTransObj ( fio_Transaction **  a_trans_p  )  [inline]
void fio_DataBase::ReleaseTransObj ( fio_Transaction a_trans  )  [inline]

Definition at line 237 of file fio_DataBase.h.

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

                                                                     {

    m_startTrans_x.Lock();
    if (!a_transaction_p->IsExclStartTrans()) {
        log_FUNC_m(StartTransaction);
        while (m_disableStartTrans) {
            log_DBG_m(dbg_NORM, "WAIT until transactions are enabled.");
            m_enabledStartTrans_c.Wait();
        }
    }
    m_startTransCount++;
//    log_DBG_m(dbg_NORM, "Start transaction. Count =" << m_startTransCount);
    m_startTrans_x.Unlock();
    return true;
}

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 239 of file fio_DataBase.cpp.

References RegularSuspend().

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

                           {
    RegularSuspend(true);
}

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

                                            {
    log_FUNC_m(Synchronize);

    // get transaction object to adopt DB access
    fio_Transaction *a_transaction_p = GetTransObj();
    // It is possible that starttransactin is not allowed, so use exclusive
    a_transaction_p->ExclusiveStartTransaction();

    m_RelFileTransLstMgr_p->Synchronize(a_transaction_p);

    a_transaction_p->EndTransaction();
    // release transaction object as not needed
    ReleaseTransObj(&a_transaction_p);

    // at this point is no UV in memory buffer
    m_jourMgr_p->SetLastSyncPosition(a_forced);

}

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

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 106 of file fio_DataBase.h.


Member Data Documentation

permanent DB information manager

Definition at line 182 of file fio_DataBase.h.

database identification it is stored

Definition at line 125 of file fio_DataBase.h.

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

Definition at line 160 of file fio_DataBase.h.

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

start transaction is enabled again

Definition at line 169 of file fio_DataBase.h.

Referenced by StartTransaction(), and UnlockDB().

Definition at line 176 of file fio_DataBase.h.

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

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

Definition at line 149 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

For exclusive access to m_exclusiveLock member.

Definition at line 152 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

journaling manager

Definition at line 137 of file fio_DataBase.h.

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

no one transaction is running

Definition at line 166 of file fio_DataBase.h.

Referenced by EndTransaction(), and LockDB().

const cmn_Path fio_DataBase::m_path [private]

The path where relative files are placed.

Definition at line 128 of file fio_DataBase.h.

Referenced by fio_DataBase().

DB is no more locked.

Definition at line 155 of file fio_DataBase.h.

Referenced by LockDB(), and UnlockDB().

In vectore are storen pointers to relative file objects.

Definition at line 133 of file fio_DataBase.h.

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

Protects access to m_disableStartTrans, m_startTransCount.

Definition at line 163 of file fio_DataBase.h.

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

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

Definition at line 145 of file fio_DataBase.h.

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

Definition at line 172 of file fio_DataBase.h.

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

Definition at line 171 of file fio_DataBase.h.

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

Definition at line 174 of file fio_DataBase.h.

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

Manage list of transaction.

See also:
fio_TransLstMgr class

Definition at line 141 of file fio_DataBase.h.

Referenced by fio_DataBase().


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