Search in sources :

Example 1 with RedisMeta

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

the class KeeperSingleDc method createSlave.

private RedisMeta createSlave(String masterIp, Integer masterPort) {
    RedisMeta slave = new RedisMeta();
    slave.setMaster(String.format("%s:%d", masterIp, masterPort));
    slave.setPort(randomPort());
    return slave;
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta)

Example 2 with RedisMeta

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

the class KeeperMultiDcChangePrimary method testChangePrimary.

@Test
public void testChangePrimary() throws Exception {
    String primaryDc = getPrimaryDc();
    String backupDc = getBackupDc();
    // change backup to primary
    when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(backupDc, getClusterId(), getShardId()));
    when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()));
    logger.info(remarkableMessage("[make dc primary]change dc primary to:" + backupDc));
    BecomePrimaryAction becomePrimaryAction = new BecomePrimaryAction(dcMetaCache, currentMetaManager, sentinelManager, offsetWaiter, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), newMasterChooser, scheduled, executors);
    PrimaryDcChangeMessage message = becomePrimaryAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
    logger.info("{}", message);
    sleep(2000);
    logger.info(remarkableMessage("[make dc backup]change dc primary to:" + backupDc));
    when(dcMetaCache.getPrimaryDc(getClusterId(), getShardId())).thenReturn(backupDc);
    when(multiDcService.getActiveKeeper(backupDc, getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()).get(0));
    when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(primaryDc, getClusterId(), getShardId()));
    when(currentMetaManager.getKeeperActive(getClusterId(), getShardId())).thenReturn(getKeeperActive(primaryDc));
    when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(primaryDc, getClusterId(), getShardId()));
    BecomeBackupAction becomeBackupAction = new BecomeBackupAction(dcMetaCache, currentMetaManager, sentinelManager, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), multiDcService, scheduled, executors);
    message = becomeBackupAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
    logger.info("{}", message);
    sleep(2000);
    RedisMeta newRedisMaster = newMasterChooser.getLastChoosenMaster();
    List<RedisMeta> allRedises = getRedises(primaryDc);
    allRedises.addAll(getRedises(backupDc));
    allRedises.remove(newRedisMaster);
    logger.info("{}\n{}", newRedisMaster, allRedises);
    sendMesssageToMasterAndTest(newRedisMaster, allRedises);
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) BecomePrimaryAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction) BecomeBackupAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomeBackupAction) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) Test(org.junit.Test)

Example 3 with RedisMeta

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

the class KeeperPsync2Continue method testExchangeMasterSlave.

@Test
public void testExchangeMasterSlave() throws Exception {
    RedisKeeperServer redisKeeperServer = getRedisKeeperServer(activeKeeper);
    int slaveChosen = 0;
    long fullSyncCount = redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount();
    for (int i = 0; i < testRound; i++) {
        logger.info(remarkableMessage("round:{}"), i);
        RedisMeta slaveToPromote = slaves.get(0);
        xslaveof(activeKeeper.getIp(), activeKeeper.getPort(), redisMaster);
        xslaveof(null, 0, slaveToPromote);
        setKeeperState(activeKeeper, KeeperState.ACTIVE, slaveToPromote.getIp(), slaveToPromote.getPort());
        sleep(3000);
        Assert.assertEquals(fullSyncCount, redisKeeperServer.getKeeperMonitor().getKeeperStats().getFullSyncCount());
        RedisMeta tmpRedisMaster = redisMaster;
        redisMaster = slaveToPromote;
        slaves.remove(slaveChosen);
        slaves.add(0, tmpRedisMaster);
    }
}
Also used : RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 4 with RedisMeta

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

the class XRedisXpipeCommandTest method testReplall.

@Test
public void testReplall() throws IOException {
    RedisMeta redis = new RedisMeta().setIp("127.0.0.1").setPort(6379);
    RedisMeta redisSlave = new RedisMeta().setIp("127.0.0.1").setPort(6479);
    RedisMeta redisSlaveSlave = new RedisMeta().setIp("127.0.0.1").setPort(6579);
    startRedis(redis);
    startRedis(redisSlave, redis);
    startRedis(redisSlaveSlave, redisSlave);
    Jedis jedisSlave = createJedis(redisSlave);
    Jedis jedisSlaveSlave = createJedis(redisSlaveSlave);
    jedisSlave.configSet("slave-read-only", "no");
    assertReplicate(jedisSlave, false, jedisSlaveSlave);
    jedisSlave.configSet("slave-repl-all", "yes");
    assertReplicate(jedisSlave, true, jedisSlaveSlave);
    jedisSlave.configSet("slave-repl-all", "no");
    assertReplicate(jedisSlave, false, jedisSlaveSlave);
}
Also used : Jedis(redis.clients.jedis.Jedis) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 5 with RedisMeta

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

the class XRedisXpipeCommandTest method testRefullsync.

@Test
public void testRefullsync() throws Exception {
    RedisMeta redis = new RedisMeta().setIp("127.0.0.1").setPort(6379);
    RedisMeta redisSlave = new RedisMeta().setIp("127.0.0.1").setPort(6479);
    startRedis(redis);
    startRedis(redisSlave, redis);
    Integer beforeFullSync = getSyncFull(redis);
    String result = new RefullSync(redis.getIp(), redis.getPort(), scheduled).execute().get(1, TimeUnit.SECONDS);
    sleep(1500);
    Integer afterFullSync = getSyncFull(redis);
    Assert.assertEquals(beforeFullSync + 1, afterFullSync.intValue());
    sendMesssageToMasterAndTest(redis, Lists.newArrayList(redisSlave));
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Aggregations

RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)55 Test (org.junit.Test)26 LinkedList (java.util.LinkedList)14 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)8 Before (org.junit.Before)7 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)5 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)5 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)4 Pair (com.ctrip.xpipe.tuple.Pair)4 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)3 PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)3 Server (com.ctrip.xpipe.simpleserver.Server)3 InetSocketAddress (java.net.InetSocketAddress)3 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)2