Search in sources :

Example 1 with KeeperMeta

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

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

Example 3 with KeeperMeta

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

the class AbstractKeeperIntegratedSingleDc method endPrepareRedisConfig.

@Override
protected void endPrepareRedisConfig(RedisMeta redisMeta, StringBuilder sb) {
    if (redisMeta.isMaster()) {
        return;
    }
    KeeperMeta activeKeeper = getKeeperActive();
    sb.append(String.format("slaveof %s %d\r\n", activeKeeper.getIp(), activeKeeper.getPort()));
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 4 with KeeperMeta

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

the class ClusterServersApiTest method testGetActiveKeeper.

@Test
public void testGetActiveKeeper() throws Exception {
    createMetaServers(metaServerCount);
    sleep(waitForMetaServerOkTime);
    logger.info(remarkableMessage("[testUpdateUpstream][begin send upstream update message]"));
    for (TestMetaServer server : getServers()) {
        String path = META_SERVER_SERVICE.GET_ACTIVE_KEEPER.getRealPath(server.getAddress());
        logger.info("[testGetActiveKeeper]{}", path);
        KeeperMeta keeperMeta = restTemplate.getForObject(path, KeeperMeta.class, "cluster1", "shard1");
        logger.info("[testGetActiveKeeper]{}", keeperMeta);
    }
}
Also used : TestMetaServer(com.ctrip.xpipe.redis.meta.server.TestMetaServer) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 5 with KeeperMeta

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

the class KeeperStateChangeJob method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    KeeperMeta activeKeeper = null;
    for (KeeperMeta keeperMeta : keepers) {
        if (keeperMeta.isActive()) {
            activeKeeper = keeperMeta;
            break;
        }
    }
    if (activeKeeper == null) {
        future().setFailure(new Exception("can not find active keeper:" + keepers));
    }
    SequenceCommandChain chain = new SequenceCommandChain(false);
    if (activeKeeperMaster != null) {
        Command<?> setActiveCommand = createKeeperSetStateCommand(activeKeeper, activeKeeperMaster);
        addActiveCommandHook(setActiveCommand);
        chain.add(setActiveCommand);
    }
    ParallelCommandChain backupChain = new ParallelCommandChain(executors);
    for (KeeperMeta keeperMeta : keepers) {
        if (!keeperMeta.isActive()) {
            Command<?> backupCommand = createKeeperSetStateCommand(keeperMeta, new Pair<String, Integer>(activeKeeper.getIp(), activeKeeper.getPort()));
            backupChain.add(backupCommand);
        }
    }
    chain.add(backupChain);
    chain.execute().addListener(new CommandFutureListener<Object>() {

        @Override
        public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
            if (commandFuture.isSuccess()) {
                future().setSuccess(null);
            } else {
                future().setFailure(commandFuture.cause());
            }
        }
    });
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

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