use of org.apache.jackrabbit.oak.api.Type.STRING in project jackrabbit-oak by apache.
the class ActiveDeletedBlobCollectorMBeanImpl method waitForRunningIndexCycles.
/**
* Wait for running index cycles for 2 minutes.
*
* @return true if all running index cycles have been through; false otherwise
*/
private boolean waitForRunningIndexCycles() {
Map<IndexStatsMBean, Long> origIndexLaneToExecutinoCountMap = Maps.asMap(Sets.newHashSet(StreamSupport.stream(asyncIndexInfoService.getAsyncLanes().spliterator(), false).map(lane -> asyncIndexInfoService.getInfo(lane).getStatsMBean()).filter(bean -> {
String beanStatus;
try {
if (bean != null) {
beanStatus = bean.getStatus();
} else {
return false;
}
} catch (Exception e) {
LOG.warn("Exception during getting status for {}. Ignoring this indexer lane", bean.getName(), e);
return false;
}
return STATUS_RUNNING.equals(beanStatus);
}).collect(Collectors.toList())), IndexStatsMBean::getTotalExecutionCount);
if (!origIndexLaneToExecutinoCountMap.isEmpty()) {
LOG.info("Found running index lanes ({}). Sleep a bit before continuing.", transform(origIndexLaneToExecutinoCountMap.keySet(), IndexStatsMBean::getName));
try {
clock.waitUntil(clock.getTime() + TimeUnit.SECONDS.toMillis(1));
} catch (InterruptedException e) {
LOG.info("Thread interrupted during initial wait", e);
Thread.currentThread().interrupt();
}
}
long start = clock.getTime();
while (!origIndexLaneToExecutinoCountMap.isEmpty()) {
Map.Entry<IndexStatsMBean, Long> indexLaneEntry = origIndexLaneToExecutinoCountMap.entrySet().iterator().next();
IndexStatsMBean indexLaneBean = indexLaneEntry.getKey();
long oldExecCnt = indexLaneEntry.getValue();
long newExecCnt = indexLaneBean.getTotalExecutionCount();
String beanStatus = indexLaneBean.getStatus();
if (!STATUS_RUNNING.equals(beanStatus) || oldExecCnt != newExecCnt) {
origIndexLaneToExecutinoCountMap.remove(indexLaneBean);
LOG.info("Lane {} has moved - oldExecCnt {}, newExecCnt {}", indexLaneBean.getName(), oldExecCnt, newExecCnt);
} else if (clock.getTime() - start > TimeUnit.MINUTES.toMillis(2)) {
LOG.warn("Timed out while waiting for running index lane executions");
break;
} else {
LOG.info("Lane {} still has execution count {}. Waiting....", indexLaneBean.getName(), newExecCnt);
try {
clock.waitUntil(clock.getTime() + TimeUnit.SECONDS.toMillis(1));
} catch (InterruptedException e) {
LOG.info("Thread interrupted", e);
Thread.currentThread().interrupt();
break;
}
}
}
return origIndexLaneToExecutinoCountMap.isEmpty();
}
Aggregations