This is an automated email from the ASF dual-hosted git repository.
yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new a241e130c08 [HUDI-6227] Improve logging in
ReflectionUtils.hasConstructor (#8732)
a241e130c08 is described below
commit a241e130c0883609caa08c2da4b3dfe60c886f2a
Author: Y Ethan Guo <[email protected]>
AuthorDate: Wed May 17 15:50:22 2023 -0700
[HUDI-6227] Improve logging in ReflectionUtils.hasConstructor (#8732)
`ReflectionUtils.hasConstructor` throws warn log if the constructor does
not exist, even in cases where it's expected, e.g., for DataHubSyncTool,
confusing users. This commit improves the logging so that by default the
debug-level logs are used.
---
.../apache/hudi/common/util/ReflectionUtils.java | 29 +++++++++++++++++++---
.../hudi/sync/common/util/TestSyncUtilHelpers.java | 4 +--
.../utilities/deltastreamer/ErrorTableUtils.java | 2 +-
3 files changed, 28 insertions(+), 7 deletions(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java
b/hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java
index df6bd3b2a31..a0d604f6a94 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/util/ReflectionUtils.java
@@ -83,19 +83,40 @@ public class ReflectionUtils {
}
/**
- * Check if the clazz has the target constructor or not.
+ * Check if the clazz has the target constructor or not, without throwing
warn-level log.
*
+ * @param clazz Class name.
+ * @param constructorArgTypes Argument types of the constructor.
+ * @return
+ */
+ public static boolean hasConstructor(String clazz, Class<?>[]
constructorArgTypes) {
+ return hasConstructor(clazz, constructorArgTypes, true);
+ }
+
+ /**
+ * Check if the clazz has the target constructor or not.
+ * <p>
* When catch {@link HoodieException} from {@link #loadClass}, it's
inconvenient to say if the exception was thrown
* due to the instantiation's own logic or missing constructor.
- *
+ * <p>
* TODO: ReflectionUtils should throw a specific exception to indicate
Reflection problem.
+ *
+ * @param clazz Class name.
+ * @param constructorArgTypes Argument types of the constructor.
+ * @param silenceWarning {@code true} to use debug-level logging;
otherwise, use warn-level logging.
+ * @return {@code true} if the constructor exists; {@code false} otherwise.
*/
- public static boolean hasConstructor(String clazz, Class<?>[]
constructorArgTypes) {
+ public static boolean hasConstructor(String clazz, Class<?>[]
constructorArgTypes, boolean silenceWarning) {
try {
getClass(clazz).getConstructor(constructorArgTypes);
return true;
} catch (NoSuchMethodException e) {
- LOG.warn("Unable to instantiate class " + clazz, e);
+ String message = "Unable to instantiate class " + clazz;
+ if (silenceWarning) {
+ LOG.debug(message, e);
+ } else {
+ LOG.warn(message, e);
+ }
return false;
}
}
diff --git
a/hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestSyncUtilHelpers.java
b/hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestSyncUtilHelpers.java
index 5e9f7159020..155c96f8560 100644
---
a/hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestSyncUtilHelpers.java
+++
b/hudi-sync/hudi-sync-common/src/test/java/org/apache/hudi/sync/common/util/TestSyncUtilHelpers.java
@@ -112,8 +112,8 @@ public class TestSyncUtilHelpers {
}
public static class DummySyncTool2 extends HoodieSyncTool {
- public DummySyncTool2(Properties props, Configuration hadoopConf) {
- super(props, hadoopConf);
+ public DummySyncTool2(Properties props) {
+ super(props);
}
@Override
diff --git
a/hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/ErrorTableUtils.java
b/hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/ErrorTableUtils.java
index a5533449a6a..881a9545461 100644
---
a/hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/ErrorTableUtils.java
+++
b/hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/ErrorTableUtils.java
@@ -48,7 +48,7 @@ public final class ErrorTableUtils {
Class<?>[] argClassArr = new Class[] {HoodieDeltaStreamer.Config.class,
SparkSession.class, TypedProperties.class, JavaSparkContext.class,
FileSystem.class};
String errMsg = "Unable to instantiate ErrorTableWriter with arguments
type " + Arrays.toString(argClassArr);
-
ValidationUtils.checkArgument(ReflectionUtils.hasConstructor(BaseErrorTableWriter.class.getName(),
argClassArr), errMsg);
+
ValidationUtils.checkArgument(ReflectionUtils.hasConstructor(BaseErrorTableWriter.class.getName(),
argClassArr, false), errMsg);
try {
return Option.of((BaseErrorTableWriter)
ReflectionUtils.getClass(errorTableWriterClass).getConstructor(argClassArr)