You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/12/17 12:54:04 UTC

[lucene-solr] branch jira/solr-15019 updated: SOLR-15019: Fix some precommit issues.

This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-15019
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/jira/solr-15019 by this push:
     new 110325f  SOLR-15019: Fix some precommit issues.
110325f is described below

commit 110325fcd73b13451401f28a0471e13c1e5ca107
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Thu Dec 17 13:53:42 2020 +0100

    SOLR-15019: Fix some precommit issues.
---
 .../solr/cluster/placement/AttributeFetcher.java   |  2 +-
 .../solr/cluster/placement/AttributeValues.java    |  1 -
 .../solr/cluster/placement/ReplicaMetric.java      | 25 ++++++++++++++++------
 .../placement/impl/AttributeFetcherImpl.java       |  8 +++----
 .../cluster/placement/AttributeFetcherForTest.java |  2 +-
 5 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
index 9f5d86d..73cba48 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java
@@ -76,7 +76,7 @@ public interface AttributeFetcher {
    * Note that this request will fetch information from nodes relevant to the collection
    * replicas and not the ones specified in {@link #fetchFrom(Set)} (though they may overlap).
    */
-  AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric> metricNames);
+  AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metricNames);
 
   /**
    * The set of nodes from which to fetch all node related attributes. Calling this method is mandatory if any of the {@code requestNode*}
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
index 3f0be31..1f075be 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java
@@ -18,7 +18,6 @@
 package org.apache.solr.cluster.placement;
 
 import org.apache.solr.cluster.Node;
-import org.apache.solr.cluster.SolrCollection;
 
 import java.util.Optional;
 
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java b/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
index 5c4e3d6..b432f6f 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/ReplicaMetric.java
@@ -27,8 +27,16 @@ import java.util.function.Function;
 public class ReplicaMetric<T> {
 
   private static final double GB = 1024 * 1024 * 1024;
+  @SuppressWarnings("unchecked")
+  private final Function<Object, T> NO_CONVERTER = v -> {
+    try {
+      return (T) v;
+    } catch (ClassCastException cce) {
+      return null;
+    }
+  };
 
-  public static final ReplicaMetric<Double> INDEX_SIZE_GB = new ReplicaMetric("sizeGB", "INDEX.sizeInBytes",
+  public static final ReplicaMetric<Double> INDEX_SIZE_GB = new ReplicaMetric<>("sizeGB", "INDEX.sizeInBytes",
       v -> {
         double sizeInBytes;
         if (!(v instanceof Number)) {
@@ -46,24 +54,27 @@ public class ReplicaMetric<T> {
         return sizeInBytes / GB;
       });
 
-  public static final ReplicaMetric<Double> QUERY_RATE_1MIN = new ReplicaMetric("queryRate", "QUERY./select.requestTimes:1minRate");
-  public static final ReplicaMetric<Double> UPDATE_RATE_1MIN = new ReplicaMetric("updateRate", "UPDATE./update.requestTimes:1minRate");
+  public static final ReplicaMetric<Double> QUERY_RATE_1MIN = new ReplicaMetric<>("queryRate", "QUERY./select.requestTimes:1minRate");
+  public static final ReplicaMetric<Double> UPDATE_RATE_1MIN = new ReplicaMetric<>("updateRate", "UPDATE./update.requestTimes:1minRate");
 
   private final String name;
   private final String internalName;
   private final Function<Object, T> converter;
 
   public ReplicaMetric(String name, String internalName) {
-    this(name, internalName, v -> (T) v);
+    this(name, internalName, null);
   }
 
   public ReplicaMetric(String name, String internalName, Function<Object, T> converter) {
     Objects.requireNonNull(name);
     Objects.requireNonNull(internalName);
-    Objects.requireNonNull(converter);
     this.name = name;
     this.internalName = internalName;
-    this.converter = converter;
+    if (converter == null) {
+      this.converter = NO_CONVERTER;
+    } else {
+      this.converter = converter;
+    }
   }
 
   public String getName() {
@@ -86,7 +97,7 @@ public class ReplicaMetric<T> {
     if (o == null || getClass() != o.getClass()) {
       return false;
     }
-    ReplicaMetric that = (ReplicaMetric) o;
+    ReplicaMetric<?> that = (ReplicaMetric<?>) o;
     return name.equals(that.name) && internalName.equals(that.internalName) && converter.equals(that.converter);
   }
 
diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
index 9101c97..bcd0eb6 100644
--- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
+++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java
@@ -48,7 +48,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {
   boolean requestedNodeSystemLoadAverage;
   Set<String> requestedNodeSystemSnitchTags = new HashSet<>();
   Set<String> requestedNodeMetricSnitchTags = new HashSet<>();
-  Map<SolrCollection, Set<ReplicaMetric>> requestedCollectionMetrics = new HashMap<>();
+  Map<SolrCollection, Set<ReplicaMetric<?>>> requestedCollectionMetrics = new HashMap<>();
 
   Set<Node> nodes = Collections.emptySet();
 
@@ -118,7 +118,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {
   }
 
   @Override
-  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric> metricNames) {
+  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metricNames) {
     requestedCollectionMetrics.put(solrCollection, Set.copyOf(metricNames));
     return this;
   }
@@ -146,7 +146,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {
     Map<String, Map<Node, Object>> metricSnitchToNodeToValue = new HashMap<>();
     Map<String, CollectionMetricsBuilder> collectionMetricsBuilders = new HashMap<>();
     Map<Node, Set<String>> nodeToReplicaInternalTags = new HashMap<>();
-    Map<String, Set<ReplicaMetric>> requestedCollectionNamesMetrics = requestedCollectionMetrics.entrySet().stream()
+    Map<String, Set<ReplicaMetric<?>>> requestedCollectionNamesMetrics = requestedCollectionMetrics.entrySet().stream()
         .collect(Collectors.toMap(e -> e.getKey().getName(), e -> e.getValue()));
 
     // In order to match the returned values for the various snitches, we need to keep track of where each
@@ -236,7 +236,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {
                 if (replica.isLeader()) {
                   shardMetricsBuilder.setLeaderMetrics(replicaMetricsBuilder);
                 }
-                Set<ReplicaMetric> requestedMetrics = requestedCollectionNamesMetrics.get(replica.getCollection());
+                Set<ReplicaMetric<?>> requestedMetrics = requestedCollectionNamesMetrics.get(replica.getCollection());
                 if (requestedMetrics == null) {
                   throw new RuntimeException("impossible error");
                 }
diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
index 46d2c4d..23a8e2f 100644
--- a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
+++ b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java
@@ -76,7 +76,7 @@ public class AttributeFetcherForTest implements AttributeFetcher {
   }
 
   @Override
-  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric> metricNames) {
+  public AttributeFetcher requestCollectionMetrics(SolrCollection solrCollection, Set<ReplicaMetric<?>> metricNames) {
     return this;
   }