Search in sources :

Example 1 with RedisError

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

the class RedisErrorParserTest method testRedisError.

@Test
public void testRedisError() {
    String message = "Can't SYNC while replicationstore fresh";
    RedisError redisError = new NoMasterlinkRedisError(message);
    ByteBuf byteBuf = new RedisErrorParser(redisError).format();
    String result = ByteBufUtils.readToString(byteBuf);
    Assert.assertEquals("-" + redisError.getMessage() + "\r\n", result);
}
Also used : NoMasterlinkRedisError(com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError) RedisError(com.ctrip.xpipe.redis.core.protocal.error.RedisError) ByteBuf(io.netty.buffer.ByteBuf) NoMasterlinkRedisError(com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 2 with RedisError

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

the class AbstractRedisesSlaveofJob method createSlaveofCommand.

private Command<?> createSlaveofCommand(RedisMeta redisMeta, String masterHost, int masterPort) {
    SimpleObjectPool<NettyClient> pool = new XpipeObjectPoolFromKeyed<InetSocketAddress, NettyClient>(clientPool, new InetSocketAddress(redisMeta.getIp(), redisMeta.getPort()));
    Command<?> command = createSlaveOfCommand(pool, masterHost, masterPort);
    return CommandRetryWrapper.buildCountRetry(retryTimes, new RetryDelay(delayBaseMilli) {

        @Override
        public boolean retry(Throwable th) {
            Throwable rootCause = ExceptionUtils.getRootCause(th);
            if (rootCause instanceof RedisError) {
                logger.info("[retry][do not retry, because redis error]{}", rootCause.getMessage());
                return false;
            }
            return super.retry(th);
        }
    }, command, scheduled);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) XpipeObjectPoolFromKeyed(com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed) RedisError(com.ctrip.xpipe.redis.core.protocal.error.RedisError) InetSocketAddress(java.net.InetSocketAddress) RetryDelay(com.ctrip.xpipe.retry.RetryDelay)

Example 3 with RedisError

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

the class ParserManagerTest method test.

@Test
public void test() {
    Assert.assertEquals(":1\r\n", ByteBufUtils.readToString(ParserManager.parse(1L)));
    Assert.assertEquals("+nihao\r\n", ByteBufUtils.readToString(ParserManager.parse("nihao")));
    Assert.assertEquals("-error\r\n", ByteBufUtils.readToString(ParserManager.parse(new RedisError("error"))));
    Assert.assertEquals("*2\r\n+str\r\n:1\r\n", ByteBufUtils.readToString(ParserManager.parse(new Object[] { "str", 1L })));
    Assert.assertEquals("$5\r\nnihao\r\n", ByteBufUtils.readToString(ParserManager.parse(new ByteArrayOutputStreamPayload("nihao"))));
    int a = 1;
    Assert.assertEquals("*2\r\n+str\r\n:1\r\n", ByteBufUtils.readToString(ParserManager.parse(new Object[] { "str", a })));
}
Also used : RedisError(com.ctrip.xpipe.redis.core.protocal.error.RedisError) ByteArrayOutputStreamPayload(com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Example 4 with RedisError

use of com.ctrip.xpipe.redis.core.protocal.error.RedisError 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

RedisError (com.ctrip.xpipe.redis.core.protocal.error.RedisError)4 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 ByteArrayOutputStreamPayload (com.ctrip.xpipe.payload.ByteArrayOutputStreamPayload)1 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)1 Fsync (com.ctrip.xpipe.redis.core.protocal.cmd.Fsync)1 NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)1 RetryDelay (com.ctrip.xpipe.retry.RetryDelay)1 ByteBuf (io.netty.buffer.ByteBuf)1 ExecutionException (java.util.concurrent.ExecutionException)1