- long startTime = System.currentTimeMillis();
- SubMonitor monitor = SubMonitor.convert(progress);
- Collection<IndexedRelationsSearcher> searcherEntries = searchers.values();
- Collection<IndexedRelationsSearcherBase> immutableSearcherEntries = immutableSearchers.values();
- int count = searcherEntries.size() + immutableSearcherEntries.size();
- Semaphore sema = new Semaphore(0);
- Stream.concat(searcherEntries.stream(), immutableSearcherEntries.stream()).parallel().forEach(base -> {
- try {
- if (base.isIndexAvailable()) {
- if (base instanceof IndexedRelationsSearcher) {
- IndexedRelationsMemorySearcher searcher = ((IndexedRelationsSearcher) base).cache;
- try {
- List<Object[]> os = searcher.allDocs(monitor, session);
- ((IndexedRelationsSearcher) base).applyChanges(monitor, session, searcher.r, os);
- } catch (Exception e) {
- LOGGER.error("Could not flush", e);
- }
- }
- }
- monitor.worked(1);
- base.changeState(monitor, session, State.READY);
- } finally {
- sema.release();
- }
- });
- sema.acquire(count);
- long totalTime = System.currentTimeMillis() - startTime;
- LOGGER.info("index flush " + totalTime);