Search in sources :

Example 11 with RedisMeta

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

the class BaseSampleMonitor method generatePlan.

@Override
public Collection<BaseSamplePlan<T>> generatePlan(List<DcMeta> dcMetas) {
    Map<Pair<String, String>, BaseSamplePlan<T>> plans = new HashMap<>();
    for (DcMeta dcMeta : dcMetas) {
        for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
            if (!addCluster(dcMeta.getId(), clusterMeta)) {
                continue;
            }
            for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
                Pair<String, String> cs = new Pair<>(clusterMeta.getId(), shardMeta.getId());
                BaseSamplePlan<T> plan = plans.get(cs);
                if (plan == null) {
                    plan = createPlan(dcMeta.getId(), clusterMeta.getId(), shardMeta.getId());
                    plans.put(cs, plan);
                }
                for (RedisMeta redisMeta : shardMeta.getRedises()) {
                    log.debug("[generatePlan]{}", redisMeta.desc());
                    addRedis(plan, dcMeta.getId(), redisMeta);
                }
                if (plan.isEmpty()) {
                    plans.remove(cs);
                }
            }
        }
    }
    return plans.values();
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Pair(com.ctrip.xpipe.tuple.Pair)

Example 12 with RedisMeta

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

the class DefaultRedisSessionManager method getInUseRedises.

private Set<HostPort> getInUseRedises() {
    Set<HostPort> redisInUse = new HashSet<>();
    List<DcMeta> dcMetas = new LinkedList<>(metaCache.getXpipeMeta().getDcs().values());
    if (dcMetas.isEmpty())
        return null;
    for (DcMeta dcMeta : dcMetas) {
        if (dcMeta == null)
            break;
        for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
            for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
                for (RedisMeta redisMeta : shardMeta.getRedises()) {
                    redisInUse.add(new HostPort(redisMeta.getIp(), redisMeta.getPort()));
                }
            }
        }
    }
    return redisInUse;
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) HostPort(com.ctrip.xpipe.endpoint.HostPort) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 13 with RedisMeta

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

the class AtLeastOneCheckerTest method testCheckerTimeout.

@Test
public void testCheckerTimeout() throws Exception {
    Server server = startServer((String) null);
    List<RedisMeta> redises = new LinkedList<>();
    redises.add(new RedisMeta().setIp("localhost").setPort(server.getPort()));
    SimpleErrorMessage check = new AtLeastOneChecker(redises, getXpipeNettyClientKeyedObjectPool(), scheduled).check();
    Assert.assertEquals(SIMPLE_RETURN_CODE.FAIL, check.getErrorType());
}
Also used : Server(com.ctrip.xpipe.simpleserver.Server) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 14 with RedisMeta

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

the class DefaultMetaServer method changePrimaryDcCheck.

@Override
public PrimaryDcCheckMessage changePrimaryDcCheck(String clusterId, String shardId, String newPrimaryDc, ForwardInfo forwardInfo) {
    logger.info("[changePrimaryDcCheck]{}, {}, {}, {}", clusterId, shardId, newPrimaryDc, forwardInfo);
    String currentPrimaryDc = dcMetaCache.getPrimaryDc(clusterId, shardId);
    String currentDc = dcMetaCache.getCurrentDc();
    if (newPrimaryDc.equalsIgnoreCase(currentPrimaryDc)) {
        return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.PRIMARY_DC_ALREADY_IS_NEW, String.format("%s already primary dc", newPrimaryDc));
    }
    if (currentDc.equalsIgnoreCase(newPrimaryDc)) {
        List<RedisMeta> redises = dcMetaCache.getShardRedises(clusterId, shardId);
        SimpleErrorMessage result = new AtLeastOneChecker(redises, keyedObjectPool, scheduled).check();
        if (result.getErrorType() == SIMPLE_RETURN_CODE.SUCCESS) {
            return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS);
        }
        return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.FAIL, "all redises dead:" + result.getErrorMessage());
    }
    return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS, String.format("current dc :%s is not new primary: %s ", currentDc, newPrimaryDc));
}
Also used : PrimaryDcCheckMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage)

Example 15 with RedisMeta

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

the class AbstractRedisesSlaveofJob method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    ParallelCommandChain commandChain = new ParallelCommandChain(executors);
    for (RedisMeta redisMeta : redises) {
        Command<?> backupCommand = createSlaveofCommand(redisMeta, masterHost, masterPort);
        commandChain.add(backupCommand);
    }
    commandChain.execute().addListener(new CommandFutureListener<Object>() {

        @Override
        public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
            if (commandFuture.isSuccess()) {
                future().setSuccess(null);
            } else {
                future().setFailure(commandFuture.cause());
            }
        }
    });
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Aggregations

RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)55 Test (org.junit.Test)26 LinkedList (java.util.LinkedList)14 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)9 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)8 Before (org.junit.Before)7 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)5 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)5 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)5 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)4 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)4 SlaveRole (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole)4 Pair (com.ctrip.xpipe.tuple.Pair)4 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)3 PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)3 Server (com.ctrip.xpipe.simpleserver.Server)3 InetSocketAddress (java.net.InetSocketAddress)3 SERVER_ROLE (com.ctrip.xpipe.api.server.Server.SERVER_ROLE)2 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)2