Search in sources :

Example 1 with STRING

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();
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) ActiveDeletedBlobCollector(org.apache.jackrabbit.oak.plugins.index.lucene.directory.ActiveDeletedBlobCollectorFactory.ActiveDeletedBlobCollector) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Iterables.transform(com.google.common.collect.Iterables.transform) PathUtils(org.apache.jackrabbit.oak.commons.PathUtils) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) LoggerFactory(org.slf4j.LoggerFactory) ManagementOperation.newManagementOperation(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.newManagementOperation) Callable(java.util.concurrent.Callable) Status.failed(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status.failed) STRING(org.apache.jackrabbit.oak.api.Type.STRING) IndexPathService(org.apache.jackrabbit.oak.plugins.index.IndexPathService) EmptyHook(org.apache.jackrabbit.oak.spi.commit.EmptyHook) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) Nonnull(javax.annotation.Nonnull) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) PROP_UNSAFE_FOR_ACTIVE_DELETION(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION) Status.initiated(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status.initiated) INDEX_DATA_CHILD_NAME(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME) Logger(org.slf4j.Logger) STATUS_RUNNING(org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_RUNNING) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Executor(java.util.concurrent.Executor) AsyncIndexInfoService(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) CompositeData(javax.management.openmbean.CompositeData) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) CheckpointMBean(org.apache.jackrabbit.oak.api.jmx.CheckpointMBean) TimeUnit(java.util.concurrent.TimeUnit) ManagementOperation(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation) TYPE_LUCENE(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE) List(java.util.List) IndexStatsMBean(org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean) Clock(org.apache.jackrabbit.oak.stats.Clock) ManagementOperation.done(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.done) Tracker(org.apache.jackrabbit.oak.spi.whiteboard.Tracker) TYPE_PROPERTY_NAME(org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME) IndexStatsMBean(org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean) Map(java.util.Map) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Iterables.transform (com.google.common.collect.Iterables.transform)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 Executor (java.util.concurrent.Executor)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 Nonnull (javax.annotation.Nonnull)1 CompositeData (javax.management.openmbean.CompositeData)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 STRING (org.apache.jackrabbit.oak.api.Type.STRING)1 CheckpointMBean (org.apache.jackrabbit.oak.api.jmx.CheckpointMBean)1 IndexStatsMBean (org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean)1 STATUS_RUNNING (org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_RUNNING)1 PathUtils (org.apache.jackrabbit.oak.commons.PathUtils)1 ManagementOperation (org.apache.jackrabbit.oak.commons.jmx.ManagementOperation)1