Search in sources :

Example 1 with DefaultSlaveOfJob

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

the class BecomePrimaryAction method makeRedisesOk.

@Override
protected void makeRedisesOk(Pair<String, Integer> newMaster, List<RedisMeta> slaves) {
    executionLog.info("[make redis master]" + newMaster);
    SimpleObjectPool<NettyClient> masterPool = keyedObjectPool.getKeyPool(new InetSocketAddress(newMaster.getKey(), newMaster.getValue()));
    Command<String> command = new DefaultSlaveOfCommand(masterPool, null, 0, scheduled);
    try {
        String result = command.execute().get();
        executionLog.info("[make redis master]" + result);
        RedisReadonly redisReadOnly = RedisReadonly.create(newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled);
        if (!(redisReadOnly instanceof SlaveOfRedisReadOnly)) {
            redisReadOnly.makeWritable();
        }
    } catch (Exception e) {
        logger.error("[makeRedisesOk]" + newMaster, e);
        executionLog.error("[make redis master fail]" + e.getMessage());
        throw new MakeRedisMasterFailException("make redis master:" + newMaster, e);
    }
    executionLog.info("[make slaves slaveof][begin]" + newMaster + "," + slaves);
    Command<Void> slavesJob = new DefaultSlaveOfJob(slaves, newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled, executors);
    try {
        slavesJob.execute().get(waitTimeoutSeconds, TimeUnit.SECONDS);
        executionLog.info("[make slaves slaveof]success");
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        logger.error("[makeRedisesOk]" + slaves + "->" + newMaster, e);
        executionLog.error("[make slaves slaveof][fail]" + e.getMessage());
        throw new MakeRedisSlaveOfMasterFailException(String.format("fail make slaves slave of:%s, %s", newMaster, e.getMessage()), e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) MakeRedisSlaveOfMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException) DefaultSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand) MakeRedisMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisMasterFailException) MakeRedisMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisMasterFailException) MakeRedisSlaveOfMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException) ChooseNewMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient)

Example 2 with DefaultSlaveOfJob

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

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

DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)3 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)2 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 DefaultSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand)1 ChooseNewMasterFailException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException)1 MakeRedisMasterFailException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisMasterFailException)1 MakeRedisSlaveOfMasterFailException (com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException)1 KeeperStateChangeJob (com.ctrip.xpipe.redis.meta.server.job.KeeperStateChangeJob)1 InetSocketAddress (java.net.InetSocketAddress)1