Search in sources :

Example 1 with InfoCommand

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

the class XRedisXpipeCommandTest method getSyncFull.

private Integer getSyncFull(RedisMeta redis) throws Exception {
    SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(redis.getIp(), redis.getPort()));
    InfoCommand infoCommand = new InfoCommand(keyPool, InfoCommand.INFO_TYPE.STATS, scheduled);
    String value = infoCommand.execute().get();
    Integer sync_full = new InfoResultExtractor(value).extractAsInteger("sync_full");
    return sync_full;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InfoResultExtractor(com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Example 2 with InfoCommand

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

the class RedisPromotor method redisModified.

private void redisModified(RedisSlave redisSlave, SimpleObjectPool<NettyClient> clientPool) throws Exception {
    try {
        logger.info("[redisModified]{}", redisSlave);
        AbstractSlaveOfCommand slaveOfCmd = new SlaveOfCommand(clientPool, scheduled);
        slaveOfCmd.execute().sync();
        InfoCommand infoServerCmd = new InfoCommand(clientPool, "server", scheduled);
        String info = infoServerCmd.execute().get();
        String masterId = null;
        List<String> lines = IOUtils.readLines(new StringReader(info));
        for (String line : lines) {
            if (line.startsWith("run_id:")) {
                masterId = line.substring("run_id:".length());
            }
        }
        InfoCommand infoLastMasterCmd = new InfoCommand(clientPool, "lastmaster", scheduled);
        String infoLastMaster = infoLastMasterCmd.execute().get();
        long keeperOffset = 0, newMasterOffset = 0;
        try {
            String[] parts = infoLastMaster.split("\\s");
            keeperOffset = Long.parseLong(parts[1]);
            newMasterOffset = Long.parseLong(parts[2]);
            redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.SLAVE_PROMTED, new SlavePromotionInfo(keeperOffset, new DefaultEndPoint(promoteServerIp, promoteServerPort), masterId, newMasterOffset));
        } catch (Exception e) {
            logger.error("[onComplete]" + promoteServerIp + ":" + promoteServerPort, e);
        }
    } catch (IOException e1) {
        logger.error("promoteSlaveToMaster", e1);
    }
}
Also used : AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand) StringReader(java.io.StringReader) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)

Example 3 with InfoCommand

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

the class DefaultSentinelManager method infoSentinel.

@Override
public String infoSentinel(Sentinel sentinel) {
    SimpleObjectPool<NettyClient> clientPool = keyedClientPool.getKeyPool(new InetSocketAddress(sentinel.getIp(), sentinel.getPort()));
    InfoCommand infoCommand = new InfoCommand(clientPool, InfoCommand.INFO_TYPE.SENTINEL, scheduled);
    infoCommand.logResponse(false);
    try {
        return infoCommand.execute().get();
    } catch (Exception e) {
        logger.error("[infoSentinel] " + sentinel, e);
    }
    return null;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Example 4 with InfoCommand

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

the class AbstractRedisTest method getInfoKey.

protected String getInfoKey(RedisMeta slaveMeta, String infoSection, String key) throws Exception {
    SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(slaveMeta.getIp(), slaveMeta.getPort()));
    String info = new InfoCommand(keyPool, infoSection, scheduled).execute().get();
    return new InfoResultExtractor(info).extract(key);
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InfoResultExtractor(com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Example 5 with InfoCommand

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

the class AbstractRedisTest method getRedisServerRole.

protected SERVER_ROLE getRedisServerRole(RedisMeta slave) throws Exception {
    SimpleObjectPool<NettyClient> clientPool = NettyPoolUtil.createNettyPool(new InetSocketAddress(slave.getIp(), slave.getPort()));
    String info = new InfoCommand(clientPool, "replication", scheduled).execute().get();
    for (String line : info.split("\r\n")) {
        String[] parts = line.split(":");
        if (parts.length >= 2 && parts[0].equals("role")) {
            String role = parts[1].trim();
            return SERVER_ROLE.of(role);
        }
    }
    return SERVER_ROLE.UNKNOWN;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)

Aggregations

InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)5 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)4 InetSocketAddress (java.net.InetSocketAddress)4 InfoResultExtractor (com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor)2 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)1 AbstractSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand)1 SlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ExecutionException (java.util.concurrent.ExecutionException)1