flyrain commented on code in PR #922: URL: https://github.com/apache/polaris/pull/922#discussion_r1984260696
########## service/common/src/main/java/org/apache/polaris/service/events/PolarisEventListener.java: ########## @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +/** + * Represents an event listener that can respond to notable moments during Polaris's execution. + * Users can either extend this interface and implement handlers for all events or, for ease, extend + * DefaultPolarisEventListener and only have to handle a subset of events. Event details are + * documented under the event objects themselves. + */ +public interface PolarisEventListener { Review Comment: Adding a new event shouldn't require recompilation or redeployment of listeners. How do we archive that with the current design? One of solutions is to remove the specific type in the listener interface, only keep the a generic event type, like the following: ``` public void handleEvent(Event event) { switch(event.getEventType()) { case "BeforeTableCommit": handleBeforeTableCommit(event.getPayload()); break; case "TableCommitted": handleTableCommitted(event.getPayload()); break; default: // Ignore or log unknown event } } ``` ########## service/common/src/main/java/org/apache/polaris/service/events/AfterTableCommitEvent.java: ########## @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +import org.apache.iceberg.TableMetadata; + +/** + * Emitted after Polaris performs a commit to a table. This is not emitted if there's an exception + * while committing. + * + * @param base The old metadata. + * @param metadata The new metadata. + */ +public record AfterTableCommitEvent(TableMetadata base, TableMetadata metadata) implements PolarisEvent {} Review Comment: ```suggestion public record AfterTableCommitEvent(TableMetadata base, TableMetadata new) implements PolarisEvent {} ``` ########## quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java: ########## @@ -1658,4 +1670,35 @@ public void testRegisterTableWithSlashlessMetadataLocation() { .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid metadata file location"); } + + @Test + public void testEventsAreEmitted() { + BasePolarisCatalog catalog = catalog(); + catalog.createNamespace(TestData.NAMESPACE); + Table table = catalog.buildTable(TestData.TABLE, TestData.SCHEMA).create(); + + String key = "foo"; + String valOld = "bar1"; + String valNew = "bar2"; + table.updateProperties().set(key, valOld).commit(); + table.updateProperties().set(key, valNew).commit(); + + BeforeTableRefreshEvent beforeRefreshEvent = + testPolarisEventListener.getLatest(BeforeTableRefreshEvent.class); Review Comment: Nit: we can keep them in one line if we are using `var` ########## service/common/src/main/java/org/apache/polaris/service/events/AfterTableRefreshEvent.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +import org.apache.iceberg.catalog.TableIdentifier; + +/** + * Emitted after Polaris refreshes its known version of a table's metadata by fetching the latest. + * + * @param tableIdentifier The identifier of the table that was refreshed. + */ +public record AfterTableRefreshEvent(TableIdentifier tableIdentifier) implements PolarisEvent {} Review Comment: Curious the use case of this event. I'd assume it's not for the performance instrument. ########## service/common/src/main/java/org/apache/polaris/service/events/AfterViewCommitEvent.java: ########## @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +import org.apache.iceberg.view.ViewMetadata; + +/** + * Emitted after Polaris performs a commit to a view. This is not emitted if there's an exception + * while committing. + * + * @param base The old metadata. + * @param metadata The new metadata. + */ +public record AfterViewCommitEvent(ViewMetadata base, ViewMetadata metadata) implements PolarisEvent {} Review Comment: Same naming suggestion, `ViewCommitted` ########## service/common/src/main/java/org/apache/polaris/service/events/AfterTableRefreshEvent.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +import org.apache.iceberg.catalog.TableIdentifier; + +/** + * Emitted after Polaris refreshes its known version of a table's metadata by fetching the latest. + * + * @param tableIdentifier The identifier of the table that was refreshed. + */ +public record AfterTableRefreshEvent(TableIdentifier tableIdentifier) implements PolarisEvent {} Review Comment: Same naming suggestion here, the name would be `TableRefreshed` ########## service/common/src/main/java/org/apache/polaris/service/events/AfterTableCommitEvent.java: ########## @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.service.events; + +import org.apache.iceberg.TableMetadata; + +/** + * Emitted after Polaris performs a commit to a table. This is not emitted if there's an exception + * while committing. + * + * @param base The old metadata. + * @param metadata The new metadata. + */ +public record AfterTableCommitEvent(TableMetadata base, TableMetadata metadata) implements PolarisEvent {} Review Comment: I'd suggest rename it to `AfterTableCommitted` or `AfterTableCommittedEvent` to indicate that a table commit successfully, because it is for that. We don't emit this event in case of any commit failure. I guess we don't need the word "After", it can be just `TableCommitted`. -- 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]
