Search in sources :

Example 1 with RedisSession

use of com.ctrip.xpipe.redis.console.health.RedisSession in project x-pipe by ctripcorp.

the class SentinelMonitor method notifyCollectors.

@Override
protected void notifyCollectors(Sample<InstanceSentinelResult> sample) {
    sample.getSamplePlan().getHostPort2SampleResult().keySet().forEach((hostPort) -> {
        RedisSession redisSession = findRedisSession(hostPort);
        redisSession.closeSubscribedChannel(helloChannel);
    });
    collectors.forEach((collector) -> {
        try {
            collector.collect((SentinelSample) sample);
        } catch (Exception e) {
            log.error("[notifyCollectors]", e);
        }
    });
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession)

Example 2 with RedisSession

use of com.ctrip.xpipe.redis.console.health.RedisSession in project x-pipe by ctripcorp.

the class DefaultSentinelCollector method isKeeperOrDead.

@VisibleForTesting
protected boolean isKeeperOrDead(String host, int port) {
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Object> role = new AtomicReference<>();
    try {
        RedisSession redisSession = sessionManager.findOrCreateSession(host, port);
        redisSession.role(new RedisSession.RollCallback() {

            @Override
            public void role(String roleDesc) {
                role.set(roleDesc);
                latch.countDown();
            }

            @Override
            public void fail(Throwable e) {
                logger.error("[isKeeperOrDead][fail]" + host + ":" + port, e);
                role.set(e);
                latch.countDown();
            }
        });
    } catch (Exception e) {
        role.set(e);
        logger.error("[isKeeperOrDead]" + host + ":" + port, e);
    }
    try {
        latch.await(2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        logger.error("[isKeeperOrDead]latch await error: {}", e);
    }
    if (role.get() instanceof String && Server.SERVER_ROLE.KEEPER.sameRole((String) role.get())) {
        return true;
    }
    if (role.get() instanceof RedisConnectionException) {
        return true;
    }
    logger.info("[isKeeperOrDead] role: {}", role.get());
    return false;
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) AtomicReference(java.util.concurrent.atomic.AtomicReference) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) CountDownLatch(java.util.concurrent.CountDownLatch) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 3 with RedisSession

use of com.ctrip.xpipe.redis.console.health.RedisSession in project x-pipe by ctripcorp.

the class DefaultRedisMasterCollector method isMaster.

@VisibleForTesting
protected boolean isMaster(String host, int port) {
    try {
        RedisSession redisSession = redisSessionManager.findOrCreateSession(host, port);
        String role = redisSession.roleSync();
        if (Server.SERVER_ROLE.MASTER.sameRole(role)) {
            return true;
        }
    } catch (Exception e) {
        logger.error(String.format("%s:%d", host, port), e);
    }
    return false;
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) ResourceNotFoundException(com.ctrip.xpipe.redis.console.service.exception.ResourceNotFoundException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 4 with RedisSession

use of com.ctrip.xpipe.redis.console.health.RedisSession in project x-pipe by ctripcorp.

the class SentinelMonitor method sampleSentinel.

private void sampleSentinel(long startNanoTime, BaseSamplePlan<InstanceSentinelResult> plan) {
    log.debug("[sampleSentinel]{}, {}", plan.getClusterId(), plan.getShardId());
    plan.getHostPort2SampleResult().forEach((hostPort, instanceSentinelResult) -> {
        log.debug("[sampleSentinel]{}, {}, {}", plan.getClusterId(), plan.getShardId(), hostPort);
        RedisSession redisSession = findRedisSession(hostPort);
        redisSession.subscribeIfAbsent(helloChannel, new RedisSession.SubscribeCallback() {

            @Override
            public void message(String channel, String message) {
                log.debug("[message]{},{}", hostPort, message);
                SentinelHello hello = SentinelHello.fromString(message);
                addInstanceSuccess(startNanoTime, hostPort, hello);
            }

            @Override
            public void fail(Throwable e) {
                addInstanceFail(startNanoTime, hostPort, e);
                log.error("[fail]" + hostPort, e);
            }
        });
    });
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession)

Aggregations

RedisSession (com.ctrip.xpipe.redis.console.health.RedisSession)4 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)2 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)1 ResourceNotFoundException (com.ctrip.xpipe.redis.console.service.exception.ResourceNotFoundException)1 RedisConnectionException (com.lambdaworks.redis.RedisConnectionException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1