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