Search in sources :

Example 16 with RedisMeta

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());
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Pair(com.ctrip.xpipe.tuple.Pair)

Example 17 with RedisMeta

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;
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList)

Example 18 with RedisMeta

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);
        }
    }
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest)

Example 19 with RedisMeta

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);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Test(org.junit.Test)

Example 20 with RedisMeta

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));
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

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