Search in sources :

Example 51 with HostPort

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();
            }
        }
    });
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) RedisClient(com.lambdaworks.redis.RedisClient) Map(java.util.Map) HashSet(java.util.HashSet)

Example 52 with HostPort

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;
}
Also used : AlertManager(com.ctrip.xpipe.redis.console.alert.AlertManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AtomicReference(java.util.concurrent.atomic.AtomicReference) Server(com.ctrip.xpipe.api.server.Server) HashSet(java.util.HashSet) QuorumConfig(com.ctrip.xpipe.redis.core.meta.QuorumConfig) DefaultRedisSessionManager(com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager) Map(java.util.Map) HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisConnectionException(com.lambdaworks.redis.RedisConnectionException) EventMonitor(com.ctrip.xpipe.api.monitor.EventMonitor) ConsoleConfig(com.ctrip.xpipe.redis.console.config.ConsoleConfig) MasterNotFoundException(com.ctrip.xpipe.redis.console.resources.MasterNotFoundException) StatefulRedisSentinelConnection(com.lambdaworks.redis.sentinel.api.StatefulRedisSentinelConnection) Logger(org.slf4j.Logger) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting) Set(java.util.Set) RedisClient(com.lambdaworks.redis.RedisClient) Sets(com.google.common.collect.Sets) RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) Pair(com.ctrip.xpipe.tuple.Pair) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Component(org.springframework.stereotype.Component) List(java.util.List) ObjectUtils(com.ctrip.xpipe.utils.ObjectUtils) StringUtil(com.ctrip.xpipe.utils.StringUtil) CatEventMonitor(com.ctrip.xpipe.monitor.CatEventMonitor) Lazy(org.springframework.context.annotation.Lazy) MetaCache(com.ctrip.xpipe.redis.console.resources.MetaCache) HostPort(com.ctrip.xpipe.endpoint.HostPort) HashSet(java.util.HashSet)

Example 53 with HostPort

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;
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 54 with HostPort

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());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 55 with HostPort

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);
        }
    }
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) List(java.util.List) Map(java.util.Map)

Aggregations

HostPort (com.ctrip.xpipe.endpoint.HostPort)79 Test (org.junit.Test)31 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)7 LinkedList (java.util.LinkedList)7 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)6 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)6 ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)4 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)4 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)4 Set (java.util.Set)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)3 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)3 DefaultRedisSessionManager (com.ctrip.xpipe.redis.console.health.DefaultRedisSessionManager)3 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)3