Search in sources :

Example 11 with RedisSlave

use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.

the class NettyMasterHandler method doReportTraffic.

@Override
protected void doReportTraffic(long readBytes, long writtenBytes, String remoteIp, int remotePort) {
    if (writtenBytes > 0) {
        String type = String.format("Keeper.Out.%s", redisKeeperServer.getClusterId());
        String name = null;
        if (redisClient instanceof RedisSlave) {
            RedisSlave slave = (RedisSlave) redisClient;
            name = String.format("slave.%s.%s.%s:%s", slave.roleDesc(), redisKeeperServer.getShardId(), remoteIp, slave.getSlaveListeningPort());
        } else {
            name = String.format("client.%s.%s", redisKeeperServer.getShardId(), remoteIp);
        }
        EventMonitor.DEFAULT.logEvent(type, name, writtenBytes);
    }
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave)

Example 12 with RedisSlave

use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.

the class NettyMasterHandler method update.

@Override
public void update(Object args, Observable observable) {
    if (args instanceof RedisSlave) {
        reportTraffic();
        RedisSlave slave = (RedisSlave) args;
        redisClient = slave;
        logger.info("[update][become redis slave]{}", args);
    }
}
Also used : RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave)

Example 13 with RedisSlave

use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.

the class KeeperSingleDcSlaveof method testMakeRedisSlave.

private void testMakeRedisSlave(boolean xslaveof) throws Exception {
    sendMessageToMasterAndTestSlaveRedis();
    RedisKeeperServer backupKeeperServer = getRedisKeeperServer(backupKeeper);
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort(), false);
    setKeeperState(activeKeeper, KeeperState.BACKUP, backupKeeper.getIp(), backupKeeper.getPort(), false);
    if (xslaveof) {
        new XSlaveofJob(slaves, backupKeeper.getIp(), backupKeeper.getPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors).execute().sync();
    } else {
        new SlaveofJob(slaves, backupKeeper.getIp(), backupKeeper.getPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors).execute().sync();
    }
    sleep(2000);
    Set<RedisSlave> slaves = backupKeeperServer.slaves();
    Assert.assertEquals(3, slaves.size());
    for (RedisSlave redisSlave : slaves) {
        PARTIAL_STATE dest = PARTIAL_STATE.PARTIAL;
        if (redisSlave.getSlaveListeningPort() == activeKeeper.getPort()) {
            logger.info("[testXSlaveof][role keeper]{}, {}", redisSlave, redisSlave.partialState());
        } else {
            logger.info("[testXSlaveof][role redis]{}, {}", redisSlave, redisSlave.partialState());
        }
        Assert.assertEquals(dest, redisSlave.partialState());
    }
    sendMessageToMasterAndTestSlaveRedis();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) XSlaveofJob(com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob) PARTIAL_STATE(com.ctrip.xpipe.api.server.PARTIAL_STATE) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) XSlaveofJob(com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob) SlaveofJob(com.ctrip.xpipe.redis.meta.server.job.SlaveofJob)

Example 14 with RedisSlave

use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.

the class KeeperSingleDcSlaveof method testSlaveofBackup.

@Test
public void testSlaveofBackup() throws Exception {
    sendMessageToMasterAndTestSlaveRedis();
    // test backupKeeper partial sync
    RedisKeeperServer backupKeeperServer = getRedisKeeperServer(backupKeeper);
    Set<RedisSlave> currentSlaves = backupKeeperServer.slaves();
    Assert.assertEquals(0, currentSlaves.size());
    logger.info(remarkableMessage("make slave slaves slaveof backup keeper"));
    new XSlaveofJob(slaves, backupKeeper.getIp(), backupKeeper.getPort(), getXpipeNettyClientKeyedObjectPool(), scheduled, executors).execute();
    logger.info(remarkableMessage("make backup keeper active"));
    // make backup active
    setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
    sleep(1000);
    currentSlaves = backupKeeperServer.slaves();
    Assert.assertEquals(slaves.size(), currentSlaves.size());
    for (RedisSlave redisSlave : currentSlaves) {
        Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisSlave.partialState());
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) XSlaveofJob(com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob) RedisSlave(com.ctrip.xpipe.redis.keeper.RedisSlave) Test(org.junit.Test)

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