【发布时间】:2020-10-26 07:12:03
【问题描述】:
我正在使用我的 Spring Boot 应用程序连接到 Hive 数据源。下面是数据源配置
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
import java.io.IOException;
@Configuration
public class HiveDataSourceConfig {
@Value("${hive.url}")
private String url;
@Value("${hive.username}")
private String username;
@Value("${hive.password}")
private String password;
public DataSource getHiveDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(url);
dataSource.setDriverClassName("org.apache.hive.jdbc.HiveDriver");
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
@Bean(name = "jdbcTemplate")
public JdbcTemplate getJDBCTemplate() throws IOException {
return new JdbcTemplate(getHiveDataSource());
}
}
这是我连接到的 JDBC-Url
jdbc:hive2://hpeeeee.hpc.company.com:8443/;ssl=true;sslTrustStore=/Users/arun/Downloads/truststore.jks;trustStorePassword=password123;transportMode=http;httpPath=one/default /蜂巢
我连接到 hive 数据库以获取 8000 多条记录。连接运行良好,有时我得到以下异常
java.sql.SQLException: org.apache.thrift.transport.TTransportException: org.apache.http.NoHttpResponseException
有时我得到以下异常
org.apache.hive.service.cli.HiveSQLException:无效的 SessionHandle:
当我在谷歌上搜索这些异常的原因时,我可以看到一些响应表明这是由于 Hive-Server 的问题...
但是,当我重新启动我的应用程序(连接到 hive 数据库)时,此故障消失并在一段时间后再次出现。
有什么想法吗?
【问题讨论】:
-
您能否检查配置单元驱动程序是否与您尝试连接的配置单元分布相匹配?有时有两个不同版本的 hive dist。你可能有类似的问题。
-
当我重新启动我的应用程序时,它工作得非常好..只有在一段时间的空闲时间后,我才得到异常
-
Hive URL 是什么?您是否通过负载均衡器连接?如果平衡器配置不正确,则连接可能会在 HiveServer2 的不同实例之间反弹,并且由于其他 HiveServer2 没有注册该客户端,因此连接将被拒绝并显示“Invalid SessionHandle”。
-
有没有办法通过 Spring boot 解决它?以便它终止所有无效会话并获得一个新会话
-
我已经用 JDBC URL 详细信息更新了我的实际帖子
标签: spring spring-boot hive spring-jdbc jdbctemplate