Search in sources :

Example 6 with RedisMeta

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

the class OneDcKeepers method testKeeperChangeState.

@Test
public void testKeeperChangeState() throws Exception {
    int round = 1000;
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            sendMessageToMaster(getRedisMaster(), 100);
        }
    }, 0, 500, TimeUnit.SECONDS.MILLISECONDS);
    RedisMeta redisMaster = getRedisMaster();
    KeeperMeta currentActive = activeKeeper;
    KeeperMeta currentBackup = backupKeeper;
    for (int i = 0; i < round; i++) {
        logger.info(remarkableMessage("round: {}"), i);
        setKeeperState(currentBackup, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
        setKeeperState(currentActive, KeeperState.BACKUP, currentBackup.getIp(), currentBackup.getPort());
        sleep(1000);
        KeeperMeta tmp = currentActive;
        currentActive = currentBackup;
        currentBackup = tmp;
    }
    waitForAnyKey();
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) IOException(java.io.IOException) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 7 with RedisMeta

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

the class AbstractIntegratedTestTemplate method failOverTestTemplate.

@SuppressWarnings("unused")
protected void failOverTestTemplate() throws Exception {
    RedisMeta redisMaster = getRedisMaster();
    stopServerListeningPort(redisMaster.getPort());
    RedisKeeperServer redisKeeperServer = getRedisKeeperServerActive(activeDc().getId());
    RedisMeta slave = getRedisSlaves(activeDc().getId()).get(0);
    SERVER_ROLE role = getRedisServerRole(slave);
    Assert.assertEquals(SERVER_ROLE.SLAVE, role);
    logger.info(remarkableMessage("[testRedisFailover][promote]{}:{})"), slave.getIp(), slave.getPort());
    String clusterId = redisMaster.parent().parent().getId();
    String shardId = redisMaster.parent().getId();
    DefaultMetaServer metaServer = getDcInfos().get(activeDc().getId()).getApplicationContext().getBean(DefaultMetaServer.class);
    // metaServer.promoteRedisMaster(clusterId, shardId, slave.getIp(), slave.getPort());
    sleep(6000);
    role = getRedisServerRole(slave);
    Assert.assertEquals(SERVER_ROLE.MASTER, role);
    Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
    changeRedisMaster(redisMaster, slave);
    sendMessageToMasterAndTestSlaveRedis();
}
Also used : DefaultMetaServer(com.ctrip.xpipe.redis.meta.server.impl.DefaultMetaServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SERVER_ROLE(com.ctrip.xpipe.api.server.Server.SERVER_ROLE)

Example 8 with RedisMeta

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

the class RedisSlaveReplAllTest method beforeRedisSlaveReplAllTest.

@Before
public void beforeRedisSlaveReplAllTest() throws IOException {
    redises.add(new RedisMeta().setIp("127.0.0.1").setPort(6379));
    redises.add(new RedisMeta().setIp("127.0.0.1").setPort(6479));
    redises.add(new RedisMeta().setIp("127.0.0.1").setPort(6579));
    redises.add(new RedisMeta().setIp("127.0.0.1").setPort(6679));
    startRedises(redises);
    slaveWritable(redises);
    sleep(2000);
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Before(org.junit.Before)

Example 9 with RedisMeta

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

the class RedisSlaveReplAllTest method startRedises.

private void startRedises(List<RedisMeta> redises) throws IOException {
    for (int i = 0; i < redises.size(); i++) {
        RedisMeta redis = redises.get(i);
        stopServerListeningPort(redis.getPort());
        if (i == 0) {
            startRedis(redis);
        } else {
            startRedis(redis, redises.get(i - 1));
        }
    }
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta)

Example 10 with RedisMeta

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

the class AbstractKeeperIntegratedSingleDc method makeKeeperRight.

protected void makeKeeperRight() throws Exception {
    List<KeeperMeta> keepers = getDcKeepers(dc, getClusterId(), getShardId());
    RedisMeta redisMaster = getRedisMaster();
    KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(redisMaster.getIp(), redisMaster.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
    job.execute().sync();
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) KeeperStateChangeJob(com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

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