Skip to content

AssignableReplica breaking hashCode and equals contracts #2299

@qqu0127

Description

@qqu0127

Describe the bug

In https://github.com/apache/helix/blob/master/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/AssignableReplica.java#L127, it overrides equals, but not hashCode. This is violating the Object.hashCode() contract and breaking lots of assumption, especially with hash-based collection.

What makes it even more awkward is the code building on top of this anti-pattern,

private static Map<String, Set<AssignableReplica>> getAllAssignableReplicas(
, it could contain "duplicated" elements (two standby replicas of a partition). It really should be a list to begin with.

Expected behavior

We should fix the hashCode and change to use List instead of Set to store values with duplication.

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions