Search in sources :

Example 21 with HostAndPort

use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.

the class JedisSentinelPoolTest method waitForJedisSentinelPoolRecognizeNewMaster.

private void waitForJedisSentinelPoolRecognizeNewMaster(JedisSentinelPool pool, HostAndPort newMaster) throws InterruptedException {
    while (true) {
        HostAndPort currentHostMaster = pool.getCurrentHostMaster();
        if (newMaster.equals(currentHostMaster))
            break;
        System.out.println("JedisSentinelPool's master is not yet changed, sleep...");
        Thread.sleep(100);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 22 with HostAndPort

use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.

the class JedisSentinelPoolTest method forceFailover.

private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
    HostAndPort oldMaster = pool.getCurrentHostMaster();
    // jedis connection should be master
    Jedis beforeFailoverJedis = pool.getResource();
    assertEquals("PONG", beforeFailoverJedis.ping());
    waitForFailover(pool, oldMaster);
    Jedis afterFailoverJedis = pool.getResource();
    assertEquals("PONG", afterFailoverJedis.ping());
    assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
    assertEquals(2, afterFailoverJedis.getDB());
    // returning both connections to the pool should not throw
    beforeFailoverJedis.close();
    afterFailoverJedis.close();
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Jedis(redis.clients.jedis.Jedis)

Example 23 with HostAndPort

use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.

the class JedisSentinelPoolTest method waitForFailover.

private void waitForFailover(JedisSentinelPool pool, HostAndPort oldMaster) throws InterruptedException {
    HostAndPort newMaster = JedisSentinelTestUtil.waitForNewPromotedMaster(MASTER_NAME, sentinelJedis1, sentinelJedis2);
    waitForJedisSentinelPoolRecognizeNewMaster(pool, newMaster);
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 24 with HostAndPort

use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.

the class ClusterNodeInformationParser method parse.

public ClusterNodeInformation parse(String nodeInfo, HostAndPort current) {
    String[] nodeInfoPartArray = nodeInfo.split(" ");
    HostAndPort node = getHostAndPortFromNodeLine(nodeInfoPartArray, current);
    ClusterNodeInformation info = new ClusterNodeInformation(node);
    if (nodeInfoPartArray.length >= SLOT_INFORMATIONS_START_INDEX) {
        String[] slotInfoPartArray = extractSlotParts(nodeInfoPartArray);
        fillSlotInformation(slotInfoPartArray, info);
    }
    return info;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort)

Example 25 with HostAndPort

use of redis.clients.jedis.HostAndPort in project new-cloud by xie-summer.

the class AppDeployCenterImpl method addHorizontalNodes.

@Override
public boolean addHorizontalNodes(Long appId, String masterHost, String slaveHost, int memory) {
    AppDesc appDesc = appDao.getAppDescById(appId);
    // 1. 寻找主从节点的可用端口
    Integer masterPort = machineCenter.getAvailablePort(masterHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
    if (masterPort == null) {
        logger.error("master host={} getAvailablePort is null", masterHost);
        return false;
    }
    Integer slavePort = 0;
    boolean hasSlave = StringUtils.isNotBlank(slaveHost);
    if (hasSlave) {
        slavePort = machineCenter.getAvailablePort(slaveHost, ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
        if (slavePort == null) {
            logger.error("slave host={} getAvailablePort is null", slaveHost);
            return false;
        }
    }
    // 2. 启动主从节点
    boolean isMasterCreate = redisDeployCenter.createRunNode(appDesc, masterHost, masterPort, memory, true);
    if (!isMasterCreate) {
        logger.error("createRunNode master failed {}:{}", masterHost, masterPort);
        return false;
    }
    if (hasSlave) {
        // 运行节点
        boolean isSlaveCreate = redisDeployCenter.createRunNode(appDesc, slaveHost, slavePort, memory, true);
        if (!isSlaveCreate) {
            logger.error("createRunNode slave failed {}:{}", slaveHost, slavePort);
            return false;
        }
    }
    // 3. 获取应用下有效节点
    Set<HostAndPort> clusterHosts = getEffectiveInstanceList(appId);
    // 4. 添加新节点: meet,复制,不做slot分配
    RedisClusterReshard clusterReshard = new RedisClusterReshard(clusterHosts, redisCenter, instanceReshardProcessDao);
    boolean joinCluster = clusterReshard.joinCluster(appId, masterHost, masterPort, slaveHost, slavePort);
    if (joinCluster) {
        // 5. 保存实例,开启统计功能
        saveInstance(appId, masterHost, masterPort, memory);
        redisCenter.deployRedisCollection(appId, masterHost, masterPort);
        if (hasSlave) {
            saveInstance(appId, slaveHost, slavePort, memory);
            redisCenter.deployRedisCollection(appId, slaveHost, slavePort);
        }
    }
    return joinCluster;
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) RedisClusterReshard(com.sohu.cache.redis.RedisClusterReshard) AppDesc(com.sohu.cache.entity.AppDesc)

Aggregations

HostAndPort (redis.clients.jedis.HostAndPort)95 Test (org.junit.Test)42 JedisCluster (redis.clients.jedis.JedisCluster)33 HashSet (java.util.HashSet)31 Jedis (redis.clients.jedis.Jedis)24 LinkedHashSet (java.util.LinkedHashSet)18 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)10 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 JedisPool (redis.clients.jedis.JedisPool)7 ClusterNodeInformation (redis.clients.util.ClusterNodeInformation)6 AppDesc (com.sohu.cache.entity.AppDesc)5 InstanceInfo (com.sohu.cache.entity.InstanceInfo)5 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)5 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JedisPubSub (redis.clients.jedis.JedisPubSub)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JSONObject (com.alibaba.fastjson.JSONObject)2