Source:
<code>public Result compute( DefaultMetadata oldMetadata, boolean tokenMapEnabled, InternalDriverContext context) { String logPrefix = context.getSessionName(); TokenFactoryRegistry tokenFactoryRegistry = context.getTokenFactoryRegistry(); assert oldMetadata.getNodes().isEmpty(); TokenFactory tokenFactory = oldMetadata.getTokenMap().map(m -> ((DefaultTokenMap) m).getTokenFactory()).orElse(null); boolean tokensChanged = false; ImmutableMap.Builder<UUID, DefaultNode> newNodesBuilder = ImmutableMap.builder(); String clusterName = null; for (NodeInfo nodeInfo : nodeInfos) { if (clusterName == null) { <START> clusterName = nodeInfo.getClusterName(); <END> } EndPoint endPoint = nodeInfo.getEndPoint(); DefaultNode node = findIn(contactPoints, endPoint); if (node == null) { node = new DefaultNode(endPoint, context); LOG.debug("[{}] Adding new node {}", logPrefix, node); } else { LOG.debug("[{}] Copying contact point {}", logPrefix, node); } if (tokenFactory == null && nodeInfo.getPartitioner() != null) { tokenFactory = tokenFactoryRegistry.tokenFactoryFor(nodeInfo.getPartitioner()); } tokensChanged |= copyInfos(nodeInfo, node, tokenFactory, context); newNodesBuilder.put(node.getHostId(), node); } ImmutableMap<UUID, DefaultNode> newNodes = newNodesBuilder.build(); ImmutableList.Builder<Object> eventsBuilder = ImmutableList.builder(); for (DefaultNode newNode : newNodes.values()) { if (findIn(contactPoints, newNode.getEndPoint()) == null) { eventsBuilder.add(NodeStateEvent.added(newNode)); } } for (DefaultNode contactPoint : contactPoints) { if (findIn(newNodes.values(), contactPoint.getEndPoint()) == null) { eventsBuilder.add(NodeStateEvent.removed(contactPoint)); } } return new Result( oldMetadata.withNodesAndClusterName( ImmutableMap.copyOf(newNodes), tokenMapEnabled, tokensChanged, tokenFactory, context, clusterName), eventsBuilder.build()); }</code><technical_language>cluster name is context.getChannelFactory() (currently package-private add a getter for it): re-check new connection ignore foreign nodes if stale entries in peers table ([JAVA-397](<LINK_0> I easier grab there, this avoids impacts topology monitor</technical_language>

Target:
public Result compute( DefaultMetadata oldMetadata, boolean tokenMapEnabled, InternalDriverContext context) { String logPrefix = context.getSessionName(); TokenFactoryRegistry tokenFactoryRegistry = context.getTokenFactoryRegistry(); assert oldMetadata.getNodes().isEmpty(); TokenFactory tokenFactory = oldMetadata.getTokenMap().map(m -> ((DefaultTokenMap) m).getTokenFactory()).orElse(null); boolean tokensChanged = false; ImmutableMap.Builder<UUID, DefaultNode> newNodesBuilder = ImmutableMap.builder(); for (NodeInfo nodeInfo : nodeInfos) { EndPoint endPoint = nodeInfo.getEndPoint(); DefaultNode node = findIn(contactPoints, endPoint); if (node == null) { node = new DefaultNode(endPoint, context); LOG.debug("[{}] Adding new node {}", logPrefix, node); } else { LOG.debug("[{}] Copying contact point {}", logPrefix, node); } if (tokenFactory == null && nodeInfo.getPartitioner() != null) { tokenFactory = tokenFactoryRegistry.tokenFactoryFor(nodeInfo.getPartitioner()); } tokensChanged |= copyInfos(nodeInfo, node, tokenFactory, context); newNodesBuilder.put(node.getHostId(), node); } ImmutableMap<UUID, DefaultNode> newNodes = newNodesBuilder.build(); ImmutableList.Builder<Object> eventsBuilder = ImmutableList.builder(); for (DefaultNode newNode : newNodes.values()) { if (findIn(contactPoints, newNode.getEndPoint()) == null) { eventsBuilder.add(NodeStateEvent.added(newNode)); } } for (DefaultNode contactPoint : contactPoints) { if (findIn(newNodes.values(), contactPoint.getEndPoint()) == null) { eventsBuilder.add(NodeStateEvent.removed(contactPoint)); } } return new Result( oldMetadata.withNodes( ImmutableMap.copyOf(newNodes), tokenMapEnabled, tokensChanged, tokenFactory, context), eventsBuilder.build()); }