This is an automated email from the ASF dual-hosted git repository.
wangzhen pushed a commit to branch branch-1.10
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/branch-1.10 by this push:
new b59a30a9f1 [KYUUBI #6918] Cache client ipAddress in kyuubi jdbc
connection
b59a30a9f1 is described below
commit b59a30a9f18d6e15eb11806db920e328e2da4e84
Author: wforget <[email protected]>
AuthorDate: Fri Feb 14 20:52:17 2025 +0800
[KYUUBI #6918] Cache client ipAddress in kyuubi jdbc connection
### Why are the changes needed?
add Utils.CLIENT_IP_ADDRESS to cache local ipAddress
closes #6918
### How was this patch tested?
minor fix
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #6919 from wForget/KYUUBI-6918.
Closes #6918
5b0efe722 [Cheng Pan] Update
kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
b8660c83b [wforget] address comment
835dfb8ef [wforget] address comment
29dd13a2e [wforget] fix style
843b29fe8 [wforget] [KYUUBI #6918] Cache client ipAddress in kyuubi jdbc
connection
Lead-authored-by: wforget <[email protected]>
Co-authored-by: Cheng Pan <[email protected]>
Signed-off-by: wforget <[email protected]>
(cherry picked from commit 51b8e7b8eb5bd64b70a2d76a57ca5b7d52088d9a)
Signed-off-by: wforget <[email protected]>
---
.../org/apache/kyuubi/jdbc/hive/KyuubiConnection.java | 8 +-------
.../src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java | 15 +++++++++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
index eaf71cfa1b..8d8922ee7f 100644
---
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
+++
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
@@ -27,8 +27,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.*;
@@ -835,11 +833,7 @@ public class KyuubiConnection implements SQLConnection,
KyuubiLoggable {
"set:hiveconf:hive.server2.thrift.resultset.default.fetch.size",
Integer.toString(fetchSize));
}
- try {
- openConf.put("kyuubi.client.ipAddress",
InetAddress.getLocalHost().getHostAddress());
- } catch (UnknownHostException e) {
- LOG.debug("Error getting Kyuubi session local client ip address", e);
- }
+ openConf.put("kyuubi.client.ipAddress", Utils.CLIENT_IP_ADDRESS);
openConf.put(Utils.KYUUBI_CLIENT_VERSION_KEY, Utils.getVersion());
openReq.setConfiguration(openConf);
diff --git
a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
index b9f256f69b..86b397437e 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
@@ -68,6 +68,21 @@ public class Utils {
public static final Pattern KYUUBI_OPERATION_HINT_PATTERN =
Pattern.compile("^__kyuubi_operation_result_(.*)__=(.*)",
Pattern.CASE_INSENSITIVE);
+ public static final String CLIENT_IP_ADDRESS;
+
+ static {
+ String localIpAddress = null;
+ try {
+ localIpAddress = InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ LOG.warn("Error getting Kyuubi local client IP address", e);
+ }
+ if (StringUtils.isBlank(localIpAddress)) {
+ localIpAddress = "unknown";
+ }
+ CLIENT_IP_ADDRESS = localIpAddress;
+ }
+
static String getMatchedUrlPrefix(String uri) throws JdbcUriParseException {
for (String urlPrefix : URL_PREFIX_LIST) {
if (uri.startsWith(urlPrefix)) {