use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class RedisPromotor method promoteSlaveToMaster.
private void promoteSlaveToMaster(RedisSlave redisSlave) throws Exception {
SimpleObjectPool<NettyClient> fsyncPool = null;
SimpleObjectPool<NettyClient> clientPool = null;
try {
fsyncPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(promoteServerIp, promoteServerPort));
clientPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(promoteServerIp, promoteServerPort));
waitUntilSlaveSync(redisSlave, this.promoteServerIp, this.promoteServerPort, waitTimeoutMilli);
try {
redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.BEGIN_PROMOTE_SLAVE);
Fsync fsyncCmd = new Fsync(fsyncPool, scheduled);
String fsyncResult = fsyncCmd.execute().get();
logger.info("[promoteSlaveToMaster][fsync done]{}, {},{}", fsyncResult, promoteServerIp, promoteServerPort);
redisModified(redisSlave, clientPool);
} catch (ExecutionException e) {
logger.error("[promoteSlaveToMaster]" + redisSlave, e.getCause());
if (e.getCause() instanceof RedisError) {
logger.info("[promoteSlaveToMaster][fsync not supported, raw redis]{}", redisSlave);
redisNotModified(redisSlave, clientPool);
} else {
logger.error("[promoteSlaveToMaster][fail]" + redisSlave);
}
}
} finally {
if (fsyncPool != null) {
fsyncPool.clear();
}
if (clientPool != null) {
clientPool.clear();
}
}
}
use of com.ctrip.xpipe.netty.commands.NettyClient 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;
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class DefaultSentinelManager method infoSentinel.
@Override
public String infoSentinel(Sentinel sentinel) {
SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(new InetSocketAddress(sentinel.getIp(), sentinel.getPort()));
InfoCommand infoCommand = new InfoCommand(clientPool, InfoCommand.INFO_TYPE.SENTINEL, scheduled);
infoCommand.logResponse(false);
try {
return infoCommand.execute().get();
} catch (Exception e) {
logger.error("[infoSentinel] " + sentinel, e);
}
return null;
}
use of com.ctrip.xpipe.netty.commands.NettyClient 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);
}
}
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class DefaultSentinelManager method removeSentinel.
@Override
public void removeSentinel(String clusterId, String shardId, ExecutionLog executionLog) {
String sentinelMonitorName = dcMetaCache.getSentinelMonitorName(clusterId, shardId);
String allSentinels = dcMetaCache.getSentinel(clusterId, shardId).getAddress();
executionLog.info(String.format("removeSentinel cluster:%s, shard:%s, masterName:%s, sentinelAddress:%s", clusterId, shardId, sentinelMonitorName, allSentinels));
if (checkEmpty(sentinelMonitorName, allSentinels, executionLog)) {
return;
}
List<InetSocketAddress> sentinels = IpUtils.parse(allSentinels);
List<Sentinel> realSentinels = getRealSentinels(sentinels, sentinelMonitorName, executionLog);
if (realSentinels == null) {
executionLog.warn("get real sentinels null");
return;
}
executionLog.info(String.format("removeSentinel realSentinels:%s", realSentinels));
for (Sentinel sentinel : realSentinels) {
SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(new InetSocketAddress(sentinel.getIp(), sentinel.getPort()));
SentinelRemove sentinelRemove = new SentinelRemove(clientPool, sentinelMonitorName, scheduled);
try {
String result = sentinelRemove.execute().get();
executionLog.info(String.format("removeSentinel %s from %s : %s", sentinelMonitorName, sentinel, result));
} catch (InterruptedException | ExecutionException e) {
executionLog.info(String.format("removeSentinel %s from %s : %s", sentinelMonitorName, sentinel, e.getMessage()));
logger.warn("[removeSentinel]" + sentinel, e);
}
}
}
Aggregations