diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 0ff2863..cc8092e 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -366,7 +366,7 @@ private void open() throws MetaException { for (URI store : metastoreUris) { LOG.info("Trying to connect to metastore with URI " + store); try { - transport = new TSocket(store.getHost(), store.getPort(), clientSocketTimeout); + transport = new TSocketKeepAlive(store.getHost(), store.getPort(), clientSocketTimeout); if (useSasl) { // Wrap thrift connection with SASL for secure connection. try { diff --git metastore/src/java/org/apache/hadoop/hive/metastore/TSocketKeepAlive.java metastore/src/java/org/apache/hadoop/hive/metastore/TSocketKeepAlive.java new file mode 100644 index 0000000..251f5db --- /dev/null +++ metastore/src/java/org/apache/hadoop/hive/metastore/TSocketKeepAlive.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.metastore; + +import java.net.SocketException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.thrift.transport.TSocket; + +public class TSocketKeepAlive extends TSocket { + + static final protected Log LOG = LogFactory.getLog(TSocketKeepAlive.class + .getName()); + + public TSocketKeepAlive(String host, int port, int timeout) { + super(host, port, timeout); + try { + this.getSocket().setKeepAlive(true); + } catch (SocketException se) { + LOG.warn("Could not set keep alive on client socket", se); + } + } + +}