View | Details | Raw Unified | Return to bug 11078
Collapse All | Expand All

(-)a/misc/migration_tools/rebuild_zebra.pl (-5 / +25 lines)
Lines 43-48 my $where; Link Here
43
my $offset;
43
my $offset;
44
my $run_as_root;
44
my $run_as_root;
45
my $run_user = (getpwuid($<))[0];
45
my $run_user = (getpwuid($<))[0];
46
my $use_flock;
46
47
47
my $verbose_logging = 0;
48
my $verbose_logging = 0;
48
my $zebraidx_log_opt = " -v none,fatal,warn ";
49
my $zebraidx_log_opt = " -v none,fatal,warn ";
Lines 185-201 open my $LockFH, q{>}, $lockfile or die "$lockfile: $!"; Link Here
185
if ($daemon_mode) {
186
if ($daemon_mode) {
186
    while (1) {
187
    while (1) {
187
        # For incremental updates, skip the update if the updates are locked
188
        # For incremental updates, skip the update if the updates are locked
188
        if (flock($LockFH, LOCK_EX|LOCK_NB)) {
189
        if (_flock($LockFH, LOCK_EX|LOCK_NB)) {
189
            do_one_pass() if ( zebraqueue_not_empty() );
190
            do_one_pass() if ( zebraqueue_not_empty() );
190
            flock($LockFH, LOCK_UN);
191
            _flock($LockFH, LOCK_UN);
191
        }
192
        }
192
        sleep $daemon_sleep;
193
        sleep $daemon_sleep;
193
    }
194
    }
194
} else {
195
} else {
195
    # all one-off invocations, wait for the lock to free
196
    # all one-off invocations, wait for the lock to free
196
    flock($LockFH, LOCK_EX);
197
    _flock($LockFH, LOCK_EX);
197
    do_one_pass();
198
    do_one_pass();
198
    flock($LockFH, LOCK_UN);
199
    _flock($LockFH, LOCK_UN);
199
}
200
}
200
201
201
202
Lines 749-754 sub do_indexing { Link Here
749
750
750
}
751
}
751
752
753
sub _flock {
754
# test if flock is present; if so, use it; if not, return true
755
# op refers to the official flock operations incl LOCK_EX, LOCK_UN, etc.
756
# combining LOCK_EX with LOCK_NB returns immediately
757
    my ($fh, $op)= @_;
758
    if( !defined($use_flock) ) {
759
        #check if flock is present; if not, you will have a fatal error
760
        my $i=eval('flock($fh, $op)');
761
        #assuming that $fh and $op are fine(..), an undef i means no flock
762
        $use_flock= defined($i)? 1: 0;
763
        print "Warning: flock could not be used!\n" if $verbose_logging && !$use_flock;
764
        return 1 if !$use_flock;
765
        return $i;
766
    }
767
    else {
768
        return 1 if !$use_flock;
769
        return flock($fh, $op);
770
    }
771
}
772
752
sub print_usage {
773
sub print_usage {
753
    print <<_USAGE_;
774
    print <<_USAGE_;
754
$0: reindex MARC bibs and/or authorities in Zebra.
775
$0: reindex MARC bibs and/or authorities in Zebra.
755
- 

Return to bug 11078