GlobalObjects
Loading...
Searching...
No Matches
glo::TransactionManager Class Reference

class to guarantee transactions. More...

#include <GloTransactionManager.h>

Classes

class  CommunicatorTransactionStack
 The transaction stack of a client communicator for a database. More...
 
class  TransactionBase
 Base class for TransactionPoint and TransactionStep. More...
 
class  TransactionPoint
 Objects of this class reflect a transaction start. More...
 
class  TransactionStep
 Objects of this class reflect a record operation. More...
 

Public Types

enum  EnStoreDelete { eTRX_STORE , eTRX_DELETE }
 

Public Member Functions

 TransactionManager ()
 
virtual ~TransactionManager ()
 
int abortTransaction (std::list< TransactionBase * > &rAbortedTransactionStepList, Communicator *pCommunicator)
 
void beginTransaction (Communicator *pCommunicator)
 
int commitTransaction (CommunicatorTransactionStack *&prRetVal, Communicator *pCommunicator)
 
void deleteTransaction (Communicator *pCommunicator)
 
int getActionRecord (Record *&prRetVal, EnStoreDelete &reAction, Communicator *pCommunicator, const ObjID &rObjID, const std::string &rsDataPath, bool bInRecursion=false)
 
bool inTransaction (Communicator *pCommunicator) const
 
int setTransactionStep (NUM_PTR &nNewTrxStepAddr, Communicator *pCommunicator, EnStoreDelete eAction, Record *pActionRecord)
 

Protected Member Functions

TransactionManager::CommunicatorTransactionStackgetTransactionStack (Communicator *pCommunicator)
 
void removeCurrentTransactionStack ()
 

Private Member Functions

 TransactionManager (const TransactionManager &)
 
TransactionManageroperator= (const TransactionManager &)
 
int writeTransactionFile (CommunicatorTransactionStack *pTransactionStack)
 

Private Attributes

std::map< ObjID, Record *, std::less< ObjID > > m_RecursionRecordMap
 
std::map< NUM_PTR, CommunicatorTransactionStack *, std::less< NUM_PTR > > m_TransactionStackMap
 
std::map< NUM_PTR, CommunicatorTransactionStack * >::iterator m_TransactionStackMapIterator
 

Detailed Description

class to guarantee transactions.

Objects of this class are instantiated and managed by the Manager.

Each database operation (save and delete) is packed into a transaction and passed to the Transaction Manager (e.g. action with the dependent objects).

The process looks like this: The transaction start (TransactionPoint) is placed on the transaction stack of the requesting instance and a transaction counter is incremented (set to 1 the first time).

Then each record operation (TransactionStep) is placed on the transaction stack. The TransactionStep contains the record as it looks like before the action and as it looks like after the respective action (e.g. saved or deleted).

If a new TransactionStart (TransactionPoint) is added, it is also placed on the transaction stack and the transaction counter is incremented again.

If a transaction abort (TransactionPoint) is added, the transaction stack is reduced until the last transaction start (TransactionPoint) and the transaction counter is decremented. When the first transaction start (TransactionPoint) is reached, the transaction is discarded.

If a transaction commit is placed on the transaction stack, the transaction counter is decremented (if 0, everything on the transaction stack is executed).

All accesses of a requesting instance to data to be made by the TableReaderInterface are first sent to the TransactionManager. If the TransactionManager holds the requested data records (see above, the data records after the action triggered by the requesting instance), these are delivered first. The rest is read directly from the tables by the TableReaderInterface.

Future: Execute means that a transaction file is written which is interpreted by the Manager (all actions sent to the TableWriterInterface). If everything has been processed by the TableWriterInterface, the transaction file will be deleted, otherwise not. For example, if the Manager crashes with an exception, the transaction file still exists if the transaction is not completed. In case of a restart, the system always tries to process an existing transaction file first.

Author
Helmut Jakoby

Member Enumeration Documentation

◆ EnStoreDelete

Internally, which action should be executed.

Enumerator
eTRX_STORE 

It should be stored.

eTRX_DELETE 

It should be deleted.

Constructor & Destructor Documentation

◆ TransactionManager() [1/2]

glo::TransactionManager::TransactionManager ( )

Standard onstructor.

◆ ~TransactionManager()

virtual glo::TransactionManager::~TransactionManager ( )
virtual

Destructor.

◆ TransactionManager() [2/2]

glo::TransactionManager::TransactionManager ( const TransactionManager & )
private

The copy constructor is not available.

Member Function Documentation

◆ abortTransaction()

int glo::TransactionManager::abortTransaction ( std::list< TransactionBase * > & rAbortedTransactionStepList,
Communicator * pCommunicator )

The current transaction is cancelled.

Parameters
[in,out]rAbortedTransactionStepListIn this list the rejected TransactionSteps are delivered (must be amongst other things released in the LockManager).
[in]pCommunicatorThe client communicator that aborts the transaction.
Returns
A return < 0 indicates an error.
Attention
The objects in the returned list must be removed from memory by the calling instance.

