Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 5f5e9602d -> b42a0cfe8
Reduce contention getting instances of CompositeType patch by schlosna; reviewed by slebresne for CASSANDRA-10433 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/bee48ebe Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/bee48ebe Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/bee48ebe Branch: refs/heads/cassandra-3.0 Commit: bee48ebe206bd02c231266858e9ae137a928689d Parents: 7875326 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Thu Oct 15 09:50:40 2015 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Thu Oct 15 09:50:40 2015 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/db/marshal/CompositeType.java | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/bee48ebe/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index c02e2fa..9a0baaa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.2.4 + * Reduce contention getting instances of CompositeType (CASSANDRA-10433) Merged from 2.1: * (cqlsh) Distinguish negative and positive infinity in output (CASSANDRA-10523) * (cqlsh) allow custom time_format for COPY TO (CASSANDRA-8970) http://git-wip-us.apache.org/repos/asf/cassandra/blob/bee48ebe/src/java/org/apache/cassandra/db/marshal/CompositeType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/CompositeType.java b/src/java/org/apache/cassandra/db/marshal/CompositeType.java index 0218411..9892118 100644 --- a/src/java/org/apache/cassandra/db/marshal/CompositeType.java +++ b/src/java/org/apache/cassandra/db/marshal/CompositeType.java @@ -19,18 +19,18 @@ package org.apache.cassandra.db.marshal; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import com.google.common.collect.ImmutableList; -import org.apache.cassandra.exceptions.ConfigurationException; -import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.cql3.Operator; +import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.exceptions.SyntaxException; import org.apache.cassandra.io.util.DataOutputBuffer; import org.apache.cassandra.io.util.DataOutputBufferFixed; import org.apache.cassandra.serializers.MarshalException; @@ -68,7 +68,7 @@ public class CompositeType extends AbstractCompositeType public final List<AbstractType<?>> types; // interning instances - private static final Map<List<AbstractType<?>>, CompositeType> instances = new HashMap<List<AbstractType<?>>, CompositeType>(); + private static final ConcurrentMap<List<AbstractType<?>>, CompositeType> instances = new ConcurrentHashMap<List<AbstractType<?>>, CompositeType>(); public static CompositeType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { @@ -98,7 +98,7 @@ public class CompositeType extends AbstractCompositeType return true; } - public static synchronized CompositeType getInstance(List<AbstractType<?>> types) + public static CompositeType getInstance(List<AbstractType<?>> types) { assert types != null && !types.isEmpty(); @@ -106,7 +106,11 @@ public class CompositeType extends AbstractCompositeType if (ct == null) { ct = new CompositeType(types); - instances.put(types, ct); + CompositeType previous = instances.putIfAbsent(types, ct); + if (previous != null) + { + ct = previous; + } } return ct; }