jerryshao opened a new issue, #14022:
URL: https://github.com/apache/gravitino/issues/14022
### Version
main branch
### Describe what's wrong
`EventListenerManager.addEventListener` wraps the listener in a plain
`EventListenerPluginWrapper` and never checks `mode()`. Only listeners loaded
from `gravitino.eventListener.names` go through the mode switch in
`assembleEventListeners` that creates an `AsyncQueueListener`. Listeners
registered in code therefore always run on the caller's thread, even when they
declare an async mode.
Two built-in listeners are affected. Both declare `ASYNC_ISOLATED`:
- `BuiltInJobTemplateEventListener`, registered in `GravitinoEnv`. On every
create-metalake request it does the following before the response is returned:
- scans `auxlib` for `gravitino-jobs-*.jar`
- opens a new `URLClassLoader` and loads the templates through
`ServiceLoader`
- writes the templates to the entity store
Its own comment says it is async "to avoid blocking metalake creation".
- The `audit-log` listener, registered in `AuditLogManager`. When audit log
is enabled, every event is written on the request thread.
### Error message and/or stacktrace
N/A
### How to reproduce
1. Enable audit log, or put `gravitino-jobs-*.jar` in `auxlib`.
2. Create a metalake.
3. The thread dump or the logs show the template loading and the audit
writes running on the Jetty request thread, not on an `async-queue-listener-*`
thread.
### Additional context
Proposed fix:
- Make `addEventListener` apply the same mode handling as `init`:
- `SYNC`: plain wrapper
- `ASYNC_ISOLATED`: its own `AsyncQueueListener`
- `ASYNC_SHARED`: the shared queue
- Make `EventBus.isHighWatermark` include async queues that are added after
the bus is created.
- In `BuiltInJobTemplateEventListener`, take the template creator from
`event.user()` instead of the current thread principal. The dispatcher thread
has no subject.
Behavior changes to note:
- Built-in templates appear shortly after `createMetalake` returns, not
before it returns.
- Audit log entries follow the async queue semantics: they can be dropped
when the queue is full, the same as configured async listeners.
--
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]