Fix rare IOOBE in sendGossip Patch by Chris Lohfink, reviewed by brandonwilliams for CASSANDRA-4774
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/29939653 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/29939653 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/29939653 Branch: refs/heads/trunk Commit: 299396537102b4ac5bf6d40952a1b6ef83ce3662 Parents: 579ed75 Author: Brandon Williams <[email protected]> Authored: Thu Aug 1 09:30:16 2013 -0500 Committer: Brandon Williams <[email protected]> Committed: Thu Aug 1 09:30:16 2013 -0500 ---------------------------------------------------------------------- src/java/org/apache/cassandra/gms/Gossiper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/29939653/src/java/org/apache/cassandra/gms/Gossiper.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/gms/Gossiper.java b/src/java/org/apache/cassandra/gms/Gossiper.java index b0284c1..0dcfb90 100644 --- a/src/java/org/apache/cassandra/gms/Gossiper.java +++ b/src/java/org/apache/cassandra/gms/Gossiper.java @@ -38,6 +38,9 @@ import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + /** * This module is responsible for Gossiping information for the local endpoint. This abstraction * maintains the list of live and dead endpoints. Periodically i.e. every 1 second this module @@ -508,11 +511,12 @@ public class Gossiper implements IFailureDetectionEventListener, GossiperMBean */ private boolean sendGossip(MessageOut<GossipDigestSyn> message, Set<InetAddress> epSet) { - int size = epSet.size(); + List<InetAddress> liveEndpoints = ImmutableList.copyOf(epSet); + + int size = liveEndpoints.size(); if (size < 1) return false; /* Generate a random number from 0 -> size */ - List<InetAddress> liveEndpoints = new ArrayList<InetAddress>(epSet); int index = (size == 1) ? 0 : random.nextInt(size); InetAddress to = liveEndpoints.get(index); if (logger.isTraceEnabled())
