Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 7ca4db0a1 -> d68325bfd refs/heads/trunk 1944e402c -> e90ec26b6
Improve efficieny of ColumnDefinition comparison patch by benedict; reviewed by sylvain for CASSANDRA-10316 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/d68325bf Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/d68325bf Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/d68325bf Branch: refs/heads/cassandra-3.0 Commit: d68325bfd3eec7c84515c81b417524c6e60b98d2 Parents: 7ca4db0 Author: Benedict Elliott Smith <[email protected]> Authored: Mon Sep 14 16:00:55 2015 +0100 Committer: Benedict Elliott Smith <[email protected]> Committed: Tue Sep 15 17:40:38 2015 +0100 ---------------------------------------------------------------------- .../apache/cassandra/config/ColumnDefinition.java | 17 +++++++++++------ .../apache/cassandra/cql3/ColumnIdentifier.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/d68325bf/src/java/org/apache/cassandra/config/ColumnDefinition.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/config/ColumnDefinition.java b/src/java/org/apache/cassandra/config/ColumnDefinition.java index 17276bc..7dc425f 100644 --- a/src/java/org/apache/cassandra/config/ColumnDefinition.java +++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java @@ -48,6 +48,7 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable< */ public enum Kind { + // NOTE: if adding a new type, must modify comparisonOrder PARTITION_KEY, CLUSTERING, REGULAR, @@ -75,13 +76,17 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable< /** * These objects are compared frequently, so we encode several of their comparison components - * into a single int value so that this can be done efficiently + * into a single long value so that this can be done efficiently */ - private final int comparisonOrder; + private final long comparisonOrder; - private static int comparisonOrder(Kind kind, boolean isComplex, int position) + private static long comparisonOrder(Kind kind, boolean isComplex, long position, ColumnIdentifier name) { - return (kind.ordinal() << 28) | (isComplex ? 1 << 27 : 0) | position; + assert position >= 0 && position < 1 << 12; + return (((long) kind.ordinal()) << 61) + | (isComplex ? 1L << 60 : 0) + | (position << 48) + | (name.prefixComparison >>> 16); } public static ColumnDefinition partitionKeyDef(CFMetaData cfm, ByteBuffer name, AbstractType<?> type, int position) @@ -147,7 +152,7 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable< this.cellPathComparator = makeCellPathComparator(kind, type); this.cellComparator = cellPathComparator == null ? ColumnData.comparator : (a, b) -> cellPathComparator.compare(a.path(), b.path()); this.asymmetricCellPathComparator = cellPathComparator == null ? null : (a, b) -> cellPathComparator.compare(((Cell)a).path(), (CellPath) b); - this.comparisonOrder = comparisonOrder(kind, isComplex(), position()); + this.comparisonOrder = comparisonOrder(kind, isComplex(), position(), name); } private static Comparator<CellPath> makeCellPathComparator(Kind kind, AbstractType<?> type) @@ -308,7 +313,7 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable< return 0; if (comparisonOrder != other.comparisonOrder) - return comparisonOrder - other.comparisonOrder; + return Long.compare(comparisonOrder, other.comparisonOrder); return this.name.compareTo(other.name); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/d68325bf/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java b/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java index 6102bb9..4880c60 100644 --- a/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java +++ b/src/java/org/apache/cassandra/cql3/ColumnIdentifier.java @@ -52,7 +52,7 @@ public class ColumnIdentifier extends org.apache.cassandra.cql3.selection.Select * since these objects are compared frequently, we stash an efficiently compared prefix of the bytes, in the expectation * that the majority of comparisons can be answered by this value only */ - private final long prefixComparison; + public final long prefixComparison; private final boolean interned; private static final long EMPTY_SIZE = ObjectSizes.measure(new ColumnIdentifier(ByteBufferUtil.EMPTY_BYTE_BUFFER, "", false));
