Search in sources :

Example 6 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class MultiMetaServer method invoke.

@Override
public Object invoke(Object proxy, final Method method, final Object[] rawArgs) throws Throwable {
    for (final MetaServer metaServer : otherServers) {
        final Object[] args = copy(rawArgs);
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                method.invoke(metaServer, args);
            }
        });
    }
    final Object[] args = copy(rawArgs);
    return method.invoke(dstServer, args);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) MetaServer(com.ctrip.xpipe.redis.meta.server.MetaServer)

Example 7 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class MigrationPartialSuccessState method doAction.

@Override
public void doAction() {
    for (final MigrationShard shard : getHolder().getMigrationShards()) {
        ShardMigrationResult shardMigrationResult = shard.getShardMigrationResult();
        if (!shardMigrationResult.stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
            shardMigrationResult.stepRetry(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC);
            String clusterName = getHolder().clusterName();
            String shardName = shard.shardName();
            logger.info("[doAction][execute]{}, {}", clusterName, shardName);
            executors.execute(new AbstractExceptionLogTask() {

                @Override
                public void doRun() {
                    logger.info("[doMigrate][start]{},{}", clusterName, shardName);
                    shard.doMigrate();
                    logger.info("[doMigrate][done]{},{}", clusterName, shardName);
                }
            });
        }
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) ShardMigrationResult(com.ctrip.xpipe.redis.console.migration.model.ShardMigrationResult)

Example 8 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class KeeperServiceImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    logger.info("[postConstruct]{}", this);
    refreshIntervalMilli = consoleConfig.getCacheRefreshInterval();
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            keepers = metaCache.allKeepers();
        }
    }, refreshIntervalMilli, refreshIntervalMilli, TimeUnit.SECONDS);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) PostConstruct(javax.annotation.PostConstruct)

Example 9 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class ByteArrayOutputStreamPayloadTest method testNewHeap.

@Test
public void testNewHeap() throws Exception {
    final MemoryPrinter memoryPrinter = new MemoryPrinter(scheduled);
    memoryPrinter.printMemory();
    final int length = 1 << 10;
    int concurrentCount = 10;
    final CountDownLatch latch = new CountDownLatch(concurrentCount);
    final ByteBuf byteBuf = directByteBuf(length);
    byteBuf.writeBytes(randomString(length).getBytes());
    byte[] dst = new byte[length];
    byteBuf.readBytes(dst);
    memoryPrinter.printMemory();
    for (int i = 0; i < concurrentCount; i++) {
        Thread current = new Thread(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                try {
                    byteBuf.readerIndex(0);
                    ByteArrayOutputStream baous = new ByteArrayOutputStream();
                    byteBuf.readBytes(baous, length);
                } finally {
                    latch.countDown();
                }
            }
        });
        current.start();
        memoryPrinter.printMemory();
    }
    latch.await();
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MemoryPrinter(com.ctrip.xpipe.testutils.MemoryPrinter) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuf(io.netty.buffer.ByteBuf) IOException(java.io.IOException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 10 with AbstractExceptionLogTask

use of com.ctrip.xpipe.concurrent.AbstractExceptionLogTask in project x-pipe by ctripcorp.

the class AbstractNettyRequestResponseCommand method doSendRequest.

@Override
protected void doSendRequest(final NettyClient nettyClient, ByteBuf byteBuf) {
    if (logRequest()) {
        logger.info("[doSendRequest]{}, {}", nettyClient, ByteBufUtils.readToString(byteBuf.slice()));
    }
    if (hasResponse()) {
        nettyClient.sendRequest(byteBuf, this);
    } else {
        nettyClient.sendRequest(byteBuf);
        // TODO sendfuture, make sure send success
        future().setSuccess(null);
        return;
    }
    if (getCommandTimeoutMilli() > 0 && scheduled != null) {
        logger.debug("[doSendRequest][schedule timeout]{}, {}", this, getCommandTimeoutMilli());
        final ScheduledFuture<?> timeoutFuture = scheduled.schedule(new AbstractExceptionLogTask() {

            @Override
            public void doRun() {
                logger.info("[run][timeout]{}", nettyClient);
                future().setFailure(new CommandTimeoutException("timeout " + +getCommandTimeoutMilli()));
            }
        }, getCommandTimeoutMilli(), TimeUnit.MILLISECONDS);
        future().addListener(new CommandFutureListener<V>() {

            @Override
            public void operationComplete(CommandFuture<V> commandFuture) {
                boolean cancel = true;
                try {
                    commandFuture.get();
                } catch (InterruptedException e) {
                } catch (ExecutionException e) {
                    if (e.getCause() instanceof CommandTimeoutException) {
                        cancel = false;
                    }
                }
                if (cancel) {
                    logger.debug("[operationComplete][cancel timeout future]");
                    timeoutFuture.cancel(false);
                }
            }
        });
    }
}
Also used : CommandTimeoutException(com.ctrip.xpipe.command.CommandTimeoutException) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)46 IOException (java.io.IOException)19 Test (org.junit.Test)18 CountDownLatch (java.util.concurrent.CountDownLatch)9 PostConstruct (javax.annotation.PostConstruct)9 ExecutionException (java.util.concurrent.ExecutionException)8 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)6 AbstractTest (com.ctrip.xpipe.AbstractTest)5 MigrationShard (com.ctrip.xpipe.redis.console.migration.model.MigrationShard)5 LinkedList (java.util.LinkedList)5 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)3 FileChannel (java.nio.channels.FileChannel)3 Semaphore (java.util.concurrent.Semaphore)3 TimeoutException (java.util.concurrent.TimeoutException)3 ReferenceFileRegion (com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion)2 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 RedisKeeperRuntimeException (com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)2 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)2 Server (com.ctrip.xpipe.simpleserver.Server)2 List (java.util.List)2