Changeset 221 for trunk/RebuildQueue

Show
Ignore:
Timestamp:
04/05/07 20:12:37 (3 years ago)
Author:
bchoate
Message:

Updates to lock mechanism to prevent premature deletion of lock file.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/RebuildQueue/plugins/RebuildQueue/lib/RebuildQueue/Daemon.pm

    r164 r221  
    309309    my $cfg = MT::ConfigMgr->instance; 
    310310 
    311     # It's unwise to ignore locking for task manager; NoLocking should be 
    312     # limited to the DBM driver. 
    313     #if ($cfg->NoLocking) { 
    314     #    ## If the user doesn't want locking, don't try to lock anything. 
    315     #    ## Safe for tasks?? 
    316     #    return sub { }; 
    317     #} 
    318  
    319311    my $temp_dir = $cfg->TempDir; 
    320312    my $mt_dir = MT->instance->{mt_dir}; 
     
    328320        my $hostname = Sys::Hostname::hostname(); 
    329321        my $lock_tmp = $lock_name . '.' . $hostname; 
    330         my $max_lock_age = 60;    ## no. of seconds til we break the lock 
    331322        my $tries = 10;           ## no. of seconds to keep trying 
    332323        my $lock_fh = gensym(); 
     
    341332                ## link() failed, but the file exists--we got the lock. 
    342333                $got_lock++; last; 
    343             } else { 
    344                 ## Couldn't get a lock; if the lock is too old, break it. 
    345                 my $lock_age = (stat $lock_name)[10]; 
    346                 unlink $lock_name if time - $lock_age > $max_lock_age; 
    347334            } 
    348335            sleep 1; 
     
    358345        my $lock_flags = LOCK_EX | LOCK_NB; 
    359346        unless (flock $lock_fh, $lock_flags) { 
     347            # Advisory lock is still active 
    360348            close $lock_fh; 
    361             unlink $lock_name; 
    362349            return; 
    363350        }