[system] / trunk / webwork / system / scripts / db3_tie.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/scripts/db3_tie.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 259 - (download) (as text) (annotate)
Sat Nov 17 17:40:22 2001 UTC (18 years, 1 month ago) by apizer
File size: 1675 byte(s)
reset TieMaxTries back to 30

    1 ################################################################################
    2 # WeBWorK
    3 #
    4 # Copyright (c) 1995-2001 WeBWorK Team, University of Rochester
    5 # All rights reserved
    6 #
    7 # $Id$
    8 ################################################################################
    9 
   10 use BerkeleyDB;
   11 use strict;
   12 
   13 my $TieMaxTries = 30;     # try to tie() 30 times, then fail
   14 my $TieSleepInterval = 2; # sleep 2 sec after failed tie()
   15 
   16 sub tie_hash {
   17   my($fh, $db_obj_ref, $hash_ref, $file_name, $mode_flag, $file_mode) = @_;
   18   # \$fh and \$db_obj_ref are not used by this routine.  Other databases may
   19   # require them. They are present to maintain a consistent interface
   20 
   21   my $db3_env = new BerkeleyDB::Env
   22     -Flags => DB_INIT_LOCK|DB_INIT_MPOOL,
   23     -LockDetect => DB_LOCK_DEFAULT;
   24 
   25   my $open_flag = lc $mode_flag eq 'r' ? DB_RDONLY : DB_CREATE;
   26 
   27   # try to achieve tie $Max_Tries times, with a wait of $Sleep_interval
   28   # between attempts.  Returns the database object to use for locking.
   29   foreach my $i (1..$TieMaxTries) {
   30     return if tie %$hash_ref, "BerkeleyDB::Hash",
   31       -Filename => $file_name,
   32       -Flags => $open_flag,
   33       -Mode => $file_mode,
   34       -Env => $db3_env;
   35     sleep $TieSleepInterval;
   36   }
   37 
   38   # We've exhausted all tries. Time to crap out.
   39   &wwerror($0, "Can't tie $file_name: $! ... $BerkeleyDB::Error");
   40 }
   41 
   42 sub untie_hash {
   43   my($fh, $db_obj_ref, $hash_ref, $file_name) = @_;
   44   ## \$fh and \$db_obj_ref are not used by this routine.  Other databases may
   45   ## require them. They are present to maintain a consistent interface
   46 
   47   (tied %$hash_ref)->db_sync();
   48 
   49   if(untie %$hash_ref) {
   50     # success!
   51     return 1;
   52   } else {
   53     wwerror($0, "Can't untie database $file_name");
   54   }
   55 }
   56 
   57 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9