最近在debug hive的一个bug,之前都是使用打印日志来跟踪源码,这种方式效率比较低(每次更改了源码都要重新编译并替换线上的jar包),java的应用可以支持remote debug的,hive也不例外,主要是通过hive --debug来实现.
在运行hive --debug时遇到如下问题:
ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options. Error occurred during initialization of VM agent library failed to init: jdwp
根据错误信息,可以看到是由于重复的jdwp参数导致。hive其实是一个shell脚本,追踪其运行情况:
cd ${HIVE_HOME}/bin;sh -x ./hive --debug
查看hive --debug的调用情况:
if [ "$DEBUG" ]; then if [ "$HELP" ]; then debug_help exit 0 else get_debug_params "$DEBUG" export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS $HIVE_MAIN_CLIENT_DEBUG_OPTS" fi fi
这里是:
HIVE_MAIN_CLIENT_DEBUG_OPTS=‘ -XX:+UseParallelGC -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y‘
HIVE_MAIN_CLIENT_DEBUG_OPTS 变量是在${HIVE_HOME}/bin/ext/debug.sh 中,这个脚本控制了debug的参数,比如说端口
get_debug_params(){ set_debug_defaults parse_debug $1 # For Debug -XX:+UseParallelGC is needed, as it is a (unfortunately not perfect) # workaround for JVM 6862295 bug, that affects some JVMs still in use if does_jvm_support_ti; then export HIVE_MAIN_CLIENT_DEBUG_OPTS=" -XX:+UseParallelGC -agentlib:jdwp=transport=dt_socket,server=y,$port,$main_suspend" export HIVE_CHILD_CLIENT_DEBUG_OPTS=" -XX:+UseParallelGC -agentlib:jdwp=transport=dt_socket,server=y,$child_suspend" else export HIVE_MAIN_CLIENT_DEBUG_OPTS=" -XX:+UseParallelGC -Xdebug -Xrunjdwp:transport=dt_socket,server=y,$port,$main_suspend" export HIVE_CHILD_CLIENT_DEBUG_OPTS=" -XX:+UseParallelGC -Xdebug -Xrunjdwp:transport=dt_socket,server=y,$child_suspend" fi
最终hive运行的命令为:
exec ${HADOOP_HOME}/bin/hadoop jar hive-cli-0.13.1.jar org.apache.hadoop.hive.cli.CliDriver --hiveconf hive.aux.jars.path=xxxxx
而在${HADOOP_HOME}/bin/hadoop中,设置HADOOP_OPTS时,又引用了HADOOP_CLIENT_OPTS这个变量,就导致jdwp 的参数重复了
只需要注释下面一行即可以:
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
这其实是一个bug:
相关的bug id
https://issues.apache.org/jira/browse/HADOOP-9455
https://issues.apache.org/jira/browse/HIVE-3936
bug描述:
HADOOP_CLIENT_OPTS appended twice causes JVM failures
在官方提供的bug id中可以看到hive0.13是fix这个bug的,具体的patch如下:
diff --git bin/hive bin/hive index 40e2c75..434ea6c 100755 --- bin/hive +++ bin/hive @@ -251,7 +251,6 @@ if [ "$DEBUG" ]; then else get_debug_params "$DEBUG" export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS $HIVE_MAIN_CLIENT_DEBUG_OPTS" - export HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS" fi fi
经过测试,这个path并没有生效。
时间: 2024-10-24 23:48:13