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

(-)a/misc/migration_tools/rebuild_zebra.pl (-2 / +23 lines)
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 139-150 my $dbh = C4::Context->dbh; Link Here
139
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
140
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
140
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
141
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
141
142
143
# We need to create our own lock directory which incorporates the database instance
144
# we are indexing to facilitate multiple instances on the same machine.
145
my $lockdir = "/var/lock/koha_rebuild_zebra_" . C4::Context->config("database");
146
mkpath($lockdir, 0, 0755) unless (-d $lockdir);
147
my $lockfile = $lockdir . "/lock";
148
142
if ( $verbose_logging ) {
149
if ( $verbose_logging ) {
143
    print "Zebra configuration information\n";
150
    print "Zebra configuration information\n";
144
    print "================================\n";
151
    print "================================\n";
145
    print "Zebra biblio directory      = $biblioserverdir\n";
152
    print "Zebra biblio directory      = $biblioserverdir\n";
146
    print "Zebra authorities directory = $authorityserverdir\n";
153
    print "Zebra authorities directory = $authorityserverdir\n";
147
    print "Koha directory              = $kohadir\n";
154
    print "Koha directory              = $kohadir\n";
155
    print "Lockfile                    = $lockfile\n";
148
    print "BIBLIONUMBER in :     $biblionumbertagfield\$$biblionumbertagsubfield\n";
156
    print "BIBLIONUMBER in :     $biblionumbertagfield\$$biblionumbertagsubfield\n";
149
    print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
157
    print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
150
    print "================================\n";
158
    print "================================\n";
Lines 156-168 if ($do_munge) { Link Here
156
164
157
my $tester = XML::LibXML->new();
165
my $tester = XML::LibXML->new();
158
166
167
# The main work is done here by calling do_one_pass().  We have added locking
168
# avoid race conditions between Full rebuilds and incremental updates either from
169
# daemon mode or periodic invocation from cron.  The race can lead to an updated
170
# record being overwritten by a rebuild if the update is applied after the export
171
# by the rebuild and before the rebuild finishes (more likely to effect large
172
# catalogs).
173
open(LockFH, ">$lockfile") or die "$lockfile: $!";
159
if ($daemon_mode) {
174
if ($daemon_mode) {
160
    while (1) {
175
    while (1) {
161
        do_one_pass() if ( zebraqueue_not_empty() );
176
        # For incremental updates, skip the update if the updates are locked
177
	if (flock(LockFH, LOCK_EX|LOCK_NB)) {
178
	    do_one_pass() if ( zebraqueue_not_empty() );
179
	    flock(LockFH, LOCK_UN);
180
	}
162
        sleep $daemon_sleep;
181
        sleep $daemon_sleep;
163
    }
182
    }
164
} else {
183
} else {
184
    # all one-off invocations, wait for the lock to free
185
    flock(LockFH, LOCK_EX);
165
    do_one_pass();
186
    do_one_pass();
187
    flock(LockFH, LOCK_UN);
166
}
188
}
167
189
168
190
169
- 

Return to bug 6435