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();
}
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;
}
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());
}
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));
}
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());
}
}
});
}
Aggregations