Search in sources :

Example 31 with RedisKeeperServer

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

the class KeeperPsync2 method assertSyncCount.

private void assertSyncCount(List<RedisKeeperServer> redisKeeperServers) {
    logger.info("[assertSyncCount]");
    int full = 0, partialError = 0;
    for (RedisKeeperServer redisKeeperServer : redisKeeperServers) {
        full += redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount();
        partialError += redisKeeperServer.getKeeperMonitor().getKeeperStats().getPartialSyncErrorCount();
    }
    Assert.assertEquals(0, partialError);
    Assert.assertEquals(totalKeepers - 1, full);
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer)

Example 32 with RedisKeeperServer

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

the class KeeperPsync2 method initKeepers.

private void initKeepers() throws Exception {
    redisKeeperServers.add(getRedisKeeperServer(activeKeeper));
    redisKeeperServers.add(getRedisKeeperServer(backupKeeper));
    setKeeperState(backupKeeper, KeeperState.ACTIVE, activeKeeper.getIp(), activeKeeper.getPort());
    KeeperMeta lastKeeper = backupKeeper;
    List<KeeperMeta> keeperMetas = new LinkedList<>();
    int portStart = Math.max(activeKeeper.getPort(), backupKeeper.getPort());
    for (int i = 0; i < totalKeepers - redisKeeperServers.size(); i++) {
        KeeperMeta keeperMeta = new KeeperMeta().setIp("localhost").setPort(++portStart);
        keeperMeta.setParent(activeKeeper.parent());
        keeperMetas.add(keeperMeta);
    }
    for (KeeperMeta keeperMeta : keeperMetas) {
        RedisKeeperServer redisKeeperServer = startKeeper(keeperMeta);
        setKeeperState(keeperMeta, KeeperState.ACTIVE, lastKeeper.getIp(), lastKeeper.getPort());
        logger.info("[initKeepers][slaveof]{}:{}  slaveof {}:{}", keeperMeta.getIp(), keeperMeta.getPort(), lastKeeper.getIp(), lastKeeper.getPort());
        redisKeeperServers.add(redisKeeperServer);
        lastKeeper = keeperMeta;
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList)

Example 33 with RedisKeeperServer

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

the class KeeperSingleDc method testReFullSync.

@Test
public void testReFullSync() throws ExecuteException, IOException {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServerActive(dc);
    DefaultReplicationStore replicationStore = (DefaultReplicationStore) redisKeeperServer.getReplicationStore();
    DcMeta dcMeta = getDcMeta();
    RedisMeta slave1 = createSlave(activeKeeper.getIp(), activeKeeper.getPort());
    int lastRdbUpdateCount = replicationStore.getRdbUpdateCount();
    logger.info(remarkableMessage("[testReFullSync][sendRandomMessage]"));
    sendRandomMessage(redisMaster, 1, replicationStoreCommandFileSize);
    for (int i = 0; i < 3; i++) {
        logger.info(remarkableMessage("[testReFullSync]{}"), i);
        startRedis(slave1);
        sleep(3000);
        int currentRdbUpdateCount = replicationStore.getRdbUpdateCount();
        logger.info("[testReFullSync]{},{}", lastRdbUpdateCount, currentRdbUpdateCount);
        Assert.assertEquals(lastRdbUpdateCount + 1, currentRdbUpdateCount);
        lastRdbUpdateCount = currentRdbUpdateCount;
        sendMesssageToMasterAndTest(100, getRedisMaster(), Lists.newArrayList(slave1));
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultReplicationStore(com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore) Test(org.junit.Test)

Example 34 with RedisKeeperServer

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

the class KeeperSingleDcEof method testEofRestart.

@Test
public void testEofRestart() throws Exception {
    sendMessageToMasterAndTestSlaveRedis();
    logger.info(remarkableMessage("stop keepers"));
    RedisKeeperServer active = getRedisKeeperServer(activeKeeper);
    LifecycleHelper.stopIfPossible(active);
    LifecycleHelper.disposeIfPossible(active);
    RedisKeeperServer backup = getRedisKeeperServer(backupKeeper);
    LifecycleHelper.stopIfPossible(backup);
    LifecycleHelper.disposeIfPossible(backup);
    logger.info(remarkableMessage("start keepers"));
    startKeepers();
    makeKeeperRight();
    sleep(2000);
    sendMessageToMasterAndTestSlaveRedis();
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) Test(org.junit.Test)

Example 35 with RedisKeeperServer

use of com.ctrip.xpipe.redis.keeper.RedisKeeperServer 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)

Aggregations

RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)44 Test (org.junit.Test)23 DefaultRedisKeeperServer (com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer)13 RedisSlave (com.ctrip.xpipe.redis.keeper.RedisSlave)6 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)5 ErrorMessage (com.ctrip.xpipe.exception.ErrorMessage)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)4 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)4 DefaultReplicationStore (com.ctrip.xpipe.redis.keeper.store.DefaultReplicationStore)4 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)3 RedisErrorParser (com.ctrip.xpipe.redis.core.protocal.protocal.RedisErrorParser)3 LinkedList (java.util.LinkedList)3 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)2 XSlaveofJob (com.ctrip.xpipe.redis.meta.server.job.XSlaveofJob)2 IOException (java.io.IOException)2 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)1 PARTIAL_STATE (com.ctrip.xpipe.api.server.PARTIAL_STATE)1 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 NoMasterlinkRedisError (com.ctrip.xpipe.redis.core.protocal.error.NoMasterlinkRedisError)1