Search in sources :

Example 1 with AbstractSlaveOfCommand

use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand 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);
    }
}
Also used : AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand) StringReader(java.io.StringReader) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)

Example 2 with AbstractSlaveOfCommand

use of com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand 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));
}
Also used : AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) InetSocketAddress(java.net.InetSocketAddress) AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand)

Aggregations

AbstractSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand)2 SlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand)2 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1