Search in sources :

Example 21 with AbstractExceptionLogTask

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

the class HickwallMetricTest method testHickWall.

@Test
public void testHickWall() throws MetricProxyException, IOException {
    int port = 11111;
    logger.info("[testHickWall]{}", port);
    scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            List<MetricData> data = new LinkedList<>();
            HostPort hostPort = new HostPort("127.0.0.1", port);
            MetricData metricData = new MetricData("delay", "cluster", "shard");
            metricData.setValue(1000);
            metricData.setHostPort(hostPort);
            metricData.setTimestampMilli(System.currentTimeMillis());
            data.add(metricData);
            hickwallMetricProxy.writeBinMultiDataPoint(data);
        }
    }, 0, 2, TimeUnit.SECONDS);
    waitForAnyKeyToExit();
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) List(java.util.List) LinkedList(java.util.LinkedList) IOException(java.io.IOException) MetricProxyException(com.ctrip.xpipe.metric.MetricProxyException) MetricData(com.ctrip.xpipe.metric.MetricData) Test(org.junit.Test) AbstractServiceTest(com.ctrip.xpipe.AbstractServiceTest)

Example 22 with AbstractExceptionLogTask

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

the class DefaultMigrationEventManager method defaultMigrationEventManager.

@PostConstruct
public void defaultMigrationEventManager() {
    scheduled = Executors.newScheduledThreadPool(1, XpipeThreadFactory.create("EventManagerCleaner"));
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            List<Long> finished = new LinkedList<>();
            currentWorkingEvents.forEach((id, migrationEvent) -> {
                if (migrationEvent.isDone()) {
                    finished.add(id);
                }
            });
            finished.forEach((id) -> removeEvent(id));
        }
    }, 60, 60, TimeUnit.SECONDS);
}
Also used : Logger(org.slf4j.Logger) CrossDcLeaderAware(com.ctrip.xpipe.api.cluster.CrossDcLeaderAware) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) PreDestroy(javax.annotation.PreDestroy) XpipeThreadFactory(com.ctrip.xpipe.utils.XpipeThreadFactory) Component(org.springframework.stereotype.Component) List(java.util.List) MigrationEventDao(com.ctrip.xpipe.redis.console.dao.MigrationEventDao) MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent) Observable(com.ctrip.xpipe.api.observer.Observable) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) List(java.util.List) LinkedList(java.util.LinkedList) PostConstruct(javax.annotation.PostConstruct)

Example 23 with AbstractExceptionLogTask

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

the class DefaultRedisSlave method sendCommandForFullSync.

protected void sendCommandForFullSync() {
    logger.info("[sendCommandForFullSync]{}, {}", this, rdbFileOffset + 1);
    processPsyncSequentially(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            beginWriteCommands(rdbFileOffset + 1);
        }
    });
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) IOException(java.io.IOException) RedisKeeperRuntimeException(com.ctrip.xpipe.redis.keeper.exception.RedisKeeperRuntimeException)

Example 24 with AbstractExceptionLogTask

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

the class RedisKeeperServerStateBackup method psync.

@Override
public boolean psync(final RedisClient redisClient, final String[] args) throws Exception {
    logger.info("[psync][server state backup, ask slave to wait]{}, {}", redisClient, this);
    if (redisKeeperServer.compareAndDo(this, new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            redisClient.sendMessage(RedisProtocol.CRLF.getBytes());
            PsyncKeeperServerStateObserver psyncKeeperServerStateObserver = new PsyncKeeperServerStateObserver(args, redisClient);
            redisKeeperServer.addObserver(psyncKeeperServerStateObserver);
            redisClient.addChannelCloseReleaseResources(new Releasable() {

                @Override
                public void release() throws Exception {
                    psyncKeeperServerStateObserver.release();
                }
            });
        }
    })) {
        // state backup
        return false;
    }
    logger.info("[psync][state change, use new state to psync]{}, {}", redisClient, redisKeeperServer);
    return redisKeeperServer.getRedisKeeperServerState().psync(redisClient, args);
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) Releasable(com.ctrip.xpipe.api.lifecycle.Releasable) IOException(java.io.IOException)

Example 25 with AbstractExceptionLogTask

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

the class BaseSampleMonitor method scanSamples.

@PostConstruct
public void scanSamples() {
    daemonThread = XpipeThreadFactory.create("SampleMonitor-" + getClass().getSimpleName(), true).newThread(new Runnable() {

        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    doScan();
                } catch (Exception e) {
                    log.error("Unexpected error when scan", e);
                } finally {
                    try {
                        Thread.sleep(config.getRedisReplicationHealthCheckInterval());
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        break;
                    }
                }
            }
        }

        private void doScan() {
            long start = System.currentTimeMillis();
            int count = 0;
            Iterator<Entry<Long, Sample<T>>> iter = samples.entrySet().iterator();
            while (iter.hasNext()) {
                count++;
                Sample<T> sample = iter.next().getValue();
                if (sample.isDone() || sample.isExpired()) {
                    try {
                        executors.execute(new AbstractExceptionLogTask() {

                            @Override
                            protected void doRun() throws Exception {
                                notifyCollectors(sample);
                            }
                        });
                    } catch (Exception e) {
                        log.error("Exception caught from notified collectors", e);
                    }
                    iter.remove();
                }
            }
            long end = System.currentTimeMillis();
            long cost = end - start;
            if (cost > 10) {
                log.info("[scan end][cost > 10 ms]count:{}, cost: {} ms", count, end - start);
            }
        }
    });
    daemonThread.start();
}
Also used : Entry(java.util.Map.Entry) 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