lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject [1/2] lucene-solr:master: SOLR-12662: Eliminate possible race conditions by moving Type-by-name map construction to Variable.Type, accessible via Variable.Type.get(name)
Date Wed, 29 Aug 2018 15:28:11 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 171cfc8e8 -> 9fcd4929d
  refs/heads/master 5a0e7a615 -> 098f475a6


SOLR-12662: Eliminate possible race conditions by moving Type-by-name map construction to
Variable.Type, accessible via Variable.Type.get(name)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/098f475a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/098f475a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/098f475a

Branch: refs/heads/master
Commit: 098f475a671c88bf09cb2e73af631fd45ee5c5ef
Parents: 5a0e7a6
Author: Steve Rowe <sarowe@apache.org>
Authored: Wed Aug 29 11:26:31 2018 -0400
Committer: Steve Rowe <sarowe@apache.org>
Committed: Wed Aug 29 11:26:31 2018 -0400

----------------------------------------------------------------------
 .../client/solrj/cloud/autoscaling/Variable.java  | 15 +++++++++++++++
 .../solrj/cloud/autoscaling/VariableBase.java     | 18 +-----------------
 2 files changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/098f475a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Variable.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Variable.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Variable.java
index d817c2f..1ffb0a5 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Variable.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Variable.java
@@ -22,7 +22,9 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.function.Consumer;
 
@@ -30,6 +32,7 @@ import org.apache.solr.common.cloud.rule.ImplicitSnitch;
 
 import static java.util.Collections.emptySet;
 import static java.util.Collections.unmodifiableSet;
+import static java.util.Collections.unmodifiableMap;
 
 /**
  * A Variable Type used in Autoscaling policy rules. Each variable type may have unique implementation
@@ -328,6 +331,18 @@ public interface Variable {
     public boolean match(Object inputVal, Operand op, Object val, String name, Row row) {
       return impl.match(inputVal, op, val, name, row);
     }
+
+    private static final Map<String, Type> typeByNameMap;
+    static {
+      HashMap<String, Type> m = new HashMap<>();
+      for (Type t : Type.values()) {
+        m.put(t.tagName, t);
+      }
+      typeByNameMap = unmodifiableMap(m);
+    }
+    static Type get(String name) {
+      return typeByNameMap.get(name);
+    }
   }
 
   @Target(ElementType.FIELD)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/098f475a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java
index 8b0c1cf..82a5ce6 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java
@@ -17,8 +17,6 @@
 
 package org.apache.solr.client.solrj.cloud.autoscaling;
 
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.solr.common.cloud.rule.ImplicitSnitch;
 import org.apache.solr.common.util.StrUtils;
@@ -77,7 +75,7 @@ public class VariableBase implements Variable {
   }
 
   public static Type getTagType(String name) {
-    Type info = getValidatetypes().get(name);
+    Type info = Type.get(name);
     if (info == null && name.startsWith(ImplicitSnitch.SYSPROP)) info = Type.STRING;
     if (info == null && name.startsWith(Clause.METRICS_PREFIX)) info = Type.LAZY;
     return info;
@@ -192,19 +190,5 @@ public class VariableBase implements Variable {
     public void getSuggestions(Suggestion.Ctx ctx) {
       perNodeSuggestions(ctx);
     }
-
-
-  }
-
-  private static Map<String, Type> validatetypes = null;
-
-  /** SOLR-12662: Lazily init validatetypes to avoid Type.values() NPE due to static initializer
ordering */
-  private static Map<String, Type> getValidatetypes() {
-    if (validatetypes == null) {
-      validatetypes = new HashMap<>();
-      for (Type t : Type.values())
-        validatetypes.put(t.tagName, t);
-    }
-    return validatetypes;
   }
 }


Mime
View raw message