You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "leeleeian (via GitHub)" <gi...@apache.org> on 2023/03/19 23:20:18 UTC
[GitHub] [kafka] leeleeian opened a new pull request, #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
leeleeian opened a new pull request, #13418:
URL: https://github.com/apache/kafka/pull/13418
Equals and hashcode methods are missing from KafkaProducer and ProducerMetadata classes.
Hashcode method is constructed by sequentially multiplying by a prime number and adding the components.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475444359
@leeleeian That all makes sense; I'm wondering if you or anyone has a use case that involves comparing producers, though?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475437343
Thanks @leeleeian. I'm wondering about the motivation for this change. Is there something in a project you're working that necessitates or at least would benefit from implementing `equals` and `hashCode` in these classes?
I ask for a couple reasons:
- The `ProducerMetadata` class isn't part of the public API, so users really shouldn't be doing things with this class directly anyways (and if they are, we don't support that use case)
- The `KafkaProducer` equality method involves comparison of fields whose classes lack an overridden `equals` method, and which are instantiated in the constructor for the producer. So it's impossible (barring reflections-based hacks) for the method to return `true` in any case where it wouldn't be already
Ultimately, if the lack of this change isn't causing anybody any inconvenience, I'm not sure we need to worry about implementing these methods right now.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475432576
cc @guozhangwang @C0urante
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1476186302
Thanks for providing more detail. I'm still confused about this part:
> The default equals method compares by address. But this is not what we want.
Wouldn't comparison by address be exactly what you want? In what case(s) would you need a different kind of comparison?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian closed pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian closed pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
URL: https://github.com/apache/kafka/pull/13418
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475442197
For KafkaProducer, when clients want to compare one producer object with another, we wouldn't want to compare their addresses, which is why I am adding the equals method to the class.
Without an equals method, how would one judge if two producer objects are equal?
I agree that I would have to add equals methods to some other classes involved if we proceed with this change.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475609004
Here is the use case.
Multiple threads use the KafkaProducer. If there is error in sending, the (previous) KafkaProducer is closed and a new KafkaProducer recreated.
For recreation, it suffices to be done by one thread - hence each thread would check whether the `KafkaProducer` instance it uses has changed. For this reason, we want to compare KafkaProducer instances.
The default equals method compares by address. But this is not what we want.
Hence this PR is proposed.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] C0urante commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "C0urante (via GitHub)" <gi...@apache.org>.
C0urante commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475590471
Can you provide some detail on that need? And how it isn't addressed by the existing non-overridden `equals` implementation?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1475449597
There is a need on the client side to keep track of kafka producer objects' identities.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [kafka] leeleeian commented on pull request #13418: MINOR: add equals and hashcode methods to KafkaProducer and ProducerMetadata
Posted by "leeleeian (via GitHub)" <gi...@apache.org>.
leeleeian commented on PR #13418:
URL: https://github.com/apache/kafka/pull/13418#issuecomment-1477157623
We're discussing the solution for our use case.
Closing this PR for now.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org