Search in sources :

Example 1 with AbstractExceptionLogTask

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

the class MigrationPartialSuccessRollBackState method doAction.

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

            @Override
            protected void doRun() throws Exception {
                try {
                    migrationShard.doRollBack();
                } catch (Exception e) {
                    logger.error("[run]" + migrationShard, e);
                    errorMessage.append(LogUtils.error(String.format("%s", migrationShard, e.toString())));
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    try {
        latch.await(migrationWaitTimeMilli, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.error("[MigrationRollBackStat][await][shard][doRollBack][fail]", e);
        errorMessage.append(LogUtils.error(String.format("[wait time exceed]%s ms", migrationWaitTimeMilli)));
    }
    String error = errorMessage.toString();
    if (StringUtil.isEmpty(error)) {
        updateAndProcess(nextAfterSuccess());
    } else {
        updateAndStop(nextAfterFail());
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with AbstractExceptionLogTask

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

the class MuchRedisData method sendDataToMaster.

private void sendDataToMaster() {
    final CountDownLatch latch = new CountDownLatch(concurrentCount);
    logger.info("[sendDataToMaster][begin]{}, {}", messageCount, messageSize);
    for (int i = 0; i < concurrentCount; i++) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                try {
                    sendMessage(getRedisMaster(), messageCount / concurrentCount, randomString(messageSize));
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    try {
        latch.await();
        logger.info("[sendDataToMaster][ end ]{}, {}", messageCount, messageSize);
    } catch (InterruptedException e) {
        logger.error("[sendDataToMaster]", e);
    }
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) ExecuteException(org.apache.commons.exec.ExecuteException)

Example 3 with AbstractExceptionLogTask

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

the class OneDcKeepers method testKeeperChangeState.

@Test
public void testKeeperChangeState() throws Exception {
    int round = 1000;
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            sendMessageToMaster(getRedisMaster(), 100);
        }
    }, 0, 500, TimeUnit.SECONDS.MILLISECONDS);
    RedisMeta redisMaster = getRedisMaster();
    KeeperMeta currentActive = activeKeeper;
    KeeperMeta currentBackup = backupKeeper;
    for (int i = 0; i < round; i++) {
        logger.info(remarkableMessage("round: {}"), i);
        setKeeperState(currentBackup, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
        setKeeperState(currentActive, KeeperState.BACKUP, currentBackup.getIp(), currentBackup.getPort());
        sleep(1000);
        KeeperMeta tmp = currentActive;
        currentActive = currentBackup;
        currentBackup = tmp;
    }
    waitForAnyKey();
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) IOException(java.io.IOException) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta) Test(org.junit.Test)

Example 4 with AbstractExceptionLogTask

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

the class RedisTest method testIncr.

@Test
public void testIncr() throws IOException {
    Jedis jedis = createJedis("localhost", 6379);
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            jedis.incr("incr");
        }
    }, 0, 100, TimeUnit.MILLISECONDS);
    waitForAnyKeyToExit();
}
Also used : Jedis(redis.clients.jedis.Jedis) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) IOException(java.io.IOException) AbstractIntegratedTest(com.ctrip.xpipe.redis.integratedtest.AbstractIntegratedTest) Test(org.junit.Test)

Example 5 with AbstractExceptionLogTask

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

the class DefaultMetaCache method postConstruct.

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

        @Override
        protected void doRun() throws Exception {
            loadCache();
        }
    }, 1000, refreshIntervalMilli, TimeUnit.MILLISECONDS);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) PostConstruct(javax.annotation.PostConstruct)

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