adutra commented on code in PR #4648:
URL: https://github.com/apache/polaris/pull/4648#discussion_r3395621784
##########
runtime/service/src/main/java/org/apache/polaris/service/events/PolarisEventListeners.java:
##########
@@ -136,4 +165,55 @@ private void deliverEvent(
public boolean hasListeners(PolarisEventType eventType) {
return eventTypesWithListeners.contains(eventType);
}
+
+ private static class ListenerExecutor implements Executor {
+
+ private final Executor delegate;
+ private final Queue<Runnable> queue;
+ private final AtomicBoolean draining = new AtomicBoolean(false);
+
+ ListenerExecutor(Executor delegate, int capacity) {
+ this.delegate = delegate;
+ this.queue =
+ capacity == -1 ? new ConcurrentLinkedQueue<>() : new
ArrayBlockingQueue<>(capacity);
+ }
+
+ @Override
+ public void execute(@NonNull Runnable task) {
+ if (!queue.offer(task)) {
+ throw new RejectedExecutionException("Event listener queue is full");
+ }
+ if (draining.compareAndSet(false, true)) {
+ try {
+ delegate.execute(this::drain);
+ } catch (Throwable t) {
+ draining.set(false);
+ throw t;
+ }
+ }
+ }
+
+ private void drain() {
+ try {
+ Runnable task;
+ while ((task = queue.poll()) != null) {
+ task.run();
+ }
+ } finally {
+ draining.set(false);
+ // A producer may have enqueued a task between the last poll() and the
set(false) above,
+ // and seen draining=true so it did not schedule a drain. Catch that
here.
+ if (!queue.isEmpty() && draining.compareAndSet(false, true)) {
+ try {
+ // re-schedule for fairness
+ delegate.execute(this::drain);
+ } catch (Exception e) {
Review Comment:
Ok that's a lot - let's go step by step 😄
> Where do task execution exceptions go in this case? 🤔
It goes to the uncaught exception handler, which by default is a
`org.jboss.threads.LoggingUncaughtExceptionHandler`. It logs a message like
this:
```
2026-06-11 11:52:36,707 ERROR [org.jbo.thr.errors] [,] [,,,]
(executor-thread-2) Thread Thread[#126,executor-thread-2,5,main] threw an
uncaught exception: java.util.concurrent.RejectedExecutionException: blah blah
at
org.apache.polaris.service.events.PolarisEventListeners$ListenerExecutor.drain(PolarisEventListeners.java:206)
at
io.smallrye.context.impl.wrappers.SlowContextualRunnable.run(SlowContextualRunnable.java:19)
at
org.jboss.threads.EnhancedViewExecutor$EnhancedViewExecutorRunnable.run(EnhancedViewExecutor.java:496)
at
io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:695)
at
org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2651)
at
org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2630)
at
org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1586)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
```
It does this for any throwable, including `Error`. Errors do not propagate
up the stack.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]