Search in sources :

Example 1 with SlaveOfCommand

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);
    }
}
Also used : ConfigRewrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand) IOException(java.io.IOException) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 2 with SlaveOfCommand

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);
    }
}
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 3 with SlaveOfCommand

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

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