Search in sources :

Example 1 with XpipeMetaManager

use of com.ctrip.xpipe.redis.core.meta.XpipeMetaManager in project x-pipe by ctripcorp.

the class ConfigCheck method fromXpipe.

private CheckCluster fromXpipe(XpipeMeta xpipeMeta, String checkCluster) {
    XpipeMetaManager xpm = new DefaultXpipeMetaManager(xpipeMeta);
    CheckCluster result = new CheckCluster(checkCluster);
    for (String dc : dcs) {
        ClusterMeta clusterMeta = xpm.getClusterMeta(dc, checkCluster);
        if (clusterMeta == null) {
            continue;
        }
        for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
            CheckShard orShard = result.getOrCreate(shardMeta.getId());
            shardMeta.getRedises().forEach(redis -> {
                orShard.addRedis(new CheckRedis(redis.getIp(), redis.getPort(), dc));
            });
        }
    }
    return result;
}
Also used : DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager) XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Example 2 with XpipeMetaManager

use of com.ctrip.xpipe.redis.core.meta.XpipeMetaManager in project x-pipe by ctripcorp.

the class DefaultMetaCache method findMasterInSameShard.

@Override
public HostPort findMasterInSameShard(HostPort hostPort) {
    XpipeMetaManager xpipeMetaManager = meta.getValue();
    XpipeMetaManager.MetaDesc metaDesc = xpipeMetaManager.findMetaDesc(hostPort);
    if (metaDesc == null) {
        throw new IllegalStateException("unfound shard for instance:" + hostPort);
    }
    String clusterName = metaDesc.getClusterId();
    String shardName = metaDesc.getShardId();
    Pair<String, RedisMeta> redisMaster = xpipeMetaManager.getRedisMaster(clusterName, shardName);
    // could be null if no master in a shard
    if (redisMaster == null) {
        return null;
    }
    RedisMeta redisMeta = redisMaster.getValue();
    return new HostPort(redisMeta.getIp(), redisMeta.getPort());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Example 3 with XpipeMetaManager

use of com.ctrip.xpipe.redis.core.meta.XpipeMetaManager in project x-pipe by ctripcorp.

the class DefaultMetaCache method findMaster.

@Override
public HostPort findMaster(String clusterId, String shardId) throws MasterNotFoundException {
    XpipeMetaManager xpipeMetaManager = meta.getValue();
    Pair<String, RedisMeta> redisMaster = xpipeMetaManager.getRedisMaster(clusterId, shardId);
    if (redisMaster == null) {
        throw new MasterNotFoundException(clusterId, shardId);
    }
    return new HostPort(redisMaster.getValue().getIp(), redisMaster.getValue().getPort());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Example 4 with XpipeMetaManager

use of com.ctrip.xpipe.redis.core.meta.XpipeMetaManager in project x-pipe by ctripcorp.

the class DefaultMetaCache method getSentinelMonitorName.

@Override
public String getSentinelMonitorName(String clusterId, String shardId) {
    XpipeMetaManager xpipeMetaManager = meta.getValue();
    Set<String> dcs = xpipeMetaManager.getDcs();
    for (String dc : dcs) {
        ShardMeta shardMeta = xpipeMetaManager.getShardMeta(dc, clusterId, shardId);
        if (shardMeta != null) {
            return shardMeta.getSentinelMonitorName();
        }
    }
    return null;
}
Also used : XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Example 5 with XpipeMetaManager

use of com.ctrip.xpipe.redis.core.meta.XpipeMetaManager in project x-pipe by ctripcorp.

the class DefaultMetaCache method inBackupDc.

@Override
public boolean inBackupDc(HostPort hostPort) {
    XpipeMetaManager xpipeMetaManager = meta.getValue();
    XpipeMetaManager.MetaDesc metaDesc = xpipeMetaManager.findMetaDesc(hostPort);
    if (metaDesc == null) {
        throw new IllegalStateException("unfound shard for instance:" + hostPort);
    }
    String instanceInDc = metaDesc.getDcId();
    String activeDc = metaDesc.getActiveDc();
    return !activeDc.equalsIgnoreCase(instanceInDc);
}
Also used : XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Aggregations

XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)9 DefaultXpipeMetaManager (com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)9 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 Pair (com.ctrip.xpipe.tuple.Pair)1