Search in sources :

Example 1 with Fsync

use of com.ctrip.xpipe.redis.core.protocal.cmd.Fsync in project x-pipe by ctripcorp.

the class RedisPromotor method promoteSlaveToMaster.

private void promoteSlaveToMaster(RedisSlave redisSlave) throws Exception {
    SimpleObjectPool<NettyClient> fsyncPool = null;
    SimpleObjectPool<NettyClient> clientPool = null;
    try {
        fsyncPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(promoteServerIp, promoteServerPort));
        clientPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(promoteServerIp, promoteServerPort));
        waitUntilSlaveSync(redisSlave, this.promoteServerIp, this.promoteServerPort, waitTimeoutMilli);
        try {
            redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.BEGIN_PROMOTE_SLAVE);
            Fsync fsyncCmd = new Fsync(fsyncPool, scheduled);
            String fsyncResult = fsyncCmd.execute().get();
            logger.info("[promoteSlaveToMaster][fsync done]{}, {},{}", fsyncResult, promoteServerIp, promoteServerPort);
            redisModified(redisSlave, clientPool);
        } catch (ExecutionException e) {
            logger.error("[promoteSlaveToMaster]" + redisSlave, e.getCause());
            if (e.getCause() instanceof RedisError) {
                logger.info("[promoteSlaveToMaster][fsync not supported, raw redis]{}", redisSlave);
                redisNotModified(redisSlave, clientPool);
            } else {
                logger.error("[promoteSlaveToMaster][fail]" + redisSlave);
            }
        }
    } finally {
        if (fsyncPool != null) {
            fsyncPool.clear();
        }
        if (clientPool != null) {
            clientPool.clear();
        }
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) Fsync(com.ctrip.xpipe.redis.core.protocal.cmd.Fsync) RedisError(com.ctrip.xpipe.redis.core.protocal.error.RedisError) InetSocketAddress(java.net.InetSocketAddress) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 Fsync (com.ctrip.xpipe.redis.core.protocal.cmd.Fsync)1 RedisError (com.ctrip.xpipe.redis.core.protocal.error.RedisError)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1