Search in sources :

Example 1 with ShardMeta

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

the class MetaServerPrepareResourcesAndStart method setupZkNodes.

private void setupZkNodes(CuratorFramework client, DcMeta dcMeta) throws Exception {
    for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
        for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
            String path = MetaZkConfig.getKeeperLeaderLatchPath(clusterMeta.getId(), shardMeta.getId());
            client.createContainers(path);
        }
    }
    String metaPath = MetaZkConfig.getMetaRootPath();
    client.createContainers(metaPath);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Example 2 with ShardMeta

use of com.ctrip.xpipe.redis.core.entity.ShardMeta 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 3 with ShardMeta

use of com.ctrip.xpipe.redis.core.entity.ShardMeta 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 4 with ShardMeta

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

the class MetaServiceTest method generateClusterMetaMockData.

private void generateClusterMetaMockData() {
    when(mockedDcService.find("ntgxh")).thenReturn(new DcTbl().setId(1L).setDcName("ntgxh").setDcLastModifiedTime("1234567"));
    when(mockedDcService.find(1L)).thenReturn(new DcTbl().setId(1L).setDcName("ntgxh").setDcLastModifiedTime("1234567"));
    when(mockedClusterService.find("cluster1")).thenReturn(new ClusterTbl().setId(1).setClusterName("cluster1").setActivedcId(1L).setClusterLastModifiedTime("1234567"));
    when(mockedDcClusterService.find("ntgxh", "cluster1")).thenReturn(new DcClusterTbl().setDcClusterId(1L).setDcClusterPhase(1));
    when(mockedShardService.findAllByClusterName("cluster1")).thenReturn(Arrays.asList(new ShardTbl().setId(1L).setShardName("shard1").setSetinelMonitorName("cluster1-shard1")));
    when(mockedShardMetaService.getShardMeta(any(DcTbl.class), any(ClusterTbl.class), any(ShardTbl.class))).thenReturn(new ShardMeta().setId("shard1").setPhase(1).setSentinelId(1L).setSentinelMonitorName("cluster1-shard1"));
}
Also used : ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Example 5 with ShardMeta

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

the class ShardMetaServiceImpl method getShardMeta.

@Override
public ShardMeta getShardMeta(final String dcName, final String clusterName, final String shardName) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
    Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {

        @Override
        public DcTbl call() throws DalException {
            return dcService.find(dcName);
        }
    });
    Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {

        @Override
        public ClusterTbl call() throws DalException {
            return clusterService.find(clusterName);
        }
    });
    Future<ShardTbl> future_shardInfo = fixedThreadPool.submit(new Callable<ShardTbl>() {

        @Override
        public ShardTbl call() throws DalException {
            return shardService.find(clusterName, shardName);
        }
    });
    Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {

        @Override
        public DcClusterTbl call() throws DalException {
            return dcClusterService.find(dcName, clusterName);
        }
    });
    Future<DcClusterShardTbl> future_dcClusterShardInfo = fixedThreadPool.submit(new Callable<DcClusterShardTbl>() {

        @Override
        public DcClusterShardTbl call() throws DalException {
            return dcClusterShardService.find(dcName, clusterName, shardName);
        }
    });
    try {
        if (null == future_dcInfo.get() || null == future_clusterInfo.get() || null == future_shardInfo.get() || null == future_dcClusterInfo.get() || null == future_dcClusterShardInfo.get()) {
            return new ShardMeta().setId(shardName);
        }
        return getShardMeta(future_dcInfo.get(), future_clusterInfo.get(), future_shardInfo.get(), future_dcClusterInfo.get(), future_dcClusterShardInfo.get());
    } catch (ExecutionException e) {
        throw new DataNotFoundException("Cannot construct shard-meta", e);
    } catch (InterruptedException e) {
        throw new ServerException("Concurrent execution failed.", e);
    } finally {
        fixedThreadPool.shutdown();
    }
}
Also used : DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Aggregations

ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)23 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)13 Test (org.junit.Test)11 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 Releasable (com.ctrip.xpipe.api.lifecycle.Releasable)1 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 DcClusterShardTbl (com.ctrip.xpipe.redis.console.model.DcClusterShardTbl)1 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)1 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)1 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)1 DefaultXpipeMetaManager (com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)1 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)1 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)1