Directory-Transactional
view release on metacpan or search on metacpan
lib/Directory/Transactional.pm view on Meta::CPAN
}
sub txn_begin {
my ( $self, @args ) = @_;
my $txn;
if ( my $p = $self->_txn ) {
# this is a child transaction
croak "Can't txn_begin if an auto transaction is still alive" if $p->auto_handle;
$txn = Directory::Transactional::TXN::Nested->new(
parent => $p,
manager => $self,
);
} else {
# this is a top level transaction
$txn = Directory::Transactional::TXN::Root->new(
@args,
manager => $self,
lib/Directory/Transactional.pm view on Meta::CPAN
directory acts like a journal entry. Recovery will rollback this transaction by
restoring all the renamed backup files. Moving the backup directory into the
work directory signifies that the transaction has comitted successfully, and
recovery will clean these files up normally.
If C<crash_detection> is enabled (the default) when reading any file from the
root directory (shared global state) the system will first check for crashed
commits.
Crashed commits are detected by means of lock files. If the backup directory is
locked that means its comitting process is still alive, but if a directory
exists without a lock then that process has crashed. A global dirty flag is
maintained to avoid needing to check all the backup directories each time.
If the commit is still running then it can be assumed that the process
comitting it still has all of its exclusive locks so reading from the root
directory is safe.
=head1 DEADLOCKS
This module does not implement deadlock detection. Unfortunately maintaing a
lib/Directory/Transactional.pm view on Meta::CPAN
=head2 Auto-Commit
If you perform any operation outside of a transaction and C<auto_commit> is
enabled a transaction will be created for you.
For operations like C<rename> or C<readdir> which do not return resource the
transaction is comitted immediately.
Operations like C<open> or C<file_stream> on the other create a transaction
that will be alive as long as the return value is alive.
This means that you should not leak filehandles when relying on autocommit.
Opening a new transaction when an automatic one is already opened is an error.
Note that this resource tracking comes with an overhead, especially on Perl
5.8, so even if you are only performing read operations it is reccomended that
you operate within the scope of a real transaction.
=head2 Open Filehandles
lib/Directory/Transactional.pm view on Meta::CPAN
If you are experiencing deadlocks it is reccomended to set this or
C<global_lock>.
=item auto_commit
If true (the default) any operation not performed within a transaction will
cause a transaction to be automatically created and comitted.
Transactions automatically created for operations which return things like
filehandles will stay alive for as long as the returned resource does.
=item crash_detection
IF true (the default), all read operations accessing global state (the root
directory) will first ensure that the global directory is not dirty.
If the perl process crashes while comitting the transaction but other
concurrent processes are still alive, the directory is left in an inconsistent
state, but all the locks are dropped. When C<crash_detection> is enabled ACID
semantics are still guaranteed, at the cost of locking and stating a file for
each read operation on the global directory.
If you disable this then you are only protected from system crashes (recovery
will be run on the next instantiation of L<Directory::Transactional>) or soft
crashes where the crashing process has a chance to run all its destructors
properly.
=back
( run in 0.762 second using v1.01-cache-2.11-cpan-39bf76dae61 )