iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

Api:Fix add the same listener to the same listeners queue multiple times

Open hejiay opened this issue 3 years ago • 7 comments

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. image As you can see above, the kafkaCreateSnapshotEventToJsonListener@18286 was added to the same queue three times. I will fix the bug.

hejiay avatar Jul 20 '23 05:07 hejiay

@hejiay where does the KafkaCreateSnapshotEventToJsonListener come from? Could you please share how you're calling register and the implementation of KafkaCreateSnapshotEventToJsonListener?

nastra avatar Jul 20 '23 08:07 nastra

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.

hejiay avatar Jul 20 '23 08:07 hejiay

This is my calling about register: image They are executed when HiveCatalog is initialized.

hejiay avatar Jul 20 '23 08:07 hejiay

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

nastra avatar Jul 20 '23 09:07 nastra

This is my implementation of KafkaCreateSnapshotEventToJsonListener:image And I don't overwrite equals() and hashCode()

hejiay avatar Jul 20 '23 09:07 hejiay

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.

github-actions[bot] avatar Sep 07 '24 00:09 github-actions[bot]

This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

github-actions[bot] avatar Sep 21 '24 00:09 github-actions[bot]