use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class LFHandler method doHandle.
@Override
protected void doHandle(String[] args, RedisClient redisClient) {
if (redisClient instanceof RedisSlave) {
if (logger.isDebugEnabled()) {
logger.debug("[doHandle][\\n get]" + redisClient);
}
RedisSlave redisSlave = (RedisSlave) redisClient;
redisSlave.ack(null);
}
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class DefaultRedisClient method becomeSlave.
@Override
public RedisSlave becomeSlave() {
RedisSlave redisSlave = null;
switch(clientRole) {
case NORMAL:
logger.info("[becomeSlave]" + this);
redisSlave = new DefaultRedisSlave(this);
notifyObservers(redisSlave);
break;
case SLAVE:
logger.info("[becomeSlave][already slave]" + this);
break;
default:
throw new IllegalStateException("unknown state:" + clientRole);
}
return redisSlave;
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class AbstractRdbDumper method doWhenDumping.
private void doWhenDumping() {
for (final RedisSlave redisSlave : redisKeeperServer.slaves()) {
if (redisSlave.getSlaveState() == SLAVE_STATE.REDIS_REPL_WAIT_RDB_DUMPING) {
logger.info("[doWhenDumping][slave waiting for rdb, resume]{}", redisSlave);
redisSlave.processPsyncSequentially(new Runnable() {
@Override
public void run() {
try {
redisKeeperServer.fullSyncToSlave(redisSlave);
} catch (Exception e) {
logger.error(String.format("fullsync to slave:%s", redisSlave), e);
}
}
});
}
}
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave 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);
}
}
}
});
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class RedisPromotor method promote.
public void promote() throws RedisSlavePromotionException {
final RedisSlave redisSlave = findSlave(this.redisKeeperServer, this.promoteServerIp, this.promoteServerPort);
if (redisSlave == null) {
String msg = String.format("%s:%s is not a connected slave", promoteServerIp, promoteServerPort);
throw new RedisSlavePromotionException(msg);
}
logger.info("[promote]{},{} ,{}:{}", redisKeeperServer, redisSlave, promoteServerIp, promoteServerPort);
new Thread() {
public void run() {
try {
promoteSlaveToMaster(redisSlave);
} catch (Exception e) {
logger.error("[run][promote slave]" + redisSlave, e);
}
}
}.start();
}
Aggregations