Directory-Transactional
view release on metacpan or search on metacpan
lib/Directory/Transactional.pm view on Meta::CPAN
=item nfs
If true (defaults to false), L<File::NFSLock> will be used for all locks
instead of C<flock>.
Note that on my machine the stress test reliably B<FAILS> with
L<File::NFSLock>, due to a race condition (exclusive write lock granted to two
writers simultaneously), even on a local filesystem. If you specify the C<nfs>
flag make sure your C<link> system call is truly atomic.
=item global_lock
If true instead of using fine grained locking, a global write lock is obtained
on the first call to C<txn_begin> and will be kept for as long as there is a
running transaction.
This is useful for avoiding deadlocks (there is no deadlock detection code in
the fine grained locking).
This flag is automatically set if C<nfs> is set.
=item timeout
If set will be used to specify a time limit for blocking calls to lock.
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
=head1 METHODS
=head2 Transaction Management
=over 4
=item txn_do $code, %callbacks
Executes C<$code> within a transaction in an C<eval> block.
If any error is thrown the transaction will be rolled back. Otherwise the
transaction is comitted.
C<%callbacks> can contain entries for C<commit> and C<rollback>, which are
called when the appropriate action is taken.
=item txn_begin
Begin a new transaction. Can be called even if there is already a running
transaction (nested transactions are supported).
=item txn_commit
Commit the current transaction. If it is a nested transaction, it will commit
to the parent transaction's work directory.
=item txn_rollback
Discard the current transaction, throwing away all changes since the last call
to C<txn_begin>.
=back
=head2 Lock Management
=over 4
=item lock_path_read $path, $no_parent
=item lock_path_write $path, $no_parent
Lock the resource at C<$path> for writing or reading.
By default the ancestors of C<$path> will be locked for reading to (from
outermost to innermost).
The only way to unlock a resource is by comitting the root transaction, or
aborting the transaction in which the resource was locked.
C<$path> does not have to be a real file in the C<root> directory, it is
possible to use symbolic names in order to avoid deadlocks.
Note that these methods are no-ops if C<global_lock> is set.
=back
=head2 File Access
=over 4
=item openr $path
=item openw $path
=item opena $path
=item open $mode, $path
Open a file for reading, writing (clobbers) or appending, or with a custom mode
for three arg open.
Using C<openw> or C<openr> is reccomended if that's all you need, because it
will not copy the file into the transaction work dir first.
( run in 1.097 second using v1.01-cache-2.11-cpan-14f38c9f855 )