Performing checkout renewal with ES turned on causes race condition in BackgroundJobs processing, manifesting with lines like: [2023/03/20 17:18:10] [WARN] No job found for id=13218 main:: /usr/share/koha/bin/background_jobs_worker.pl (114) in worker-output.log. This is due to calling -- inside transaction -- $item_object->store in C4::Circulation::AddRenewal. [Koha::Item->store in turn calls $indexer->index_records, which in installations with ES creates BackgroundJob]. The solution could be similar to that proposed in Bug 33019, i.e. calling $item_object->store with {skip_record_index => 1} and calling $indexer->index_records after the transaction ends.
Created attachment 148569 [details] [review] Bug 33309: Index items after renewal transaction completes This patch ensures a record is indexed only after the renewal transaction has completed successfully. Otherwise the job cannot be found by the background process worker, becaue it was not yet in the DB To test: 1 - Make sure you are using ES, and the es indexer is running 2 - tail -f /var/log/koha/kohadev/*.log 3 - Issue an item to a patron and renew it 4 - Note error in es-indexer-output.log like: [2023/03/21 12:22:36] [WARN] No job found for id=157 main:: /kohadevbox/koha/misc/workers/es_indexer_daemon.pl (129) 5 - Apply patch 6 - Renew again 7 There should be no error 8 - Search for the record and confirm items info displays correctly 9 - View the background jobs in admin, confirm the most recent job has completed
The only comment I would have for the testers -- since it is a race condition, not for every renewal would happen the issue signalized by "No job found for id=nnn"; sometimes everything would proceed smoothly.
Created attachment 148573 [details] [review] Bug 33309: Index items after renewal transaction completes This patch ensures a record is indexed only after the renewal transaction has completed successfully. Otherwise the job cannot be found by the background process worker, becaue it was not yet in the DB To test: 1 - Make sure you are using ES, and the es indexer is running 2 - tail -f /var/log/koha/kohadev/*.log 3 - Issue an item to a patron and renew it 4 - Note error in es-indexer-output.log like: [2023/03/21 12:22:36] [WARN] No job found for id=157 main:: /kohadevbox/koha/misc/workers/es_indexer_daemon.pl (129) 5 - Apply patch 6 - Renew again 7 There should be no error 8 - Search for the record and confirm items info displays correctly 9 - View the background jobs in admin, confirm the most recent job has completed Signed-off-by: Janusz Kaczmarek <januszop@gmail.com>
Created attachment 148605 [details] [review] Bug 33309: Index items after renewal transaction completes This patch ensures a record is indexed only after the renewal transaction has completed successfully. Otherwise the job cannot be found by the background process worker, becaue it was not yet in the DB To test: 1 - Make sure you are using ES, and the es indexer is running 2 - tail -f /var/log/koha/kohadev/*.log 3 - Issue an item to a patron and renew it 4 - Note error in es-indexer-output.log like: [2023/03/21 12:22:36] [WARN] No job found for id=157 main:: /kohadevbox/koha/misc/workers/es_indexer_daemon.pl (129) 5 - Apply patch 6 - Renew again 7 There should be no error 8 - Search for the record and confirm items info displays correctly 9 - View the background jobs in admin, confirm the most recent job has completed Signed-off-by: Janusz Kaczmarek <januszop@gmail.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Pushed to master for 23.05. Nice work everyone, thanks!
Nice work everyone! Pushed to stable for 22.11.x
Backported to 22.05.x for upcoming 22.05.12
applied to 21.11.x for 21.11.20