Public Member Functions | Public Attributes | Private Types | Private Attributes

fio_TransGroupLock< _T, _defTransEl > Class Template Reference
[Classes for large file i/o, relative file, and DataBase]

#include <fio_TransGroupLock.h>

Collaboration diagram for fio_TransGroupLock< _T, _defTransEl >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 fio_TransGroupLock (int a_hashSize, int a_groups)
void LockByIDOwn (const fio_LockEl_t &a_ID)
bool CanLockByID (_T a_ID)
void LockByID (_T a_ID)
bool CanLockByIDOwn (fio_LockEl_t &a_ID)
void UnLockByID (_T a_id)
void UnLockByOwn (int a_groupID)
void UnLockAndFlush (fio_Transaction &a_trans)
void ReserveGroup (fio_Transaction *a_trans_p, int a_maxNumOfLocks, int a_maxWaitSeconds)
void ReleaseGroup (fio_Transaction &a_trans)

Public Attributes

 log_CLASSID_m

Private Types

typedef cmn_IDOwn< _T > fio_LockEl_t
typedef stx_GroupOfEl< _T,
_defTransEl > 
fio_ElemInTrans_v
typedef stx_Groups
< fio_ElemInTrans_v, _T > 
fio_TransGroupLock_t
typedef cmn_LockIDbyOwn< _T, 10 > fio_LockEl_v
typedef cmn_LockIDHash
< fio_LockEl_v, _T > 
fio_Hash_t
typedef fio_TransGroupLock< _T,
_defTransEl >
::fio_ElemInTrans_v::iterator 
fio_ElemInTrans_i

Private Attributes

fio_Hash_t m_hash
stx_XStack m_freeGroups
fio_TransGroupLock_t m_whoLockedElem

Detailed Description

template<class _T, int _defTransEl>
class fio_TransGroupLock< _T, _defTransEl >

Definition at line 43 of file fio_TransGroupLock.h.


Member Typedef Documentation

template<class _T , int _defTransEl>
typedef fio_TransGroupLock<_T, _defTransEl>::fio_ElemInTrans_v::iterator fio_TransGroupLock< _T, _defTransEl >::fio_ElemInTrans_i [private]

Definition at line 53 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
typedef stx_GroupOfEl<_T, _defTransEl> fio_TransGroupLock< _T, _defTransEl >::fio_ElemInTrans_v [private]

Definition at line 46 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
typedef cmn_LockIDHash<fio_LockEl_v, _T> fio_TransGroupLock< _T, _defTransEl >::fio_Hash_t [private]

Definition at line 50 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
typedef cmn_IDOwn<_T> fio_TransGroupLock< _T, _defTransEl >::fio_LockEl_t [private]

Definition at line 44 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
typedef cmn_LockIDbyOwn<_T, 10> fio_TransGroupLock< _T, _defTransEl >::fio_LockEl_v [private]

Definition at line 49 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
typedef stx_Groups<fio_ElemInTrans_v, _T> fio_TransGroupLock< _T, _defTransEl >::fio_TransGroupLock_t [private]

Definition at line 47 of file fio_TransGroupLock.h.


Constructor & Destructor Documentation

template<class _T , int _defTransEl>
fio_TransGroupLock< _T, _defTransEl >::fio_TransGroupLock ( int  a_hashSize,
int  a_groups 
) [inline]

Definition at line 56 of file fio_TransGroupLock.h.

References log_FUNC_m, fio_TransGroupLock< _T, _defTransEl >::m_freeGroups, and stx_XStack::Push().

        :
        m_hash(a_hashSize),
        m_whoLockedElem(a_groups)
    {
        log_FUNC_m(fio_TransGroupLock)
        // reserve as many IDs as group count
        for (int j = a_groups - 1; j >= 0; j--) {
            m_freeGroups.Push(j);
        }
    };

Here is the call graph for this function:


Member Function Documentation

template<class _T , int _defTransEl>
bool fio_TransGroupLock< _T, _defTransEl >::CanLockByID ( _T  a_ID  )  [inline]

Definition at line 114 of file fio_TransGroupLock.h.

