Search in sources :

Example 81 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project voldemort by voldemort.

the class RebalanceScheduler method scheduleNextTask.

/**
     * Schedule at most one task.
     * 
     * The scheduled task *must* invoke 'doneTask()' upon
     * completion/termination.
     * 
     * @param executeService flag to control execution of the service, some tests pass
     *        in value 'false'
     * @return The task scheduled or null if not possible to schedule a task at
     *         this time.
     */
protected synchronized StealerBasedRebalanceTask scheduleNextTask(boolean executeService) {
    // Make sure there is work left to do.
    if (doneSignal.getCount() == 0) {
        logger.info("All tasks completion signaled... returning");
        return null;
    }
    // Limit number of tasks outstanding.
    if (this.numTasksExecuting >= maxParallelRebalancing) {
        logger.info("Executing more tasks than [" + this.numTasksExecuting + "] the parallel allowed " + maxParallelRebalancing);
        return null;
    }
    // Shuffle list of stealer IDs each time a new task to schedule needs to
    // be found. Randomizing the order should avoid prioritizing one
    // specific stealer's work ahead of all others.
    List<Integer> stealerIds = new ArrayList<Integer>(tasksByStealer.keySet());
    Collections.shuffle(stealerIds);
    for (int stealerId : stealerIds) {
        if (nodeIdsWithWork.contains(stealerId)) {
            logger.info("Stealer " + stealerId + " is already working... continuing");
            continue;
        }
        for (StealerBasedRebalanceTask sbTask : tasksByStealer.get(stealerId)) {
            int donorId = sbTask.getStealInfos().get(0).getDonorId();
            if (nodeIdsWithWork.contains(donorId)) {
                logger.info("Stealer " + stealerId + " Donor " + donorId + " is already working... continuing");
                continue;
            }
            // Book keeping
            addNodesToWorkerList(Arrays.asList(stealerId, donorId));
            numTasksExecuting++;
            // Remove this task from list thus destroying list being
            // iterated over. This is safe because returning directly out of
            // this branch.
            tasksByStealer.get(stealerId).remove(sbTask);
            try {
                if (executeService) {
                    logger.info("Stealer " + stealerId + " Donor " + donorId + " going to schedule work");
                    service.execute(sbTask);
                }
            } catch (RejectedExecutionException ree) {
                logger.error("Stealer " + stealerId + "Rebalancing task rejected by executor service.", ree);
                throw new VoldemortRebalancingException("Stealer " + stealerId + "Rebalancing task rejected by executor service.");
            }
            return sbTask;
        }
    }
    printRemainingTasks(stealerIds);
    return null;
}
Also used : VoldemortRebalancingException(voldemort.server.rebalance.VoldemortRebalancingException) StealerBasedRebalanceTask(voldemort.client.rebalance.task.StealerBasedRebalanceTask) ArrayList(java.util.ArrayList) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 82 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project lucene-solr by apache.

the class DefaultSolrCoreState method doRecovery.

