Search in sources :

Example 1 with ClusterShardHostPort

use of com.ctrip.xpipe.endpoint.ClusterShardHostPort in project x-pipe by ctripcorp.

the class SentinelCollector4Keeper method collect.

@Override
public void collect(SentinelSample sentinelSample) {
    String clusterId = sentinelSample.getSamplePlan().getClusterId();
    String shardId = sentinelSample.getSamplePlan().getShardId();
    sentinelSample.getSamplePlan().getHostPort2SampleResult().forEach(((hostPort, instanceSentinelResult) -> {
        if (metaCache.inBackupDc(hostPort)) {
            ClusterShardHostPort entry = new ClusterShardHostPort(clusterId, shardId, hostPort);
            doCollect(entry, instanceSentinelResult);
        }
    }));
}
Also used : AlertManager(com.ctrip.xpipe.redis.console.alert.AlertManager) ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort) Logger(org.slf4j.Logger) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) SentinelManager(com.ctrip.xpipe.redis.console.redis.SentinelManager) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) Component(org.springframework.stereotype.Component) ObjectUtils(com.ctrip.xpipe.utils.ObjectUtils) StringUtil(com.ctrip.xpipe.utils.StringUtil) HostPort(com.ctrip.xpipe.endpoint.HostPort) MetaCache(com.ctrip.xpipe.redis.console.resources.MetaCache) ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort)

Example 2 with ClusterShardHostPort

use of com.ctrip.xpipe.endpoint.ClusterShardHostPort in project x-pipe by ctripcorp.

the class OuterClientServiceProcessor method quorumMarkInstanceDown.

private void quorumMarkInstanceDown(ClusterShardHostPort clusterShardHostPort) {
    HostPort hostPort = clusterShardHostPort.getHostPort();
    List<HEALTH_STATE> health_states = consoleServiceManager.allHealthStatus(hostPort.getHost(), hostPort.getPort());
    logger.info("[quorumMarkInstanceDown]{}, {}", clusterShardHostPort, health_states);
    boolean quorum = consoleServiceManager.quorumSatisfy(health_states, (state) -> state == HEALTH_STATE.UNHEALTHY || state == HEALTH_STATE.DOWN);
    if (quorum) {
        finalStateSetterManager.set(clusterShardHostPort, false);
    } else {
        logger.info("[quorumMarkInstanceDown][quorum fail]{}, {}", clusterShardHostPort, quorum);
        alertManager.alert(clusterShardHostPort.getClusterName(), clusterShardHostPort.getShardName(), hostPort, ALERT_TYPE.QUORUM_DOWN_FAIL, hostPort.toString());
    }
}
Also used : ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 3 with ClusterShardHostPort

use of com.ctrip.xpipe.endpoint.ClusterShardHostPort in project x-pipe by ctripcorp.

the class OuterClientServiceProcessor method masterUp.

private boolean masterUp(ClusterShardHostPort clusterShardHostPort) {
    // master up
    HostPort redisMaster = metaCache.findMasterInSameShard(clusterShardHostPort.getHostPort());
    boolean masterUp = allMonitorCollector.getState(redisMaster) == HEALTH_STATE.UP;
    if (!masterUp) {
        logger.info("[masterUp][master down instance:{}, master:{}]", clusterShardHostPort, redisMaster);
    }
    return masterUp;
}
Also used : ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 4 with ClusterShardHostPort

use of com.ctrip.xpipe.endpoint.ClusterShardHostPort in project x-pipe by ctripcorp.

the class SentinelCollector4Keeper method doCollect.

private void doCollect(ClusterShardHostPort entry, InstanceSentinelResult result) {
    Set<SentinelHello> hellos = result.getHellos();
    for (SentinelHello hello : hellos) {
        HostPort masterAddr = hello.getMasterAddr();
        String monitorName = hello.getMonitorName();
        boolean masterGood = ObjectUtils.equals(masterAddr, metaCache.findMasterInSameShard(entry.getHostPort()));
        boolean monitorGood = StringUtil.trimEquals(monitorName, metaCache.getSentinelMonitorName(entry.getClusterName(), entry.getShardName()));
        SentinelCollectorAction.getAction(masterGood, monitorGood).doAction(this, hello, entry);
    }
}
Also used : ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 5 with ClusterShardHostPort

use of com.ctrip.xpipe.endpoint.ClusterShardHostPort in project x-pipe by ctripcorp.

the class OuterClientServiceProcessor method onEvent.

@Override
public void onEvent(AbstractInstanceEvent instanceEvent) throws HealthEventProcessorException {
    HostPort hostPort = instanceEvent.getHostPort();
    Pair<String, String> clusterShard = metaCache.findClusterShard(hostPort);
    if (!instanceInBackupDc(hostPort)) {
        logger.info("[onEvent][instance not in backupDc]{}, {}", clusterShard, hostPort);
        return;
    }
    ClusterShardHostPort clusterShardHostPort = new ClusterShardHostPort(hostPort);
    if (clusterShard != null) {
        clusterShardHostPort.setClusterName(clusterShard.getKey());
        clusterShardHostPort.setShardName(clusterShard.getValue());
    }
    if (instanceEvent instanceof InstanceUp) {
        finalStateSetterManager.set(clusterShardHostPort, true);
    } else if (instanceEvent instanceof InstanceDown) {
        if (masterUp(clusterShardHostPort)) {
            quorumMarkInstanceDown(clusterShardHostPort);
        } else {
            logger.info("[onEvent][master down, do not call client service]{}", instanceEvent);
        }
    } else {
        throw new IllegalStateException("unknown event:" + instanceEvent);
    }
}
Also used : ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort) HostPort(com.ctrip.xpipe.endpoint.HostPort) ClusterShardHostPort(com.ctrip.xpipe.endpoint.ClusterShardHostPort)

Aggregations

ClusterShardHostPort (com.ctrip.xpipe.endpoint.ClusterShardHostPort)5 HostPort (com.ctrip.xpipe.endpoint.HostPort)5 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)1 AlertManager (com.ctrip.xpipe.redis.console.alert.AlertManager)1 SentinelManager (com.ctrip.xpipe.redis.console.redis.SentinelManager)1 MetaCache (com.ctrip.xpipe.redis.console.resources.MetaCache)1 Sentinel (com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel)1 ObjectUtils (com.ctrip.xpipe.utils.ObjectUtils)1 StringUtil (com.ctrip.xpipe.utils.StringUtil)1 Set (java.util.Set)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1