我正在使用cloudera hive jdbc https://www.cloudera.com/downloads/connectors/hive/jdbc/2-6-2.html
有时,当呼叫getConnection((失败(并非总是取决于服务器稳定性(时,它显示了以下例外:
MyDAO - Cannot create connection from DataSource@21f421b8
at com.cloudera.hiveserver2.hivecommon.api.HS2Client.closeSession(Unknown Source)
at com.cloudera.hiveserver2.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source)
at com.cloudera.hiveserver2.jdbc.core.LoginTimeoutConnection.connect(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.AbstractDataSource.getSimbaConnection(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.AbstractDataSource.getConnection(Unknown Source)
,当我与NetStat CMD核对时:
netstat -an --tcp --program
建立了一个新的插座连接,我必须等待大约1小时,然后查看TCP连接消失。
问题是:
- 为什么当我调用getConnection((时,闭合((被称为?
- 是因为CLOSESESSION((失败,TCP连接无法释放?它是否被认为是连接泄漏?
我对驱动程序进行了分配,检查H2SCLIENT类:
public void closeSession() throws ErrorException {
if (this.m_hasOpenSession) {
try {
TCloseSessionReq var1 = new TCloseSessionReq();
var1.setSessionHandle(this.m_openSessionResp.getSessionHandle());
this.m_client.CloseSession(var1);
if (null != this.m_client && null != this.m_client.getInputProtocol() && null != this.m_client.getInputProtocol().getTransport()) {
this.m_client.getInputProtocol().getTransport().close(); //line 8
}
this.m_hasOpenSession = false;
} catch (Exception var3) {
ErrorException var2 = HiveJDBCCommonDriver.s_HiveMessages.createGeneralException(HiveJDBCMessageKey.CONN_SESSION_ERR.name(), "Close Session Error");
var2.initCause(var3);
throw var2;
}
}
}
如果无法达到第8行,则插座连接未关闭。该结束也应在捕获块中或最终块中调用:
public void closeSession() throws ErrorException {
if (this.m_hasOpenSession) {
try {
TCloseSessionReq var1 = new TCloseSessionReq();
var1.setSessionHandle(this.m_openSessionResp.getSessionHandle());
this.m_client.CloseSession(var1);
var2.initCause(var3);
throw var2;
} finally {
if (null != this.m_client && null != this.m_client.getInputProtocol() && null != this.m_client.getInputProtocol().getTransport()) {
this.m_client.getInputProtocol().getTransport().close(); //line 8
}
}
}
}