From f66adb0278aa56e8c2696db6f3fe24d311bf7b44 Mon Sep 17 00:00:00 2001 From: Stefan Miklosovic Date: Tue, 23 May 2023 10:58:17 +0200 Subject: [PATCH] Remove unnecessary shuffling of GossipDigests in Gossiper#makeRandomGossipDigest This patch also fixes the bug when creating GossipDigests in case epState in Gossiper#makeRandomGossipDigest was null. Previously, if it was null, it used generation and maxVersion of the last non-null epState instead of zeros. patch by Cameron Zemek; reviewed by Stefan Miklosovic and Brandon Williams for CASSANDRA-18546 --- CHANGES.txt | 1 + .../org/apache/cassandra/gms/Gossiper.java | 33 ++++++++----------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1923eb004c..786a8a6c92 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0.11 + * Remove unnecessary shuffling of GossipDigests in Gossiper#makeRandomGossipDigest (CASSANDRA-18546) Merged from 3.11: Merged from 3.0: diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java index ed5788e6ba..17e315a109 100644 --- a/src/java/org/apache/cassandra/gms/Gossiper.java +++ b/src/java/org/apache/cassandra/gms/Gossiper.java @@ -34,7 +34,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.util.concurrent.ListenableFutureTask; import com.google.common.util.concurrent.Uninterruptibles; @@ -52,7 +51,6 @@ import org.apache.cassandra.utils.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.util.concurrent.FastThreadLocal; import org.apache.cassandra.concurrent.DebuggableScheduledThreadPoolExecutor; import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor; import org.apache.cassandra.concurrent.Stage; @@ -63,13 +61,8 @@ import org.apache.cassandra.net.RequestCallback; import org.apache.cassandra.net.Message; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.service.StorageService; -import org.apache.cassandra.utils.CassandraVersion; -import org.apache.cassandra.utils.ExecutorUtils; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.JVMStabilityInspector; -import org.apache.cassandra.utils.MBeanWrapper; -import org.apache.cassandra.utils.NoSpamLogger; -import org.apache.cassandra.utils.Pair; import org.apache.cassandra.utils.RecomputingSupplier; import static org.apache.cassandra.config.CassandraRelevantProperties.GOSSIPER_QUARANTINE_DELAY; @@ -293,7 +286,7 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean if (logger.isTraceEnabled()) logger.trace("My heartbeat is now {}", endpointStateMap.get(FBUtilities.getBroadcastAddressAndPort()).getHeartBeatState().getHeartBeatVersion()); final List gDigests = new ArrayList<>(); - Gossiper.instance.makeRandomGossipDigest(gDigests); + Gossiper.instance.makeGossipDigest(gDigests); if (gDigests.size() > 0) { @@ -699,29 +692,29 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean } /** - * The gossip digest is built based on randomization - * rather than just looping through the collection of live endpoints. - * - * @param gDigests list of Gossip Digests. + * @param gDigests list of Gossip Digests to be filled */ - private void makeRandomGossipDigest(List gDigests) + private void makeGossipDigest(List gDigests) { EndpointState epState; - int generation = 0; - int maxVersion = 0; + int generation; + int maxVersion; // local epstate will be part of endpointStateMap - List endpoints = new ArrayList<>(endpointStateMap.keySet()); - Collections.shuffle(endpoints, random); - for (InetAddressAndPort endpoint : endpoints) + for (Entry entry : endpointStateMap.entrySet()) { - epState = endpointStateMap.get(endpoint); + epState = entry.getValue(); if (epState != null) { generation = epState.getHeartBeatState().getGeneration(); maxVersion = getMaxEndpointStateVersion(epState); } - gDigests.add(new GossipDigest(endpoint, generation, maxVersion)); + else + { + generation = 0; + maxVersion = 0; + } + gDigests.add(new GossipDigest(entry.getKey(), generation, maxVersion)); } if (logger.isTraceEnabled())