yifan-c commented on code in PR #106:
URL: 
https://github.com/apache/cassandra-analytics/pull/106#discussion_r2136734076


##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/data/CassandraDataLayer.java:
##########
@@ -422,7 +424,23 @@ public boolean readIndexOffset()
 
     protected void initInstanceMap()
     {
-        instanceMap = 
clusterConfig.stream().collect(Collectors.toMap(SidecarInstance::hostname, 
Function.identity()));
+        if (tokenPartitioner != null)
+        {
+            instanceMap = tokenPartitioner.ring().instances().stream()
+                    .filter(instance -> datacenter == null || 
datacenter.equals(instance.dataCenter()))
+                    .map(instance -> instance.nodeName()).distinct()
+                    .map(nodeName -> new SidecarInstanceImpl(nodeName, 
sidecarClientConfig.effectivePort()))
+                    .collect(Collectors.toMap(SidecarInstance::hostname, 
Function.identity()));
+        }
+        else
+        {
+            instanceMap = Collections.emptyMap();
+        }

Review Comment:
   Should it fail early if `tokenPartitioner` is `null`? It is unexpected to 
have the `null` value. 
   Alternatively, the `if-else` can be removed and only keep the `instanceMap` 
assignment. 



##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/data/CassandraDataLayer.java:
##########
@@ -422,7 +424,23 @@ public boolean readIndexOffset()
 
     protected void initInstanceMap()
     {
-        instanceMap = 
clusterConfig.stream().collect(Collectors.toMap(SidecarInstance::hostname, 
Function.identity()));
+        if (tokenPartitioner != null)
+        {
+            instanceMap = tokenPartitioner.ring().instances().stream()
+                    .filter(instance -> datacenter == null || 
datacenter.equals(instance.dataCenter()))
+                    .map(instance -> instance.nodeName()).distinct()

Review Comment:
   Can we consider the port as well for the uniqueness check? Just the same as 
line#353. 



##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/data/ClientConfig.java:
##########
@@ -115,6 +121,7 @@ protected ClientConfig(Map<String, String> options)
         this.snapshotName = MapUtils.getOrDefault(options, SNAPSHOT_NAME_KEY, 
"sbr_" + UUID.randomUUID().toString().replace("-", ""));
         this.datacenter = options.get(MapUtils.lowerCaseKey(DC_KEY));
         this.createSnapshot = MapUtils.getBoolean(options, 
CREATE_SNAPSHOT_KEY, true);
+        this.createSnapshotFilterDistinctInstances = 
MapUtils.getBoolean(options, CREATE_SNAPSHOT_FILTER_DISTINCT_INSTANCES_KEY, 
true);

Review Comment:
   `CREATE_SNAPSHOT_FILTER_DISTINCT_INSTANCES_KEY` was discussed and removed in 
#93 



-- 
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]

Reply via email to