use of com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand in project x-pipe by ctripcorp.
the class TransactionalSlaveOfCommand method failXslaveof.
private void failXslaveof(Throwable e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
if ((rootCause instanceof IOException)) {
logger.info("[failXslaveof][do not try slaveof]");
fail(e);
return;
}
logger.error("[doExecute][xlaveof fail, try slaveof]" + ip + ":" + port, e);
TransactionalCommand slaveofTransaction = new TransactionalCommand(getClientPool(), scheduled, new SlaveOfCommand(null, ip, port, scheduled), new ConfigRewrite(null, scheduled));
try {
slaveofTransaction.execute().addListener(new CommandFutureListener<Object[]>() {
@Override
public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
if (!commandFuture.isSuccess()) {
fail(commandFuture.cause());
} else {
logger.info("[doExecute][slaveof success]{}", this);
future().setSuccess(commandFuture.get());
}
}
});
} catch (Exception ex) {
fail(ex);
}
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand in project x-pipe by ctripcorp.
the class RedisPromotor method redisModified.
private void redisModified(RedisSlave redisSlave, SimpleObjectPool<NettyClient> clientPool) throws Exception {
try {
logger.info("[redisModified]{}", redisSlave);
AbstractSlaveOfCommand slaveOfCmd = new SlaveOfCommand(clientPool, scheduled);
slaveOfCmd.execute().sync();
InfoCommand infoServerCmd = new InfoCommand(clientPool, "server", scheduled);
String info = infoServerCmd.execute().get();
String masterId = null;
List<String> lines = IOUtils.readLines(new StringReader(info));
for (String line : lines) {
if (line.startsWith("run_id:")) {
masterId = line.substring("run_id:".length());
}
}
InfoCommand infoLastMasterCmd = new InfoCommand(clientPool, "lastmaster", scheduled);
String infoLastMaster = infoLastMasterCmd.execute().get();
long keeperOffset = 0, newMasterOffset = 0;
try {
String[] parts = infoLastMaster.split("\\s");
keeperOffset = Long.parseLong(parts[1]);
newMasterOffset = Long.parseLong(parts[2]);
redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.SLAVE_PROMTED, new SlavePromotionInfo(keeperOffset, new DefaultEndPoint(promoteServerIp, promoteServerPort), masterId, newMasterOffset));
} catch (Exception e) {
logger.error("[onComplete]" + promoteServerIp + ":" + promoteServerPort, e);
}
} catch (IOException e1) {
logger.error("promoteSlaveToMaster", e1);
}
}
use of com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand in project x-pipe by ctripcorp.
the class RedisPromotor method redisNotModified.
private void redisNotModified(RedisSlave redisSlave, SimpleObjectPool<NettyClient> clientPool) throws InterruptedException, ExecutionException, IOException {
logger.info("[redisNotModified]{}", redisSlave);
AbstractSlaveOfCommand slaveOfCmd = new SlaveOfCommand(clientPool, scheduled);
slaveOfCmd.execute().sync();
redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.SLAVE_PROMTED, new InetSocketAddress(promoteServerIp, promoteServerPort));
}
Aggregations