use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class BecomePrimaryAction method chooseNewMaster.
@Override
protected Pair<String, Integer> chooseNewMaster(String clusterId, String shardId) {
List<RedisMeta> redises = dcMetaCache.getShardRedises(clusterId, shardId);
String desc = MetaUtils.toString(redises);
executionLog.info("[chooseNewMaster][from]" + desc);
RedisMeta newMaster = newMasterChooser.choose(redises);
if (newMaster == null) {
throw ChooseNewMasterFailException.chooseNull(redises);
}
return new Pair<>(newMaster.getIp(), newMaster.getPort());
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class BecomePrimaryAction method getAllSlaves.
@Override
protected List<RedisMeta> getAllSlaves(Pair<String, Integer> newMaster, List<RedisMeta> shardRedises) {
List<RedisMeta> result = new LinkedList<>();
Iterator<RedisMeta> iterator = shardRedises.iterator();
while (iterator.hasNext()) {
RedisMeta current = iterator.next();
if (ObjectUtils.equals(current.getIp(), newMaster.getKey()) && ObjectUtils.equals(current.getPort(), newMaster.getValue())) {
continue;
}
result.add(current);
}
return result;
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class DefaultXpipeMetaManagerTest method testUpdateRedisMaster.
@Test
public void testUpdateRedisMaster() throws MetaException {
Pair<String, RedisMeta> redisMaster = metaManager.getRedisMaster(clusterId, shardId);
Assert.assertEquals(redisMaster.getKey(), "jq");
boolean result = metaManager.updateRedisMaster(redisMaster.getKey(), clusterId, shardId, redisMaster.getValue());
Assert.assertTrue(!result);
KeeperMeta activeKeeper = null;
for (KeeperMeta keeperMeta : metaManager.getKeepers(dc, clusterId, shardId)) {
if (keeperMeta.getMaster().equals(String.format("%s:%d", redisMaster.getValue().getIp(), redisMaster.getValue().getPort()))) {
activeKeeper = keeperMeta;
}
}
Assert.assertNotNull(activeKeeper);
for (RedisMeta redis : metaManager.getRedises(dc, clusterId, shardId)) {
if (!redis.equals(redisMaster.getValue())) {
String master = String.format("%s:%d", redis.getIp(), redis.getPort());
Assert.assertNotEquals(activeKeeper.getMaster(), master);
result = metaManager.updateRedisMaster(redisMaster.getKey(), clusterId, shardId, redis);
Assert.assertTrue(result);
KeeperMeta active = metaManager.getKeeperActive(redisMaster.getKey(), clusterId, shardId);
Assert.assertEquals(active.getMaster(), master);
}
}
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class DcMetaComparatorTest method testModifyRedisConfig.
@Test
public void testModifyRedisConfig() {
ClusterMeta clusterMeta = (ClusterMeta) future.getClusters().values().toArray()[0];
ShardMeta shardMeta = (ShardMeta) clusterMeta.getShards().values().toArray()[0];
RedisMeta redisMeta = shardMeta.getRedises().get(0);
redisMeta.setPort(redisMeta.getPort() + 10000);
DcMetaComparator dcMetaComparator = new DcMetaComparator(current, future);
dcMetaComparator.compare();
Assert.assertEquals(0, dcMetaComparator.getRemoved().size());
Assert.assertEquals(0, dcMetaComparator.getAdded().size());
Assert.assertEquals(1, dcMetaComparator.getMofified().size());
ClusterMetaComparator comparator = (ClusterMetaComparator) dcMetaComparator.getMofified().toArray()[0];
Assert.assertEquals(clusterMeta.getId(), comparator.getCurrent().getId());
Assert.assertEquals(0, comparator.getAdded().size());
Assert.assertEquals(0, comparator.getRemoved().size());
Assert.assertEquals(1, comparator.getMofified().size());
ShardMetaComparator shardMetaComparator = (ShardMetaComparator) comparator.getMofified().toArray()[0];
Assert.assertEquals(1, shardMetaComparator.getAdded().size());
Assert.assertEquals(1, shardMetaComparator.getRemoved().size());
Assert.assertEquals(0, shardMetaComparator.getMofified().size());
logger.debug("{}", dcMetaComparator);
}
use of com.ctrip.xpipe.redis.core.entity.RedisMeta in project x-pipe by ctripcorp.
the class SimpleTest method test.
@Test
public void test() throws Exception {
RedisMeta slave = new RedisMeta();
slave.setIp("localhost");
slave.setPort(6379);
System.out.println(getRedisServerRole(slave));
}
Aggregations