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);
}
});
}
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;
}
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;
}
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);
}
});
});
}
Aggregations