NAME
Perinci::Tx::Manager - Transaction manager
VERSION
version 0.25
SYNOPSIS
# used by Perinci::Access::InProcess
DESCRIPTION
This class implements transaction and undo manager (TM), as specified by Rinci::function::Transaction and Riap::Transaction. It is meant to be instantiated by Perinci::Access::InProcess, but will also be passed to transactional functions to save undo/redo data.
It uses SQLite database to store transaction list and undo/redo data as well as transaction data directory to provide trash_dir/tmp_dir for functions that require it.
ATTRIBUTES
_tx_id
This is just a convenience so that methods that require tx_id will get the default value from here if tx_id not specified in arguments.
_nest_level
Nest level (by default 1, the outermost, increases by one for each increased nest level). A transactional function can call another transactional function, and that constitutes a nesting.
Internally, subcalls are also recorded in the call
table, and its undo/redo steps in the undo_step
/redo_step
table. However, during rollback/undo/redo, the transaction manager only directly processes outermost calls (those with nest_level=1). The function's is responsible for using the subcall (and its steps) information.
METHODS
new(%args) => OBJ
Create new object. Arguments:
pa => OBJ
Perinci::Access::InProcess object. This is required by Perinci::Tx::Manager to load/get functions when it wants to perform undo/redo/recovery. Perinci::Access::InProcess conveniently require() the Perl modules and wraps the functions.
data_dir => STR (default
~/.perinci/.tx
)max_txs => INT (default 1000)
Limit maximum number of transactions maintained by the TM, including all rolled back and committed transactions, since they are still recorded in the database. The default is 1000.
Not yet implemented.
After this limit is reached, cleanup will be performed to delete rolled back transactions, and after that committed transactions.
max_open_txs => INT (default 100)
Limit maximum number of open (in progress, aborted, prepared) transactions. This exclude resolved transactions (rolled back and committed). The default is no limit.
Not yet implemented.
After this limit is reached, starting a new transaction will fail.
max_committed_txs => INT (default 100)
Limit maximum number of committed transactions that is recorded by the database. This is equal to the number of undo steps that are remembered.
After this limit is reached, cleanup will automatically be performed so that the oldest committed transactions are purged.
Not yet implemented.
max_open_age => INT
Limit the maximum age of open transactions (in seconds). If this limit is reached, in progress transactions will automatically be purged because it times out.
Not yet implemented.
max_committed_age => INT
Limit the maximum age of committed transactions (in seconds). If this limit is reached, the old transactions will start to be purged.
Not yet implemented.
$tx->begin(%args) => RESP
Start a new transaction.
Arguments: tx_id (str, required, unless already supplied via _tx_id()), twopc (bool, optional, currently must be false since distributed transaction is not yet supported), summary (optional).
TM will create an entry for this transaction in its database.
$tx->record_call(%args) => RESP
Record a function call. This method needs to be called before function does any step.
Arguments: tx_id, f (optional, function name, will be retrieved from caller(1) if not specified, assuming the call is from the function itself), args (required, function arguments).
TM will create an entry for this call in its database.
Return call ID in enveloped response.
$tx->record_undo_step(%args) => RESP
Record an undo step. This method needs to be called before performing a step.
Arguments: tx_id, call_id, data (an array).
$tx->record_redo_step(%args) => RESP
Record a redo step. This method needs to be called before performing an undo step.
Arguments: tx_id, call_id, data (an array).
$tx->get_undo_steps(%args) => RESP
Will return (in enveloped response) an array of undo steps, e.g. [200, "OK", [["step1"], ["step2", "arg"], ...]] for the particular call.
Arguments: tx_id, call_id.
$tx->get_redo_steps(%args) => RESP
Will return (in enveloped response) an array of redo steps, e.g. [200, "OK", [["step2"], ["step1"], ...]] for the particular call.
Arguments: tx_id, call_id.
$tx->get_trash_dir => RESP
$tx->get_tmp_dir => RESP
$tx->commit(%args) => RESP
Arguments: tx_id
$tx->rollback(%args) => RESP
Arguments: tx_id, sp (optional, savepoint name to rollback to a specific savepoint only).
Currently rolling back to a savepoint is not implemented.
$tx->prepare(%args) => RESP
Currently will return 501 (not implemented). This TM does not support distributed transaction.
Arguments: tx_id
$tx->savepoint(%args) => RESP
Arguments: tx_id, sp (savepoint name).
Currently not implemented.
$tx->release_savepoint(%args) => RESP
Arguments: tx_id, sp (savepoint name).
Currently not implemented.
$tx->undo(%args) => RESP
Arguments: tx_id
$tx->redo(%args) => RESP
Arguments: tx_id
$tx->list(%args) => RESP
List transactions. Return an array of results sorted by creation date (in ascending order).
Arguments: detail (bool, default 0, whether to return transaction records instead of just a list of transaction ID's).
$tx->discard(%args) => RESP
Discard (forget) a committed transaction. The transaction will no longer be undoable.
Arguments: tx_id
$tx->discard_all(%args) => RESP
Discard (forget) all committed transactions.
SEE ALSO
DESCRIPTION
This module has Rinci metadata.
FUNCTIONS
None are exported by default, but they are exportable.
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.