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 with thread-id 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, const TransactionOwner &rCommunicatorWithTreadID)
 
void beginTransaction (const TransactionOwner &rCommunicatorWithTreadID)
 
int commitTransaction (CommunicatorTransactionStack *&prRetVal, const TransactionOwner &rCommunicatorWithTreadID)
 
void deleteAllTransactions (Communicator *pCommunicator)
 
int getActionRecord (Record *&prRetVal, EnStoreDelete &reAction, const TransactionOwner &rCommunicatorWithTreadID, const ObjID &rObjID, const std::string &rsDataPath, bool bInRecursion=false)
 
int getActionRecord (std::shared_ptr< Record > &rRetVal, EnStoreDelete &reAction, const TransactionOwner &rCommunicatorWithTreadID, const ObjID &rObjID, const std::string &rsDataPath, bool bInRecursion=false)
 
bool inTransaction (const TransactionOwner &rCommunicatorWithTreadID) const
 
int setTransactionStep (NUM_PTR &nNewTrxStepAddr, const TransactionOwner &rCommunicatorWithTreadID, EnStoreDelete eAction, Record *pActionRecord)
 

Protected Member Functions

TransactionManager::CommunicatorTransactionStackgetTransactionStack (const TransactionOwner &rCommunicatorWithTreadID)
 
void removeCurrentTransactionStack ()
 

Private Member Functions

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

Private Attributes

std::unordered_map< ObjID, Record *, glo::ObjID::HashFunctionm_RecursionRecordMap
 
std::map< TransactionOwner, CommunicatorTransactionStack *, std::less< TransactionOwner > > m_TransactionStackMap
 
std::map< TransactionOwner, 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,
const TransactionOwner & rCommunicatorWithTreadID )

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]rCommunicatorWithTreadIDThe client communicator with thread-id 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 ( const TransactionOwner & rCommunicatorWithTreadID)

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

Parameters
[in]rCommunicatorWithTreadIDThe client communicator with thread-id that starts the transaction.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ commitTransaction()

int glo::TransactionManager::commitTransaction ( CommunicatorTransactionStack *& prRetVal,
const TransactionOwner & rCommunicatorWithTreadID )

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]rCommunicatorWithTreadIDThe client communicator with thread-id 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.

◆ deleteAllTransactions()

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

All transactions, if present, of the passed client communicator are removed.

Parameters
[in]pCommunicatorThe client communicator.

◆ getActionRecord() [1/2]

int glo::TransactionManager::getActionRecord ( Record *& prRetVal,
EnStoreDelete & reAction,
const TransactionOwner & rCommunicatorWithTreadID,
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]rCommunicatorWithTreadIDThe client communicator with thread-id 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(). It is recommended to use the method of the same name with a std::shared_ptr.
Note
For Glo developers: Is implemented in GloRecordAttributeFunctions.cpp, so that extensions of data set attributes can be made there collectively.

◆ getActionRecord() [2/2]

int glo::TransactionManager::getActionRecord ( std::shared_ptr< Record > & rRetVal,
EnStoreDelete & reAction,
const TransactionOwner & rCommunicatorWithTreadID,
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]rRetValThe record, if available.
[in,out]reActionThe action how the record should be handled; save or delete.
[in]rCommunicatorWithTreadIDThe client communicator with thread-id 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.

◆ getTransactionStack()

TransactionManager::CommunicatorTransactionStack * glo::TransactionManager::getTransactionStack ( const TransactionOwner & rCommunicatorWithTreadID)
protected

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

Parameters
[in]rCommunicatorWithTreadIDThe client communicator with thread-id.
Returns
The pointer to an existing transaction stack, if any. If the client communicator has no transaction running, the return value is == nullptr.

◆ inTransaction()

bool glo::TransactionManager::inTransaction ( const TransactionOwner & rCommunicatorWithTreadID) const

Checks if passed client communicator has a transaction running.

Parameters
[in]rCommunicatorWithTreadIDThe client communicator with thread-id.
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,
const TransactionOwner & rCommunicatorWithTreadID,
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]rCommunicatorWithTreadIDThe client communicator with thread-ID that wants to process the record in a 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::unordered_map< ObjID, Record *, glo::ObjID::HashFunction > glo::TransactionManager::m_RecursionRecordMap
private

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

◆ m_TransactionStackMap

std::map< TransactionOwner, CommunicatorTransactionStack *, std::less<TransactionOwner> > 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<TransactionOwner,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: