[
https://issues.apache.org/jira/browse/CASSANDRA-9519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14620367#comment-14620367
]
Sylvain Lebresne commented on CASSANDRA-9519:
---------------------------------------------
bq. I think this should be enough to fix it.
If it is, I don't understand why, so you might want to elaborate what the
problem is and why that fixes it.
What I personally think the problem is is that while CASSANDRA-8448 made the
{{scores}} map copy-on-write, we're still accessing the volatile/shared
{{scores}} reference in {{compareEndpoints}}, so successive calls to that
method may return different results for the same inputs (because scores have
changed) and to the best of my knowledge that's the "contract" that
{{Collections.sort}} bitch about breaking. In other words, we need to ensure
that during a given call to {{Collections.sort}}, the result of
{{compareEndpoints}} should be stable (return the same output for the same
inputs). In other words, all calls to {{compareEndpoints}} used by a call to
{{sortByProximity}} should use the same scores. Meaning that we should grabe a
reference to the {{scores}} map at the beginning of {{sortByProximity}} and
only use that.
I've pushed a patch doing that
[here|https://github.com/pcmanus/cassandra/commits/9519]. It's worth noting
that we can't do that with the {{compareEndpoints}} signature exposed by
{{IEndpointSnitch}} since we need to pass it the (immutable) {{scores}} map. So
the public {{DynamicEndpointSnitch.compareEndpoints()}} method now throw an
{{UnsupportedOperationException}}. Which, is worth noting, could be a problem
if custom snitch implementation are wrapping the dynamic snitch and use that
{{compareEndpoints}} method (or if something wrap a dynamic snitch with a
dynamic snitch, but I think we're cool with refusing that). I don't see why
you'd wrap the dynamic snitch so it's probably fine, but worth mentioning
nonetheless.
> CASSANDRA-8448 Doesn't seem to be fixed
> ---------------------------------------
>
> Key: CASSANDRA-9519
> URL: https://issues.apache.org/jira/browse/CASSANDRA-9519
> Project: Cassandra
> Issue Type: Bug
> Components: Core
> Reporter: Jeremiah Jordan
> Fix For: 2.1.x, 2.2.x
>
> Attachments: 9519.txt
>
>
> Still seeing the "Comparison method violates its general contract!" in 2.1.5
> {code}
> java.lang.IllegalArgumentException: Comparison method violates its general
> contract!
> at java.util.TimSort.mergeHi(TimSort.java:895) ~[na:1.8.0_45]
> at java.util.TimSort.mergeAt(TimSort.java:512) ~[na:1.8.0_45]
> at java.util.TimSort.mergeCollapse(TimSort.java:437) ~[na:1.8.0_45]
> at java.util.TimSort.sort(TimSort.java:241) ~[na:1.8.0_45]
> at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_45]
> at java.util.ArrayList.sort(ArrayList.java:1454) ~[na:1.8.0_45]
> at java.util.Collections.sort(Collections.java:175) ~[na:1.8.0_45]
> at
> org.apache.cassandra.locator.AbstractEndpointSnitch.sortByProximity(AbstractEndpointSnitch.java:49)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.locator.DynamicEndpointSnitch.sortByProximityWithScore(DynamicEndpointSnitch.java:158)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.locator.DynamicEndpointSnitch.sortByProximityWithBadness(DynamicEndpointSnitch.java:187)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.locator.DynamicEndpointSnitch.sortByProximity(DynamicEndpointSnitch.java:152)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.service.StorageProxy.getLiveSortedEndpoints(StorageProxy.java:1530)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.service.StorageProxy.getRangeSlice(StorageProxy.java:1688)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:256)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:209)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.statements.SelectStatement.execute(SelectStatement.java:63)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:238)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:260)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> at
> org.apache.cassandra.cql3.QueryProcessor.process(QueryProcessor.java:272)
> ~[cassandra-all-2.1.5.469.jar:2.1.5.469]
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)