Search in sources :

Example 26 with KeeperMeta

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

the class DefaultDynamicStateManager method add.

@Override
public void add(ClusterMeta clusterMeta) {
    clusterMetas.put(clusterMeta.getId(), clusterMeta);
    for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
        for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
            final KeeperKey keeperKey = createKeeperKey(clusterMeta.getId(), shardMeta.getId(), keeperMeta);
            @SuppressWarnings("unused") KeeperHeartBeatManager keeperHeartBeatManager = MapUtils.getOrCreate(keepers, keeperKey, new ObjectFactory<KeeperHeartBeatManager>() {

                @Override
                public KeeperHeartBeatManager create() {
                    KeeperHeartBeatManager keeperHeartBeatManager = new DefaultKeeperHeartBeatManager(keeperKey, scheduled);
                    keeperHeartBeatManager.addObserver(DefaultDynamicStateManager.this);
                    return keeperHeartBeatManager;
                }
            });
        }
    }
}
Also used : ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) KeeperHeartBeatManager(com.ctrip.xpipe.redis.meta.server.keeper.KeeperHeartBeatManager) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 27 with KeeperMeta

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

the class DefaultKeeperStateChangeHandler method keeperMasterChanged.

@Override
public void keeperMasterChanged(String clusterId, String shardId, Pair<String, Integer> newMaster) {
    logger.info("[keeperMasterChanged]{},{},{}", clusterId, shardId, newMaster);
    KeeperMeta activeKeeper = currentMetaManager.getKeeperActive(clusterId, shardId);
    if (activeKeeper == null) {
        logger.info("[keeperMasterChanged][no active keeper, do nothing]{},{},{}", clusterId, shardId, newMaster);
        return;
    }
    if (!activeKeeper.isActive()) {
        throw new IllegalStateException("[active keeper not active]{}" + activeKeeper);
    }
    logger.info("[keeperMasterChanged][set active keeper master]{}, {}", activeKeeper, newMaster);
    List<KeeperMeta> keepers = new LinkedList<>();
    keepers.add(activeKeeper);
    keyedOneThreadTaskExecutor.execute(new Pair<String, String>(clusterId, shardId), new KeeperStateChangeJob(keepers, newMaster, clientPool, scheduled, executors));
}
Also used : KeeperStateChangeJob(com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) LinkedList(java.util.LinkedList)

Example 28 with KeeperMeta

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

the class DefaultKeeperStateChangeHandler method keeperActiveElected.

@Override
public void keeperActiveElected(String clusterId, String shardId, KeeperMeta activeKeeper) {
    logger.info("[keeperActiveElected]{},{},{}", clusterId, shardId, activeKeeper);
    List<KeeperMeta> keepers = currentMetaManager.getSurviveKeepers(clusterId, shardId);
    if (keepers == null || keepers.size() == 0) {
        logger.info("[keeperActiveElected][none keeper survive, do nothing]");
        return;
    }
    Pair<String, Integer> activeKeeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
    KeeperStateChangeJob keeperStateChangeJob = new KeeperStateChangeJob(keepers, activeKeeperMaster, clientPool, scheduled, executors);
    if (!dcMetaCache.isCurrentDcPrimary(clusterId, shardId)) {
        List<RedisMeta> slaves = dcMetaCache.getShardRedises(clusterId, shardId);
        logger.info("[keeperActiveElected][current dc backup, set slave to new keeper]{},{},{}", clusterId, shardId, slaves);
        keeperStateChangeJob.setActiveSuccessCommand(new DefaultSlaveOfJob(slaves, activeKeeper.getIp(), activeKeeper.getPort(), clientPool, scheduled, executors));
    }
    keyedOneThreadTaskExecutor.execute(new Pair<String, String>(clusterId, shardId), keeperStateChangeJob);
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) KeeperStateChangeJob(com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 29 with KeeperMeta

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

the class DefaultMultiDcService method getActiveKeeper.

@Override
public KeeperMeta getActiveKeeper(String dcName, String clusterId, String shardId) {
    dcName = dcName.toLowerCase();
    DcInfo dcInfo = metaServerConfig.getDcInofs().get(dcName);
    if (dcInfo == null) {
        logger.error("[doChooseKeeperMaster][dc info null]{}", dcName);
        return null;
    }
    MetaServerMultiDcService metaServerMultiDcService = metaServerMultiDcServiceManager.getOrCreate(dcInfo.getMetaServerAddress());
    KeeperMeta keeperMeta = metaServerMultiDcService.getActiveKeeper(clusterId, shardId);
    return keeperMeta;
}
Also used : MetaServerMultiDcService(com.ctrip.xpipe.redis.core.metaserver.MetaServerMultiDcService) DcInfo(com.ctrip.xpipe.redis.core.meta.DcInfo) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 30 with KeeperMeta

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

the class BackupDcClusterRedisStateAjust method doRun.

@Override
protected void doRun() throws Exception {
    ClusterMeta clusterMeta = currentMetaManager.getClusterMeta(clusterId);
    if (clusterMeta == null) {
        logger.warn("[doRun][cluster null]{}", clusterId);
        return;
    }
    for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
        logger.debug("[doRun]{}, {}", clusterId, shardMeta.getId());
        KeeperMeta keeperActive = currentMetaManager.getKeeperActive(clusterId, shardMeta.getId());
        if (keeperActive == null) {
            logger.debug("[doRun][keeper active null]{}, {}", clusterId, shardMeta.getId());
            continue;
        }
        List<RedisMeta> redisesNeedChange = getRedisesNeedToChange(shardMeta, keeperActive);
        if (redisesNeedChange.size() == 0) {
            continue;
        }
        logger.info("[doRun][change state]{}, {}, {}", clusterId, keeperActive, redisesNeedChange);
        new DefaultSlaveOfJob(redisesNeedChange, keeperActive.getIp(), keeperActive.getPort(), pool, scheduled, executors).execute().addListener(new CommandFutureListener<Void>() {

            @Override
            public void operationComplete(CommandFuture<Void> commandFuture) throws Exception {
                if (!commandFuture.isSuccess()) {
                    logger.error("[operationComplete][fail]" + commandFuture.command(), commandFuture.cause());
                }
            }
        });
    }
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) 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