Fix DynamicCompositeType same type comparison patch by slebresne; reviewed by jbellis for CASSANDRA-4711
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5e15927f Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5e15927f Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5e15927f Branch: refs/heads/trunk Commit: 5e15927ffffb9aa47b69a7089b1aa2d8f3f1f093 Parents: d51643c Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Mon Oct 29 11:12:48 2012 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Mon Oct 29 11:12:48 2012 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/db/marshal/DynamicCompositeType.java | 20 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/5e15927f/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 191c935..05b7ef3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ * fix potential infinite loop in get_count (CASSANDRA-4833) * fix compositeType.{get/from}String methods (CASSANDRA-4842) * (CQL) fix CREATE COLUMNFAMILY permissions check (CASSANDRA-4864) + * Fix DynamicCompositeType same type comparison (CASSANDRA-4711) 1.1.6 http://git-wip-us.apache.org/repos/asf/cassandra/blob/5e15927f/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java index 0f0127a..06ecdfc 100644 --- a/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java +++ b/src/java/org/apache/cassandra/db/marshal/DynamicCompositeType.java @@ -120,15 +120,15 @@ public class DynamicCompositeType extends AbstractCompositeType * We compare component of different types by comparing the * comparator class names. We start with the simple classname * first because that will be faster in almost all cases, but - * allback on the full name if necessary - */ + * fallback on the full name if necessary + */ int cmp = comp1.getClass().getSimpleName().compareTo(comp2.getClass().getSimpleName()); if (cmp != 0) - return cmp < 0 ? FixedValueComparator.instance : ReversedType.getInstance(FixedValueComparator.instance); + return cmp < 0 ? FixedValueComparator.alwaysLesserThan : FixedValueComparator.alwaysGreaterThan; cmp = comp1.getClass().getName().compareTo(comp2.getClass().getName()); if (cmp != 0) - return cmp < 0 ? FixedValueComparator.instance : ReversedType.getInstance(FixedValueComparator.instance); + return cmp < 0 ? FixedValueComparator.alwaysLesserThan : FixedValueComparator.alwaysGreaterThan; // if cmp == 0, we're actually having the same type, but one that // did not have a singleton instance. It's ok (though inefficient). @@ -307,11 +307,19 @@ public class DynamicCompositeType extends AbstractCompositeType */ private static class FixedValueComparator extends AbstractType<Void> { - public static final FixedValueComparator instance = new FixedValueComparator(); + public static final FixedValueComparator alwaysLesserThan = new FixedValueComparator(-1); + public static final FixedValueComparator alwaysGreaterThan = new FixedValueComparator(1); + + private final int cmp; + + public FixedValueComparator(int cmp) + { + this.cmp = cmp; + } public int compare(ByteBuffer v1, ByteBuffer v2) { - return -1; + return cmp; } public Void compose(ByteBuffer bytes)