XWIKI-9909: Concurrent database migration cause SOLR indexer to fail in place of waiting

- fix the race condition fully
- some minor refactoring to increase readability

(cherry-picked from commit 0c63cd328c8cbb91c1226a2269512ab71cbf232d on master)