#include <robusttransaction.hxx>
Inheritance diagram for pqxx::robusttransaction< ISOLATIONLEVEL >:
Public Types | |
typedef isolation_traits< ISOLATIONLEVEL > | isolation_tag |
Isolation level is read_committed by default. | |
Public Member Functions | |
robusttransaction (connection_base &C, const PGSTD::string &TName) | |
robusttransaction (connection_base &C) | |
virtual | ~robusttransaction () throw () |
robusttransaction is similar to transaction, but spends more effort (and performance!) to deal with the hopefully rare case that the connection to the backend is lost just as the current transaction is being committed. In this case, there is no way to determine whether the backend managed to commit the transaction before noticing the loss of connection.
In such cases, this class tries to reconnect to the database and figure out what happened. It will need to store and manage some information (pretty much a user-level transaction log) in the back-end for each and every transaction just on the off chance that this problem might occur. This service level was made optional since you may not want to pay this overhead where it is not necessary. Certainly the use of this class makes no sense for local connections, or for transactions that read the database but never modify it, or for noncritical database manipulations.
Besides being slower, it's theoretically possible that robusttransaction actually fails more instead of less often than a normal transaction. This is due to the added work and complexity. What robusttransaction tries to achieve is to be more deterministic, not more successful per se.
When a user first uses a robusttransaction in a database, the class will attempt to create a log table there to keep vital transaction-related state information in. This table, located in that same database, will be called PQXXLOG_*user*, where *user* is the PostgreSQL username for that user. If the log table can not be created, the transaction fails immediately.
If the user does not have permission to create the log table, the database administrator may create one for him beforehand, and give ownership (or at least full insert/update rights) to the user. The table must contain two non-unique fields (which will never be null): "name" (of text type, varchar(256) by default) and "date" (of timestamp type). Older verions of robusttransaction also added a unique "id" field; this field is now obsolete and the log table's implicit oids are used instead. The log tables' names may be made configurable in a future version of libpqxx.
The transaction log table contains records describing unfinished transactions, i.e. ones that have been started but not, as far as the client knows, committed or aborted. This can mean any of the following:
It is safe to drop a log table when it is not in use (ie., it is empty or all records in it represent states 2-4 above). Each robusttransaction will attempt to recreate the table at its next time of use.
|
Isolation level is read_committed by default.
Reimplemented from pqxx::basic_robusttransaction. |
|
|
|
|
|
|