Example usage for org.apache.commons.lang3.concurrent LazyInitializer get

List of usage examples for org.apache.commons.lang3.concurrent LazyInitializer get

Introduction

In this page you can find the example usage for org.apache.commons.lang3.concurrent LazyInitializer get.

Prototype

@Override
public T get() throws ConcurrentException 

Source Link

Document

Returns the object wrapped by this instance.

Usage

From source file:com.spotify.reaper.service.SegmentRunner.java

boolean canRepair(RepairSegment segment, String keyspace, JmxProxy coordinator,
        LazyInitializer<Set<String>> busyHosts) {
    Collection<String> allHosts;
    try {/*  w ww.  ja  v a  2  s . c o  m*/
        // when hosts are coming up or going down, this method can throw an
        //  UndeclaredThrowableException
        allHosts = coordinator.tokenRangeToEndpoint(keyspace, segment.getTokenRange());
    } catch (RuntimeException e) {
        LOG.warn("SegmentRunner couldn't get token ranges from coordinator: ", e);
        String msg = "SegmentRunner couldn't get token ranges from coordinator";
        repairRunner.updateLastEvent(msg);
        return false;
    }

    for (String hostName : allHosts) {
        LOG.debug("checking host '{}' for pending compactions and other repairs (can repair?)" + " Run id '{}'",
                hostName, segment.getRunId());
        try (JmxProxy hostProxy = context.jmxConnectionFactory.connect(hostName)) {
            int pendingCompactions = hostProxy.getPendingCompactions();
            if (pendingCompactions > MAX_PENDING_COMPACTIONS) {
                LOG.info(
                        "SegmentRunner declined to repair segment {} because of too many pending "
                                + "compactions (> {}) on host \"{}\"",
                        segmentId, MAX_PENDING_COMPACTIONS, hostProxy.getHost());
                String msg = String.format("Postponed due to pending compactions (%d)", pendingCompactions);
                repairRunner.updateLastEvent(msg);
                return false;
            }
            if (hostProxy.isRepairRunning()) {
                LOG.info("SegmentRunner declined to repair segment {} because one of the hosts ({}) was "
                        + "already involved in a repair", segmentId, hostProxy.getHost());
                String msg = "Postponed due to affected hosts already doing repairs";
                repairRunner.updateLastEvent(msg);
                if (!busyHosts.get().contains(hostName)) {
                    LOG.warn("A host ({}) reported that it is involved in a repair, but there is no record "
                            + "of any ongoing repair involving the host. Sending command to abort all repairs "
                            + "on the host.", hostProxy.getHost());
                    hostProxy.cancelAllRepairs();
                }
                return false;
            }
        } catch (ReaperException e) {
            LOG.warn("SegmentRunner declined to repair segment {} because one of the hosts ({}) could "
                    + "not be connected with", segmentId, hostName);
            String msg = String.format("Postponed due to inability to connect host %s", hostName);
            repairRunner.updateLastEvent(msg);
            return false;
        } catch (RuntimeException e) {
            LOG.warn("SegmentRunner declined to repair segment {} because of an error collecting "
                    + "information from one of the hosts ({}): {}", segmentId, hostName, e);
            String msg = String.format("Postponed due to inability to collect " + "information from host %s",
                    hostName);
            repairRunner.updateLastEvent(msg);
            LOG.warn("Open files amount for process: " + getOpenFilesAmount());
            return false;
        } catch (ConcurrentException e) {
            LOG.warn("Exception thrown while listing all nodes in cluster \"{}\" with ongoing repairs: " + "{}",
                    clusterName, e);
            return false;
        }
    }
    LOG.info("It is ok to repair segment '{}' on repair run with id '{}'", segment.getId(), segment.getRunId());
    return true;
}