Search in sources :

Example 1 with RedisInfo

use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.

the class DefaultOffsetwaiter method doWait.

private boolean doWait(String masterReplId, Long masterOffset, HostPort hostPort, ExecutionLog executionLog) {
    int waitMilli = metaServerConfig.getWaitforOffsetMilli();
    long endTime = System.currentTimeMillis() + waitMilli;
    String slaveReplId = null;
    Long slaveOffset = null;
    executionLog.info(String.format("wait timeout config:%d ms", waitMilli));
    while (true) {
        InfoReplicationComplementCommand command = new InfoReplicationComplementCommand(keyedObjectPool.getKeyPool(new InetSocketAddress(hostPort.getHost(), hostPort.getPort())), scheduled);
        try {
            RedisInfo redisInfo = command.execute().get(waitMilli, TimeUnit.MILLISECONDS);
            if ((redisInfo instanceof MasterInfo) || !(redisInfo instanceof SlaveInfo)) {
                executionLog.info("target role:" + (redisInfo == null ? "null" : redisInfo.getClass().getSimpleName()));
                break;
            }
            SlaveInfo slaveInfo = (SlaveInfo) redisInfo;
            slaveReplId = slaveInfo.getMasterReplId();
            slaveOffset = slaveInfo.getSlaveReplOffset();
            if (!StringUtil.isEmpty(slaveReplId) && !StringUtil.isEmpty(masterReplId)) {
                if (!slaveReplId.equalsIgnoreCase(masterReplId)) {
                    executionLog.info(String.format("master replid not equal with slave replid, break. %s %s", masterReplId, slaveReplId));
                    break;
                }
            }
            if (slaveOffset >= masterOffset) {
                executionLog.info(String.format("wait succeed:%d >= %d", slaveOffset, masterOffset));
                return true;
            }
        } catch (Exception e) {
            executionLog.error(e.getMessage());
            logger.error("[waitfor]" + hostPort, e);
        }
        long current = System.currentTimeMillis();
        if (current >= endTime) {
            executionLog.error("wait time out, exit");
            break;
        }
        sleep(1);
    }
    if (slaveOffset != null) {
        executionLog.info(String.format("master offset:%s, slave offset:%d, sub:%d", masterOffset, slaveOffset, masterOffset - slaveOffset));
    }
    return false;
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) InetSocketAddress(java.net.InetSocketAddress) RedisInfo(com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo) SlaveInfo(com.ctrip.xpipe.redis.core.protocal.pojo.SlaveInfo) InfoReplicationComplementCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoReplicationComplementCommand)

Example 2 with RedisInfo

use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.

the class DefaultPrimaryDcPrepareToChange method prepare.

@Override
public MetaServerConsoleService.PreviousPrimaryDcMessage prepare(String clusterId, String shardId) {
    logger.info("[prepare]{}, {}", clusterId, shardId);
    MetaServerConsoleService.PreviousPrimaryDcMessage message = new MetaServerConsoleService.PreviousPrimaryDcMessage();
    ExecutionLog executionLog = new ExecutionLog(String.format("meta server:%s", currentClusterServer.getClusterInfo()));
    Pair<String, Integer> keeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
    message.setMasterAddr(new HostPort(keeperMaster.getKey(), keeperMaster.getValue()));
    executionLog.info("[prepare]" + keeperMaster);
    RedisInfo redisInfo = getInfoReplication(keeperMaster, executionLog);
    MasterInfo masterInfo = convert(redisInfo, executionLog);
    message.setMasterInfo(masterInfo);
    logger.info("[prepare]{}, {}, {}", keeperMaster, redisInfo, masterInfo);
    makeMasterReadOnly(clusterId, shardId, keeperMaster, true, executionLog);
    removeSentinel(clusterId, shardId, executionLog);
    message.setMessage(executionLog.getLog());
    return message;
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) MetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService) HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisInfo(com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo)

Example 3 with RedisInfo

use of com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo in project x-pipe by ctripcorp.

the class DefaultPrimaryDcPrepareToChange method getInfoReplication.

public RedisInfo getInfoReplication(Pair<String, Integer> redisMaster, ExecutionLog executionLog) {
    InfoReplicationComplementCommand command = new InfoReplicationComplementCommand(keyedObjectPool.getKeyPool(new InetSocketAddress(redisMaster.getKey(), redisMaster.getValue())), scheduled);
    try {
        executionLog.info("[getInfoReplication]" + redisMaster);
        RedisInfo redisInfo = command.execute().get(waitForMasterInfoMilli, TimeUnit.MILLISECONDS);
        executionLog.info("[getInfoReplication]" + redisInfo);
        return redisInfo;
    } catch (InterruptedException e) {
        logger.error("[getInfoReplication]" + redisMaster, e);
        executionLog.error(e.getMessage());
    } catch (ExecutionException e) {
        logger.error("[getInfoReplication]" + redisMaster, e);
        executionLog.error(e.getMessage());
    } catch (TimeoutException e) {
        logger.error("[getInfoReplication]" + redisMaster, e);
        executionLog.error(e.getMessage());
    }
    return null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RedisInfo(com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo) ExecutionException(java.util.concurrent.ExecutionException) InfoReplicationComplementCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoReplicationComplementCommand) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RedisInfo (com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo)3 InfoReplicationComplementCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoReplicationComplementCommand)2 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)2 InetSocketAddress (java.net.InetSocketAddress)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 MetaServerConsoleService (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService)1 SlaveInfo (com.ctrip.xpipe.redis.core.protocal.pojo.SlaveInfo)1 ExecutionLog (com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1