◆ beginTransaction()

void glo::TransactionManager::beginTransaction ( Communicator * pCommunicator)

Starts a new transaction by placing a new TransactionPoint on the transaction stack.

Parameters
[in]pCommunicatorThe client communicator that starts the transaction.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ commitTransaction()

int glo::TransactionManager::commitTransaction ( CommunicatorTransactionStack *& prRetVal,
Communicator * pCommunicator )

Current transaction is accepted.

Parameters
[in,out]prRetValIf return > 0, then the transaction stack of the client communicator is delivered to perform the steps.
[in]pCommunicatorThe client communicator that commits the transaction.
Returns
A return > 0 indicates that the delivered transaction stack can be processed.
A return == 0 indicates that within a nested transaction has been accepted.
A return value < 0 indicates an error.
Attention
The returned object must be removed from memory by the calling instance.

◆ deleteTransaction()

void glo::TransactionManager::deleteTransaction ( Communicator * pCommunicator)

One, possibly existing, transaction of the passed client communicator is removed.

Parameters
[in]pCommunicatorThe client communicator.

◆ getActionRecord()

int glo::TransactionManager::getActionRecord ( Record *& prRetVal,
EnStoreDelete & reAction,
Communicator * pCommunicator,
const ObjID & rObjID,
const std::string & rsDataPath,
bool bInRecursion = false )

Returns the last data record appended in the transaction stack including the database action with the passed object ID and the client communicator.

Parameters
[in,out]prRetValThe record, if available.
[in,out]reActionThe action how the record should be handled; save or delete.
[in]pCommunicatorThe client communicator that wanted to edit the record in a transaction.
[in]rObjIDThe object ID of the desired record.
[in]rsDataPathThe file path to retrieve the object IDs from files, if necessary.
[in]bInRecursionIf true, then call in itself.
Returns
A return value < 0 indicates an error.
Attention
The calling instance must remove the possibly supplied record from memory with Record::forget().
Note
For Glo developers: Is implemented in GloRecordAttributeFunctions.cpp, so that extensions of data set attributes can be made there collectively.

◆ getTransactionStack()

TransactionManager::CommunicatorTransactionStack * glo::TransactionManager::getTransactionStack ( Communicator * pCommunicator)
protected

Returns a pointer to the transaction stack of the passed client communicator.

Parameters
[in]pCommunicatorThe client communicator.
Returns
The pointer to an existing transaction stack, if any. If the client communicator has no transaction running, the return value is == NULL_PTR.

◆ inTransaction()

bool glo::TransactionManager::inTransaction ( Communicator * pCommunicator) const

Checks if passed client communicator has a transaction running.

Parameters
[in]pCommunicatorThe client communicator.
Returns
If true, the passed client communicator has a transaction running.

◆ operator=()

TransactionManager & glo::TransactionManager::operator= ( const TransactionManager & )
private

The assignment operator is not available.

◆ removeCurrentTransactionStack()

void glo::TransactionManager::removeCurrentTransactionStack ( )
protected

Removes the current transaction stack. If there is a subsequent tramsaction, it becomes the current transaction in the m_TransactionStackMap.

◆ setTransactionStep()

int glo::TransactionManager::setTransactionStep ( NUM_PTR & nNewTrxStepAddr,
Communicator * pCommunicator,
EnStoreDelete eAction,
Record * pActionRecord )

Generates a TransactionStep and places it on the transaction stack.

Parameters
[in,out]nNewTrxStepAddrThe address of the created TransactionStep to manage indexes (see also IndexPool::ObjectStrIndex::m_ReservedIndexMultiMap).
[in]pCommunicatorThe client communicator that aborts the transaction.
[in]eActionThe action how to handle the record; save or delete.
[in]pActionRecordThe record to be saved or deleted. The record is copied and not 'remembert'.
Returns
A return value < 0 indicates an error.

◆ writeTransactionFile()

int glo::TransactionManager::writeTransactionFile ( CommunicatorTransactionStack * pTransactionStack)
private

Not yet implemented!

Member Data Documentation

◆ m_RecursionRecordMap

std::map< ObjID, Record *, std::less<ObjID> > glo::TransactionManager::m_RecursionRecordMap
private

If records are read recursively, the already read records come in here.

◆ m_TransactionStackMap

std::map< NUM_PTR, CommunicatorTransactionStack *, std::less<NUM_PTR> > glo::TransactionManager::m_TransactionStackMap
private

A map with the transactions. Key is the address of the Communicator for which a transaction has been created, casted to NUM_PTR.

◆ m_TransactionStackMapIterator

std::map<NUM_PTR,CommunicatorTransactionStack*>::iterator glo::TransactionManager::m_TransactionStackMapIterator
private

An internal iterator on the map with the transactions (m_TransactionStackMap).


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