use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.
the class ShardIndexingPressure method rejectShardRequest.
private void rejectShardRequest(ShardIndexingPressureTracker tracker, long bytes, long nodeTotalBytes, long shardTotalBytes, RejectionTracker rejectionTracker, String operationType) {
long nodeBytesWithoutOperation = nodeTotalBytes - bytes;
long shardBytesWithoutOperation = shardTotalBytes - bytes;
ShardId shardId = tracker.getShardId();
rejectionTracker.incrementTotalRejections();
throw new OpenSearchRejectedExecutionException("rejected execution of " + operationType + " operation [" + "shard_detail=[" + shardId.getIndexName() + "][" + shardId.id() + "], " + "shard_total_bytes=" + shardBytesWithoutOperation + ", " + "shard_operation_bytes=" + bytes + ", " + "shard_max_coordinating_and_primary_bytes=" + tracker.getPrimaryAndCoordinatingLimits() + ", " + "shard_max_replica_bytes=" + tracker.getReplicaLimits() + "] OR [" + "node_total_bytes=" + nodeBytesWithoutOperation + ", " + "node_operation_bytes=" + bytes + ", " + "node_max_coordinating_and_primary_bytes=" + primaryAndCoordinatingLimits + ", " + "node_max_replica_bytes=" + replicaLimits + "]", false);
}
use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.
the class RetryableActionTests method testRetryableActionWillRetry.
public void testRetryableActionWillRetry() {
int expectedRetryCount = randomIntBetween(1, 8);
final AtomicInteger remainingFailedCount = new AtomicInteger(expectedRetryCount);
final AtomicInteger retryCount = new AtomicInteger();
final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(30), future) {
@Override
public void tryAction(ActionListener<Boolean> listener) {
if (remainingFailedCount.getAndDecrement() == 0) {
listener.onResponse(true);
} else {
if (randomBoolean()) {
listener.onFailure(new OpenSearchRejectedExecutionException());
} else {
throw new OpenSearchRejectedExecutionException();
}
}
}
@Override
public boolean shouldRetry(Exception e) {
retryCount.getAndIncrement();
return e instanceof OpenSearchRejectedExecutionException;
}
};
retryableAction.run();
taskQueue.runAllRunnableTasks();
long previousDeferredTime = 0;
for (int i = 0; i < expectedRetryCount; ++i) {
assertTrue(taskQueue.hasDeferredTasks());
final long deferredExecutionTime = taskQueue.getLatestDeferredExecutionTime();
final long millisBound = 10 << i;
assertThat(deferredExecutionTime, lessThanOrEqualTo(millisBound + previousDeferredTime));
previousDeferredTime = deferredExecutionTime;
taskQueue.advanceTime();
taskQueue.runAllRunnableTasks();
}
assertEquals(expectedRetryCount, retryCount.get());
assertTrue(future.actionGet());
}
use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.
the class RetryableActionTests method testRetryableActionTimeout.
public void testRetryableActionTimeout() {
final AtomicInteger retryCount = new AtomicInteger();
final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(1), future) {
@Override
public void tryAction(ActionListener<Boolean> listener) {
if (randomBoolean()) {
listener.onFailure(new OpenSearchRejectedExecutionException());
} else {
throw new OpenSearchRejectedExecutionException();
}
}
@Override
public boolean shouldRetry(Exception e) {
retryCount.getAndIncrement();
return e instanceof OpenSearchRejectedExecutionException;
}
};
retryableAction.run();
taskQueue.runAllRunnableTasks();
long previousDeferredTime = 0;
while (previousDeferredTime < 1000) {
assertTrue(taskQueue.hasDeferredTasks());
previousDeferredTime = taskQueue.getLatestDeferredExecutionTime();
taskQueue.advanceTime();
taskQueue.runAllRunnableTasks();
}
assertFalse(taskQueue.hasDeferredTasks());
assertFalse(taskQueue.hasRunnableTasks());
expectThrows(OpenSearchRejectedExecutionException.class, future::actionGet);
}
use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.
the class RetryableActionTests method testRetryableActionCancelled.
public void testRetryableActionCancelled() {
final AtomicInteger executedCount = new AtomicInteger();
final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(30), future) {
@Override
public void tryAction(ActionListener<Boolean> listener) {
if (executedCount.incrementAndGet() == 1) {
throw new OpenSearchRejectedExecutionException();
} else {
listener.onResponse(true);
}
}
@Override
public boolean shouldRetry(Exception e) {
return e instanceof OpenSearchRejectedExecutionException;
}
};
retryableAction.run();
taskQueue.runAllRunnableTasks();
assertTrue(taskQueue.hasDeferredTasks());
taskQueue.advanceTime();
retryableAction.cancel(new OpenSearchException("Cancelled"));
taskQueue.runAllRunnableTasks();
// A second run will not occur because it is cancelled
assertEquals(1, executedCount.get());
expectThrows(OpenSearchException.class, future::actionGet);
}
use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.
the class RemoteConnectionStrategy method connect.
/**
* Triggers a connect round unless there is one running already. If there is a connect round running, the listener will either
* be queued or rejected and failed.
*/
void connect(ActionListener<Void> connectListener) {
boolean runConnect = false;
final ActionListener<Void> listener = ContextPreservingActionListener.wrapPreservingContext(connectListener, transportService.getThreadPool().getThreadContext());
boolean closed;
synchronized (mutex) {
closed = this.closed.get();
if (closed) {
assert listeners.isEmpty();
} else {
if (listeners.size() >= maxPendingConnectionListeners) {
assert listeners.size() == maxPendingConnectionListeners;
listener.onFailure(new OpenSearchRejectedExecutionException("connect listener queue is full"));
return;
} else {
listeners.add(listener);
}
runConnect = listeners.size() == 1;
}
}
if (closed) {
connectListener.onFailure(new AlreadyClosedException("connect handler is already closed"));
return;
}
if (runConnect) {
ExecutorService executor = transportService.getThreadPool().executor(ThreadPool.Names.MANAGEMENT);
executor.submit(new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
ActionListener.onFailure(getAndClearListeners(), e);
}
@Override
protected void doRun() {
connectImpl(new ActionListener<Void>() {
@Override
public void onResponse(Void aVoid) {
ActionListener.onResponse(getAndClearListeners(), aVoid);
}
@Override
public void onFailure(Exception e) {
ActionListener.onFailure(getAndClearListeners(), e);
}
});
}
});
}
}
Aggregations