diff --git a/core/src/main/java/org/apache/gravitino/listener/EventBus.java b/core/src/main/java/org/apache/gravitino/listener/EventBus.java index 4d39930bb7e..d0aad072082 100644 --- a/core/src/main/java/org/apache/gravitino/listener/EventBus.java +++ b/core/src/main/java/org/apache/gravitino/listener/EventBus.java @@ -23,8 +23,11 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.gravitino.listener.api.EventListenerPlugin; +import org.apache.gravitino.listener.api.EventListenerPlugin.PreEventCheckException; import org.apache.gravitino.listener.api.event.Event; import org.apache.gravitino.listener.api.event.PreEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The {@code EventBus} class serves as a mechanism to dispatch events to registered listeners. It @@ -32,6 +35,7 @@ * within its internal management. */ public class EventBus { + private static final Logger LOG = LoggerFactory.getLogger(EventListenerManager.class); // Holds instances of EventListenerPlugin. These instances can either be // EventListenerPluginWrapper, @@ -82,7 +86,17 @@ List getPostEventListeners() { } public void dispatchPreEvent(PreEvent event) { - preEventListeners.forEach(postEventListener -> postEventListener.onPreEvent(event)); + preEventListeners.forEach( + preEventListener -> { + try { + preEventListener.onPreEvent(event); + } catch (PreEventCheckException e) { + // todo transform to ValidateException for IcebergRESTServer + throw new RuntimeException(e); + } catch (Exception e) { + LOG.warn("PreEvent handle exception,", e); + } + }); } private void dispatchPostEvent(Event event) { diff --git a/core/src/main/java/org/apache/gravitino/listener/api/EventListenerPlugin.java b/core/src/main/java/org/apache/gravitino/listener/api/EventListenerPlugin.java index 9c82f8217a8..4858169667b 100644 --- a/core/src/main/java/org/apache/gravitino/listener/api/EventListenerPlugin.java +++ b/core/src/main/java/org/apache/gravitino/listener/api/EventListenerPlugin.java @@ -34,6 +34,9 @@ */ @DeveloperApi public interface EventListenerPlugin { + + class PreEventCheckException extends RuntimeException {} + /** * Defines the operational modes for event processing within an event listener, catering to both * synchronous and asynchronous processing strategies. Each mode determines how events are @@ -108,7 +111,9 @@ enum Mode { */ void onPostEvent(Event event) throws RuntimeException; - void onPreEvent(PreEvent preEvent) throws RuntimeException; + // The related operation will fail, if throwing PreEventCheckException, will ignore other + // Exceptions. + void onPreEvent(PreEvent preEvent) throws PreEventCheckException; /** * Specifies the default operational mode for event processing by the plugin. The default