Skip to content

KAFKA 6673 - Implemented missing override equals method#4745

Merged
guozhangwang merged 6 commits intoapache:trunkfrom
asutosh936:KAFKA-6673
May 9, 2018
Merged

KAFKA 6673 - Implemented missing override equals method#4745
guozhangwang merged 6 commits intoapache:trunkfrom
asutosh936:KAFKA-6673

Conversation

@asutosh936
Copy link
Copy Markdown
Contributor

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@asutosh936
Copy link
Copy Markdown
Contributor Author

The fix is to implement the missing override equals() method.

@KoenDG
Copy link
Copy Markdown
Contributor

KoenDG commented Mar 22, 2018

As I stated on the kafka jira:

That implementation would just do an identity comparison. Because Stamped and Segment don't have an explicit super class, just Object.

And Object's equals is this:

public boolean equals(Object obj) {
    return (this == obj);
}

The whole idea behind this ticket is that the equals method should act logically the same as the compareTo method, as to have only 1 kind of behavior.

@asutosh936
Copy link
Copy Markdown
Contributor Author

@KoenDG - Thanks for the review. Have tried to mimic compareTo logic for similar behavior.

@asutosh936
Copy link
Copy Markdown
Contributor Author

@KoenDG - Are we good with the changes? Anything else needed as part of this PR?

@KoenDG
Copy link
Copy Markdown
Contributor

KoenDG commented Apr 8, 2018

@asutosh936 They're fine for me. But I just made the ticket. I can't actually merge this.

@asutosh936
Copy link
Copy Markdown
Contributor Author

Can someone review and provide feedback?

@asutosh936
Copy link
Copy Markdown
Contributor Author

@hachikuji @guozhangwang @ewencp

Could someone please review and merge, if code change looks good.

@guozhangwang
Copy link
Copy Markdown
Contributor

@bbejeck could you take a look?

@asutosh936 Did you run unit tests locally and make sure they are passed?

@guozhangwang
Copy link
Copy Markdown
Contributor

retest this please

Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch @asutosh936 . There are a couple of things that need fixing here.

The test failures are from findbugs warnings that need to be addressed. If you run ./gradlew streams:clean streams:test then look at the report in streams/build/reports/findbugs/main.html you can read what needs to change.

The more general idea is that when foo.compareTo(bar) returns 0, then foo.equals(bar) should return true and and a non-zero return from compareTo means equals should return false.

@Override
public boolean equals(Object other) {

if (getClass() != other.getClass()) return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check other for null

if (getClass() != other.getClass()) return false;

long otherTimestamp = ((Stamped<?>) other).timestamp;
return timestamp > otherTimestamp;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation of equals will return false for timestamps of the same value; maybe this could be something like return Long.compare(timestamp, otherTimestamp) == 0


@Override
public int hashCode() {
return super.hashCode();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since equality is measured by comparing timestamps something like return Objects.hash(timestamp); should be used instead.


@Override
public int hashCode() {
return super.hashCode();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.


@Override
public boolean equals(Object obj) {
if (getClass() != obj.getClass()) return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a check for null on obj here as well

if (getClass() != obj.getClass()) return false;

Segment segment = (Segment) obj;
return Long.compare(id, segment.id) > 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left this out of my previous review.

This needs to change as well as it will return false for two Segment instances with the same id.

Also, this statement will always evaluate to false as Long.compare(x, y) only returns -1, 0, or 1.

@asutosh936
Copy link
Copy Markdown
Contributor Author

Thanks @bbejeck will implement Your review comments and update.

@asutosh936
Copy link
Copy Markdown
Contributor Author

@bbejeck @guozhangwang
Implemented review comments and validated. Please review.

@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented May 9, 2018

retest this please

Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asutosh936 thanks for the changes. LGTM.

@guozhangwang guozhangwang merged commit 5ca9ed5 into apache:trunk May 9, 2018
@guozhangwang
Copy link
Copy Markdown
Contributor

Merged to trunk, thanks @asutosh936 !

ijuma added a commit to ijuma/kafka that referenced this pull request May 11, 2018
…-record-version

* apache-github/trunk:
  KAFKA-6894: Improve err msg when connecting processor with global store (apache#5000)
  KAFKA-6893; Create processors before starting acceptor in SocketServer (apache#4999)
  MINOR: Fix typo in ConsumerRebalanceListener JavaDoc (apache#4996)
  MINOR: Remove deprecated valueTransformer.punctuate (apache#4993)
  MINOR: Update dynamic broker configuration doc for truststore update (apache#4954)
  KAFKA-6870 Concurrency conflicts in SampledStat (apache#4985)
  KAFKA-6361: Fix log divergence between leader and follower after fast leader fail over (apache#4882)
  KAFKA-6813: Remove deprecated APIs in KIP-182, Part II (apache#4976)
  KAFKA-6878 Switch the order of underlying.init and initInternal (apache#4988)
  KAFKA-6299; Fix AdminClient error handling when metadata changes (apache#4295)
  KAFKA-6878: NPE when querying global state store not in READY state (apache#4978)
  KAFKA 6673: Implemented missing override equals method (apache#4745)
  KAFKA-6834: Handle compaction with batches bigger than max.message.bytes (apache#4953)
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
Reviewers: Guozhang Wang <guozhang@confluent.io>, Bill Bejeck <bill@confluent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants