Author: cws
Date: Fri Oct 19 18:26:50 2012
New Revision: 1400210

URL: http://svn.apache.org/viewvc?rev=1400210&view=rev
Log:
HIVE-3590. TCP KeepAlive and connection timeout for the HiveServer (Esteban 
Gutierrez via cws)

Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/conf/hive-default.xml.template
    hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1400210&r1=1400209&r2=1400210&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java 
(original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Fri 
Oct 19 18:26:50 2012
@@ -645,6 +645,12 @@ public class HiveConf extends Configurat
      * This will be removed once the rest of the DML changes are committed.
      */
     
HIVE_INTERNAL_DDL_LIST_BUCKETING_ENABLE("hive.internal.ddl.list.bucketing.enable",
 false),
+
+    // Allow TCP Keep alive socket option for for HiveServer or a maximum 
timeout for the socket.
+
+    SERVER_READ_SOCKET_TIMEOUT("hive.server.read.socket.timeout", 10),
+    SERVER_TCP_KEEP_ALIVE("hive.server.tcp.keepalive", true),
+
     ;
 
     public final String varname;

Modified: hive/trunk/conf/hive-default.xml.template
URL: 
http://svn.apache.org/viewvc/hive/trunk/conf/hive-default.xml.template?rev=1400210&r1=1400209&r2=1400210&view=diff
==============================================================================
--- hive/trunk/conf/hive-default.xml.template (original)
+++ hive/trunk/conf/hive-default.xml.template Fri Oct 19 18:26:50 2012
@@ -1491,5 +1491,19 @@
    <description>The number of miliseconds between HMSHandler retry 
attempts</description>
 </property>
 
+
+<property>
+   <name>hive.server.read.socket.timeout</name>
+   <value>10</value>
+   <description>Timeout for the HiveServer to close the connection if no 
response from the client in N seconds, defaults to 10 seconds.</description>
+</property>
+
+<property>
+   <name>hive.server.tcp.keepalive</name>
+   <value>true</value>
+   <description>Whether to enable TCP keepalive for the Hive server. Keepalive 
will prevent accumulation of half-open connections.</description>
+</property>
+
+
 </configuration>
 

Modified: 
hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java?rev=1400210&r1=1400209&r2=1400210&view=diff
==============================================================================
--- hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java 
(original)
+++ hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java 
Fri Oct 19 18:26:50 2012
@@ -42,6 +42,7 @@ import org.apache.hadoop.hive.conf.HiveC
 import org.apache.hadoop.hive.metastore.HiveMetaStore;
 import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.hadoop.hive.metastore.api.Schema;
+import org.apache.hadoop.hive.metastore.TServerSocketKeepAlive;
 import org.apache.hadoop.hive.ql.CommandNeedRetryException;
 import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.plan.api.QueryPlan;
@@ -651,6 +652,7 @@ public class HiveServer extends ThriftHi
 
       cli.parse(args);
 
+
       // NOTE: It is critical to do this prior to initializing log4j, otherwise
       // any log specific settings via hiveconf will be ignored
       Properties hiveconf = cli.addHiveconfToSystemProperties();
@@ -665,7 +667,11 @@ public class HiveServer extends ThriftHi
 
       HiveConf conf = new HiveConf(HiveServerHandler.class);
       ServerUtils.cleanUpScratchDir(conf);
-      TServerTransport serverTransport = new TServerSocket(cli.port);
+
+
+      boolean tcpKeepAlive = 
conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE);
+
+      TServerTransport serverTransport = tcpKeepAlive ? new 
TServerSocketKeepAlive(cli.port) : new TServerSocket(cli.port, 1000 * 
conf.getIntVar(HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT));
 
       // set all properties specified on the command line
       for (Map.Entry<Object, Object> item : hiveconf.entrySet()) {
@@ -688,6 +694,9 @@ public class HiveServer extends ThriftHi
         + " with " + cli.minWorkerThreads + " min worker threads and "
         + cli.maxWorkerThreads + " max worker threads";
       HiveServerHandler.LOG.info(msg);
+
+      HiveServerHandler.LOG.info("TCP keepalive = " + tcpKeepAlive);
+
       if (cli.isVerbose()) {
         System.err.println(msg);
       }


Reply via email to