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