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);
}
}
}
Aggregations