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.

NOTE: It is imperative that if you are going to use DB_File with mod_perl
that you use some kind of locking wrapper -- just placing a flock before the
tie, like in regular CGI, does not cut it. For more information about why
you must do this, see the mod_perl guide:
    http://perl.apache.org/guide/dbm.html#mod_perl_and_dbm

Here are the three locking wrappers:

Tie::DB_Lock -- DB_File wrapper which creates copies of the database file
for read access, so that you have kind of a multiversioning concurrent read
system. However, updates are still serial. Use for databases where reads may
be lengthy and consistency problems may occur.

Tie::DB_LockFile -- DB_File wrapper that has the ability to lock and unlock
the database while it is being used. Avoids the tie-before-flock problem by
simply re-tie-ing the database when you get or drop a lock. Because of the
flexibility in dropping an re-acquiring the lock in the middle of a session,
this can be massaged into a system that will work with long updates and/or
reads if the application follows the hints in the POD documentation.

DB_File::Lock-- extremely lightweight DB_File wrapper that simply flocks a
lockfile before tie-ing the database and drops the lock after the untie.
Allows one to use the same lockfile for multiple databases to avoid deadlock
problems, if desired. Use for databases where updates are reads are quick
and simple flock locking semantics are enough.

This posted for reference by request of Stas. :-)

 - David Harris
   Principal Engineer, DRH Internet Services

Reply via email to