use of org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean in project jackrabbit-oak by apache.
the class AsyncIndexerServiceTest method asyncReg.
@Test
public void asyncReg() throws Exception {
injectDefaultServices();
Map<String, Object> config = ImmutableMap.<String, Object>of("asyncConfigs", new String[] { "async:5" });
MockOsgi.activate(service, context.bundleContext(), config);
assertNotNull(context.getService(Runnable.class));
assertEquals(TimeUnit.MINUTES.toMillis(15), getIndexUpdate("async").getLeaseTimeOut());
AsyncIndexUpdate indexUpdate = getIndexUpdate("async");
IndexStatsMBean mbean = context.getService(IndexStatsMBean.class);
assertNotNull(mbean);
assertEquals("async", mbean.getName());
MockOsgi.deactivate(service, context.bundleContext());
assertNull(context.getService(Runnable.class));
assertTrue(indexUpdate.isClosed());
}
use of org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean in project jackrabbit-oak by apache.
the class SimpleToken method lock.
@Override
public SimpleToken lock(String asyncIndexerLane) {
IndexStatsMBean mbean = getIndexStatsMBean(asyncIndexerLane);
if (IndexStatsMBean.STATUS_RUNNING.equals(mbean.getStatus())) {
log.info("Aborting current indexing run of async indexer for lane [{}]", asyncIndexerLane);
}
mbean.abortAndPause();
retry(mbean, TIMEOUT_SECONDS, 1000);
log.info("Aborted and paused async indexer for lane [{}]", asyncIndexerLane);
return new SimpleToken(asyncIndexerLane);
}
use of org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean 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