Search in sources :

Example 21 with KeeperMeta

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

the class RedisKeeperServerStateUnknownTest method testActive.

@Test
public void testActive() throws IOException {
    // active
    KeeperMeta keeperMeta = redisKeeperServer.getCurrentKeeperMeta();
    ShardStatus shardStatus = createShardStatus(keeperMeta, null, redisMasterMeta);
    unknown.setShardStatus(shardStatus);
    RedisKeeperServerState newState = redisKeeperServer.getRedisKeeperServerState();
    Assert.assertTrue(newState instanceof RedisKeeperServerStateActive);
    Assert.assertEquals(new InetSocketAddress(redisMasterMeta.getIp(), redisMasterMeta.getPort()), newState.getMaster().getSocketAddress());
}
Also used : RedisKeeperServerState(com.ctrip.xpipe.redis.keeper.RedisKeeperServerState) ShardStatus(com.ctrip.xpipe.redis.core.meta.ShardStatus) InetSocketAddress(java.net.InetSocketAddress) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 22 with KeeperMeta

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

the class RedisKeeperServerStateUnknownTest method testBackup.

@Test
public void testBackup() throws IOException {
    // active
    KeeperMeta keeperMeta = SerializationUtils.clone(redisKeeperServer.getCurrentKeeperMeta());
    keeperMeta.setPort(keeperMeta.getPort() + 1);
    ShardStatus shardStatus = createShardStatus(keeperMeta, null, redisMasterMeta);
    unknown.setShardStatus(shardStatus);
    RedisKeeperServerState newState = redisKeeperServer.getRedisKeeperServerState();
    Assert.assertTrue(newState instanceof RedisKeeperServerStateBackup);
    Assert.assertEquals(new InetSocketAddress(keeperMeta.getIp(), keeperMeta.getPort()), newState.getMaster().getSocketAddress());
}
Also used : RedisKeeperServerState(com.ctrip.xpipe.redis.keeper.RedisKeeperServerState) ShardStatus(com.ctrip.xpipe.redis.core.meta.ShardStatus) InetSocketAddress(java.net.InetSocketAddress) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 23 with KeeperMeta

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

the class RedisMetaServiceImpl method getKeeperMeta.

@Override
public KeeperMeta getKeeperMeta(ShardMeta shardMeta, RedisTbl redisInfo) {
    KeeperMeta keeperMeta = new KeeperMeta();
    if (null != redisInfo) {
        keeperMeta.setId(redisInfo.getRunId());
        keeperMeta.setIp(redisInfo.getRedisIp());
        keeperMeta.setPort(redisInfo.getRedisPort());
        keeperMeta.setKeeperContainerId(redisInfo.getKeepercontainerId());
    }
    keeperMeta.setParent(shardMeta);
    return keeperMeta;
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 24 with KeeperMeta

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

the class AbstractChangePrimaryDcAction method makeKeepersOk.

protected void makeKeepersOk(String clusterId, String shardId, Pair<String, Integer> newMaster) {
    List<KeeperMeta> keepers = currentMetaManager.getSurviveKeepers(clusterId, shardId);
    executionLog.info("[makeKeepersOk]" + keepers);
    KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(newMaster.getKey(), newMaster.getValue()), keyedObjectPool, 1000, 1, scheduled, executors);
    try {
        job.execute().get(waitTimeoutSeconds / 2, TimeUnit.SECONDS);
        executionLog.info("[makeKeepersOk]success");
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        logger.error("[makeKeepersOk]" + e.getMessage());
        executionLog.info("[makeKeepersOk][fail]" + e.getMessage());
    }
}
Also used : KeeperStateChangeJob(com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 25 with KeeperMeta

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

the class BecomeBackupAction method doChangePrimaryDc.

@Override
protected PrimaryDcChangeMessage doChangePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
    doChangeMetaCache(clusterId, shardId, newPrimaryDc);
    changeSentinel(clusterId, shardId, null);
    Pair<String, Integer> newMaster = chooseNewMaster(clusterId, shardId);
    if (newMaster == null) {
        executionLog.error("[doChangePrimaryDc][new master null]");
        return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.FAIL, executionLog.getLog());
    }
    executionLog.info(String.format("[chooseNewMaster]%s:%d", newMaster.getKey(), newMaster.getValue()));
    makeKeepersOk(clusterId, shardId, newMaster);
    List<RedisMeta> slaves = getAllSlaves(newMaster, dcMetaCache.getShardRedises(clusterId, shardId));
    KeeperMeta activeKeeper = currentMetaManager.getKeeperActive(clusterId, shardId);
    makeRedisesOk(new Pair<>(activeKeeper.getIp(), activeKeeper.getPort()), slaves);
    return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.SUCCESS, executionLog.getLog());
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) 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