Search in sources :

Example 26 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class MinSlavesRedisReadOnly method createTransactionalCommand.

private Command<?> createTransactionalCommand(int number) {
    SimpleObjectPool<NettyClient> clientPool = keyedObjectPool.getKeyPool(new InetSocketAddress(ip, port));
    ConfigSetMinSlavesToWrite configSetMinSlavesToWrite = new ConfigSetMinSlavesToWrite(null, number, scheduled);
    return new TransactionalCommand(clientPool, scheduled, configSetMinSlavesToWrite, new ConfigRewrite(null, scheduled));
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) ConfigRewrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite) InetSocketAddress(java.net.InetSocketAddress) ConfigSetMinSlavesToWrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigSetCommand.ConfigSetMinSlavesToWrite) TransactionalCommand(com.ctrip.xpipe.redis.core.protocal.cmd.transaction.TransactionalCommand)

Example 27 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class BecomePrimaryAction method makeRedisesOk.

@Override
protected void makeRedisesOk(Pair<String, Integer> newMaster, List<RedisMeta> slaves) {
    executionLog.info("[make redis master]" + newMaster);
    SimpleObjectPool<NettyClient> masterPool = keyedObjectPool.getKeyPool(new InetSocketAddress(newMaster.getKey(), newMaster.getValue()));
    Command<String> command = new DefaultSlaveOfCommand(masterPool, null, 0, scheduled);
    try {
        String result = command.execute().get();
        executionLog.info("[make redis master]" + result);
        RedisReadonly redisReadOnly = RedisReadonly.create(newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled);
        if (!(redisReadOnly instanceof SlaveOfRedisReadOnly)) {
            redisReadOnly.makeWritable();
        }
    } catch (Exception e) {
        logger.error("[makeRedisesOk]" + newMaster, e);
        executionLog.error("[make redis master fail]" + e.getMessage());
        throw new MakeRedisMasterFailException("make redis master:" + newMaster, e);
    }
    executionLog.info("[make slaves slaveof][begin]" + newMaster + "," + slaves);
    Command<Void> slavesJob = new DefaultSlaveOfJob(slaves, newMaster.getKey(), newMaster.getValue(), keyedObjectPool, scheduled, executors);
    try {
        slavesJob.execute().get(waitTimeoutSeconds, TimeUnit.SECONDS);
        executionLog.info("[make slaves slaveof]success");
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        logger.error("[makeRedisesOk]" + slaves + "->" + newMaster, e);
        executionLog.error("[make slaves slaveof][fail]" + e.getMessage());
        throw new MakeRedisSlaveOfMasterFailException(String.format("fail make slaves slave of:%s, %s", newMaster, e.getMessage()), e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) MakeRedisSlaveOfMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException) DefaultSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand) MakeRedisMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisMasterFailException) MakeRedisMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisMasterFailException) MakeRedisSlaveOfMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.MakeRedisSlaveOfMasterFailException) ChooseNewMasterFailException(com.ctrip.xpipe.redis.meta.server.dcchange.exception.ChooseNewMasterFailException) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient)

Example 28 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class PrimaryDcKeeperMasterChooserAlgorithm method isMaster.

protected boolean isMaster(RedisMeta redisMeta) {
    try {
        SimpleObjectPool<NettyClient> clientPool = keyedObjectPool.getKeyPool(new InetSocketAddress(redisMeta.getIp(), redisMeta.getPort()));
        Role role = new RoleCommand(clientPool, checkRedisTimeoutSeconds * 1000, false, scheduled).execute().get(checkRedisTimeoutSeconds, TimeUnit.SECONDS);
        return SERVER_ROLE.MASTER == role.getServerRole();
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        logger.error("[isMaster]" + redisMeta, e);
    }
    return false;
}
Also used : Role(com.ctrip.xpipe.redis.core.protocal.pojo.Role) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) RoleCommand(com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 29 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class XpipeNettyClientPoolTest method testDeadBorrow.

@Test
public void testDeadBorrow() throws Exception {
    XpipeNettyClientPool clientPool = new XpipeNettyClientPool(new InetSocketAddress("127.0.0.1", serverPort.getPort()));
    clientPool.initialize();
    clientPool.start();
    NettyClient nettyClient = clientPool.borrowObject();
    Channel channel1 = nettyClient.channel();
    clientPool.returnObject(nettyClient);
    NettyClient nettyClient2 = clientPool.borrowObject();
    Assert.assertEquals(channel1, nettyClient2.channel());
    logger.info("[testDeadBorrow][close client]");
    channel1.close();
    nettyClient2 = clientPool.borrowObject();
    Assert.assertNotEquals(channel1, nettyClient2.channel());
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 30 with NettyClient

use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.

the class AbstractCommandTest method createClientPool.

protected FixedObjectPool<NettyClient> createClientPool(String host, int port) throws Exception {
    NettyClientFactory nettyClientFactory = new NettyClientFactory(new InetSocketAddress(host, port));
    nettyClientFactory.start();
    stoppables.add(nettyClientFactory);
    NettyClient nettyClient = nettyClientFactory.makeObject().getObject();
    FixedObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
    return clientPool;
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) NettyClientFactory(com.ctrip.xpipe.netty.commands.NettyClientFactory) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool)

Aggregations

NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)37 InetSocketAddress (java.net.InetSocketAddress)31 Test (org.junit.Test)8 ExecutionException (java.util.concurrent.ExecutionException)6 AbstractTest (com.ctrip.xpipe.AbstractTest)4 InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)4 Server (com.ctrip.xpipe.simpleserver.Server)4 IOException (java.io.IOException)4 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)3 SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)3 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)3 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)3 AbstractSentinelCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSentinelCommand)3 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)3 DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)2 XpipeException (com.ctrip.xpipe.exception.XpipeException)2 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)2 XpipeObjectPoolFromKeyed (com.ctrip.xpipe.pool.XpipeObjectPoolFromKeyed)2 DefaultSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultSlaveOfCommand)2 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)2