58
58
import com .alibaba .polardbx .common .utils .MergeHashMap ;
59
59
import com .alibaba .polardbx .common .utils .Pair ;
60
60
import com .alibaba .polardbx .common .utils .TStringUtil ;
61
+ import com .alibaba .polardbx .common .utils .logger .Level ;
61
62
import com .alibaba .polardbx .common .utils .logger .Logger ;
62
63
import com .alibaba .polardbx .common .utils .logger .LoggerFactory ;
63
64
import com .alibaba .polardbx .common .utils .thread .ThreadCpuStatUtil ;
225
226
*/
226
227
public final class ServerConnection extends FrontendConnection implements Reschedulable {
227
228
228
- private static final Logger logger = LoggerFactory .getLogger (ServerConnection .class );
229
+ protected static final Logger logger = LoggerFactory .getLogger (ServerConnection .class );
229
230
private static final Logger io_logger = LoggerFactory .getLogger ("net_error" );
230
231
private static final Logger cdcLogger = LoggerFactory .getLogger ("cdc_log" );
231
232
private static final ErrorPacket shutDownError = PacketUtil .getShutdown ();
@@ -2089,29 +2090,18 @@ public void handleError(ErrorCode errCode, Throwable t) {
2089
2090
}
2090
2091
2091
2092
public void handleError (ErrorCode errCode , Throwable t , String sql , boolean fatal ) {
2092
-
2093
- String db = this .schema ;
2094
- if (db == null ) {
2095
- db = "" ;
2096
- }
2097
2093
// 取得配置文件
2098
2094
SchemaConfig schema = getSchemaConfig ();
2099
2095
2100
2096
String message = t .getMessage ();
2101
- Throwable ex ;
2102
2097
if (!ErrorCode .match (message )) {
2103
- logger .error (t .getMessage (), t );
2104
2098
if (t instanceof NullPointerException ) {
2105
- ex = new TddlRuntimeException ( ERR_SERVER , "unknown NPE" ) ;
2099
+ message = "unknown NPE" ;
2106
2100
// NPE (NullPointerException) may not have been handled correctly,
2107
2101
// to avoid the exception being swallowed, print the exception stack trace again.
2108
2102
} else {
2109
- ex = new TddlRuntimeException ( ERR_SERVER , message );
2103
+ message = t . getMessage ( );
2110
2104
}
2111
- logger .error (ex .getMessage (), t );
2112
- message = ex .getMessage ();
2113
- } else {
2114
- ex = t ;
2115
2105
}
2116
2106
2117
2107
String sqlState = null ;
@@ -2152,35 +2142,8 @@ public void handleError(ErrorCode errCode, Throwable t, String sql, boolean fata
2152
2142
io_logger .info (toString (), t );
2153
2143
}
2154
2144
} else {
2155
- if (ex instanceof EOFException || ex instanceof ClosedChannelException ) {
2156
- if (logger .isInfoEnabled ()) {
2157
- buildMDC ();
2158
- logger .info (ex );
2159
- }
2160
- } else if (isConnectionReset (ex )) {
2161
- if (logger .isInfoEnabled ()) {
2162
- buildMDC ();
2163
- logger .info (ex );
2164
- }
2165
- } else if (isTableNotFount (ex ) || isColumnNotFount (ex )) {
2166
- if (logger .isDebugEnabled ()) {
2167
- buildMDC ();
2168
- logger .debug (ex );
2169
- }
2170
- } else if (isMySQLIntegrityConstraintViolationException (ex )) {
2171
- if (logger .isDebugEnabled ()) {
2172
- buildMDC ();
2173
- logger .debug (ex );
2174
- }
2175
- } else {
2176
- if (logger .isWarnEnabled ()) {
2177
- buildMDC ();
2178
- if (schema != null ) {
2179
- schema .getDataSource ().getStatistics ().errorCount ++;
2180
- }
2181
- logger .warn ("[ERROR-CODE: " + errCode + "][" + this .traceId + "] SQL: " + sql , ex );
2182
- }
2183
- }
2145
+ // use origin exception t to judge log level
2146
+ logError (logger , errCode , sql , t , schema );
2184
2147
}
2185
2148
2186
2149
switch (errCode ) {
@@ -2196,6 +2159,38 @@ public void handleError(ErrorCode errCode, Throwable t, String sql, boolean fata
2196
2159
}
2197
2160
}
2198
2161
2162
+ protected void logError (Logger logger , ErrorCode errCode , String sql , Throwable ex , SchemaConfig schema ) {
2163
+ if (ex instanceof EOFException || ex instanceof ClosedChannelException ) {
2164
+ if (logger .isInfoEnabled ()) {
2165
+ buildMDC ();
2166
+ logger .info (ex );
2167
+ }
2168
+ } else if (isConnectionReset (ex )) {
2169
+ if (logger .isInfoEnabled ()) {
2170
+ buildMDC ();
2171
+ logger .info (ex );
2172
+ }
2173
+ } else if (isTableNotFount (ex ) || isColumnNotFount (ex )) {
2174
+ if (logger .isDebugEnabled ()) {
2175
+ buildMDC ();
2176
+ logger .debug (ex );
2177
+ }
2178
+ } else if (isMySQLIntegrityConstraintViolationException (ex )) {
2179
+ if (logger .isDebugEnabled ()) {
2180
+ buildMDC ();
2181
+ logger .debug (ex );
2182
+ }
2183
+ } else {
2184
+ if (logger .isWarnEnabled ()) {
2185
+ buildMDC ();
2186
+ if (schema != null ) {
2187
+ schema .getDataSource ().getStatistics ().errorCount ++;
2188
+ }
2189
+ logger .warn ("[ERROR-CODE: " + errCode + "][" + this .traceId + "] SQL: " + sql , ex );
2190
+ }
2191
+ }
2192
+ }
2193
+
2199
2194
public void handleErrorForTrx (Throwable t ) {
2200
2195
// Handle specific errors.
2201
2196
if (t .getMessage ().contains ("Unknown system variable 'innodb_mark_distributed'" )) {
0 commit comments