https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43231

--- Comment #12 from Lisette Scheer <[email protected]> ---
Created attachment 210674
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210674&action=edit
Bug 43231: Don't let a failed ES mapping update abort the DB upgrade

The atomic update for bug 40658 (making local-number sortable) calls
Koha::SearchEngine::Elasticsearch::Indexer->update_mappings() directly
whenever Elasticsearch is enabled.

If the existing index already has local-number mapped as a plain
integer (as it did before local-number was made sortable),
Elasticsearch refuses the in-place mapping change:

  mapper [local-number] cannot be changed from type [integer] to [text]

update_mappings() catches that internally and marks the index status
as needing a full recreate/reindex, but it then re-throws, so the
exception was left to propagate out of the atomic update and abort the
whole schema upgrade - even though Elasticsearch was enabled and
otherwise working fine, and even though the failure is a known,
already-handled case.

Wrap the call in try/catch so a mapping failure only produces a
warning in the upgrade output, and the schema upgrade continues. The
"index needs to be recreated" status set by update_mappings() is
already surfaced by admin/searchengine/elasticsearch/mappings.pl and
acted on by misc/search_tools/rebuild_elasticsearch.pl, so no extra
plumbing is needed to alert admins or fix the index afterwards.

To test:
This needs Elasticsearch, and you have to fake an instance that was indexed
before bug 40658: an index where local-number is an integer, while the database
now maps local-number to text (Elasticsearch cannot change that in place).

1. Start KTD with Elasticsearch (any of es7/es8/es9 will do), e.g.
     ktd --search-engine es8 up -d
   then open a shell with
     ktd --shell
   and make sure the SearchEngine system preference is set to "Elasticsearch".
2. In the shell, build the index so that local-number is an integer:
     perl misc/search_tools/rebuild_elasticsearch.pl -d -r -b
   Check it with:
     curl -s "es:9200/koha_kohadev_biblios/_mapping?pretty" | grep -A3
'"local-number" : {'
   => the field has "type" : "integer"
3. Make the database look like it did before bug 40658 and map local-number
   to text. Run "ktd --dbshell" (outside the shell) and paste:
     UPDATE search_field SET type = '' WHERE name = 'local-number';
     UPDATE search_marc_to_field SET sort = 0
       WHERE search_field_id IN (SELECT id FROM search_field WHERE name =
'local-number');
     UPDATE systempreferences SET value = '25.1200058' WHERE variable =
'Version';
   (The Version preference is stored without dots: 25.12.00.058 is 25.1200058.
   Going back to just before 25.12.00.059 makes the upgrade run the Bug 40658
   revision again.)
4. WITHOUT this patch: in the shell run
     perl installer/data/mysql/updatedatabase.pl
   => The upgrade stops at 25.12.00.059 with:
     ERROR: Exception 'Koha::Exception' thrown 'Unable to update mappings for
     index "koha_kohadev_biblios". Reason was: "mapper [local-number] cannot be
     changed from type [integer] to [text]". Index needs to be recreated and
     reindexed'
   Nothing after 25.12.00.059 is applied (the command exits with status 1 and
   the Version preference is still 25.1200058).
5. Apply this patch, repeat step 3 (the failed run changed the database), and
   run the upgrade again.
   => This time the 25.12.00.059 revision prints a warning instead:
     Unable to update Elasticsearch mappings for local-number (...). A full
     reindex is required, run misc/search_tools/rebuild_elasticsearch.pl -r -b
   and the upgrade carries on: 25.12.00.060 and all the later revisions are
   applied, and the Version preference ends up at the current version.
6. In the staff interface go to Administration > Catalog > Search engine
   configuration (Elasticsearch).
   => It says "Index 'koha_kohadev' needs to be recreated."
7. In the shell run
     perl misc/search_tools/rebuild_elasticsearch.pl -r -b
   and reload the page from step 6.
   => The warning is gone.
8. Sign off :-D

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: David Nind <[email protected]>
Signed-off-by: Lisette Scheer <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to