▲业务通过MySQL-JDBC的Loadbalance能提访问多个DDM节点。MySQL-JDBC提供负载均衡能力。 问题说明
MySQL JDBC驱动的客户端负载均衡能力,一直运行得好好,性能嗷嗷叫。可是前一阵子竟无故出现业务请求失败。我是负责电商订单模块的,涉及到真实的Money,这个问题可吓了宝宝一身冷汗……
于是赶紧查看了后台日志,发现是访问DDM出现了异常,二话不说直接提了工单给华为云DDM服务。
} catch (SQLException e) {
if (shouldExceptionTriggerConnectionSwitch(e) && newConn != null) {
// connection error, close up shop on current connection
invalidateConnection(newConn);
}
}
}
syncSessionState()函数,在执行完SQL之后,又会调用postProcess()函数,如此嵌套循环就来了。
if (!this.conn.getAutoCommit()) {
this.matchingAfterStatementCount = 0;
// auto-commit is enabled:
} else {
if (this.proxy != null) {
// increment the match count if no regex specified, or if matches:
if (this.matchingAfterStatementRegex == null || sql.matches(this.matchingAfterStatementRegex)) {
this.matchingAfterStatementCount++;
}
}
// trigger rebalance if count exceeds threshold:
if (this.matchingAfterStatementCount >= this.matchingAfterStatementThreshold) {
this.matchingAfterStatementCount = 0;
try {
if (this.proxy != null) {
this.proxy.pickNewConnection();
}
} catch (SQLException e) {
// eat this exception, the auto-commit statement completed, but we could not rebalance for some reason. User may get exception when using
// connection next.
}
// Don't count SETs neither SHOWs. Those are mostly used internally and must not trigger a connection switch.
if (!this.countStatements || StringUtils.startsWithIgnoreCase(sql, "SET") || StringUtils.startsWithIgnoreCase(sql, "SHOW")) {
return originalResultSet;