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