Search in sources :

Example 1 with KeeperStateChangeJob

use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob in project x-pipe by ctripcorp.

the class AbstractKeeperIntegratedMultiDc method makeKeeperRight.

private void makeKeeperRight() throws Exception {
    logger.info(remarkableMessage("makeKeeperRight"));
    DcMeta dcMeta = activeDc();
    List<KeeperMeta> keepers = getDcKeepers(dcMeta.getId(), getClusterId(), getShardId());
    RedisMeta redisMaster = getRedisMaster();
    KeeperStateChangeJob job = new KeeperStateChangeJob(keepers, new Pair<String, Integer>(redisMaster.getIp(), redisMaster.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
    job.execute().sync();
    for (DcMeta backupDc : backupDcs()) {
        List<KeeperMeta> backupKeepers = getDcKeepers(backupDc.getId(), getClusterId(), getShardId());
        job = new KeeperStateChangeJob(backupKeepers, new Pair<String, Integer>(activeDcKeeperActive.getIp(), activeDcKeeperActive.getPort()), getXpipeNettyClientKeyedObjectPool(), scheduled, executors);
        job.execute().sync();
    }
}
Also used : KeeperStateChangeJob(com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob) Pair(com.ctrip.xpipe.tuple.Pair)

Example 2 with KeeperStateChangeJob

use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob 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 KeeperStateChangeJob

use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob 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 4 with KeeperStateChangeJob

use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob 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 5 with KeeperStateChangeJob

use of com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob 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)

Aggregations

KeeperStateChangeJob (com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob)5 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)1 Pair (com.ctrip.xpipe.tuple.Pair)1 LinkedList (java.util.LinkedList)1