Search in sources :

Example 1 with AddSentinelException

use of com.ctrip.xpipe.redis.meta.server.dcchange.exception.AddSentinelException in project x-pipe by ctripcorp.

the class DefaultSentinelManager method addSentinel.

@Override
public void addSentinel(String clusterId, String shardId, HostPort redisMaster, ExecutionLog executionLog) {
    String sentinelMonitorName = dcMetaCache.getSentinelMonitorName(clusterId, shardId);
    String allSentinels = dcMetaCache.getSentinel(clusterId, shardId).getAddress();
    executionLog.info(String.format("[addSentinel]%s,%s,%s, monitorName:%s, master:%s:%d", clusterId, shardId, allSentinels, sentinelMonitorName, redisMaster.getHost(), redisMaster.getPort()));
    if (checkEmpty(sentinelMonitorName, allSentinels, executionLog)) {
        return;
    }
    int quorum = DEFAULT_SENTINEL_QUORUM;
    List<InetSocketAddress> sentinels = IpUtils.parse(allSentinels);
    if (sentinels.size() < quorum) {
        throw new IllegalStateException(String.format("sentinel size < quorum, %d < %d", sentinels.size(), quorum));
    }
    int addSize = Math.min(sentinels.size(), DEFAULT_SENTINEL_ADD_SIZE);
    for (int i = 0; i < addSize; i++) {
        InetSocketAddress sentinelAddress = sentinels.get(i);
        SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(sentinelAddress);
        SentinelAdd command = new SentinelAdd(clientPool, sentinelMonitorName, redisMaster.getHost(), redisMaster.getPort(), quorum, scheduled);
        try {
            String result = command.execute().get();
            executionLog.info(String.format("add to sentinel %s : %s", sentinelAddress, result));
        } catch (InterruptedException | ExecutionException e) {
            throw new AddSentinelException(sentinelAddress, clusterId, shardId, redisMaster.getHost(), redisMaster.getPort(), e);
        }
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) SentinelAdd(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd) AddSentinelException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.AddSentinelException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 SentinelAdd (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand.SentinelAdd)1 AddSentinelException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.AddSentinelException)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1