Api:Fix add the same listener to the same listeners queue multiple times
Apache Iceberg version
1.3.0 (latest release)
Query engine
Flink
Please describe the bug 🐞
When I register create snaoshot event listener to listeners, I found that same listener would be added to the same listeners queue multiple times.
As you can see above, the kafkaCreateSnapshotEventToJsonListener@18286 was added to the same queue three times.
I will fix the bug.
@hejiay where does the KafkaCreateSnapshotEventToJsonListener come from? Could you please share how you're calling register and the implementation of KafkaCreateSnapshotEventToJsonListener?
Thank you, the KafkaCreateSnapshotEventToJsonListener is my implementation of Listener, it sends create snapshot event to kafka topic when a snapshot was created.I register it into listeners when catalog initialize.
And I found that when I execute the unit test [TestFlinkHiveCatalog.testCreateCatalogWithWarehouseLocation()], the HiveCatalog would be initialized four times and the same KafkaCreateSnapshotEventToJsonListener object would be registered into the same eventType queue four times. So a snapshot event would be sent to kafka four times.
This is my calling about register:
They are executed when
HiveCatalog is initialized.
Could you also please share the implementation of KafkaCreateSnapshotEventToJsonListener if possible? I'm mainly interested whether it implements equals() / hashCode(), because most listeners won't have that implemented and so adding a if (!listeners.contains(...)) check wouldn't really help. Here's also a short example of how listeners are registered in the tests: https://github.com/apache/iceberg/blob/96f0f22bd829a5dbe0ac8194c70a878493300b7d/api/src/test/java/org/apache/iceberg/events/TestListeners.java#L27-L28
This is my implementation of KafkaCreateSnapshotEventToJsonListener:
And I don't overwrite
equals() and hashCode()
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'