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 <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2026-05-21 23:44:46 -03:00 committed by Lucas Gass
parent 9b3751f507
commit 3183061da9
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 37 additions and 4 deletions

View File

@ -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()',
}
);