Lines 5-10
use strict;
Link Here
|
5 |
|
5 |
|
6 |
use C4::Context; |
6 |
use C4::Context; |
7 |
use Getopt::Long; |
7 |
use Getopt::Long; |
|
|
8 |
use Fcntl qw(:flock); |
8 |
use File::Temp qw/ tempdir /; |
9 |
use File::Temp qw/ tempdir /; |
9 |
use File::Path; |
10 |
use File::Path; |
10 |
use C4::Biblio; |
11 |
use C4::Biblio; |
Lines 153-164
my $dbh = C4::Context->dbh;
Link Here
|
153 |
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber",""); |
154 |
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber",""); |
154 |
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber",""); |
155 |
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber",""); |
155 |
|
156 |
|
|
|
157 |
# Protect against simultaneous update of the zebra index by using a lock file. |
158 |
# Create our own lock directory if its missing. This shouild be created |
159 |
# by koha-zebra-ctl.sh. |
160 |
|
161 |
my $lockdir = C4::Context->config("zebra_lockdir") // "/var/lock"; |
162 |
mkpath($lockdir, 0, oct(755)) unless (-d $lockdir); |
163 |
my $lockfile = $lockdir . "/rebuild..LCK"; |
164 |
|
156 |
if ( $verbose_logging ) { |
165 |
if ( $verbose_logging ) { |
157 |
print "Zebra configuration information\n"; |
166 |
print "Zebra configuration information\n"; |
158 |
print "================================\n"; |
167 |
print "================================\n"; |
159 |
print "Zebra biblio directory = $biblioserverdir\n"; |
168 |
print "Zebra biblio directory = $biblioserverdir\n"; |
160 |
print "Zebra authorities directory = $authorityserverdir\n"; |
169 |
print "Zebra authorities directory = $authorityserverdir\n"; |
161 |
print "Koha directory = $kohadir\n"; |
170 |
print "Koha directory = $kohadir\n"; |
|
|
171 |
print "Lockfile = $lockfile\n"; |
162 |
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n"; |
172 |
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n"; |
163 |
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n"; |
173 |
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n"; |
164 |
print "================================\n"; |
174 |
print "================================\n"; |
Lines 170-182
if ($do_munge) {
Link Here
|
170 |
|
180 |
|
171 |
my $tester = XML::LibXML->new(); |
181 |
my $tester = XML::LibXML->new(); |
172 |
|
182 |
|
|
|
183 |
# The main work is done here by calling do_one_pass(). We have added locking |
184 |
# avoid race conditions between Full rebuilds and incremental updates either from |
185 |
# daemon mode or periodic invocation from cron. The race can lead to an updated |
186 |
# record being overwritten by a rebuild if the update is applied after the export |
187 |
# by the rebuild and before the rebuild finishes (more likely to effect large |
188 |
# catalogs). |
189 |
open my $LockFH, q{>}, $lockfile or die "$lockfile: $!"; |
173 |
if ($daemon_mode) { |
190 |
if ($daemon_mode) { |
174 |
while (1) { |
191 |
while (1) { |
175 |
do_one_pass() if ( zebraqueue_not_empty() ); |
192 |
# For incremental updates, skip the update if the updates are locked |
|
|
193 |
if (flock($LockFH, LOCK_EX|LOCK_NB)) { |
194 |
do_one_pass() if ( zebraqueue_not_empty() ); |
195 |
flock($LockFH, LOCK_UN); |
196 |
} |
176 |
sleep $daemon_sleep; |
197 |
sleep $daemon_sleep; |
177 |
} |
198 |
} |
178 |
} else { |
199 |
} else { |
|
|
200 |
# all one-off invocations, wait for the lock to free |
201 |
flock($LockFH, LOCK_EX); |
179 |
do_one_pass(); |
202 |
do_one_pass(); |
|
|
203 |
flock($LockFH, LOCK_UN); |
180 |
} |
204 |
} |
181 |
|
205 |
|
182 |
|
206 |
|