use of com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException in project x-pipe by ctripcorp.
the class BecomePrimaryAction method makeRedisesOk.
@Override
protected void makeRedisesOk(Pair<String, Integer> newMaster, List<RedisMeta> slaves) {
executionLog.info("[make redis master]" + newMaster);
SimpleObjectPool<NettyClient> masterPool = keyedObjectPool.getKeyPool(new InetSocketAddress(newMaster.getKey(), newMaster.getValue()));
Command<String> command = new DefaultSlaveOfCommand(masterPool, null, 0, scheduled);
try {
String result = command.execute().get();
executionLog.info("[make redis master]" + result);
RedisReadonly redisReadOnly = RedisReadonly.create(newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled);
if (!(redisReadOnly instanceof SlaveOfRedisReadOnly)) {
redisReadOnly.makeWritable();
}
} catch (Exception e) {
logger.error("[makeRedisesOk]" + newMaster, e);
executionLog.error("[make redis master fail]" + e.getMessage());
throw new MakeRedisMasterFailException("make redis master:" + newMaster, e);
}
executionLog.info("[make slaves slaveof][begin]" + newMaster + "," + slaves);
Command<Void> slavesJob = new DefaultSlaveOfJob(slaves, newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled, executors);
try {
slavesJob.execute().get(waitTimeoutSeconds, TimeUnit.SECONDS);
executionLog.info("[make slaves slaveof]success");
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("[makeRedisesOk]" + slaves + "->" + newMaster, e);
executionLog.error("[make slaves slaveof][fail]" + e.getMessage());
throw new MakeRedisSlaveOfMasterFailException(String.format("fail make slaves slave of:%s, %s", newMaster, e.getMessage()), e);
}
}
Aggregations