Search in sources :

Example 1 with SERVER_ROLE

use of com.ctrip.xpipe.api.server.Server.SERVER_ROLE 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 2 with SERVER_ROLE

use of com.ctrip.xpipe.api.server.Server.SERVER_ROLE in project x-pipe by ctripcorp.

the class AbstractNewMasterChooser method getMasters.

protected Pair<List<RedisMeta>, List<RedisMeta>> getMasters(List<RedisMeta> allRedises) {
    List<RedisMeta> masters = new LinkedList<>();
    List<RedisMeta> tmpAliveServers = new LinkedList<>();
    CountDownLatch latch = new CountDownLatch(allRedises.size());
    for (RedisMeta redisMeta : allRedises) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                try {
                    SERVER_ROLE role = serverRole(redisMeta);
                    if (role == SERVER_ROLE.MASTER) {
                        synchronized (masters) {
                            masters.add(redisMeta);
                        }
                    }
                    if (role != SERVER_ROLE.UNKNOWN) {
                        synchronized (tmpAliveServers) {
                            tmpAliveServers.add(redisMeta);
                        }
                    }
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    try {
        latch.await(CHECK_NEW_MASTER_TIMEOUT_SECONDS * 2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        logger.error("[getMasters]" + allRedises, e);
    }
    List<RedisMeta> aliveServers = sortAccording(allRedises, tmpAliveServers);
    return new Pair<>(masters, aliveServers);
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) SERVER_ROLE(com.ctrip.xpipe.api.server.Server.SERVER_ROLE) LinkedList(java.util.LinkedList) ChooseNewMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException) Pair(com.ctrip.xpipe.tuple.Pair)

Aggregations

SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)2 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)1 ChooseNewMasterFailException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException)1 DefaultMetaServer (com.ctrip.xpipe.redis.meta.server.impl.DefaultMetaServer)1 Pair (com.ctrip.xpipe.tuple.Pair)1 LinkedList (java.util.LinkedList)1