Search in sources :

Example 1 with SequenceCommandChain

use of com.ctrip.xpipe.command.SequenceCommandChain in project x-pipe by ctripcorp.

the class DcMetaBuilder method doExecute.

@Override
protected void doExecute() throws Exception {
    SequenceCommandChain sequenceCommandChain = new SequenceCommandChain(false);
    ParallelCommandChain parallelCommandChain = new ParallelCommandChain(executors);
    parallelCommandChain.add(retry3TimesUntilSuccess(new GetAllDcClusterShardDetailCommand(dcId)));
    parallelCommandChain.add(retry3TimesUntilSuccess(new Cluster2DcClusterMapCommand()));
    parallelCommandChain.add(retry3TimesUntilSuccess(new GetDcIdNameMapCommand()));
    sequenceCommandChain.add(parallelCommandChain);
    sequenceCommandChain.add(retry3TimesUntilSuccess(new BuildDcMetaCommand()));
    logger.info("[doExecute] commands: {}", sequenceCommandChain);
    sequenceCommandChain.future().addListener(commandFuture -> {
        if (commandFuture.isSuccess()) {
            future().setSuccess(dcMeta);
        } else {
            future().setFailure(commandFuture.cause());
        }
    });
    sequenceCommandChain.execute(executors);
}
Also used : ParallelCommandChain(com.ctrip.xpipe.command.ParallelCommandChain) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 2 with SequenceCommandChain

use of com.ctrip.xpipe.command.SequenceCommandChain in project x-pipe by ctripcorp.

the class DefaultSlaveOfCommand method doExecute.

@Override
protected void doExecute() throws CommandExecutionException {
    SimpleObjectPool<NettyClient> clientPool = getClientPool();
    UntilSuccess slaveOf = new UntilSuccess();
    slaveOf.add(new XSlaveofCommand(clientPool, ip, port, scheduled));
    slaveOf.add(new SlaveOfCommand(clientPool, ip, port, scheduled));
    SequenceCommandChain chain = new SequenceCommandChain(false);
    chain.add(slaveOf);
    chain.add(new ConfigRewrite(clientPool, scheduled));
    chain.execute().addListener(new CommandFutureListener<Object>() {

        @Override
        public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
            if (commandFuture.isSuccess()) {
                future().setSuccess(RedisClientProtocol.OK);
            } else {
                future().setFailure(commandFuture.cause());
            }
        }
    });
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) UntilSuccess(com.ctrip.xpipe.command.UntilSuccess) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 3 with SequenceCommandChain

use of com.ctrip.xpipe.command.SequenceCommandChain in project x-pipe by ctripcorp.

the class AbstractFakeRedisTest method sendInmemoryPsync.

protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset) throws Exception {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(ip, port));
    NettyClient nettyClient = null;
    try {
        nettyClient = pool.borrowObject();
        SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
        chain.add(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString()));
        InMemoryPsync psync = new InMemoryPsync(clientPool, runid, offset, scheduled);
        chain.add(psync);
        psync.addPsyncObserver(new PsyncObserver() {

            private long masterRdbOffset = 0;

            @Override
            public void reFullSync() {
            }

            @Override
            public void onFullSync() {
            }

            @Override
            public void onContinue(String requestReplId, String responseReplId) {
            }

            @Override
            public void endWriteRdb() {
                new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
            }

            @Override
            public void beginWriteRdb(EofType eofType, long masterRdbOffset) throws IOException {
                this.masterRdbOffset = masterRdbOffset;
            }
        });
        chain.execute();
        return psync;
    } finally {
        if (nettyClient != null) {
            pool.returnObject(nettyClient);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) EofType(com.ctrip.xpipe.redis.core.protocal.protocal.EofType) IOException(java.io.IOException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain) NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) FixedObjectPool(com.ctrip.xpipe.pool.FixedObjectPool) InMemoryPsync(com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync) PsyncObserver(com.ctrip.xpipe.redis.core.protocal.PsyncObserver)

Example 4 with SequenceCommandChain

use of com.ctrip.xpipe.command.SequenceCommandChain in project x-pipe by ctripcorp.

