Search in sources :

Example 1 with NoMasterlinkRedisError

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

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

the class PsyncHandler method doHandle.

@Override
protected void doHandle(final String[] args, final RedisClient redisClient) throws Exception {
    // in non-psync executor
    final RedisKeeperServer redisKeeperServer = redisClient.getRedisKeeperServer();
    if (redisKeeperServer.rdbDumper() == null && redisKeeperServer.getReplicationStore().isFresh()) {
        redisClient.sendMessage(new RedisErrorParser(new NoMasterlinkRedisError("Can't SYNC while replicationstore fresh")).format());
        return;
    }
    if (!redisKeeperServer.getRedisKeeperServerState().psync(redisClient, args)) {
        return;
    }
    final RedisSlave redisSlave = redisClient.becomeSlave();
    if (redisSlave == null) {
        logger.warn("[doHandle][psync client already slave]" + redisClient);
        try {
            redisClient.close();
        } catch (IOException e) {
            logger.error("[doHandle]" + redisClient, e);
        }
        return;
    }
    // transfer to psync executor, which will do psync dedicatedly
    redisSlave.processPsyncSequentially(new Runnable() {

        @Override
        public void run() {
            try {
                innerDoHandle(args, redisSlave, redisKeeperServer);
            } catch (Throwable th) {
                try {
                    logger.error("[run]" + redisClient, th);
                    if (redisSlave.isOpen()) {
                        redisSlave.close();
                    }
                } catch (IOException e) {
                    logger.error("[run][close]" + redisSlave, th);
                }
            }
        }
    });
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) IOException(java.io.IOException) RedisErrorParser(com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser) NoMasterlinkRedisError(com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)

Aggregations

NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)2 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 RedisError (com.ctrip.xpipe.redis.core.protocal.error.RedisError)1 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)1 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)1 RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)1 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 Test (org.junit.Test)1