<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Remote debug HiveServer2 in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Remote-debug-HiveServer2/m-p/101783#M14457</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm running HDP-2.2.6.0-2800 and am trying to remote debug the HiveServer2 process.&lt;/P&gt;&lt;P&gt;My problem is that I don't get the line numbers to match when setting breakpoints in the code and stepping through the code.&lt;/P&gt;&lt;P&gt;This usually happens when the source code on my local machine from which I am running the debugger does not match the compiled code running on the server I'm debugging.&lt;/P&gt;&lt;P&gt;Has anyone got this to work? In that case how?&lt;/P&gt;&lt;P&gt;Here are my instructions to reproduce this problem using the HDP-2.2.4 sandbox (there is no 2.2.6 sandbox afaik):&lt;/P&gt;&lt;P&gt;======================================&lt;/P&gt;&lt;P&gt;1. Create a new HDP-2.2.4 sandbox instance.&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;2. Add the following snippet to Advanced hive-env -&amp;gt; hive-env template &lt;/P&gt;&lt;P&gt;&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;PRE&gt;# Enable remote debugging of hiveserver2.
if [ "$SERVICE" = "hiveserver2" ]; then
  export HADOOP_OPTS="$HADOOP_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
fi&lt;/PRE&gt;&lt;P&gt;3. Modify the /usr/hdp/2.2.4.2-2/hive/bin/hive.distro file by replacing the following section &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;PRE&gt;# Make sure we're using a compatible version of Hadoop
if [ "x$HADOOP_VERSION" == "x" ]; then
  HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 1) {print $2;}}');
fi&lt;/PRE&gt;&lt;P&gt;With this: (When you start the hiveserver with the agent flags, it 
print an additional line to stdout which confuses this awk script)&lt;/P&gt;&lt;PRE&gt;# Make sure we're using a compatible version of Hadoop
if [ "$SERVICE" == 'hiveserver2' ]; then
  if [ "x$HADOOP_VERSION" == "x" ]; then
    HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 2) {print $2;}}');
  fi
else
  if [ "x$HADOOP_VERSION" == "x" ]; then
    HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 1) {print $2;}}');
  fi
fi
&lt;/PRE&gt;&lt;P&gt;4. Clone the hive git repo and change to the branch-0.14 branch.&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;5. Create a remote debug connection to the hiveserver2 java process&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;(i'm using IntelliJ IDEA to setup the project)&lt;/P&gt;&lt;P&gt;6. Set a breakpoint in org.apache.hive.service.cli.session.SessionManager, line 268, i.e.&lt;/P&gt;&lt;PRE&gt;if (withImpersonation) {
	HiveSessionImplwithUGI sessionWithUGI = new HiveSessionImplwithUGI(protocol, username, password,hiveConf, ipAddress, delegationToken);
	session = HiveSessionProxy.getProxy(sessionWithUGI, sessionWithUGI.getSessionUgi());
	sessionWithUGI.setProxySession(session);
} else {
      session = new HiveSessionImpl(protocol, username, password, hiveConf, ipAddress);
}

session.setSessionManager(this);
session.setOperationManager(operationManager); // &amp;lt;--- Set breakpoint here for example
try {
      session.initialize(sessionConf);
      if (isOperationLogEnabled) {
      	session.setOperationLogSessionDir(operationLogRootDir);
      }
      session.open();
} catch (Exception e) {
      throw new HiveSQLException("Failed to open new session", e);
}&lt;/PRE&gt;
&lt;P&gt;7. Start a new hive session, I'm using beeline &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;8. See that the hiveserver2 execution is halted at the breakpoint. &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;9. Try to "Step into" the session.setOperationManager method, and you actually end up in &lt;/P&gt;&lt;PRE&gt;org.apache.hive.service.cli.session.HiveSessionImpl.getSessionHandle()&lt;/PRE&gt;&lt;P&gt; An obvious line mismatch here as you can see.&lt;/P&gt;&lt;P&gt;Perhaps I am missing something here.&lt;/P&gt;&lt;P&gt;Grateful for any tips.&lt;/P&gt;&lt;P&gt;/Thomas&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jan 2016 18:10:52 GMT</pubDate>
    <dc:creator>ThomasLarsson</dc:creator>
    <dc:date>2016-01-07T18:10:52Z</dc:date>
    <item>
      <title>Remote debug HiveServer2</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Remote-debug-HiveServer2/m-p/101783#M14457</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm running HDP-2.2.6.0-2800 and am trying to remote debug the HiveServer2 process.&lt;/P&gt;&lt;P&gt;My problem is that I don't get the line numbers to match when setting breakpoints in the code and stepping through the code.&lt;/P&gt;&lt;P&gt;This usually happens when the source code on my local machine from which I am running the debugger does not match the compiled code running on the server I'm debugging.&lt;/P&gt;&lt;P&gt;Has anyone got this to work? In that case how?&lt;/P&gt;&lt;P&gt;Here are my instructions to reproduce this problem using the HDP-2.2.4 sandbox (there is no 2.2.6 sandbox afaik):&lt;/P&gt;&lt;P&gt;======================================&lt;/P&gt;&lt;P&gt;1. Create a new HDP-2.2.4 sandbox instance.&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;2. Add the following snippet to Advanced hive-env -&amp;gt; hive-env template &lt;/P&gt;&lt;P&gt;&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;PRE&gt;# Enable remote debugging of hiveserver2.
