Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LeastActiveBalancingPolicy.ShufflingCompare comparisons stable #646

Merged
merged 1 commit into from
Jan 13, 2014

Conversation

jancona
Copy link
Contributor

@jancona jancona commented Jan 9, 2014

This avoids a problem where mutable state in ConcurrentHClientPool causes

IllegalArgumentException: Comparison method violates its general contract!

failures when running in Java 7.

The default sort algorithm changed in Java 7 (see this blog post for details and links). The new TimSort algorithm is pickier about the Comparable and Comparator honoring their contract. It appears that because ConcurrentHClientPool. getNumActive can return different values while the sort is going on, that can trigger the error.

We've ran into this issue immediately after deploying one of our apps in production on Java 7. We have worked around the issue by setting the system property java.util.Arrays.useLegacyMergeSort=true. We did not see the issue in our pre-production environments. Looking at the Java 7 source the new algorithm is only used when the list to be sorted is 32 or more elements. Our production cluster has 36 hosts in the list, while our pre-production clusters are much smaller.

I've included a test which shows the error when run agains the old ShufflingCompare implementation in Java 7. It passes with this new implementation or with the old one under Java 6.

My solution was to cache the compared values for the duration of the sort. If someone has a better idea, I'm all ears.

I'd like to see this backported to the 1.0 branch if possible. The commit should apply cleanly.

…o avoid a problem where

mutable state in ConcurrentHClientPool causes
    IllegalArgumentException: Comparison method violates its general contract!
failures when running in Java 7.
zznate added a commit that referenced this pull request Jan 13, 2014
Make LeastActiveBalancingPolicy.ShufflingCompare comparisons stable
@zznate zznate merged commit d48e723 into hector-client:master Jan 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants