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


##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -205,54 +214,32 @@ private void fetchClusterStatusForCollOrAlias(
       }
     }
 
-    // TODO use an Iterable to stream the data to the client instead of 
gathering it all in mem
-
-    NamedList<Object> collectionProps = new SimpleOrderedMap<>();
-
-    collectionStream.forEach(
-        clusterStateCollection -> {
-          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));
-          }
-
-          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());
-
-          if (collectionVsAliases.containsKey(name) && 
!collectionVsAliases.get(name).isEmpty()) {
-            collectionStatus.put("aliases", collectionVsAliases.get(name));
+    MapWriter collectionPropsWriter =
+        ew -> {
+          Iterator<Map<String, Object>> it =
+              collectionStream
+                  .map(
+                      (collectionState) ->
+                          collectionPropsResponse(
+                              collectionState,
+                              collectionVsAliases,
+                              routeKey,
+                              liveNodes,
+                              requestedShards))
+                  .iterator();
+          while (it.hasNext()) {
+            Map<String, Object> props = it.next();
+            props.forEach(
+                (key, value) -> {
+                  try {
+                    ew.put(key, value);
+                  } catch (IOException e) {
+                    throw new RuntimeException(e);
+                  }
+                });

Review Comment:
   I should mention Solr has two similar APIs, ClusterStatus & ColStatus.  See 
org.apache.solr.handler.admin.ColStatus#getColStatus.  It'd be awesome if there 
was a single method that takes a DocCollection (and some other params as 
needed) to produce a NamedList.  At least ColStatus's code doesn't have the sad 
JSON round-trip.  Maybe it's own PR or not as you wish.  



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -205,54 +214,32 @@ private void fetchClusterStatusForCollOrAlias(
       }
     }
 
-    // TODO use an Iterable to stream the data to the client instead of 
gathering it all in mem
-
-    NamedList<Object> collectionProps = new SimpleOrderedMap<>();
-
-    collectionStream.forEach(
-        clusterStateCollection -> {
-          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));
-          }
-
-          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());
-
-          if (collectionVsAliases.containsKey(name) && 
!collectionVsAliases.get(name).isEmpty()) {
-            collectionStatus.put("aliases", collectionVsAliases.get(name));
+    MapWriter collectionPropsWriter =
+        ew -> {
+          Iterator<Map<String, Object>> it =
+              collectionStream
+                  .map(
+                      (collectionState) ->
+                          collectionPropsResponse(
+                              collectionState,
+                              collectionVsAliases,
+                              routeKey,
+                              liveNodes,
+                              requestedShards))
+                  .iterator();
+          while (it.hasNext()) {

Review Comment:
   Oh; now that I see you are iterating it yourself (I had thought that would 
be driven externally), you shouldn't bother calling .iterator then looping; you 
can loop directly with stream.forEach



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