DB_File-Lock

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - added test of database creation failure
    - added test of database access through object interface
    - added test of RECNO database creation and usage

0.04 Fri Aug 11 09:08:48 EDT 2000
    - Three good fixes from Robert Mathews <rmathews@excitecorp.com>.
      (Thanks to him for submitting a patch!) In his own words:
      (1) The first one is nothing big: test 16 fails with BerkeleyDB
          v1.85 on solaris 5.6.  This seems to be due to the fact that
          we're creating a database (and therefore writing to it),
          but it's only read-locked.
      (2) The second is that TIEHASH assumes that SUPER::TIEHASH
          will succeed.  If it doesn't, the lockfile gets left open,
          and DESTROY is never called to close it.
      (3) I ran into one other issue: umask isn't restored if sysopen
          on the lockfile fails.  Fixed that too.

0.03 Wed Feb  2 11:06:08 EST 2000
    - stupid me! version 0.02 didn't ship with a Makefile.PL, only a Makefile.old.
      seems that I deleted the wrong file before taring up the archive after testing.
    - Lock.pm didn't have $VERSION set correctly.

Lock.pm  view on Meta::CPAN

 [$X =] tie %hash,  'DB_File::Lock', [$filename, $flags, $mode, $DB_HASH], $locking;

 ...use the same way as DB_File for the rest of the interface...

=head1 DESCRIPTION

This module provides a wrapper for the DB_File module, adding locking.

When you need locking, simply use this module in place of DB_File and
add an extra argument onto the tie command specifying if the file should
be locked for reading or writing.

The alternative is to write code like:

  open(LOCK, "<$db_filename.lock") or die;
  flock(LOCK, LOCK_SH) or die;
  tie(%db_hash, 'DB_File', $db_filename,  O_RDONLY, 0600, $DB_HASH) or die;
  ... then read the database ...
  untie(%db_hash);
  close(LOCK);

Lock.pm  view on Meta::CPAN

  # lots of processing not related to database
  
  # open database file with lock
  # work with database
  # close database and release lock

Also realize that when acquiring two locks at the same time, a deadlock
situation can be caused.

You can enter a deadlock situation if two processes simultaneously try to
acquire locks on two separate databases. Each has locked only one of
the databases, and cannot continue without locking the second. Yet this
will never be freed because it is locked by the other process. If your
processes all ask for their DB files in the same order, this situation
cannot occur.

=head1 OTHER LOCKING MODULES

There are three locking wrappers for DB_File in CPAN right now. Each one
implements locking differently and has different goals in mind. It is
therefore worth knowing the difference, so that you can pick the right
one for your application.

README  view on Meta::CPAN

DB_File::Lock version 0.05
by David Harris <dharris@drh.net>


    -- WHAT DOES THIS MODULE DO?

This module provides a wrapper for the DB_File module, adding locking.

When you need locking, simply use this module in place of DB_File and
add an extra argument onto the tie command specifying if the file should
be locked for reading or writing.

The alternative is to write code like:

  open(LOCK, "<$db_filename.lock") or die;
  flock(LOCK, LOCK_SH) or die;
  tie(%db_hash, 'DB_File', $db_filename,  O_RDONLY, 0600, $DB_HASH) or die;
  ... then read the database ...
  untie(%db_hash);
  close(LOCK);



( run in 0.966 second using v1.01-cache-2.11-cpan-49f99fa48dc )