Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created July 15, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frsyuki/e73c89db36c2069a7589 to your computer and use it in GitHub Desktop.
Save frsyuki/e73c89db36c2069a7589 to your computer and use it in GitHub Desktop.
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