Manage Hibernate ORM exceptions thrown during mass indexing. Treat them in a global Failure Handler.
Description
Activity
Yoann RodièreApril 13, 2022 at 9:37 AM
The idea is to be able to log the identifiers that prevent the load (and won’t be indexed so), before the thread terminates
Ok. Then you don’t need InterruptedException
. This exception is typically caused by an external factor (like someone trying to kill a JVM process). It shouldn’t be thrown just because a particular entity cannot be loaded/indexed, or you have particularly wrong code somewhere
FrafApril 13, 2022 at 9:27 AM
Yes maybe. The idea is to be able to log the identifiers that prevent the load (and won’t be indexed so), before the thread terminates. Like this, we can isolate bad DB records not conforming to JPA mapping (often the case after DB data migration/integration).
Yoann RodièreApril 13, 2022 at 8:34 AM
Thanks for reporting this.
InterruptedException
should be handled by the indexation failure handlerMassIndexingFailureHandler
.
This looks like a completely separate improvement? I’ll remove this part of the description to avoid confusion; please open another ticket if you want to discuss it.
Also I don’t agree with it: if a thread gets interrupted, it should stop, period. That means not only the entities currently being loaded, but all the following entities won’t be indexed at all. If we stop the indexing process, there’s no point reporting the failure to the failure handler: , we’ll just let the mass indexer’s start
/ startAndWait
method throw an exception to let the caller know something failed.
In hibernate-search-mapper-orm-6.1.1.Final.jar library, the massIndexer run from it doesn’t catch hibernate orm exception, but only indexation exception. The latter are managed through a
MassIndexingFailureHandler
set on massIndexer Object :massIndexer.failureHandler(massIndexingFailureHandler);
Like this, indexation process is never interrupted contrary to mass load process.
Before the process of indexation, mass load is performed with class
HibernateOrmMassEntityLoader
. Method is :public void load(List<I> identifiers) throws InterruptedException {...}
Indeed, the process of mass indexing is concerning as well the hibernate ORM mass loading as the hibernate search mass indexing.
Suggested from : https://discourse.hibernate.org/t/massindexer-a-lot-of-database-records-are-not-indexed/6232/3