mlbiscoc commented on code in PR #2916:
URL: https://github.com/apache/solr/pull/2916#discussion_r1894038654


##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -342,76 +356,47 @@ public static Map<String, Object> 
postProcessCollectionJSON(Map<String, Object>
     return collection;
   }
 
-  private class SolrCollectionProperiesIterator implements 
Iterator<NamedList<Object>> {
-
-    final Iterator<DocCollection> it;
-    Map<String, List<String>> collectionVsAliases;
-    String routeKey;
-    List<String> liveNodes;
-    String shard;
-
-    public SolrCollectionProperiesIterator(
-        Iterator<DocCollection> it,
-        Map<String, List<String>> collectionVsAliases,
-        String routeKey,
-        List<String> liveNodes,
-        String shard) {
-      this.it = it;
-      this.collectionVsAliases = collectionVsAliases;
-      this.routeKey = routeKey;
-      this.liveNodes = liveNodes;
-      this.shard = shard;
-    }
-
-    @Override
-    public boolean hasNext() {
-      return it.hasNext();
-    }
-
-    @Override
-    public NamedList<Object> next() {
-      NamedList<Object> collectionProps = new SimpleOrderedMap<>();
-      DocCollection clusterStateCollection = it.next();
-      Map<String, Object> collectionStatus;
-      String name = clusterStateCollection.getName();
-
-      Set<String> requestedShards = new HashSet<>();
-      if (routeKey != null) {
-        DocRouter router = clusterStateCollection.getRouter();
-        Collection<Slice> slices = router.getSearchSlices(routeKey, null, 
clusterStateCollection);
-        for (Slice slice : slices) {
-          requestedShards.add(slice.getName());
-        }
-      }
-      if (shard != null) {
-        String[] paramShards = shard.split(",");
-        requestedShards.addAll(Arrays.asList(paramShards));
+  private Map<String, Object> collectionPropsResponse(
+      DocCollection clusterStateCollection,
+      Map<String, List<String>> collectionVsAliases,
+      String routeKey,
+      List<String> liveNodes,
+      Set<String> requestedShards) {
+    Map<String, Object> collectionProps = new HashMap<>();
+    Map<String, Object> collectionStatus;
+    String name = clusterStateCollection.getName();
+
+    if (routeKey != null) {
+      DocRouter router = clusterStateCollection.getRouter();
+      Collection<Slice> slices = router.getSearchSlices(routeKey, null, 
clusterStateCollection);
+      for (Slice slice : slices) {
+        requestedShards.add(slice.getName());

Review Comment:
   This is a bug. I moved that old logic into here without realizing that 
parameter is manipulated. Changed `requestedShards` to `Set.of()` for 
immutability and made changes accordingly.



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -342,76 +356,47 @@ public static Map<String, Object> 
postProcessCollectionJSON(Map<String, Object>
     return collection;
   }
 
-  private class SolrCollectionProperiesIterator implements 
Iterator<NamedList<Object>> {
-
-    final Iterator<DocCollection> it;
-    Map<String, List<String>> collectionVsAliases;
-    String routeKey;
-    List<String> liveNodes;
-    String shard;
-
-    public SolrCollectionProperiesIterator(
-        Iterator<DocCollection> it,
-        Map<String, List<String>> collectionVsAliases,
-        String routeKey,
-        List<String> liveNodes,
-        String shard) {
-      this.it = it;
-      this.collectionVsAliases = collectionVsAliases;
-      this.routeKey = routeKey;
-      this.liveNodes = liveNodes;
-      this.shard = shard;
-    }
-
-    @Override
-    public boolean hasNext() {
-      return it.hasNext();
-    }
-
-    @Override
-    public NamedList<Object> next() {
-      NamedList<Object> collectionProps = new SimpleOrderedMap<>();
-      DocCollection clusterStateCollection = it.next();
-      Map<String, Object> collectionStatus;
-      String name = clusterStateCollection.getName();
-
-      Set<String> requestedShards = new HashSet<>();
-      if (routeKey != null) {
-        DocRouter router = clusterStateCollection.getRouter();
-        Collection<Slice> slices = router.getSearchSlices(routeKey, null, 
clusterStateCollection);
-        for (Slice slice : slices) {
-          requestedShards.add(slice.getName());
-        }
-      }
-      if (shard != null) {
-        String[] paramShards = shard.split(",");
-        requestedShards.addAll(Arrays.asList(paramShards));
+  private Map<String, Object> collectionPropsResponse(
+      DocCollection clusterStateCollection,
+      Map<String, List<String>> collectionVsAliases,
+      String routeKey,
+      List<String> liveNodes,
+      Set<String> requestedShards) {
+    Map<String, Object> collectionProps = new HashMap<>();
+    Map<String, Object> collectionStatus;
+    String name = clusterStateCollection.getName();
+
+    if (routeKey != null) {
+      DocRouter router = clusterStateCollection.getRouter();
+      Collection<Slice> slices = router.getSearchSlices(routeKey, null, 
clusterStateCollection);
+      for (Slice slice : slices) {
+        requestedShards.add(slice.getName());
       }
+    }
 
-      byte[] bytes = Utils.toJSON(clusterStateCollection);
-      @SuppressWarnings("unchecked")
-      Map<String, Object> docCollection = (Map<String, Object>) 
Utils.fromJSON(bytes);
-      collectionStatus = getCollectionStatus(docCollection, name, 
requestedShards);
+    byte[] bytes = Utils.toJSON(clusterStateCollection);
+    @SuppressWarnings("unchecked")
+    Map<String, Object> docCollection = (Map<String, Object>) 
Utils.fromJSON(bytes);
+    collectionStatus = getCollectionStatus(docCollection, name, 
requestedShards);
 
-      collectionStatus.put("znodeVersion", 
clusterStateCollection.getZNodeVersion());
-      collectionStatus.put(
-          "creationTimeMillis", 
clusterStateCollection.getCreationTime().toEpochMilli());
+    collectionStatus.put("znodeVersion", 
clusterStateCollection.getZNodeVersion());
+    collectionStatus.put(
+        "creationTimeMillis", 
clusterStateCollection.getCreationTime().toEpochMilli());
 
-      if (collectionVsAliases.containsKey(name) && 
!collectionVsAliases.get(name).isEmpty()) {
-        collectionStatus.put("aliases", collectionVsAliases.get(name));
-      }
-      String configName = clusterStateCollection.getConfigName();
-      collectionStatus.put("configName", configName);
-      if (solrParams.getBool("prs", false) && 
clusterStateCollection.isPerReplicaState()) {
-        PerReplicaStates prs = clusterStateCollection.getPerReplicaStates();
-        collectionStatus.put("PRS", prs);
-      }
-      collectionProps.add(name, collectionStatus);
-
-      // now we need to walk the collectionProps tree to cross-check replica 
state with live
-      // nodes
-      crossCheckReplicaStateWithLiveNodes(liveNodes, collectionProps);
-      return collectionProps;
+    if (collectionVsAliases.containsKey(name) && 
!collectionVsAliases.get(name).isEmpty()) {
+      collectionStatus.put("aliases", collectionVsAliases.get(name));
+    }
+    String configName = clusterStateCollection.getConfigName();
+    collectionStatus.put("configName", configName);
+    if (solrParams.getBool("prs", false) && 
clusterStateCollection.isPerReplicaState()) {
+      PerReplicaStates prs = clusterStateCollection.getPerReplicaStates();
+      collectionStatus.put("PRS", prs);
     }
+    collectionProps.put(name, collectionStatus);

Review Comment:
   Yeah taking a deeper look, this extra map isn't needed. I kind of did it 
because of `crossCheckReplicaStateWithLiveNodes` but instead I modified that 
method and just return `collectionStatus`.



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