Search in sources :

Example 1 with RedisConnectionException

use of com.lambdaworks.redis.RedisConnectionException 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)

Aggregations

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