Discussion thread | TBD |
---|---|
Vote thread | TBD |
ISSUE | https://github.com/apache/incubator-paimon/issues/1811 |
Release | TBD |
Motivation
Currently, Paimon doesn’t have event notification mechanism. In many users' production environments, users need to perceive the state changes of Paimon table, such as whether a new file has been committed to the table, in which partitions the committed files are, the size and number of the committed files, the status and type of compaction, operations like table creation, deletion, and schema changes, etc. So, we need to introduce a Listener system for Paimon.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public interface Listener extends Serializable { /** Initialize a listener given a map of catalog properties. */ void initialize(Map<String, String> options); /** Notify an event. */ void notify(Event event); /** The identifying name of a Listener. */ String name(); } |
Listeners
...
} |
ListenerFactory
A Factory for Listener.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
/**public registrationinterface andListenerFactory notification for listeners. */ public class Listenersextends Serializable { private List<Listener> listeners = new ArrayList<>(); /** RegisterInitialize a listener to Listeners. */ public register(Listener listener) { } /** Notifies all Listener that a specific event has occurredgiven a map of catalog properties. */ publicListener void notifycreate(EventOptions event) { }options); /** CreateThe aidentifying Listenersname withoutof anya Listener. */ public static Listeners emptyListeners() { }String name(); } |
Proposed Changes
Listener
...
Listeners ListenerFactory are loaded via SPI and initialized created Listener with the options of the catalog when CatalogFactory creates a catalog. Multiple initialized Listeners are registered in Listeners. There is no strict order between multiple listeners, and an exception thrown by one listener will not affect others. When implementing their own listeners, users should try to avoid long-running calls.
...
Suppose the user has a Listener and ListenerFactory implementation as shown below, and places it into the classpath.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public class MyListener implements Listener{ public MyListener(String value1, String value2) { .... } @Override public void notify(Event event) { ... } } |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public interface MyListenerFactory implements ListenerFactory { @Override initialize(Map<String, String> options) { public Listener create(Options options) { String value1 = options.get("key1"); String value2 = options.get("key2"); .... return } @Override public void notify(Event event) { ... new MyListener(value1, value2); } @Override @Override public String name() { return "my_listener"; } } |
Adding the corresponding configuration during the creation of the catalog will activate the listener named "my_listener". The params key1 and key2 will be
...