dsmiley commented on code in PR #2599:
URL: https://github.com/apache/solr/pull/2599#discussion_r1702298437
##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseHttpClusterStateProvider.java:
##########
@@ -413,4 +412,11 @@ public String getQuorumHosts() {
}
return String.join(",", this.liveNodes);
}
+
+ public enum ClusterStateRequestType {
Review Comment:
private
##########
solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java:
##########
@@ -976,7 +980,17 @@ public Map<String, Object> execute(
CLUSTERSTATUS,
(req, rsp, h) -> {
Map<String, Object> all =
- copy(req.getParams(), null, COLLECTION_PROP, SHARD_ID_PROP,
_ROUTE_, "prs");
+ copy(
Review Comment:
I have a small request; feel free to dismiss as scope creep.
The "copy" here is pointless and furthermore it means we have to go add a
whole bunch of parameter references within CollectionsHandler. The conversion
to ZkNodeProps is also pointless. For other commands involving the Overseer,
there's a point to it but that doesn't apply to this one and some others for
that matter. Couldn't you just change ClusterStatus's constructor to accept
the request , and use params in there instead of the ZkNodeProps?
If that's too much scope creep for you, a smaller subset of this is simply
removing the copy, and thus remove all the parameter references here. Done;
fewer lines of code.
##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -139,6 +184,7 @@ public void getClusterStatus(NamedList<Object> results)
if (didNotFindCollection && isAlias) {
// In this case this.collection is an alias name not a collection
// get all collections and filter out collections not in the alias
+ // clusterState.getCollectionsMap() should be replaced with an
inexpensive call
Review Comment:
Use "TODO", and nice catch :-)
Probably deserves a JIRA.
##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -97,6 +101,55 @@ public ClusterStatus(ZkStateReader zkStateReader,
ZkNodeProps props) {
public void getClusterStatus(NamedList<Object> results)
throws KeeperException, InterruptedException {
+ List<String> liveNodes = null;
+ NamedList<Object> clusterStatus = new SimpleOrderedMap<>();
+
+ boolean includeAll = this.message.getBool(INCLUDE_ALL, true);
+ boolean withLiveNodes =
+ this.message.getBool(LIVENODES_PROP, includeAll) || (collection !=
null);
+ boolean withClusterProperties = this.message.getBool(CLUSTER_PROP,
includeAll);
+ boolean withRoles = this.message.getBool(ZkStateReader.ROLES_PROP,
includeAll);
+ boolean withCollection = includeAll || (collection != null);
+
+ if (withLiveNodes) {
+ liveNodes =
+
zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null,
true);
+ // add live_nodes
+ clusterStatus.add("live_nodes", liveNodes);
+ }
+ if (withCollection) {
+ fetchClusterStatusForCollOrAlias(clusterStatus, liveNodes);
+ }
+
+ Map<String, Object> clusterProps = Collections.emptyMap();
+ if (withClusterProperties) {
+ // read cluster properties
+ clusterProps = zkStateReader.getClusterProperties();
+ if (clusterProps == null || clusterProps.isEmpty()) {
+ clusterProps = Collections.emptyMap();
+ }
+ }
+ clusterStatus.add("properties", clusterProps);
+
+ // add the roles map
+ if (withRoles) {
+ Map<?, ?> roles = null;
+ if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES, true)) {
+ roles =
+ (Map<?, ?>)
+ Utils.fromJSON(
+ zkStateReader.getZkClient().getData(ZkStateReader.ROLES,
null, null, true));
+ }
+ if (roles != null) {
Review Comment:
Is the null check necessary? Could a null value or empty map be equivalent?
The other categories result in a label to hold what was requested. So I'm
thinking we should do so here as well.
##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/ClusterStateProvider.java:
##########
@@ -108,8 +112,7 @@ default DocCollection getCollection(String name) throws
IOException {
/** Obtain a cluster property, or the default value if it doesn't exist. */
default <T> T getClusterProperty(String key, T defaultValue) {
@SuppressWarnings({"unchecked"})
- T value = (T) getClusterProperties().get(key);
- if (value == null) return defaultValue;
+ T value = (T) getClusterProperties().getOrDefault(key, defaultValue);
return value;
Review Comment:
one line; no need to declare
##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -96,39 +96,43 @@ public static Health combine(Collection<Health> states) {
public ClusterStatus(ZkStateReader zkStateReader, ZkNodeProps props) {
this.zkStateReader = zkStateReader;
this.message = props;
- collectionParam = props.getStr(ZkStateReader.COLLECTION_PROP);
- liveNodesParam = props.getBool(ZkStateReader.LIVENODES_PROP, false);
- clusterPropertiesParam = props.getBool(ZkStateReader.CLUSTER_PROP, false);
- rolesParam = props.getBool(ZkStateReader.ROLES_PROP, false);
- includeAll = props.getBool(ZkStateReader.INCLUDE_ALL, true);
+ collection = props.getStr(ZkStateReader.COLLECTION_PROP);
}
public void getClusterStatus(NamedList<Object> results)
throws KeeperException, InterruptedException {
-
List<String> liveNodes = null;
NamedList<Object> clusterStatus = new SimpleOrderedMap<>();
- if (includeAll || collectionParam != null || liveNodesParam) {
+
+ boolean includeAll = this.message.getBool(INCLUDE_ALL, true);
+ boolean withLiveNodes =
+ this.message.getBool(LIVENODES_PROP, includeAll) || (collection !=
null);
+ boolean withClusterProperties = this.message.getBool(CLUSTER_PROP,
includeAll);
+ boolean withRoles = this.message.getBool(ZkStateReader.ROLES_PROP,
includeAll);
+ boolean withCollection = includeAll || (collection != null);
+
+ if (withLiveNodes) {
liveNodes =
zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null,
true);
// add live_nodes
clusterStatus.add("live_nodes", liveNodes);
}
-
- if (includeAll || collectionParam != null)
+ if (withCollection) {
fetchClusterStatusForCollOrAlias(clusterStatus, liveNodes);
+ }
- if (includeAll || clusterPropertiesParam) {
+ Map<String, Object> clusterProps = Collections.emptyMap();
+ if (withClusterProperties) {
// read cluster properties
- Map<String, Object> clusterProps = zkStateReader.getClusterProperties();
- if (clusterProps != null && !clusterProps.isEmpty()) {
- clusterStatus.add("properties", clusterProps);
+ clusterProps = zkStateReader.getClusterProperties();
+ if (clusterProps == null || clusterProps.isEmpty()) {
+ clusterProps = Collections.emptyMap();
}
}
+ clusterStatus.add("properties", clusterProps);
Review Comment:
shouldn't we *not* add this unless `withClusterProperties`?
--
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]