Search in sources :

Example 6 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.

the class ShardServiceImpl method createShardDeleteEvent.

@VisibleForTesting
protected ShardDeleteEvent createShardDeleteEvent(String clusterName, String shardName, ShardTbl shardTbl, Map<Long, SetinelTbl> sentinelTblMap) {
    String monitorName = shardTbl.getSetinelMonitorName();
    ShardDeleteEvent shardDeleteEvent = new ShardDeleteEvent(clusterName, shardName, executors);
    shardDeleteEvent.setShardMonitorName(monitorName);
    // Splicing sentinel address as "127.0.0.1:6379,127.0.0.2:6380"
    StringBuffer sb = new StringBuffer();
    for (SetinelTbl setinelTbl : sentinelTblMap.values()) {
        sb.append(setinelTbl.getSetinelAddress()).append(",");
    }
    sb.deleteCharAt(sb.length() - 1);
    shardDeleteEvent.setShardSentinels(sb.toString());
    shardEventListeners.forEach(shardEventListener -> shardDeleteEvent.addObserver(shardEventListener));
    return shardDeleteEvent;
}
Also used : ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 7 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.

the class HealthChecker method warmup.

@VisibleForTesting
protected void warmup() {
    int period = 1000;
    XpipeMeta xpipeMeta = null;
    while (xpipeMeta == null) {
        log.info("[warmup] waiting for metaCache initialized");
        try {
            Thread.sleep(period);
            xpipeMeta = metaCache.getXpipeMeta();
            Thread.sleep(period);
        } catch (Exception e) {
            log.error("[warmup]", e);
        }
    }
    try {
        List<DcMeta> dcsToCheck = new LinkedList<>(xpipeMeta.getDcs().values());
        for (DcMeta dc : dcsToCheck) {
            dc.accept(healthCheckVisitor);
        }
    } catch (Exception e) {
        log.error("[warmup] error: {}", e);
    }
}
Also used : XpipeMeta(com.ctrip.xpipe.redis.core.entity.XpipeMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) LinkedList(java.util.LinkedList) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 8 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting 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;
}
Also used : RedisSession(com.ctrip.xpipe.redis.console.health.RedisSession) ResourceNotFoundException(com.ctrip.xpipe.redis.console.service.exception.ResourceNotFoundException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 9 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.

the class DefaultBacklogActiveCollector method analysisInfoReplication.

@VisibleForTesting
void analysisInfoReplication(String infoReplication, String cluster, String shard, HostPort hostPort) {
    boolean isBacklogActive = RedisInfoUtils.getReplBacklogActive(infoReplication);
    String role = RedisInfoUtils.getRole(infoReplication);
    if (!isBacklogActive && Server.SERVER_ROLE.SLAVE.sameRole(role)) {
        // master last io seconds ago == server.master ? unix time - last ! -1
        if (RedisInfoUtils.isMasterSyncInProgress(infoReplication) || RedisInfoUtils.getMasterLastIoSecondsAgo(infoReplication) == -1) {
            logger.info("[analysisInfoReplication] master sync in progress, waiting for {}, {}, {}", cluster, shard, hostPort);
            return;
        }
        RedisConf redisConf = redisConfManager.findOrCreateConfig(hostPort.getHost(), hostPort.getPort());
        if ((!StringUtil.isEmpty(redisConf.getRedisVersion()) && StringUtil.compareVersion(redisConf.getRedisVersion(), "4.0.0") >= 0) || !StringUtil.isEmpty(redisConf.getXredisVersion())) {
            String message = "Redis replication backlog not active";
            alertManager.alert(cluster, shard, hostPort, ALERT_TYPE.REPL_BACKLOG_NOT_ACTIVE, message);
        } else {
            logger.warn("[analysisInfoReplication]Redis {}-{}-{} backlog_active is 0, " + "but redis is not xredis or with version greater than 4.0.0", cluster, shard, hostPort);
        }
    }
}
Also used : RedisConf(com.ctrip.xpipe.redis.console.health.redisconf.RedisConf) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 10 with VisibleForTesting

use of com.ctrip.xpipe.utils.VisibleForTesting in project x-pipe by ctripcorp.

the class DefaultSentinelManager method getRealSentinels.

@VisibleForTesting
protected List<Sentinel> getRealSentinels(List<InetSocketAddress> sentinels, String sentinelMonitorName) {
    List<Sentinel> realSentinels = null;
    for (InetSocketAddress sentinelAddress : sentinels) {
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
        AbstractSentinelCommand.Sentinels sentinelsCommand = new AbstractSentinelCommand.Sentinels(clientPool, sentinelMonitorName, scheduled);
        try {
            realSentinels = sentinelsCommand.execute().get();
            logger.info("[getRealSentinels]get sentinels from {} : {}", sentinelAddress, realSentinels);
            if (realSentinels.size() > 0) {
                realSentinels.add(new Sentinel(sentinelAddress.toString(), sentinelAddress.getHostString(), sentinelAddress.getPort()));
                logger.info("[getRealSentinels]sentinels for monitor {}, list as: {}", sentinelMonitorName, realSentinels);
                break;
            }
        } catch (Exception e) {
            logger.warn("[getRealSentinels]get sentinels from " + sentinelAddress, e);
        }
    }
    return realSentinels;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Sentinel(com.ctrip.xpipe.redis.core.protocal.pojo.Sentinel) InetSocketAddress(java.net.InetSocketAddress) AbstractSentinelCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Aggregations

VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)12 RedisSession (com.ctrip.xpipe.redis.console.health.RedisSession)2 RedisConf (com.ctrip.xpipe.redis.console.health.redisconf.RedisConf)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 RetryCondition (com.ctrip.xpipe.redis.console.job.retry.RetryCondition)1 RetryNTimesOnCondition (com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition)1 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)1 SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)1 ClusterListClusterModel (com.ctrip.xpipe.redis.console.model.consoleportal.ClusterListClusterModel)1 ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)1 MasterNotFoundException (com.ctrip.xpipe.redis.console.resources.MasterNotFoundException)1 ResourceNotFoundException (com.ctrip.xpipe.redis.console.service.exception.ResourceNotFoundException)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)1 DcMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)1