@Override
public void doRecovery(CoreContainer cc, CoreDescriptor cd) {
    Runnable recoveryTask = new Runnable() {

        @Override
        public void run() {
            MDCLoggingContext.setCoreDescriptor(cc, cd);
            try {
                if (SKIP_AUTO_RECOVERY) {
                    log.warn("Skipping recovery according to sys prop solrcloud.skip.autorecovery");
                    return;
                }
                // check before we grab the lock
                if (cc.isShutDown()) {
                    log.warn("Skipping recovery because Solr is shutdown");
                    return;
                }
                // if we can't get the lock, another recovery is running
                // we check to see if there is already one waiting to go
                // after the current one, and if there is, bail
                boolean locked = recoveryLock.tryLock();
                try {
                    if (!locked) {
                        if (recoveryWaiting.get() > 0) {
                            return;
                        }
                        recoveryWaiting.incrementAndGet();
                    } else {
                        recoveryWaiting.incrementAndGet();
                        cancelRecovery();
                    }
                    recoveryLock.lock();
                    try {
                        recoveryWaiting.decrementAndGet();
                        // to be air tight we must also check after lock
                        if (cc.isShutDown()) {
                            log.warn("Skipping recovery because Solr is shutdown");
                            return;
                        }
                        log.info("Running recovery");
                        recoveryThrottle.minimumWaitBetweenActions();
                        recoveryThrottle.markAttemptingAction();
                        recoveryStrat = recoveryStrategyBuilder.create(cc, cd, DefaultSolrCoreState.this);
                        recoveryStrat.setRecoveringAfterStartup(recoveringAfterStartup);
                        Future<?> future = cc.getUpdateShardHandler().getRecoveryExecutor().submit(recoveryStrat);
                        try {
                            future.get();
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                            throw new SolrException(ErrorCode.SERVER_ERROR, e);
                        } catch (ExecutionException e) {
                            throw new SolrException(ErrorCode.SERVER_ERROR, e);
                        }
                    } finally {
                        recoveryLock.unlock();
                    }
                } finally {
                    if (locked)
                        recoveryLock.unlock();
                }
            } finally {
                MDCLoggingContext.clear();
            }
        }
    };
    try {
        // we make recovery requests async - that async request may
        // have to 'wait in line' a bit or bail if a recovery is 
        // already queued up - the recovery execution itself is run
        // in another thread on another 'recovery' executor.
        // The update executor is interrupted on shutdown and should 
        // not do disk IO.
        // The recovery executor is not interrupted on shutdown.
        //
        // avoid deadlock: we can't use the recovery executor here
        cc.getUpdateShardHandler().getUpdateExecutor().submit(recoveryTask);
    } catch (RejectedExecutionException e) {
    // fine, we are shutting down
    }
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) SolrException(org.apache.solr.common.SolrException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 83 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project geode by apache.

the class StatRecorderJUnitTest method recorderHandlesRejectedExecution.

@Test
public void recorderHandlesRejectedExecution() throws Exception {
    Message msg = mock(Message.class);
    when(msg.getHeader(any(Short.class))).thenReturn(Header.createDataHeader(1L, (short) 1, true));
    when(msg.size()).thenReturn(150L);
    // GEODE-1178, the TP protocol may throw a RejectedExecutionException & StatRecorder should
    // retry
    when(mockDownProtocol.down(any(Event.class))).thenThrow(new RejectedExecutionException());
    // after the first down() throws an exception we want StatRecorder to retry, so
    // we set the Manager to say no shutdown is in progress the first time and then say
    // one IS in progress so we can break out of the StatRecorder exception handling loop
    when(services.getCancelCriterion()).thenReturn(new Services().getCancelCriterion());
    Manager manager = mock(Manager.class);
    when(services.getManager()).thenReturn(manager);
    when(manager.shutdownInProgress()).thenReturn(Boolean.FALSE, Boolean.TRUE);
    verify(mockDownProtocol, never()).down(isA(Event.class));
    Event evt = new Event(Event.MSG, msg);
    recorder.down(evt);
    verify(mockDownProtocol, times(2)).down(isA(Event.class));
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) Message(org.jgroups.Message) Event(org.jgroups.Event) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 84 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project geode by apache.

the class CustomEntryConcurrentHashMap method clear.

/**
   * Removes all of the mappings from this map.
   */
@Override
public void clear() {
    ArrayList<HashEntry<?, ?>> entries = null;
    try {
        for (int i = 0; i < this.segments.length; ++i) {
            entries = this.segments[i].clear(entries);
        }
    } finally {
        if (entries != null) {
            final ArrayList<HashEntry<?, ?>> clearedEntries = entries;
            final Runnable runnable = new Runnable() {

                public void run() {
                    for (HashEntry<?, ?> he : clearedEntries) {
                        for (HashEntry<?, ?> p = he; p != null; p = p.getNextEntry()) {
                            synchronized (p) {
                                ((OffHeapRegionEntry) p).release();
                            }
                        }
                    }
                }
            };
            boolean submitted = false;
            InternalDistributedSystem ids = InternalDistributedSystem.getConnectedInstance();
            if (ids != null) {
                try {
                    ids.getDistributionManager().getWaitingThreadPool().execute(runnable);
                    submitted = true;
                } catch (RejectedExecutionException e) {
                // fall through with submitted false
                } catch (CancelException e) {
                // fall through with submitted false
                } catch (NullPointerException e) {
                // fall through with submitted false
                }
            }
            if (!submitted) {
                String name = this.getClass().getSimpleName() + "@" + this.hashCode() + " Clear Thread";
                Thread thread = new Thread(runnable, name);
                thread.setDaemon(true);
                thread.start();
            }
        }
    }
}
Also used : OffHeapRegionEntry(org.apache.geode.internal.cache.OffHeapRegionEntry) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) CancelException(org.apache.geode.CancelException)

Example 85 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class JMSTopicService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    final JMSServerManager jmsManager = jmsServer.getValue();
    final Runnable task = new Runnable() {

        @Override
        public void run() {
            try {
                jmsManager.createTopic(false, name, jndi);
                topic = new ActiveMQTopic(name);
                context.complete();
            } catch (Throwable e) {
                context.failed(MessagingLogger.ROOT_LOGGER.failedToCreate(e, "queue"));
            }
        }
    };
    try {
        executorInjector.getValue().execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)246 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)34 Test (org.junit.Test)34 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 Executor (java.util.concurrent.Executor)18 ExecutionException (java.util.concurrent.ExecutionException)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9