use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method checkReset.
protected void checkReset(String clusterId, String shardId, String sentinelMonitorName, Set<SentinelHello> hellos) {
Set<HostPort> allKeepers = metaCache.allKeepers();
hellos.forEach((hello) -> {
HostPort sentinelAddr = hello.getSentinelAddr();
RedisClient redisConnection = null;
try {
redisConnection = sessionManager.findRedisConnection(sentinelAddr.getHost(), sentinelAddr.getPort());
StatefulRedisSentinelConnection<String, String> connection = redisConnection.connectSentinel();
List<Map<String, String>> slaves = connection.sync().slaves(sentinelMonitorName);
boolean shoudReset = false;
String reason = null;
Set<HostPort> keepers = new HashSet<>();
for (Map<String, String> slave : slaves) {
String host = slave.get("ip");
int port = Integer.parseInt(slave.get("port"));
HostPort currentSlave = new HostPort(host, port);
if (allKeepers.contains(currentSlave)) {
keepers.add(currentSlave);
}
Pair<String, String> clusterShard = metaCache.findClusterShard(currentSlave);
if (clusterShard == null) {
if (isKeeperOrDead(host, port)) {
shoudReset = true;
reason = String.format("[%s]keeper or dead, current:%s,%s, but no clustershard", currentSlave, clusterId, shardId);
} else {
String message = String.format("sentinel monitors redis %s not in xpipe", currentSlave.toString());
alertManager.alert(clusterId, shardId, currentSlave, ALERT_TYPE.SENTINEL_MONITOR_REDUNDANT_REDIS, message);
}
continue;
}
if (!ObjectUtils.equals(clusterId, clusterShard.getKey()) || !ObjectUtils.equals(shardId, clusterShard.getValue())) {
shoudReset = true;
reason = String.format("[%s], current:%s,%s, but meta:%s:%s", currentSlave, clusterId, shardId, clusterShard.getKey(), clusterShard.getValue());
break;
}
}
if (!shoudReset && keepers.size() >= 2) {
shoudReset = true;
reason = String.format("%s,%s, has %d keepers:%s", clusterId, shardId, keepers.size(), keepers);
}
if (shoudReset) {
logger.info("[reset][sentinelAddr]{}, {}, {}", sentinelAddr, sentinelMonitorName, reason);
EventMonitor.DEFAULT.logEvent(SENTINEL_TYPE, String.format("[%s]%s,%s", ALERT_TYPE.SENTINEL_RESET, sentinelAddr, reason));
connection.sync().reset(sentinelMonitorName);
}
} catch (Exception e) {
logger.error("[doAction][checkReset]" + hello, e);
} finally {
if (redisConnection != null) {
redisConnection.shutdown();
}
}
});
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method checkToAdd.
protected Set<SentinelHello> checkToAdd(String clusterId, String shardId, String sentinelMonitorName, Set<HostPort> masterDcSentinels, Set<SentinelHello> hellos, HostPort masterAddr, QuorumConfig quorumConfig) {
if (masterAddr == null) {
logger.warn("[checkToAdd][no monitor name]{}, {}", clusterId, shardId);
return Sets.newHashSet();
}
if (StringUtil.isEmpty(sentinelMonitorName)) {
logger.warn("[checkToAdd][no monitor name]{}, {}", clusterId, shardId);
return Sets.newHashSet();
}
if (hellos.size() >= quorumConfig.getTotal()) {
return Sets.newHashSet();
}
if (!checkMasterConsistent(masterAddr, hellos)) {
logger.info("[collect][master not consistent]{}, {}, {}", sentinelMonitorName, masterAddr, hellos);
return Sets.newHashSet();
}
Set<HostPort> currentSentinels = new HashSet<>();
hellos.forEach((hello -> currentSentinels.add(hello.getSentinelAddr())));
Set<SentinelHello> toAdd = new HashSet<>();
int toAddSize = quorumConfig.getTotal() - hellos.size();
int i = 0;
for (HostPort hostPort : masterDcSentinels) {
if (!currentSentinels.contains(hostPort)) {
i++;
if (i > toAddSize) {
break;
}
toAdd.add(new SentinelHello(hostPort, masterAddr, sentinelMonitorName));
}
}
return toAdd;
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class SentinelHello method fromString.
/**
* 10.15.95.133,33322,642d5452b3ffd243fdfc31a2ccf5b0b5963c161f,1942,FlightIntlGDSCacheGroup1,10.15.94.178,6379,0
*
* @param helloStr
* @return
*/
public static SentinelHello fromString(String helloStr) {
String[] split = helloStr.split("\\s*,\\s*");
if (split.length < 8) {
throw new IllegalArgumentException("hello not corrent:" + helloStr);
}
SentinelHello hello = new SentinelHello();
hello.helloStr = helloStr;
hello.sentinelAddr = new HostPort(split[0], Integer.parseInt(split[1]));
hello.masterAddr = new HostPort(split[5], Integer.parseInt(split[6]));
hello.monitorName = split[4];
return hello;
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DiskLessMonitor method addRedis.
@Override
protected void addRedis(BaseSamplePlan<DiskLessInstanceResult> plan, String dcId, RedisMeta redisMeta) {
HostPort hostPort = new HostPort(redisMeta.getIp(), redisMeta.getPort());
log.debug("[addRedis]{}", hostPort);
plan.addRedis(dcId, redisMeta, new DiskLessInstanceResult());
}
use of com.ctrip.xpipe.endpoint.HostPort in project x-pipe by ctripcorp.
the class DiskLessMonitor method sampleDiskLessOptionCheck.
private void sampleDiskLessOptionCheck(long startNanoTime, BaseSamplePlan<DiskLessInstanceResult> plan) {
for (Map.Entry<HostPort, DiskLessInstanceResult> entry : plan.getHostPort2SampleResult().entrySet()) {
HostPort hostPort = entry.getKey();
try {
RedisSession redisSession = findRedisSession(hostPort);
redisSession.conf(REPL_DISKLESS_SYNC, new Callbackable<List<String>>() {
@Override
public void success(List<String> message) {
addInstanceSuccess(startNanoTime, hostPort, message);
}
@Override
public void fail(Throwable throwable) {
addInstanceFail(startNanoTime, hostPort, throwable);
}
});
} catch (Exception e) {
addInstanceFail(startNanoTime, hostPort.getHost(), hostPort.getPort(), e);
}
}
}
Aggregations