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/fda3d8ee Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fda3d8ee Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fda3d8ee Branch: refs/heads/cassandra-2.2 Commit: fda3d8ee25adc4837bb5754f718062e522c04788 Parents: 5a9820d Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Thu Oct 15 09:50:40 2015 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Thu Jun 30 17:06:24 2016 +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/fda3d8ee/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 354a1c2..02afcc2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.15 + * Reduce contention getting instances of CompositeType (CASSANDRA-10433) * Account for partition deletions in tombstone histogram (CASSANDRA-12112) * Avoid stalling paxos when the paxos state expires (CASSANDRA-12043) * Remove finished incoming streaming connections from MessagingService (CASSANDRA-11854) http://git-wip-us.apache.org/repos/asf/cassandra/blob/fda3d8ee/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 f8ac22d..d25336d 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.serializers.MarshalException; import org.apache.cassandra.utils.ByteBufferUtil; @@ -67,7 +67,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 { @@ -97,7 +97,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(); @@ -105,7 +105,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; }