diff --git a/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java b/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java index 7b03f7f096e8..e351e6432e59 100644 --- a/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java +++ b/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java @@ -37,6 +37,7 @@ import org.apache.hadoop.hive.metastore.annotation.NoReconnect; import org.apache.hadoop.hive.metastore.api.*; import org.apache.hadoop.hive.metastore.api.Package; +import org.apache.hadoop.hive.metastore.client.ThriftHiveMetaStoreClient; import org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy; import org.apache.thrift.TException; @@ -47,6 +48,16 @@ @InterfaceStability.Evolving public interface IMetaStoreClient extends AutoCloseable { + /** + * Returns the underlying Thrift client used to communicate with the Hive + * Metastore server, if this implementation exposes one. Default + * implementation throws {@link UnsupportedOperationException}. + */ + default ThriftHiveMetaStoreClient getThriftClient() { + throw new UnsupportedOperationException( + "MetaStore client does not expose a Thrift client"); + } + /** * Returns whether current client is compatible with conf argument or not * @return diff --git a/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java b/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java index 1351600e737a..7786c36ca673 100644 --- a/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java +++ b/standalone-metastore/metastore-client/src/main/java/org/apache/hadoop/hive/metastore/client/ThriftHiveMetaStoreClient.java @@ -427,6 +427,15 @@ public static AtomicInteger getConnCount() { return connCount; } + /** + * Returns the underlying generated Thrift {@link ThriftHiveMetastore.Iface} that this + * client delegates to. Exposed for callers (such as Impala's CatalogMetastoreServer) + * that need to forward requests to the underlying snake_case Thrift API directly. + */ + public ThriftHiveMetastore.Iface getClient() { + return client; + } + @Override public boolean isLocalMetaStore() { return localMetaStore; diff --git a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/TServerSocketKeepAlive.java b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/TServerSocketKeepAlive.java new file mode 100644 index 000000000000..cb796683742d --- /dev/null +++ b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/TServerSocketKeepAlive.java @@ -0,0 +1,48 @@ +/* + * 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.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransportException; + +/** + * Wraps a {@link TServerSocket} and enables TCP keepalive on every accepted + * client connection. Useful for long-lived Metastore RPCs where idle + * connections might otherwise be dropped by intermediate firewalls/load + * balancers without notifying the application. + */ +public class TServerSocketKeepAlive extends TServerSocket { + + public TServerSocketKeepAlive(TServerSocket serverSocket) throws TTransportException { + super(serverSocket.getServerSocket()); + } + + @Override + public TSocket accept() throws TTransportException { + TSocket ts = super.accept(); + try { + ts.getSocket().setKeepAlive(true); + } catch (SocketException se) { + throw new TTransportException(se); + } + return ts; + } +} diff --git a/standalone-metastore/pom.xml b/standalone-metastore/pom.xml index 320c2cbd4dea..5037f1289dbf 100644 --- a/standalone-metastore/pom.xml +++ b/standalone-metastore/pom.xml @@ -123,7 +123,7 @@ 4.5.13 4.5.8 11.28 - 9.4.57.v20241219 + 9.4.58.v20250814 1.3.2 26.0.6