Bug 21872: Simplify conditions and exit on invalid combination of arguments
authorDavid Gustafsson <david.gustafsson@ub.gu.se>
Thu, 14 Feb 2019 14:06:35 +0000 (15:06 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 10 May 2019 12:31:49 +0000 (12:31 +0000)
Change to zero based indexing for slice index to simplify some
conditions. Exit with error message if trying to combine processes
and biblio numbers arguments.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/BiblioUtils.pm
Koha/MetadataRecord/Authority.pm
misc/search_tools/rebuild_elastic_search.pl

index c83d945..88395a9 100644 (file)
@@ -131,8 +131,6 @@ sub get_all_biblios_iterator {
     if ($options{slice}) {
         $slice_count = $options{slice}->{count};
         $slice_modulo = $options{slice}->{index};
-        $slice_modulo = 0 if ($slice_modulo == $slice_count);
-
         $search_terms = \[ ' mod(biblionumber, ?) = ?', $slice_count, $slice_modulo];
     }
 
index db14c5d..3a188e7 100644 (file)
@@ -183,8 +183,6 @@ sub get_all_authorities_iterator {
     if ($options{slice}) {
         $slice_count = $options{slice}->{count};
         $slice_modulo = $options{slice}->{index};
-        $slice_modulo = 0 if ($slice_modulo == $slice_count);
-
         $search_terms->{authid} = \[ ' mod ? = ?', $slice_count, $slice_modulo];
         $search_terms = {
             '-and' => [
index 588a955..696c0b1 100755 (executable)
@@ -125,6 +125,10 @@ unless ($index_authorities || $index_biblios) {
     $index_authorities = $index_biblios = 1;
 }
 
+if ($processes && @record_numbers) {
+    die "Argument p|processes cannot be combined with bn|bnumber";
+}
+
 pod2usage(1) if $help;
 pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
 
@@ -135,11 +139,12 @@ _verify_index_state($Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX, $dele
 
 my $slice_index = 0;
 my $slice_count = $processes // 1;
+my %iterator_options;
 
 if ($slice_count > 1) {
     # Fire up child processes for processing slices from 2 on. This main process will handle slice 1.
-    $slice_index = 1;
-    for (my $proc = 2; $proc <= $processes; $proc++) {
+    $slice_index = 0;
+    for (my $proc = 1; $proc < $slice_count; $proc++) {
         my $pid = fork();
         die "Failed to fork a child process\n" unless defined $pid;
         if ($pid == 0) {
@@ -149,12 +154,8 @@ if ($slice_count > 1) {
         }
     }
     # Fudge the commit count a bit to spread out the Elasticsearch commits
-    $commit *= 1 + 0.10 * ($slice_index - 1);
-}
-
-my %iterator_options;
-if ($slice_index) {
-    _log(1, "Processing slice $slice_index of $slice_count\n");
+    $commit *= 1 + 0.10 * $slice_index;
+    _log(1, "Processing slice @{[$slice_index + 1]} of $slice_count\n");
     $iterator_options{slice} = { index => $slice_index, count => $slice_count };
 }
 
@@ -193,16 +194,16 @@ if ($index_authorities) {
     _do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX);
 }
 
-if ($slice_index == 1) {
+if ($slice_index == 0) {
     # Main process, wait for children
-    for (my $proc = 2; $proc <= $processes; $proc++) {
+    for (my $proc = 1; $proc < $processes; $proc++) {
         wait();
     }
 }
 
 =head2 _verify_index_state
 
-    _                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       verify_index_state($Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX, 1);
+    _verify_index_state($Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX, 1);
 
 Checks the index state and recreates it if requested.