Search in sources :

Example 6 with RedisSlave

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);
    }
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave)

Example 7 with RedisSlave

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;
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave)

Example 8 with 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);
                    }
                }
            });
        }
    }
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) IOException(java.io.IOException)

Example 9 with RedisSlave

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

Example 10 with RedisSlave

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();
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)

Aggregations

RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)14 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)6 Test (org.junit.Test)4 IOException (java.io.IOException)3 XSlaveofJob (com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob)2 PARTIAL_STATE (com.ctrip.xpipe.api.server.PARTIAL_STATE)1 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)1 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 DefaultKeeperMonitor (com.ctrip.xpipe.redis.keeper.monitor.impl.DefaultKeeperMonitor)1 SlaveofJob (com.ctrip.xpipe.redis.meta.server.job.SlaveofJob)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 Before (org.junit.Before)1