This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add workaround for a deadlock issue of Class.getAnnotation() (JDK-7122142) | |
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java | |
index a80feb9..c92b4f6 100644 | |
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java | |
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java | |
@@ -1613,16 +1613,20 @@ public static boolean isDeterministic(GenericUDF genericUDF) { | |
// the deterministic annotation declares | |
return false; | |
} | |
- UDFType genericUDFType = genericUDF.getClass().getAnnotation(UDFType.class); | |
- if (genericUDFType != null && genericUDFType.deterministic() == false) { | |
- return false; | |
+ synchronized(UDFType.class) { | |
+ UDFType genericUDFType = genericUDF.getClass().getAnnotation(UDFType.class); | |
+ if (genericUDFType != null && genericUDFType.deterministic() == false) { | |
+ return false; | |
+ } | |
} | |
if (genericUDF instanceof GenericUDFBridge) { | |
GenericUDFBridge bridge = (GenericUDFBridge) (genericUDF); | |
- UDFType bridgeUDFType = bridge.getUdfClass().getAnnotation(UDFType.class); | |
- if (bridgeUDFType != null && bridgeUDFType.deterministic() == false) { | |
- return false; | |
+ synchronized(UDFType.class) { | |
+ UDFType bridgeUDFType = bridge.getUdfClass().getAnnotation(UDFType.class); | |
+ if (bridgeUDFType != null && bridgeUDFType.deterministic() == false) { | |
+ return false; | |
+ } | |
} | |
} | |
@@ -1638,16 +1642,20 @@ public static boolean isDeterministic(GenericUDF genericUDF) { | |
* Returns whether a GenericUDF is stateful or not. | |
*/ | |
public static boolean isStateful(GenericUDF genericUDF) { | |
- UDFType genericUDFType = genericUDF.getClass().getAnnotation(UDFType.class); | |
- if (genericUDFType != null && genericUDFType.stateful()) { | |
- return true; | |
+ synchronized(UDFType.class) { | |
+ UDFType genericUDFType = genericUDF.getClass().getAnnotation(UDFType.class); | |
+ if (genericUDFType != null && genericUDFType.stateful()) { | |
+ return true; | |
+ } | |
} | |
if (genericUDF instanceof GenericUDFBridge) { | |
GenericUDFBridge bridge = (GenericUDFBridge) genericUDF; | |
- UDFType bridgeUDFType = bridge.getUdfClass().getAnnotation(UDFType.class); | |
- if (bridgeUDFType != null && bridgeUDFType.stateful()) { | |
- return true; | |
+ synchronized(UDFType.class) { | |
+ UDFType bridgeUDFType = bridge.getUdfClass().getAnnotation(UDFType.class); | |
+ if (bridgeUDFType != null && bridgeUDFType.stateful()) { | |
+ return true; | |
+ } | |
} | |
} | |
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java | |
index 5aa3e82..df32949 100644 | |
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java | |
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/GroupByDesc.java | |
@@ -228,9 +228,11 @@ public boolean isDistinctLike() { | |
for (AggregationDesc ad : aggregators) { | |
if (!ad.getDistinct()) { | |
GenericUDAFEvaluator udafEval = ad.getGenericUDAFEvaluator(); | |
- UDFType annot = udafEval.getClass().getAnnotation(UDFType.class); | |
- if (annot == null || !annot.distinctLike()) { | |
- return false; | |
+ synchronized(UDFType.class) { | |
+ UDFType annot = udafEval.getClass().getAnnotation(UDFType.class); | |
+ if (annot == null || !annot.distinctLike()) { | |
+ return false; | |
+ } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment