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;
}
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
}
}
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));
}
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();
}
}
}
}
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();
}
}
Aggregations