Skip to content

Commit

Permalink
fix(db): The method of determining whether opening the global client …
Browse files Browse the repository at this point in the history
…session is incorrect

* Refactor global client session check in DefaultDBSessionManage

* Add log for failed column 'time' lookup in DefaultDBSessionManage
  • Loading branch information
zijiacj authored Dec 31, 2024
1 parent cc2a493 commit 8796da2
Showing 1 changed file with 14 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.oceanbase.odc.core.shared.constant.DialectType.OB_MYSQL;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -300,38 +301,19 @@ private boolean isGlobalClientSessionEnabled(ConnectionSession connectionSession
|| VersionUtils.isLessThan(obVersion, GLOBAL_CLIENT_SESSION_OB_VERSION_NUMBER)) {
return false;
}
try {
Integer proxyId = getOBProxyConfig(connectionSession, "proxy_id");
Integer clientSessionIdVersion = getOBProxyConfig(connectionSession, "client_session_id_version");

return proxyId != null
&& proxyId >= GLOBAL_CLIENT_SESSION_PROXY_ID_MIN
&& proxyId <= GLOBAL_CLIENT_SESSION_PROXY_ID_MAX
&& clientSessionIdVersion != null
&& clientSessionIdVersion == GLOBAL_CLIENT_SESSION_ID_VERSION;
} catch (Exception e) {
log.warn("Failed to determine if global client session is enabled: {}", e.getMessage());
return false;
}
}

/**
* Gets the value of OBProxy's configuration variable If an exception occurs or the version does not
* support, return null.
*
* @param connectionSession
* @param configName
* @return
*/
private Integer getOBProxyConfig(ConnectionSession connectionSession, String configName) {
try {
return connectionSession.getSyncJdbcExecutor(ConnectionSessionConstants.BACKEND_DS_KEY)
.query("show proxyconfig like '" + configName + "';",
rs -> rs.next() ? rs.getInt("value") : null);
} catch (Exception e) {
log.warn("Failed to obtain the value of OBProxy's configuration variable: {}", e.getMessage());
return null;
}
// Check whether the global session is open
// If the global session is open, the "time" column will be displayed in the result set after
// executing the sql statement of "show processlist"
return connectionSession.getSyncJdbcExecutor(ConnectionSessionConstants.BACKEND_DS_KEY)
.query("show processlist", rs -> {
try {
int columnIndex = rs.findColumn("time");
return columnIndex > 0;
} catch (SQLException e) {
log.warn("Failed to find the column 'time' in the result set", e);
return false;
}
});
}

private boolean isUnknownThreadIdError(Exception e) {
Expand Down

0 comments on commit 8796da2

Please sign in to comment.