References cmn_LockIDHash< _V, _T >::CanLockByID(), and fio_TransGroupLock< _T, _defTransEl >::m_hash.

                              {
        return m_hash.CanLockByID(a_ID);
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
bool fio_TransGroupLock< _T, _defTransEl >::CanLockByIDOwn ( fio_LockEl_t a_ID  )  [inline]

Definition at line 122 of file fio_TransGroupLock.h.

References cmn_LockIDHash< _V, _T >::CanLockByIDOwn(), eLckOtherOwn, eLckSameOwn, eLocked, eNotLocked, stx_Groups< _G, _T >::InsertEl(), fio_TransGroupLock< _T, _defTransEl >::m_hash, cmn_IDOwn< _T >::m_id, cmn_IDOwn< _T >::m_ownerID, and fio_TransGroupLock< _T, _defTransEl >::m_whoLockedElem.

                                            {
        switch (m_hash.CanLockByIDOwn(a_ID)) {
        case eNotLocked   :
            m_whoLockedElem.InsertEl(a_ID.m_ownerID, a_ID.m_id);
            return true;
            break;
        case eLckSameOwn  :
            return true;
            break;
        case eLckOtherOwn :
            return false;
        case eLocked :
            return false;
            break;
        default: 
            return false;
            break;
        }
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::LockByID ( _T  a_ID  )  [inline]

Definition at line 118 of file fio_TransGroupLock.h.

References cmn_LockIDHash< _V, _T >::LockByID(), and fio_TransGroupLock< _T, _defTransEl >::m_hash.

                           {
        m_hash.LockByID(a_ID);
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn ( const fio_LockEl_t a_ID  )  [inline]

Definition at line 76 of file fio_TransGroupLock.h.

References cmn_LockIDbyOwn< _T, _size >::CanLockByIDOwnNoMutex(), dbg_DETAIL, elementIsNotLocked_d, fio_Transaction::EndTransaction(), stx_Groups< _G, _T >::GetGroup(), stx_GroupOfEl< _T, _defGroupEl >::GetOwner(), cmn_LockIDHash< _V, _T >::HashFunc(), stx_Groups< _G, _T >::InsertEl(), ivd_NULLCHK_m, cmn_LockIDHash< _V, _T >::LockByIDOwn(), log_DBG_m, log_FUNC_m, fio_TransGroupLock< _T, _defTransEl >::m_hash, cmn_IDOwn< _T >::m_id, cmn_IDOwn< _T >::m_ownerID, fio_TransGroupLock< _T, _defTransEl >::m_whoLockedElem, cmn_LockIDbyOwn< _T, _size >::ReleaseMutex(), s_className, cmn_LockIDbyOwn< _T, _size >::SetMutex(), cmn_LockOwn::SetNeedFlush(), fio_Transaction::StartTransaction(), and fio_TransGroupLock< _T, _defTransEl >::UnLockByOwn().

                                               {
        log_FUNC_m(LockByIDOwn)
        // get vector that hold a lock of element
        fio_LockEl_v &lockVec = m_hash.HashFunc(a_ID);
        lockVec.SetMutex(); 
        // return the ownerID if element is locket othervice 0 and lock it
        int elemOwner = lockVec.CanLockByIDOwnNoMutex(a_ID);
        if (elemOwner == elementIsNotLocked_d) {
            m_whoLockedElem.InsertEl(a_ID.m_ownerID, a_ID.m_id);
        }
        else if (elemOwner != a_ID.m_ownerID) {
            log_DBG_m(dbg_DETAIL, "Element " << a_ID << " is locked by another owner " << elemOwner);
            if (elemOwner >= 0) { // then element is hold by multy element transaction
                                 // othervise only one element is locked with no owner
                // owner of locked element can't gone away its element is still locked by hash
                // send message "release locked elements" to owner
                m_whoLockedElem.GetGroup(elemOwner).GetOwner()->SetNeedFlush();
            }
            lockVec.ReleaseMutex(); // release the lock vector, that owner can unlock element
//            fio_Transaction* trans = reinterpret_cast<fio_Transaction*> 
            // fix bug 699  
            fio_Transaction* trans = dynamic_cast<fio_Transaction*>
                                    (m_whoLockedElem.GetGroup(a_ID.m_ownerID).GetOwner());
            ivd_NULLCHK_m(trans, fio_Transaction::s_className);
            // flush current transaction in meantime
            trans->EndTransaction();
            UnLockByOwn(a_ID.m_ownerID); // release all locked elements
            trans->StartTransaction();
            // owner is anounced. Current transaction is flushed, 
            // so it doesn't hold locked elements. 
            // Now wait for lock element by itself.
            m_hash.LockByIDOwn(a_ID);
            m_whoLockedElem.InsertEl(a_ID.m_ownerID, a_ID.m_id);
            return; // already unlocked
        }
        lockVec.ReleaseMutex();
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::ReleaseGroup ( fio_Transaction a_trans  )  [inline]

Definition at line 173 of file fio_TransGroupLock.h.

References fio_Transaction::EndTransIfStarted(), cmn_LockOwn::GetGroupID(), log_FUNC_m, fio_TransGroupLock< _T, _defTransEl >::m_freeGroups, stx_XStack::Push(), and fio_TransGroupLock< _T, _defTransEl >::UnLockByOwn().

                                                {
        log_FUNC_m(ReleaseGroup)
        a_trans.EndTransIfStarted();
//FIX 634        a_trans.EndTransaction();
        UnLockByOwn(a_trans.GetGroupID());
        m_freeGroups.Push(a_trans.GetGroupID());
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::ReserveGroup ( fio_Transaction a_trans_p,
int  a_maxNumOfLocks,
int  a_maxWaitSeconds 
) [inline]

Definition at line 163 of file fio_TransGroupLock.h.

References stx_Groups< _G, _T >::GetGroup(), cmn_LockOwn::LockOwnInit(), log_FUNC_m, fio_TransGroupLock< _T, _defTransEl >::m_freeGroups, fio_TransGroupLock< _T, _defTransEl >::m_whoLockedElem, stx_XStack::Pop(), and stx_GroupOfEl< _T, _defGroupEl >::SetOwner().

                                            {
        log_FUNC_m(ReserveGroup)
        int grpID = m_freeGroups.Pop();
        a_trans_p->LockOwnInit(grpID, a_maxNumOfLocks, a_maxWaitSeconds);
        m_whoLockedElem.GetGroup(grpID).SetOwner(a_trans_p);
//FIX 634        a_trans_p->StartTransaction();
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::UnLockAndFlush ( fio_Transaction a_trans  )  [inline]

Definition at line 154 of file fio_TransGroupLock.h.

References dbg_DETAIL, fio_Transaction::EndTransaction(), cmn_LockOwn::GetGroupID(), log_DBG_m, log_FUNC_m, and fio_TransGroupLock< _T, _defTransEl >::UnLockByOwn().

                                                  {
        log_FUNC_m(UnLockAndFlush)
        log_DBG_m(dbg_DETAIL, "Owner " << a_trans.GetGroupID() << " will flush and unlock.");
        a_trans.EndTransaction();
        UnLockByOwn(a_trans.GetGroupID());
//FIX 634        a_trans.StartTransaction();
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::UnLockByID ( _T  a_id  )  [inline]

Definition at line 142 of file fio_TransGroupLock.h.

References fio_TransGroupLock< _T, _defTransEl >::m_hash, and cmn_LockIDHash< _V, _T >::UnLockByID().

                             {
        m_hash.UnLockByID(a_id);
    };

Here is the call graph for this function:

template<class _T , int _defTransEl>
void fio_TransGroupLock< _T, _defTransEl >::UnLockByOwn ( int  a_groupID  )  [inline]

Member Data Documentation

template<class _T , int _defTransEl>
fio_TransGroupLock< _T, _defTransEl >::log_CLASSID_m

Definition at line 66 of file fio_TransGroupLock.h.

template<class _T , int _defTransEl>
stx_XStack fio_TransGroupLock< _T, _defTransEl >::m_freeGroups [private]
template<class _T , int _defTransEl>
fio_Hash_t fio_TransGroupLock< _T, _defTransEl >::m_hash [private]
template<class _T , int _defTransEl>
fio_TransGroupLock_t fio_TransGroupLock< _T, _defTransEl >::m_whoLockedElem [private]

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