Search in sources :

Example 36 with AbstractExceptionLogTask

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

the class AbstractIntervalCheck method checkStart.

protected void checkStart() {
    if (clusterServer != null && !clusterServer.amILeader()) {
        logger.debug("[generatePlan][not leader quit]");
        return;
    }
    long current = System.currentTimeMillis();
    if (current - lastStartTime < getIntervalMilli()) {
        logger.debug("[generatePlan][too quick {}, quit]", current - lastStartTime);
        return;
    }
    lastStartTime = current;
    executors.execute(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            doCheck();
        }
    });
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 37 with AbstractExceptionLogTask

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

the class ControllableFileAbstractTest method testSizeAndFileLength.

@Test
public void testSizeAndFileLength() throws IOException {
    RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
    FileChannel channel = randomAccessFile.getChannel();
    byte[] data = randomString(randomInt(0, 1000)).getBytes();
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            channel.write(ByteBuffer.wrap(data));
        }
    }, 0, 1, TimeUnit.MILLISECONDS);
    int testCount = 1 << 15;
    long begin = System.currentTimeMillis();
    Long size = 0L;
    for (int i = 0; i < testCount; i++) {
        // size = channel.size();
        size = file.length();
    }
    long end = System.currentTimeMillis();
    logger.info("each {} ns", (end - begin) * 1000000 / testCount);
    logger.info("{}", size);
}
Also used : FileChannel(java.nio.channels.FileChannel) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) TimeoutException(java.util.concurrent.TimeoutException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 38 with AbstractExceptionLogTask

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

the class DefaultRedisSessionManagerTest method testPubSub.

@Test
public void testPubSub() {
    RedisSession redisSession = redisSessionManager.findOrCreateSession(host, port);
    for (int i = 0; i < channels; i++) {
        redisSession.subscribeIfAbsent(channelName(channel, i), new RedisSession.SubscribeCallback() {

            @Override
            public void message(String channel, String message) {
                logger.info("[message]{}, {}", channel, message);
            }

            @Override
            public void fail(Throwable e) {
                logger.error("[fail]", e);
            }
        });
    }
    sleep(subscribeTimeoutSeconds * 2 * 1000);
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        public void doRun() {
            for (int i = 0; i < channels; i++) {
                redisSession.publish(channelName(channel, i), randomString(10));
            }
        }
    }, 0, 5, TimeUnit.SECONDS);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Test(org.junit.Test) AbstractConsoleTest(com.ctrip.xpipe.redis.console.AbstractConsoleTest)

Example 39 with AbstractExceptionLogTask

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

the class MigrationCheckingState method doShardCheck.

private void doShardCheck(MigrationCluster migrationCluster) {
    List<MigrationShard> migrationShards = migrationCluster.getMigrationShards();
    for (final MigrationShard migrationShard : migrationShards) {
        migrationShard.retry(ShardMigrationStep.CHECK);
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            public void doRun() {
                migrationShard.doCheck();
            }
        });
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 40 with AbstractExceptionLogTask

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

the class MigrationForcePublishState method doAction.

@Override
public void doAction() {
    CountDownLatch latch = new CountDownLatch(getHolder().getMigrationShards().size());
    for (MigrationShard migrationShard : getHolder().getMigrationShards()) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            public void doRun() {
                try {
                    logger.info("[doOtherDcMigrate][start]{},{}", getHolder().clusterName(), migrationShard.getCurrentShard().getShardName());
                    migrationShard.doMigrateOtherDc();
                    logger.info("[doOtherDcMigrate][done]{},{}", getHolder().clusterName(), migrationShard.getCurrentShard().getShardName());
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    try {
        latch.await();
        updateAndProcess(nextAfterSuccess());
    } catch (InterruptedException e) {
        logger.error("[MigrationForcePublishState][tryAction][Interrupted][will retry]", e);
        updateAndProcess(nextAfterFail());
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) CountDownLatch(java.util.concurrent.CountDownLatch)

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