From 245c0b00539de5806038106ec4de889ee6ee233a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Thu, 21 May 2026 23:44:46 -0300 Subject: [PATCH] Bug 42669: Fix es_indexer_daemon.pl silent job failure and NoNodes recovery When update_index() throws, the daemon now: - On NoNodes: aborts the batch, recreates the indexer object to reset the dead-node connection pool, and resets jobs to 'new' for retry. - On other errors: marks jobs as 'failed' instead of 'finished'. This prevents silent data loss where records disappear from search results because their indexing jobs were incorrectly marked as done. Signed-off-by: Martin Renvoize Signed-off-by: Lisette Scheer Signed-off-by: Lucas Gass (cherry picked from commit 3183061da95420fab5d2775e2b7019c9d29b642c) Signed-off-by: Baptiste Wojtkowski --- misc/workers/es_indexer_daemon.pl | 41 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/misc/workers/es_indexer_daemon.pl b/misc/workers/es_indexer_daemon.pl index 374e639fd6..9b7fa109de 100755 --- a/misc/workers/es_indexer_daemon.pl +++ b/misc/workers/es_indexer_daemon.pl @@ -211,6 +211,8 @@ $conn->disconnect; sub commit { my (@jobs) = @_; + return unless @jobs; + my @bib_records; my @auth_records; @@ -241,32 +243,63 @@ sub commit { } } + my $index_ok = 1; + my $no_nodes = 0; + if (@auth_records) { my $auth_chunks = natatime $at_a_time, @auth_records; - while ( ( my @auth_chunk = $auth_chunks->() ) ) { + while ( !$no_nodes && ( my @auth_chunk = $auth_chunks->() ) ) { try { $auth_indexer->update_index( \@auth_chunk ); } catch { $logger->warn( sprintf "Update of elastic index failed with: %s", $_ ); + if ( "$_" =~ /NoNodes/ ) { + $no_nodes = 1; + $auth_indexer = + Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + } else { + $index_ok = 0; + } }; } } - if (@bib_records) { + if ( !$no_nodes && @bib_records ) { my $biblio_chunks = natatime $at_a_time, @bib_records; - while ( ( my @bib_chunk = $biblio_chunks->() ) ) { + while ( !$no_nodes && ( my @bib_chunk = $biblio_chunks->() ) ) { try { $biblio_indexer->update_index( \@bib_chunk ); } catch { $logger->warn( sprintf "Update of elastic index failed with: %s", $_ ); + if ( "$_" =~ /NoNodes/ ) { + $no_nodes = 1; + $biblio_indexer = + Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + } else { + $index_ok = 0; + } }; } } + if ($no_nodes) { + + # ES is unreachable — reset jobs to 'new' so they are retried after reconnection + $logger->warn("Elasticsearch unavailable (NoNodes), resetting jobs for retry"); + $jobs->update( + { + progress => 0, + status => 'new', + started_on => undef, + } + ); + return; + } + # Finish $jobs->update( { progress => 1, - status => 'finished', + status => $index_ok ? 'finished' : 'failed', ended_on => \'NOW()', } );