yifan-c commented on code in PR #171:
URL: https://github.com/apache/cassandra-sidecar/pull/171#discussion_r1955372649
##########
server/src/main/java/org/apache/cassandra/sidecar/restore/RingTopologyRefresher.java:
##########
@@ -139,18 +268,65 @@ private <T> T
prepareAndFetch(BiFunction<StorageOperations, NodeSettings, T> fet
});
}
+ private void dispatchRingTopologyChangeAsync(String keyspace,
TokenRangeReplicasResponse oldTopology, TokenRangeReplicasResponse newTopology)
+ {
+ // Dispatch onRingTopologyChanged in another thread as it might block
+ // This method cannot block, since it is invoked by
org.apache.cassandra.sidecar.restore.RingTopologyRefresher.ReplicaByTokenRangePerKeyspace.loadOne
+ // in the `compute` lambda.
+ listenersByKeyspace.getOrDefault(keyspace,
Collections.emptySet()).forEach(listener -> {
+ executorPool.runBlocking(() ->
listener.onRingTopologyChanged(keyspace, oldTopology, newTopology));
+ });
+ }
+
+ private static void populateEndpointToMetadata(InstanceMetadata
instanceMetadata,
+ Map<String, Integer>
allNodes,
+ Map<String,
InstanceMetadata> localEndpointsToMetadata)
+ {
+ String ip = ipOf(instanceMetadata);
+ Integer port = allNodes.get(ip);
+ if (port == null)
+ {
+ // the configured local instance is not in the C* ring yet (not
even joining). Exit early for such node
+ return;
+ }
+ String endpointWithPort =
StringUtils.cassandraFormattedHostAndPort(ip, port);
+ localEndpointsToMetadata.put(endpointWithPort, instanceMetadata);
+ }
+
+ private static String ipOf(InstanceMetadata instanceMetadata)
+ {
+ String ipAddress = instanceMetadata.ipAddress();
+ if (ipAddress == null)
+ {
+ try
+ {
+ return instanceMetadata.refreshIpAddress();
+ }
+ catch (UnknownHostException uhe)
+ {
+ LOGGER.debug("Failed to resolve IP address. host={}",
instanceMetadata.host());
+ }
+ }
+ return ipAddress;
Review Comment:
addressed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]