GlobalObjects
|
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::CommunicatorTransactionStack * | getTransactionStack (const TransactionOwner &rCommunicatorWithTreadID) |
void | removeCurrentTransactionStack () |
Private Member Functions | |
TransactionManager (const TransactionManager &) | |
TransactionManager & | operator= (const TransactionManager &) |
int | writeTransactionFile (CommunicatorTransactionStack *pTransactionStack) |
Private Attributes | |
std::unordered_map< ObjID, Record *, glo::ObjID::HashFunction > | m_RecursionRecordMap |
std::map< TransactionOwner, CommunicatorTransactionStack *, std::less< TransactionOwner > > | m_TransactionStackMap |
std::map< TransactionOwner, CommunicatorTransactionStack * >::iterator | m_TransactionStackMapIterator |
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.
glo::TransactionManager::TransactionManager | ( | ) |
Standard onstructor.
|
virtual |
Destructor.
|
private |
The copy constructor is not available.
int glo::TransactionManager::abortTransaction | ( | std::list< TransactionBase * > & | rAbortedTransactionStepList, |
const TransactionOwner & | rCommunicatorWithTreadID ) |
The current transaction is cancelled.
[in,out] | rAbortedTransactionStepList | In this list the rejected TransactionSteps are delivered (must be amongst other things released in the LockManager). |
[in] | rCommunicatorWithTreadID | The client communicator with thread-id that aborts the transaction. |
void glo::TransactionManager::beginTransaction | ( | const TransactionOwner & | rCommunicatorWithTreadID | ) |
Starts a new transaction by placing a new TransactionPoint on the transaction stack.
[in] | rCommunicatorWithTreadID | The client communicator with thread-id that starts the transaction. |
eut::ErrorNException | An exception is thrown if an error occurs. |
int glo::TransactionManager::commitTransaction | ( | CommunicatorTransactionStack *& | prRetVal, |
const TransactionOwner & | rCommunicatorWithTreadID ) |
Current transaction is accepted.
[in,out] | prRetVal | If return > 0, then the transaction stack of the client communicator is delivered to perform the steps. |
[in] | rCommunicatorWithTreadID | The client communicator with thread-id that commits the transaction. |
void glo::TransactionManager::deleteAllTransactions | ( | Communicator * | pCommunicator | ) |
All transactions, if present, of the passed client communicator are removed.
[in] | pCommunicator | The client communicator. |
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.
[in,out] | prRetVal | The record, if available. |
[in,out] | reAction | The action how the record should be handled; save or delete. |
[in] | rCommunicatorWithTreadID | The client communicator with thread-id that wanted to edit the record in a transaction. |
[in] | rObjID | The object ID of the desired record. |
[in] | rsDataPath | The file path to retrieve the object IDs from files, if necessary. |
[in] | bInRecursion | If true, then call in itself. |
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.
[in,out] | rRetVal | The record, if available. |
[in,out] | reAction | The action how the record should be handled; save or delete. |
[in] | rCommunicatorWithTreadID | The client communicator with thread-id that wanted to edit the record in a transaction. |
[in] | rObjID | The object ID of the desired record. |
[in] | rsDataPath | The file path to retrieve the object IDs from files, if necessary. |
[in] | bInRecursion | If true, then call in itself. |
|
protected |
Returns a pointer to the transaction stack of the passed client communicator.
[in] | rCommunicatorWithTreadID | The client communicator with thread-id. |
bool glo::TransactionManager::inTransaction | ( | const TransactionOwner & | rCommunicatorWithTreadID | ) | const |
Checks if passed client communicator has a transaction running.
[in] | rCommunicatorWithTreadID | The client communicator with thread-id. |
|
private |
The assignment operator is not available.
|
protected |
Removes the current transaction stack. If there is a subsequent tramsaction, it becomes the current transaction in the m_TransactionStackMap.
int glo::TransactionManager::setTransactionStep | ( | NUM_PTR & | nNewTrxStepAddr, |
const TransactionOwner & | rCommunicatorWithTreadID, | ||
EnStoreDelete | eAction, | ||
Record * | pActionRecord ) |
Generates a TransactionStep and places it on the transaction stack.
[in,out] | nNewTrxStepAddr | The address of the created TransactionStep to manage indexes (see also IndexPool::ObjectStrIndex::m_ReservedIndexMultiMap). |
[in] | rCommunicatorWithTreadID | The client communicator with thread-ID that wants to process the record in a transaction. |
[in] | eAction | The action how to handle the record; save or delete. |
[in] | pActionRecord | The record to be saved or deleted. The record is copied and not 'remembert'. |
|
private |
Not yet implemented!
|
private |
If records are read recursively, the already read records come in here.
|
private |
A map with the transactions. Key is the address of the Communicator for which a transaction has been created, casted to NUM_PTR.
|
private |
An internal iterator on the map with the transactions (m_TransactionStackMap).