Search in sources :

Example 31 with KeeperMeta

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

the class DefaultKeeperActiveElectAlgorithm method select.

@Override
public KeeperMeta select(String clusterId, String shardId, List<KeeperMeta> toBeSelected) {
    if (toBeSelected.size() > 0) {
        KeeperMeta result = toBeSelected.get(0);
        result.setActive(true);
        return result;
    }
    return null;
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 32 with KeeperMeta

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

the class BackupDcKeeperMasterChooserAlgorithm method doChoose.

@Override
protected Pair<String, Integer> doChoose() {
    String dcName = dcMetaCache.getPrimaryDc(clusterId, shardId);
    KeeperMeta keeperMeta = multiDcService.getActiveKeeper(dcName, clusterId, shardId);
    logger.debug("[doChooseKeeperMaster]{}, {}, {}, {}", dcName, clusterId, shardId, keeperMeta);
    if (keeperMeta == null) {
        return null;
    }
    return new Pair<>(keeperMeta.getIp(), keeperMeta.getPort());
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Pair(com.ctrip.xpipe.tuple.Pair)

Example 33 with KeeperMeta

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

the class AbstractRedisKeeperServerState method setShardStatus.

@Override
public void setShardStatus(ShardStatus shardStatus) throws IOException {
    if (shardStatus.getRedisMaster() != null && shardStatus.getUpstreamKeeper() != null) {
        logger.error("[setShardStatus][active keeper and upstream keeper both not null]{}, {}", shardStatus.getActiveKeeper(), shardStatus.getUpstreamKeeper());
        return;
    }
    KeeperMeta currentKeeperMeta = redisKeeperServer.getCurrentKeeperMeta();
    KeeperMeta activeKeeper = shardStatus.getActiveKeeper();
    if (activeKeeper == null) {
        logger.info("[setShardStatus][active keeper null]");
        return;
    }
    if (activeKeeper.getIp().equals(currentKeeperMeta.getIp()) && activeKeeper.getPort().equals(currentKeeperMeta.getPort())) {
        RedisMeta redisMaster = shardStatus.getRedisMaster();
        KeeperMeta upstreamKeeer = shardStatus.getUpstreamKeeper();
        InetSocketAddress masterAddress = null;
        if (redisMaster != null) {
            masterAddress = new InetSocketAddress(redisMaster.getIp(), redisMaster.getPort());
        }
        if (upstreamKeeer != null) {
            masterAddress = new InetSocketAddress(upstreamKeeer.getIp(), upstreamKeeer.getPort());
        }
        becomeActive(masterAddress);
    } else {
        becomeBackup(new InetSocketAddress(activeKeeper.getIp(), activeKeeper.getPort()));
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 34 with KeeperMeta

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

the class KeeperContainerService method add.

public RedisKeeperServer add(KeeperTransMeta keeperTransMeta) {
    KeeperMeta keeperMeta = keeperTransMeta.getKeeperMeta();
    enrichKeeperMetaFromKeeperTransMeta(keeperMeta, keeperTransMeta);
    String keeperServerKey = assembleKeeperServerKey(keeperTransMeta);
    if (!redisKeeperServers.containsKey(keeperServerKey)) {
        synchronized (this) {
            if (!redisKeeperServers.containsKey(keeperServerKey)) {
                if (runningPorts.contains(keeperMeta.getPort())) {
                    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Add keeper for cluster %s shard %s failed since port %d is already used", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId(), keeperMeta.getPort())), null);
                }
                try {
                    RedisKeeperServer redisKeeperServer = doAdd(keeperTransMeta, keeperMeta);
                    cacheKeeper(keeperServerKey, redisKeeperServer);
                    return redisKeeperServer;
                } catch (Throwable ex) {
                    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.INTERNAL_EXCEPTION, String.format("Add keeper for cluster %s shard %s failed", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), ex);
                }
            }
        }
    }
    throw new RedisKeeperRuntimeException(new ErrorMessage<>(KeeperContainerErrorCode.KEEPER_ALREADY_EXIST, String.format("Keeper already exists for cluster %s shard %s", keeperTransMeta.getClusterId(), keeperTransMeta.getShardId())), null);
}
Also used : DefaultRedisKeeperServer(com.ctrip.xpipe.redis.keeper.impl.DefaultRedisKeeperServer) RedisKeeperServer(com.ctrip.xpipe.redis.keeper.RedisKeeperServer) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException) ErrorMessage(com.ctrip.xpipe.exception.ErrorMessage) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 35 with KeeperMeta

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

the class DefaultXpipeMetaManagerTest method testUpdateKeeperActive.

@Test
public void testUpdateKeeperActive() throws MetaException {
    List<KeeperMeta> backups = metaManager.getKeeperBackup(dc, clusterId, shardId);
    Assert.assertNotNull(metaManager.getKeeperActive(dc, clusterId, shardId));
    ;
    KeeperMeta backup = backups.get(0);
    metaManager.updateKeeperActive(dc, clusterId, shardId, backups.get(0));
    KeeperMeta newActive = metaManager.getKeeperActive(dc, clusterId, shardId);
    Assert.assertEquals(backup.getIp(), newActive.getIp());
    Assert.assertEquals(backup.getPort(), newActive.getPort());
    metaManager.updateKeeperActive(dc, clusterId, shardId, new KeeperMeta());
    Assert.assertNull(metaManager.getKeeperActive(dc, clusterId, shardId));
}
Also used : KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

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