if [ "$SERVICE" = "hiveserver2" ]; then
  export HADOOP_OPTS="$HADOOP_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
fi&lt;/PRE&gt;&lt;P&gt;3. Modify the /usr/hdp/2.2.4.2-2/hive/bin/hive.distro file by replacing the following section &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;PRE&gt;# Make sure we're using a compatible version of Hadoop
if [ "x$HADOOP_VERSION" == "x" ]; then
  HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 1) {print $2;}}');
fi&lt;/PRE&gt;&lt;P&gt;With this: (When you start the hiveserver with the agent flags, it 
print an additional line to stdout which confuses this awk script)&lt;/P&gt;&lt;PRE&gt;# Make sure we're using a compatible version of Hadoop
if [ "$SERVICE" == 'hiveserver2' ]; then
  if [ "x$HADOOP_VERSION" == "x" ]; then
    HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 2) {print $2;}}');
  fi
else
  if [ "x$HADOOP_VERSION" == "x" ]; then
    HADOOP_VERSION=$($HADOOP version | awk '{if (NR == 1) {print $2;}}');
  fi
fi
&lt;/PRE&gt;&lt;P&gt;4. Clone the hive git repo and change to the branch-0.14 branch.&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;5. Create a remote debug connection to the hiveserver2 java process&amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;(i'm using IntelliJ IDEA to setup the project)&lt;/P&gt;&lt;P&gt;6. Set a breakpoint in org.apache.hive.service.cli.session.SessionManager, line 268, i.e.&lt;/P&gt;&lt;PRE&gt;if (withImpersonation) {
	HiveSessionImplwithUGI sessionWithUGI = new HiveSessionImplwithUGI(protocol, username, password,hiveConf, ipAddress, delegationToken);
	session = HiveSessionProxy.getProxy(sessionWithUGI, sessionWithUGI.getSessionUgi());
	sessionWithUGI.setProxySession(session);
} else {
      session = new HiveSessionImpl(protocol, username, password, hiveConf, ipAddress);
}

session.setSessionManager(this);
session.setOperationManager(operationManager); // &amp;lt;--- Set breakpoint here for example
try {
      session.initialize(sessionConf);
      if (isOperationLogEnabled) {
      	session.setOperationLogSessionDir(operationLogRootDir);
      }
      session.open();
} catch (Exception e) {
      throw new HiveSQLException("Failed to open new session", e);
}&lt;/PRE&gt;
&lt;P&gt;7. Start a new hive session, I'm using beeline &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;8. See that the hiveserver2 execution is halted at the breakpoint. &amp;lt;br/&amp;gt;&lt;/P&gt;&lt;P&gt;9. Try to "Step into" the session.setOperationManager method, and you actually end up in &lt;/P&gt;&lt;PRE&gt;org.apache.hive.service.cli.session.HiveSessionImpl.getSessionHandle()&lt;/PRE&gt;&lt;P&gt; An obvious line mismatch here as you can see.&lt;/P&gt;&lt;P&gt;Perhaps I am missing something here.&lt;/P&gt;&lt;P&gt;Grateful for any tips.&lt;/P&gt;&lt;P&gt;/Thomas&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 18:10:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Remote-debug-HiveServer2/m-p/101783#M14457</guid>
      <dc:creator>ThomasLarsson</dc:creator>
      <dc:date>2016-01-07T18:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Remote debug HiveServer2</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Remote-debug-HiveServer2/m-p/101784#M14458</link>
      <description>&lt;P&gt;I found the source code, here: &lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/hortonworks/hive-release/releases" target="_blank"&gt;https://github.com/hortonworks/hive-release/releases&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 20:46:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Remote-debug-HiveServer2/m-p/101784#M14458</guid>
      <dc:creator>ThomasLarsson</dc:creator>
      <dc:date>2016-01-07T20:46:25Z</dc:date>
    </item>
  </channel>
</rss>

