Search in sources :

Example 1 with RedisSlavePromotionException

use of com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException in project x-pipe by ctripcorp.

the class SlaveOfCommandHandler method handleForwarding.

private void handleForwarding(String[] args, RedisClient redisClient) {
    if (args[0].equalsIgnoreCase(NO)) {
        String ip = args[2];
        // already validated
        int port = Integer.parseInt(args[3]);
        try {
            redisClient.getRedisKeeperServer().promoteSlave(ip, port);
            redisClient.sendMessage(new BulkStringParser(RedisProtocol.OK).format());
            return;
        } catch (RedisSlavePromotionException e) {
            logger.error("[doHandle]{},{},{}", redisClient, ip, port);
            redisClient.sendMessage(new RedisErrorParser(e.getMessage()).format());
        }
    }
}
Also used : BulkStringParser(com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringParser) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) RedisErrorParser(com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)

Example 2 with RedisSlavePromotionException

use of com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException in project x-pipe by ctripcorp.

the class RedisPromotor method promote.

public void promote() throws RedisSlavePromotionException {
    final RedisSlave redisSlave = findSlave(this.redisKeeperServer, this.promoteServerIp, this.promoteServerPort);
    if (redisSlave == null) {
        String msg = String.format("%s:%s is not a connected slave", promoteServerIp, promoteServerPort);
        throw new RedisSlavePromotionException(msg);
    }
    logger.info("[promote]{},{} ,{}:{}", redisKeeperServer, redisSlave, promoteServerIp, promoteServerPort);
    new Thread() {

        public void run() {
            try {
                promoteSlaveToMaster(redisSlave);
            } catch (Exception e) {
                logger.error("[run][promote slave]" + redisSlave, e);
            }
        }
    }.start();
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)

Aggregations

RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)2 BulkStringParser (com.ctrip.xpipe.redis.core.protocal.protocal.BulkStringParser)1 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)1 RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1