the class AbstractRedisMasterReplication method masterConnected.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void masterConnected(Channel channel) {
    connectedTime = System.currentTimeMillis();
    this.masterChannel = channel;
    clientPool = new FixedObjectPool<NettyClient>(new DefaultNettyClient(channel));
    checkTimeout(channel);
    checkKeeper();
    SequenceCommandChain chain = new SequenceCommandChain(false);
    chain.add(listeningPortCommand());
    chain.add(new FailSafeCommandWrapper<>(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString(), CAPA.PSYNC2.toString())));
    try {
        executeCommand(chain).addListener(new CommandFutureListener() {

            @Override
            public void operationComplete(CommandFuture commandFuture) throws Exception {
                if (commandFuture.isSuccess()) {
                    sendReplicationCommand();
                } else {
                    logger.error("[operationComplete][listeningPortCommand]", commandFuture.cause());
                }
            }
        });
    } catch (Exception e) {
        logger.error("[masterConnected]" + channel, e);
    }
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) Replconf(com.ctrip.xpipe.redis.core.protocal.cmd.Replconf) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) DefaultNettyClient(com.ctrip.xpipe.netty.commands.DefaultNettyClient) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Example 5 with SequenceCommandChain

use of com.ctrip.xpipe.command.SequenceCommandChain in project x-pipe by ctripcorp.

the class TransactionalCommand method doWork.

@SuppressWarnings("unchecked")
protected void doWork(final SimpleObjectPool<NettyClient> clientPool) {
    SequenceCommandChain chain = new SequenceCommandChain(false);
    for (RedisCommand currentCommand : commands) {
        OneTranscationCommand oneTranscationCommand = new OneTranscationCommand(clientPool, currentCommand, scheduled);
        chain.add(oneTranscationCommand);
    }
    chain.execute().addListener(new CommandFutureListener() {

        @Override
        public void operationComplete(CommandFuture commandFuture) throws Exception {
            if (!commandFuture.isSuccess()) {
                logger.error("[doWork][fail]", commandFuture.cause());
            }
            endTranscation(clientPool);
        }
    });
}
Also used : CommandFuture(com.ctrip.xpipe.api.command.CommandFuture) CommandFutureListener(com.ctrip.xpipe.api.command.CommandFutureListener) AbstractRedisCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractRedisCommand) RedisCommand(com.ctrip.xpipe.redis.core.protocal.RedisCommand) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) ReturnObjectException(com.ctrip.xpipe.pool.ReturnObjectException) BorrowObjectException(com.ctrip.xpipe.pool.BorrowObjectException) SequenceCommandChain(com.ctrip.xpipe.command.SequenceCommandChain)

Aggregations

SequenceCommandChain (com.ctrip.xpipe.command.SequenceCommandChain)5 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)3 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)3 CommandFuture (com.ctrip.xpipe.api.command.CommandFuture)2 CommandFutureListener (com.ctrip.xpipe.api.command.CommandFutureListener)2 Replconf (com.ctrip.xpipe.redis.core.protocal.cmd.Replconf)2 IOException (java.io.IOException)2 ParallelCommandChain (com.ctrip.xpipe.command.ParallelCommandChain)1 UntilSuccess (com.ctrip.xpipe.command.UntilSuccess)1 XpipeException (com.ctrip.xpipe.exception.XpipeException)1 DefaultNettyClient (com.ctrip.xpipe.netty.commands.DefaultNettyClient)1 BorrowObjectException (com.ctrip.xpipe.pool.BorrowObjectException)1 FixedObjectPool (com.ctrip.xpipe.pool.FixedObjectPool)1 ReturnObjectException (com.ctrip.xpipe.pool.ReturnObjectException)1 PsyncObserver (com.ctrip.xpipe.redis.core.protocal.PsyncObserver)1 RedisCommand (com.ctrip.xpipe.redis.core.protocal.RedisCommand)1 AbstractRedisCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractRedisCommand)1 InMemoryPsync (com.ctrip.xpipe.redis.core.protocal.cmd.InMemoryPsync)1 EofType (com.ctrip.xpipe.redis.core.protocal.protocal.EofType)1 InetSocketAddress (java.net.InetSocketAddress)1