fix race referencing tokenMetadataCache patch by jbellis; reviewed by rbranson for CASSANDRA-6485
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a3d91dc9 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a3d91dc9 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a3d91dc9 Branch: refs/heads/cassandra-2.0 Commit: a3d91dc9d67572e16d9ad92f22b89eb969373899 Parents: 1145573 Author: Jonathan Ellis <[email protected]> Authored: Fri Dec 13 22:10:13 2013 -0600 Committer: Jonathan Ellis <[email protected]> Committed: Fri Dec 13 22:10:13 2013 -0600 ---------------------------------------------------------------------- CHANGES.txt | 7 ++----- .../cassandra/locator/AbstractReplicationStrategy.java | 11 ++++++----- 2 files changed, 8 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3d91dc9/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b7bbe09..e586592 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,9 +1,6 @@ -1.2.14 - * Randomize batchlog candidates selection (CASSANDRA-6481) - - 1.2.13 - * Fix thundering herd on endpoint cache invalidation (CASSANDRA-6345) + * Randomize batchlog candidates selection (CASSANDRA-6481) + * Fix thundering herd on endpoint cache invalidation (CASSANDRA-6345, 6485) * Optimize FD phi calculation (CASSANDRA-6386) * Improve initial FD phi estimate when starting up (CASSANDRA-6385) * Don't list CQL3 table in CLI describe even if named explicitely http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3d91dc9/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java b/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java index 51c4119..c36fde4 100644 --- a/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java +++ b/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java @@ -116,19 +116,20 @@ public abstract class AbstractReplicationStrategy ArrayList<InetAddress> endpoints = getCachedEndpoints(keyToken); if (endpoints == null) { - if (tokenMetadataClone == null) + TokenMetadata tm; // local reference in case another thread nulls tMC out from under us + if ((tm = tokenMetadataClone) == null) { // synchronize to prevent thundering herd post-invalidation synchronized (this) { - if (tokenMetadataClone == null) - tokenMetadataClone = tokenMetadata.cloneOnlyTokenMap(); + if ((tm = tokenMetadataClone) == null) + tm = tokenMetadataClone = tokenMetadata.cloneOnlyTokenMap(); } // if our clone got invalidated, it's possible there is a new token to account for too - keyToken = TokenMetadata.firstToken(tokenMetadataClone.sortedTokens(), searchToken); + keyToken = TokenMetadata.firstToken(tm.sortedTokens(), searchToken); } - endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tokenMetadataClone)); + endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tm)); cachedEndpoints.put(keyToken, endpoints); }
