Search in sources :

Example 41 with KeeperMeta

use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.

the class AddKeeperCommandTest method beforeAddKeeperCommandTest.

@Before
public void beforeAddKeeperCommandTest() {
    KeeperMeta keeperMeta = new KeeperMeta();
    keeperMeta.setPort(keeperPort);
    keeperMeta.setIp("localhost");
    keeperTransMeta = new KeeperTransMeta("clusterId", "shardId", keeperMeta);
    addKeeperCommand = new AddKeeperCommand(keeperContainerService, keeperTransMeta, scheduled, timeoutMilli, checkInterval);
}
Also used : KeeperTransMeta(com.ctrip.xpipe.redis.core.entity.KeeperTransMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Before(org.junit.Before)

Example 42 with KeeperMeta

use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.

the class DemoStarter method startKeepers.

private void startKeepers(String dc, String clusterId, String shardId, Integer index) throws Exception {
    DcMeta dcMeta = getDcMeta(dc);
    MetaServerKeeperService metaService = createMetaService(dcMeta.getMetaServers());
    LeaderElectorManager leaderElectorManager = createLeaderElectorManager(dcMeta);
    int count = 0;
    for (KeeperMeta keeperMeta : getDcKeepers(dc, clusterId, shardId)) {
        if (index == null || index == count) {
            startKeeper(keeperMeta, metaService, leaderElectorManager);
        }
        count++;
    }
}
Also used : MetaServerKeeperService(com.ctrip.xpipe.redis.core.metaserver.MetaServerKeeperService) LeaderElectorManager(com.ctrip.xpipe.api.cluster.LeaderElectorManager) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 43 with KeeperMeta

use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.

the class KeeperPsync2 method testKeeperPsync2.

@Test
public void testKeeperPsync2() throws Exception {
    // init
    initKeepers();
    sleep(2000);
    assertSyncCount(redisKeeperServers);
    for (int i = 0; i < testRound; i++) {
        logger.info(remarkableMessage("[testRound]{}"), i);
        KeeperMeta lastKeeper = new KeeperMeta().setIp(redisMaster.getIp()).setPort(redisMaster.getPort());
        List<RedisKeeperServer> currentKeepers = new LinkedList<>();
        for (int j = 0; j < totalKeepers; j++) {
            int current = randomInt(0, redisKeeperServers.size() - 1);
            RedisKeeperServer currentRedisKeeperServer = redisKeeperServers.get(current);
            setKeeperState(currentRedisKeeperServer.getCurrentKeeperMeta(), KeeperState.ACTIVE, lastKeeper.getIp(), lastKeeper.getPort());
            redisKeeperServers.remove(currentRedisKeeperServer);
            logger.info("[testKeeperPsync2][slaveof]{}:{}  slaveof {}:{}", currentRedisKeeperServer.getCurrentKeeperMeta().getIp(), currentRedisKeeperServer.getCurrentKeeperMeta().getPort(), lastKeeper.getIp(), lastKeeper.getPort());
            lastKeeper = currentRedisKeeperServer.getCurrentKeeperMeta();
            currentKeepers.add(currentRedisKeeperServer);
        }
        sendMessageToMaster(redisMaster, 10);
        redisKeeperServers = currentKeepers;
        sleep(2000);
        assertSyncCount(redisKeeperServers);
        assertCommandsEquals(redisKeeperServers);
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 44 with KeeperMeta

use of com.ctrip.xpipe.redis.core.entity.KeeperMeta 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 45 with KeeperMeta

use of com.ctrip.xpipe.redis.core.entity.KeeperMeta in project x-pipe by ctripcorp.

the class KeeperSingleDc method testBackupActiveChangeManyTimes.

@Test
public void testBackupActiveChangeManyTimes() throws Exception {
    for (int i = 0; i < 3; i++) {
        logger.info(remarkableMessage("------{}-------"), i);
        // exchange role
        // make backup active
        logger.info(remarkableMessage("make keeper active {}:{}"), backupKeeper.getIp(), backupKeeper.getPort());
        setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
        // make active backup
        logger.info(remarkableMessage("make keeper backup {}:{}"), activeKeeper.getIp(), activeKeeper.getPort());
        setKeeperState(activeKeeper, KeeperState.BACKUP, backupKeeper.getIp(), backupKeeper.getPort());
        sleep(2000);
        Assert.assertEquals(KeeperState.ACTIVE, getKeeperState(backupKeeper));
        Assert.assertEquals(KeeperState.BACKUP, getKeeperState(activeKeeper));
        KeeperMeta tmp = backupKeeper;
        backupKeeper = activeKeeper;
        activeKeeper = tmp;
    }
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Aggregations

KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)50 Test (org.junit.Test)28 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)8 KeeperTransMeta (com.ctrip.xpipe.redis.core.entity.KeeperTransMeta)6 LinkedList (java.util.LinkedList)6 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)4 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)4 KeeperStateChangeJob (com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob)4 InetSocketAddress (java.net.InetSocketAddress)4 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)3 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)3 ShardStatus (com.ctrip.xpipe.redis.core.meta.ShardStatus)3 Before (org.junit.Before)3 RedisKeeperServerState (com.ctrip.xpipe.redis.keeper.RedisKeeperServerState)2 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)2 Server (com.ctrip.xpipe.simpleserver.Server)2 Pair (com.ctrip.xpipe.tuple.Pair)2 ExecutionException (java.util.concurrent.ExecutionException)2 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2