Search in sources :

Example 1 with ConfigRewrite

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

the class TransactionalSlaveOfCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    logger.info("[doExecute][try xslaveof]{}", this);
    TransactionalCommand slaveofTransaction = new TransactionalCommand(getClientPool(), scheduled, new XSlaveofCommand(null, ip, port, scheduled), new ConfigRewrite(null, scheduled));
    try {
        slaveofTransaction.execute().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (!commandFuture.isSuccess()) {
                    failXslaveof(commandFuture.cause());
                } else {
                    logger.info("[doExecute][xslaveof success]{}", this);
                    future().setSuccess(commandFuture.get());
                }
            }
        });
    } catch (Exception e) {
        failXslaveof(e);
    }
}
Also used : XSlaveofCommand(com.ctrip.xpipe.redis.core.protocal.cmd.XSlaveofCommand) ConfigRewrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 2 with ConfigRewrite

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

the class TransactionalSlaveOfCommand method failXslaveof.

private void failXslaveof(Throwable e) {
    Throwable rootCause = ExceptionUtils.getRootCause(e);
    if ((rootCause instanceof IOException)) {
        logger.info("[failXslaveof][do not try slaveof]");
        fail(e);
        return;
    }
    logger.error("[doExecute][xlaveof fail, try slaveof]" + ip + ":" + port, e);
    TransactionalCommand slaveofTransaction = new TransactionalCommand(getClientPool(), scheduled, new SlaveOfCommand(null, ip, port, scheduled), new ConfigRewrite(null, scheduled));
    try {
        slaveofTransaction.execute().addListener(new CommandFutureListener<Object[]>() {

            @Override
            public void operationComplete(CommandFuture<Object[]> commandFuture) throws Exception {
                if (!commandFuture.isSuccess()) {
                    fail(commandFuture.cause());
                } else {
                    logger.info("[doExecute][slaveof success]{}", this);
                    future().setSuccess(commandFuture.get());
                }
            }
        });
    } catch (Exception ex) {
        fail(ex);
    }
}
Also used : ConfigRewrite(com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand) IOException(java.io.IOException) IOException(java.io.IOException) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException)

Example 3 with ConfigRewrite

use of com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite 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)

Aggregations

ConfigRewrite (com.ctrip.xpipe.redis.core.protocal.cmd.ConfigRewrite)3 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)2 IOException (java.io.IOException)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 ConfigSetMinSlavesToWrite (com.ctrip.xpipe.redis.core.protocal.cmd.ConfigSetCommand.ConfigSetMinSlavesToWrite)1 SlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand)1 XSlaveofCommand (com.ctrip.xpipe.redis.core.protocal.cmd.XSlaveofCommand)1 TransactionalCommand (com.ctrip.xpipe.redis.core.protocal.cmd.transaction.TransactionalCommand)1 InetSocketAddress (java.net.InetSocketAddress)1