@@ -, +, @@
conditions.
---
etc/koha-conf.xml | 1 +
misc/migration_tools/rebuild_zebra.pl | 25 ++++++++++++++++++++++++-
rewrite-config.PL | 1 +
3 files changed, 26 insertions(+), 1 deletion(-)
--- a/etc/koha-conf.xml
+++ a/etc/koha-conf.xml
@@ -283,6 +283,7 @@ __PAZPAR2_TOGGLE_XML_POST__
__OPAC_TMPL_DIR__
__INTRANET_TMPL_DIR__
__INTRANET_TMPL_DIR__/prog/en/includes/
+ __LOCK_DIR__
__LOG_DIR__
__DOC_DIR__
__BACKUP_DIR__
--- a/misc/migration_tools/rebuild_zebra.pl
+++ a/misc/migration_tools/rebuild_zebra.pl
@@ -5,6 +5,7 @@ use strict;
use C4::Context;
use Getopt::Long;
+use Fcntl qw(:flock);
use File::Temp qw/ tempdir /;
use File::Path;
use C4::Biblio;
@@ -139,12 +140,20 @@ my $dbh = C4::Context->dbh;
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
+# We need to create our own lock directory which incorporates the database instance
+# we are indexing to facilitate multiple instances on the same machine.
+
+my $lockdir = C4::Context->config("lockdir") . "/koha_rebuild_zebra_" . C4::Context->config("database");
+mkpath($lockdir, 0, 0755) unless (-d $lockdir);
+my $lockfile = $lockdir . "/lock";
+
if ( $verbose_logging ) {
print "Zebra configuration information\n";
print "================================\n";
print "Zebra biblio directory = $biblioserverdir\n";
print "Zebra authorities directory = $authorityserverdir\n";
print "Koha directory = $kohadir\n";
+ print "Lockfile = $lockfile\n";
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
print "================================\n";
@@ -156,13 +165,27 @@ if ($do_munge) {
my $tester = XML::LibXML->new();
+# The main work is done here by calling do_one_pass(). We have added locking
+# avoid race conditions between Full rebuilds and incremental updates either from
+# daemon mode or periodic invocation from cron. The race can lead to an updated
+# record being overwritten by a rebuild if the update is applied after the export
+# by the rebuild and before the rebuild finishes (more likely to effect large
+# catalogs).
+open(LockFH, ">$lockfile") or die "$lockfile: $!";
if ($daemon_mode) {
while (1) {
- do_one_pass() if ( zebraqueue_not_empty() );
+ # For incremental updates, skip the update if the updates are locked
+ if (flock(LockFH, LOCK_EX|LOCK_NB)) {
+ do_one_pass() if ( zebraqueue_not_empty() );
+ flock(LockFH, LOCK_UN);
+ }
sleep $daemon_sleep;
}
} else {
+ # all one-off invocations, wait for the lock to free
+ flock(LockFH, LOCK_EX);
do_one_pass();
+ flock(LockFH, LOCK_UN);
}
--- a/rewrite-config.PL
+++ a/rewrite-config.PL
@@ -102,6 +102,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr";
"__KOHA_GROUP__" => "koha",
"__ZEBRA_PASS__" => "zebrastripes",
"__ZEBRA_USER__" => "kohauser",
+ "__LOCK_DIR__" => "$ENV{'INSTALL_BASE'}/var/lock",
'__BACKUP_DIR__' => "$prefix/var/spool",
'__INTRANET_CGI_DIR__' => "$prefix/intranet/cgi-bin",
'__INTRANET_TMPL_DIR__' => "$prefix/intranet/templates",
--