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


##########
cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/CassandraClusterInfo.java:
##########
@@ -381,67 +392,68 @@ private InstanceAvailability 
determineInstanceAvailability(RingInstance instance
 
     private TokenRangeMapping<RingInstance> getTokenRangeReplicas()
     {
-        Map<String, Set<String>> writeReplicasByDC;
-        Map<String, Set<String>> pendingReplicasByDC;
-        Map<String, ReplicaMetadata> replicaMetadata;
-        Set<RingInstance> blockedInstances;
+        return getTokenRangeReplicas(this::getTokenRangesAndReplicaSets,
+                                     this::getPartitioner,
+                                     this::getReplicationFactor,
+                                     this::instanceIsBlocked);
+    }
+
+    @VisibleForTesting
+    static TokenRangeMapping<RingInstance> 
getTokenRangeReplicas(Supplier<TokenRangeReplicasResponse> topologySupplier,
+                                                                 
Supplier<Partitioner> partitionerSupplier,
+                                                                 
Supplier<ReplicationFactor> replicationFactorSupplier,
+                                                                 Predicate<? 
super RingInstance> blockedInstancePredicate)
+    {
+        long start = System.nanoTime();
+        TokenRangeReplicasResponse response = topologySupplier.get();
+        long elapsedTimeNanos = System.nanoTime() - start;
+        Multimap<RingInstance, Range<BigInteger>> tokenRangesByInstance = 
getTokenRangesByInstance(response.writeReplicas(),
+                                                                               
                    response.replicaMetadata());
+        LOGGER.info("Retrieved token ranges for {} instances from write 
replica set in {} milliseconds",
+                    tokenRangesByInstance.size(),
+                    TimeUnit.NANOSECONDS.toMillis(elapsedTimeNanos));
+
         Set<RingInstance> replacementInstances;
-        Multimap<RingInstance, Range<BigInteger>> tokenRangesByInstance;
-        try
-        {
-            long start = System.nanoTime();
-            TokenRangeReplicasResponse response = 
getTokenRangesAndReplicaSets();
-            long elapsedTimeNanos = System.nanoTime() - start;
-            replicaMetadata = response.replicaMetadata();
-
-            tokenRangesByInstance = 
getTokenRangesByInstance(response.writeReplicas(), response.replicaMetadata());
-            LOGGER.info("Retrieved token ranges for {} instances from write 
replica set in {} nanoseconds",
-                        tokenRangesByInstance.size(),
-                        elapsedTimeNanos);
-
-            replacementInstances = response.replicaMetadata()
-                                           .values()
-                                           .stream()
-                                           .filter(m -> 
m.state().equalsIgnoreCase(InstanceState.REPLACING.name()))
-                                           .map(RingInstance::new)
-                                           .collect(Collectors.toSet());
-
-            blockedInstances = response.replicaMetadata()
+        replacementInstances = response.replicaMetadata()
                                        .values()
                                        .stream()
+                                       .filter(m -> 
m.state().equalsIgnoreCase(InstanceState.REPLACING.name()))
                                        .map(RingInstance::new)
-                                       .filter(this::instanceIsBlocked)
                                        .collect(Collectors.toSet());
 
-            Set<String> blockedIps = blockedInstances.stream().map(i -> 
i.ringInstance().address())
-                                                     
.collect(Collectors.toSet());
+        Set<RingInstance> blockedInstances;
+        blockedInstances = response.replicaMetadata()

Review Comment:
   done. 



-- 
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: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to