PostgreSQL 教程 — — — — —— 參考: 菜鳥教程 ORDBMS 術語 在我們開始學習 PostgreSQL 資料庫前,讓我們先瞭解下 ORDBMS 的一些術語: 資料庫: 資料庫是一些關聯表的集合。 數據表: 表是數據的矩陣。在一個資料庫中的表看起來像一個簡單的電子錶格。 列: ...
來源: https://plantegg.github.io/2020/07/03/MySQL%20JDBC%20StreamResult%20%E5%92%8C%20net_write_timeout/
MySQL JDBC StreamResult 和 net_write_timeout
MySQL JDBC 拉取數據的三種方式
MySQL JDBC 在從 MySQL 拉取數據的時候有三種方式:
- 簡單模式,也就是預設模式,數據都先要從MySQL Server發到client的OS TCP buffer,然後JDBC把 OS buffer讀取到JVM記憶體中,讀取到JVM記憶體的過程中憋著不讓client讀取,全部讀完再通知inputStream.read(). 數據大的話容易導致JVM OOM
- useCursorFetch=true,配合FetchSize,也就是MySQL Server把查到的數據先緩存到本地磁碟,然後按照FetchSize挨個發給client。這需要占用MySQL很高的IOPS(先寫磁碟緩存),其次每次Fetch需要一個RTT,效率不高。
- Stream讀取,Stream讀取是在執行SQL前設置FetchSize:statement.setFetchSize(Integer.MIN_VALUE),同時確保游標是只讀、向前滾動的(為游標的預設值),MySQL JDBC內置的操作方法是將Statement強制轉換為:com.mysql.jdbc.StatementImpl,調用其方法:enableStreamingResults(),這2者達到的效果是一致的,都是啟動Stream流方式讀取數據。這個時候MySQL不停地發數據,inputStream.read()不停地讀取。一般來說發數據更快些,很快client的OS TCP recv buffer就滿了,這時MySQL停下來等buffer有空閑就繼續發數據。等待過程中如果超過 net_write_timeout MySQL就會報錯,中斷這次查詢。
從這裡的描述來看,數據小的時候第一種方式還能接受,但是數據大了容易OOM,方式三看起來不錯,但是要特別註意 net_write_timeout。
1和3對MySQL Server來說處理上沒有啥區別,也感知不到這兩種方式的不同。只是對1來說從OS Buffer中的數據複製到JVM記憶體中速度快,JVM攢多了數據記憶體就容易爆掉;對3來說JDBC一條條將OS Buffer中的數據複製到JVM(記憶體複製速度快)同時返回給execute挨個處理(慢),一般來說挨個處理要慢一些,這就導致了從OS Buffer中複製數據較慢,容易導致 TCP Receive Buffer滿了,那麼MySQL Server感知到的就是TCP 傳輸視窗為0了,導致暫停傳輸數據。
在數據量很小的時候方式三沒什麼優勢,因為總是多一次set net_write_tiemout,也就是多了一次RTT。
MySQL timeout
- Creates a statement by calling
Connection.createStatement()
. - Calls
Statement.executeQuery()
. - The statement transmits the Query to MySqlServer by using the internal connection.
- The statement creates a new timeout-execution thread for timeout process.
- For version 5.1.x, it changes to assign 1 thread for each connection.
- Registers the timeout execution to the thread.
- Timeout occurs.
- The timeout-execution thread creates a connection that has the same configurations as the statement.
- Transmits the cancel Query (KILL QUERY “connectionId“) by using the connection.
net_read_timeout
Command-Line Format | --net-read-timeout=# |
---|---|
System Variable | net_read_timeout |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 30 |
Minimum Value | 1 |
Maximum Value | 31536000 |
Unit | seconds |
The number of seconds to wait for more data from a connection before aborting the read. When the server is reading from the client, net_read_timeout
is the timeout value controlling when to abort.
如下圖,MySQL Server監聽3017埠,195228號包 客戶端發一個SQL 給 MySQL Server,但是似乎這個時候正好網路異常,30秒鐘後(從 SQL 請求的前一個 ack 開始算,Server應該一直都沒有收到),Server 端觸發 net_read_timeout 超時異常(疑問:這裡沒有 net_read_timeout 描述的讀取了一半的現象)
解決方案:建議調大 net_read_timeout 以應對可能出現的網路丟包
net_write_timeout
show processlist 看到的State的值一直處於“Sending to client”,說明SQL這個語句已經執行完畢,而此時由於請求的數據太多,MySQL不停寫入net buffer,而net buffer又不停的將數據寫入服務端的網路棧,伺服器端的網路棧(socket send buffer)被寫滿了,又沒有被客戶端讀取並消化,這時讀數據的流程就被MySQL暫停了。直到客戶端完全讀取了服務端網路棧的數據,這個狀態才會消失。
先看下 net_write_timeout
的解釋:The number of seconds to wait for a block to be written to a connection before aborting the write. 只針對執行查詢中的等待超時,網路不好,tcp buffer滿了(應用遲遲不讀走數據)等容易導致mysql server端報net_write_timeout錯誤,指的是mysql server hang在那裡長時間無法發送查詢結果。
Property | Value |
---|---|
Command-Line Format | --net-write-timeout=# |
System Variable | net_write_timeout |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 60 |
Minimum Value | 1 |
報這個錯就是RDS等了net_write_timeout這麼久沒寫數據,可能是客戶端卡死沒有讀走數據,也可能是從多個分片挨個拉取,還沒開始拉第7片前面6片拉取耗時就超過了net_write_timeout。
案例:DRDS 到 MySQL 多個分片拉取數據生成了許多 cursor 併發執行,但拉數據的時候是串列拉取的,如果用戶端拉取數據過慢會導致最後一個 cursor 執行完成之後要等待很久.會超過 MySQL 的 net_write_timeout 配置從而引發報錯. 也就是最後一個cursor打開後一直沒有去讀取數據,直到MySQL Server 觸發 net_write_timeout 異常
首先可以嘗試在 DRDS jdbcurl 配置 netTimeoutForStreamingResults 參數,設置為 0 可以使其一直等待,或設置一個合理的值(秒).
從JDBC驅動中可以看到,當調用PreparedStatement的executeQuery() 方法的時候,如果我們是去獲取流式resultset的話,就會預設執行SET net_write_timeout= ? 這個命令去重新設置timeout時間。源代碼如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | if (doStreaming && this.connection.getNetTimeoutForStreamingResults() > 0) { java.sql.Statement stmt = null; try { stmt = this.connection.createStatement(); ((com.mysql.jdbc.StatementImpl)stmt).executeSimpleNonQuery(this.connection, "SET net_write_timeout=" + this.connection.getNetTimeoutForStreamingResults()); } finally { if (stmt != null) { stmt.close(); } } } //另外DRDS代碼 AppLoader.java 中寫死了net_write_timeout 8小時 ds.putConnectionProperties(ConnectionProperties.NET_WRITE_TIMEOUT, 28800); |
而 this.connection.getNetTimeoutForStreamingResults() 預設是600秒,或者在JDBC連接串種通過屬性 netTimeoutForStreamingResults 來指定。
netTimeoutForStreamingResults 預設值:
What value should the driver automatically set the server setting ‘net_write_timeout’ to when the streaming result sets feature is in use? Value has unit of seconds, the value “0” means the driver will not try and adjust this value.
Default Value | 600 |
---|---|
Since Version | 5.1.0 |
一般在數據導出場景中容易出現 net_write_timeout 這個錯誤,比如這個錯誤堆棧:
或者:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ErrorMessage: Communications link failure The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 709,806 milliseconds ago. - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 7 milliseconds ago. The last packet sent successfully to the server was 709,806 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3427) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3327) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870) at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1928) at com.mysql.jdbc.RowDataDynamic.nextRecord(RowDataDynamic.java:378) at com.mysql.jdbc.RowDataDynamic.next(RowDataDynamic.java:358) at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6337) at com.alibaba.datax.plugin.rdbms.reader.CommonRdbmsReader$Task.startRead(CommonRdbmsReader.java:275) at com.alibaba.datax.plugin.reader.drdsreader.DrdsReader$Task.startRead(DrdsReader.java:148) at com.alibaba.datax.core.taskgroup.runner.ReaderRunner.run(ReaderRunner.java:62) at java.lang.Thread.run(Thread.java:834) Caused by: java.io.EOFException: Can not read response from server. Expected to read 258 bytes, read 54 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2914) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3387) ... 11 more |
特別註意
JDBC驅動報如下錯誤
Application was streaming results when the connection failed. Consider raising value of ‘net_write_timeout’ on the server. - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Application was streaming results when the connection failed. Consider raising value of ‘net_write_timeout’ on the server.
不一定是 net_write_timeout
設置過小導致的,JDBC 在 streaming 流模式下只要連接異常就會報如上錯誤,比如:
- 連接被 TCP reset
- 連接因為某種原因(比如 QueryTimeOut、比如用戶監控kill 慢查詢) 觸發 kill Query導致連接中斷
比如出現內核bug,內核卡死不發包的話,客戶端同樣報 net_write_timeout 錯誤
max_allowed_packet
: 單個SQL或者單條記錄的最大大小
一些其他的 Timeout
connectTimeout:表示等待和MySQL資料庫建立socket鏈接的超時時間,預設值0,表示不設置超時,單位毫秒,建議30000。 JDBC驅動連接屬性
queryTimeout:超時後jdbc驅動觸發新建一個連接來發送一個 kill 給DB
socketTimeout:JDBC參數,表示客戶端發送請求給MySQL資料庫後block在read的等待數據的超時時間,linux系統預設的socketTimeout為30分鐘,可以不設置。socketTimeout 超時不會觸發發kill,只會斷開連接。
要特別註意socketTimeout僅僅是指等待socket數據時間,如果在傳輸數據那麼這個值就沒有用了。socketTimeout通過mysql-connector中的NativeProtocol最終設置在socketOptions上
static final int SO_TIMEOUT。 Set a timeout on blocking Socket operations:
ServerSocket.accept();
SocketInputStream.read();
DatagramSocket.receive();The option must be set prior to entering a blocking operation to take effect. If the timeout expires and the operation would continue to block, java.io.InterruptedIOException is raised. The Socket is not closed in this case.
Statement Timeout:用來限制statement的執行時長,timeout的值通過調用JDBC的java.sql.Statement.setQueryTimeout(int timeout) API進行設置。不過現在開發者已經很少直接在代碼中設置,而多是通過框架來進行設置。
max_execution_time
:The execution timeout for SELECT
statements, in milliseconds. If the value is 0, timeouts are not enabled. MySQL 屬性,可以set修改,一般用來設置一個查詢最長不超過多少秒,避免一個慢查詢一直在跑,跟statement timeout對應。
Property | Value |
---|---|
Command-Line Format | --max-execution-time=# |
System Variable | max_execution_time |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 0 |
wait_timeout
The number of seconds the server waits for activity on a noninteractive connection before closing it. MySQL 屬性,一般設置tcp keepalive後這個值基本不會超時(這句話存疑 202110)。
On thread startup, the session wait_timeout
value is initialized from the global wait_timeout
value or from the global interactive_timeout
value, depending on the type of client (as defined by the CLIENT_INTERACTIVE
connect option to mysql_real_connect()
). See also interactive_timeout
.
Property | Value |
---|---|
Command-Line Format | --wait-timeout=# |
System Variable | wait_timeout |
Scope | Global, Session |
Dynamic | Yes |
Type | Integer |
Default Value | 28800 |
Minimum Value | 1 |
Maximum Value (Other) | 31536000 |
Maximum Value (Windows) | 2147483 |
一般來說應該設置: max_execution_time/statement timeout < Tranction Timeout < socketTimeout
SocketTimeout
這個 httpclient 的bug 就是在 TCP 連接握手成功(只受ConnectTimeout影響,SocketTimeout還不起作用)後,還需要進行 SSL的數據交換(HandShake),但因為httpclient是在連接建立後(含 SSL HandShake)才設置的 SocketTimeout,導致在SSL HandShake的時候卡在了讀數據,此時恰好還沒設置SocketTimeout,導致連接永久卡死在SSL HandShake的讀數據
所以代碼的fix方案就是在建連接前就設置好 SocketTimeout。
一次PreparedStatement 執行
useServerPrepStmts=true&cachePrepStmts=true
5.0.5版本後的驅動 useServerPrepStmts 預設值是false;另外跨Statement是沒法重用PreparedStatement預編譯的,還需要設置 cachePrepStmts 才可以。
對於打開預編譯的URL(String url = “jdbc:mysql://localhost:3306/studb?useServerPrepStmts=true&cachePrepStmts=true“)獲取資料庫連接之後,本質是獲取預編譯語句 pstmt = conn.prepareStatement(sql)時會向MySQL服務端發送一個RPC,發送一個預編譯的SQL模板(驅動會拼接MySQL預編譯語句prepare s1 from ‘select from user where id = ?’),然會MySQL服務端會編譯好收到的SQL模板,再會為此預編譯模板語句分配一個 serverStatementId發送給JDBC驅動,這樣以後PreparedStatement就會持有當前預編譯語句的服務端的serverStatementId,並且會把此 PreparedStatement緩存在當前資料庫連接中,以後對於相同SQL模板的操作 pstmt.executeUpdate(),都用相同的PreparedStatement,執行SQL時只需要發送 serverStatementId *和參數,節省一次SQL編譯, 直接執行。並且對於每一個連接(驅動端及MySQL服務端)都有自己的prepare cache,具體的源碼實現是在com.mysql.jdbc.ServerPreparedStatement中實現。
根據SQL模板和設置的參數,解析成一條完整的SQL語句,最後根據MySQL協議,序列化成位元組流,RPC發送給MySQL服務端
1 2 | // 解析封裝需要發送的SQL語句,序列化成MySQL協議對應的位元組流 Buffer sendPacket = fillSendPacket(); |
準備好需要發送的MySQL協議的位元組流(sendPacket)後,就可以一路通過ConnectionImpl.execSQL –> MysqlIO.sqlQueryDirect –> MysqlIO.send – > OutPutStram.write把位元組流數據通過Socket發送給MySQL伺服器,然後線程阻塞等待服務端返回結果數據,拿到數據後再根據MySQL協議反序列化成我們熟悉的ResultSet對象。
案例
設置JDBC參數不合理(不設置的話預設值是:queryTimeout=10s,socketTimeout=10s),會導致在異常情況下,第二條get獲得了第一條的結果,拿到了錯誤的數據,資料庫則表現正常
socketTimeout觸發後,連接拋CommunicationsException(嚴重異常,觸發後連接應該斷開), 但JDBC會檢查請求是否被cancle了,如果cancle就會拋出MySQLTimeoutException異常,這是一個普通異常,連接會被重新放回連接池重用(導致下一個獲取這個連接的線程可能會得到前一個請求的response)。
queryTimeout(queryTimeoutKillsConnection=True–來強制關閉連接)會觸發啟動一個新的連接向server發送 kill id的命令,MySQL5.7增加了max_statement_time/max_execution_time來做到在server上直接檢測到這種查詢,然後結束掉。
jdbc 和 RDS之間 socket_timeout
jdbc驅動設置socketTimeout=1459,如果是socketTimeout觸發客戶端斷開後,server端的SQL會繼續執行,如果是client被kill則server端的SQL會被終止
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # java -cp /home/admin/drds-server/lib/*:. Test "jdbc:mysql://172.16.40.215:3008/bank_000000?socketTimeout=1459" "user" "pass" "select sleep(2)" "1" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 1,461 milliseconds ago. The last packet sent successfully to the server was 1,461 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3749) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3649) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4090) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2658) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2811) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2806) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2764) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1399) at Test.main(Test.java:29) Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:171) at java.net.SocketInputStream.read(SocketInputStream.java:141) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3183) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3659) ... 8 more 或者開協程後的錯誤堆棧 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 1,460 milliseconds ago. The last packet sent successfully to the server was 1,459 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3749) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3649) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4090) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2658) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2811) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2806) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2764) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1399) at Test.main(Test.java:29) Caused by: java.net.SocketTimeoutException: time out at sun.nio.ch.WispSocketImpl$1$1.read0(WispSocketImpl.java:244) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:208) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:201) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3183) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3659) ... 8 more |
對應抓包,沒有 kill動作
CN 和 DN 間socket_timeout案例
設置CN到DN的socket_timeout為2秒,然後執行一個sleep
CN上抓包分析(stream 5是客戶端到CN、stream6是CN到DN)如下,首先CN會計時2秒鐘後發送quit給DN,然後斷開和DN的連接,並返回一個錯誤給client,client發送quit斷開連接:
CN完整報錯堆棧:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | 2022-06-01 12:10:00.178 [ServerExecutor-bucket-2-19-thread-181] ERROR com.alibaba.druid.pool.DruidPooledStatement - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] CommunicationsException, druid version 1.1.24, jdbcUrl : jdbc:mysql://172.16.40.215:3008/bank_000000?maintainTimeStats=false&rewriteBatchedStatements=false&failOverReadOnly=false&cacheResultSetMetadata=true&allowMultiQueries=true&clobberStreamingResults=true&autoReconnect=false&usePsMemOptimize=true&useServerPrepStmts=true&netTimeoutForStreamingResults=0&useSSL=false&metadataCacheSize=256&readOnlyPropagatesToServer=false&prepStmtCacheSqlLimit=4096&connectTimeout=5000&socketTimeout=9000000&cachePrepStmts=true&characterEncoding=utf8&prepStmtCacheSize=256, testWhileIdle true, idle millis 11861, minIdle 5, poolingCount 4, timeBetweenEvictionRunsMillis 60000, lastValidIdleMillis 11861, driver com.mysql.jdbc.Driver, exceptionSorter com.alibaba.polardbx.common.jdbc.sorter.MySQLExceptionSorter 2022-06-01 12:10:00.179 [ServerExecutor-bucket-2-19-thread-181] ERROR com.alibaba.druid.pool.DruidDataSource - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] discard connection com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure at sun.reflect.GeneratedConstructorAccessor72.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3749) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3649) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4090) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2658) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1281) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:782) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1367) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) at com.alibaba.polardbx.group.jdbc.TGroupDirectPreparedStatement.execute(TGroupDirectPreparedStatement.java:84) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQueryInner(MyJdbcHandler.java:1133) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQuery(MyJdbcHandler.java:990) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.doInit(MyPhyQueryCursor.java:83) at com.alibaba.polardbx.executor.cursor.AbstractCursor.init(AbstractCursor.java:53) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.<init>(MyPhyQueryCursor.java:67) at com.alibaba.polardbx.repo.mysql.spi.CursorFactoryMyImpl.repoCursor(CursorFactoryMyImpl.java:42) at com.alibaba.polardbx.repo.mysql.handler.MyPhyQueryHandler.handle(MyPhyQueryHandler.java:24) at com.alibaba.polardbx.executor.handler.HandlerCommon.handlePlan(HandlerCommon.java:102) at com.alibaba.polardbx.executor.AbstractGroupExecutor.executeInner(AbstractGroupExecutor.java:58) at com.alibaba.polardbx.executor.AbstractGroupExecutor.execByExecPlanNode(AbstractGroupExecutor.java:36) at com.alibaba.polardbx.executor.TopologyExecutor.execByExecPlanNode(TopologyExecutor.java:34) at com.alibaba.polardbx.transaction.TransactionExecutor.execByExecPlanNode(TransactionExecutor.java:120) at com.alibaba.polardbx.executor.ExecutorHelper.executeByCursor(ExecutorHelper.java:155) at com.alibaba.polardbx.executor.ExecutorHelper.execute(ExecutorHelper.java:70) at com.alibaba.polardbx.executor.PlanExecutor.execByExecPlanNodeByOne(PlanExecutor.java:130) at com.alibaba.polardbx.executor.PlanExecutor.execute(PlanExecutor.java:75) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeQuery(TConnection.java:682) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeSQL(TConnection.java:457) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.executeSQL(TPreparedStatement.java:65) at com.alibaba.polardbx.matrix.jdbc.TStatement.executeInternal(TStatement.java:133) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.execute(TPreparedStatement.java:50) at com.alibaba.polardbx.server.ServerConnection.innerExecute(ServerConnection.java:1131) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:883) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:850) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:844) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:82) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:31) at com.alibaba.polardbx.server.ServerQueryHandler.executeSql(ServerQueryHandler.java:155) at com.alibaba.polardbx.server.ServerQueryHandler.executeStatement(ServerQueryHandler.java:133) at com.alibaba.polardbx.server.ServerQueryHandler.queryRaw(ServerQueryHandler.java:118) at com.alibaba.polardbx.net.FrontendConnection.query(FrontendConnection.java:460) at com.alibaba.polardbx.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:49) at com.alibaba.polardbx.net.FrontendConnection.lambda$handleData$0(FrontendConnection.java:753) at com.alibaba.polardbx.common.utils.thread.RunnableWithCpuCollector.run(RunnableWithCpuCollector.java:36) at com.alibaba.polardbx.common.utils.thread.ServerThreadPool$RunnableAdapter.run(ServerThreadPool.java:793) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:874) at com.alibaba.wisp.engine.WispTask.runOutsideWisp(WispTask.java:277) at com.alibaba.wisp.engine.WispTask.runCommand(WispTask.java:252) at com.alibaba.wisp.engine.WispTask.access$100(WispTask.java:33) at com.alibaba.wisp.engine.WispTask$CacheableCoroutine.run(WispTask.java:223) at java.dyn.CoroutineBase.startInternal(CoroutineBase.java:60) Caused by: java.net.SocketTimeoutException: time out at sun.nio.ch.WispSocketImpl$1$1.read0(WispSocketImpl.java:244) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:208) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:201) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3183) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3659) ... 53 common frames omitted 2022-06-01 12:10:00.179 [ServerExecutor-bucket-2-19-thread-181] WARN com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] [TDDL] [1461cdf8b2809000]Execute ERROR on GROUP: BANK_000000_GROUP, ATOM: dskey_bank_000000_group#pxc-xdb-s-pxcunrcbmk4g9lcpk0f24#172.16.40.215-3008#bank_000000, MERGE_UNION_SIZE:1, SQL: /*DRDS /10.101.32.6/1461cdf8b2809000/0// */SELECT SLEEP(?) AS `sleep(236)`, PARAM: [236], ERROR: Communications link failure, tddl version: 5.4.13-16522656 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure at sun.reflect.GeneratedConstructorAccessor72.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3749) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3649) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4090) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2658) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1281) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:782) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1367) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) at com.alibaba.polardbx.group.jdbc.TGroupDirectPreparedStatement.execute(TGroupDirectPreparedStatement.java:84) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQueryInner(MyJdbcHandler.java:1133) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQuery(MyJdbcHandler.java:990) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.doInit(MyPhyQueryCursor.java:83) at com.alibaba.polardbx.executor.cursor.AbstractCursor.init(AbstractCursor.java:53) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.<init>(MyPhyQueryCursor.java:67) at com.alibaba.polardbx.repo.mysql.spi.CursorFactoryMyImpl.repoCursor(CursorFactoryMyImpl.java:42) at com.alibaba.polardbx.repo.mysql.handler.MyPhyQueryHandler.handle(MyPhyQueryHandler.java:24) at com.alibaba.polardbx.executor.handler.HandlerCommon.handlePlan(HandlerCommon.java:102) at com.alibaba.polardbx.executor.AbstractGroupExecutor.executeInner(AbstractGroupExecutor.java:58) at com.alibaba.polardbx.executor.AbstractGroupExecutor.execByExecPlanNode(AbstractGroupExecutor.java:36) at com.alibaba.polardbx.executor.TopologyExecutor.execByExecPlanNode(TopologyExecutor.java:34) at com.alibaba.polardbx.transaction.TransactionExecutor.execByExecPlanNode(TransactionExecutor.java:120) at com.alibaba.polardbx.executor.ExecutorHelper.executeByCursor(ExecutorHelper.java:155) at com.alibaba.polardbx.executor.ExecutorHelper.execute(ExecutorHelper.java:70) at com.alibaba.polardbx.executor.PlanExecutor.execByExecPlanNodeByOne(PlanExecutor.java:130) at com.alibaba.polardbx.executor.PlanExecutor.execute(PlanExecutor.java:75) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeQuery(TConnection.java:682) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeSQL(TConnection.java:457) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.executeSQL(TPreparedStatement.java:65) at com.alibaba.polardbx.matrix.jdbc.TStatement.executeInternal(TStatement.java:133) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.execute(TPreparedStatement.java:50) at com.alibaba.polardbx.server.ServerConnection.innerExecute(ServerConnection.java:1131) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:883) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:850) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:844) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:82) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:31) at com.alibaba.polardbx.server.ServerQueryHandler.executeSql(ServerQueryHandler.java:155) at com.alibaba.polardbx.server.ServerQueryHandler.executeStatement(ServerQueryHandler.java:133) at com.alibaba.polardbx.server.ServerQueryHandler.queryRaw(ServerQueryHandler.java:118) at com.alibaba.polardbx.net.FrontendConnection.query(FrontendConnection.java:460) at com.alibaba.polardbx.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:49) at com.alibaba.polardbx.net.FrontendConnection.lambda$handleData$0(FrontendConnection.java:753) at com.alibaba.polardbx.common.utils.thread.RunnableWithCpuCollector.run(RunnableWithCpuCollector.java:36) at com.alibaba.polardbx.common.utils.thread.ServerThreadPool$RunnableAdapter.run(ServerThreadPool.java:793) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:874) at com.alibaba.wisp.engine.WispTask.runOutsideWisp(WispTask.java:277) at com.alibaba.wisp.engine.WispTask.runCommand(WispTask.java:252) at com.alibaba.wisp.engine.WispTask.access$100(WispTask.java:33) at com.alibaba.wisp.engine.WispTask$CacheableCoroutine.run(WispTask.java:223) at java.dyn.CoroutineBase.startInternal(CoroutineBase.java:60) Caused by: java.net.SocketTimeoutException: time out at sun.nio.ch.WispSocketImpl$1$1.read0(WispSocketImpl.java:244) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:208) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:201) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3183) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3659) ... 53 common frames omitted 2022-06-01 12:10:00.179 [ServerExecutor-bucket-2-19-thread-181] WARN com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] [TDDL] Reset conn socketTimeout failed, lastSocketTimeout is 9000000, tddl version: 5.4.13-16522656 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1326) at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1321) at com.mysql.jdbc.ConnectionImpl.setNetworkTimeout(ConnectionImpl.java:5888) at com.alibaba.polardbx.atom.utils.NetworkUtils.setNetworkTimeout(NetworkUtils.java:18) at com.alibaba.polardbx.group.jdbc.TGroupDirectConnection.setNetworkTimeout(TGroupDirectConnection.java:433) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.resetPhyConnSocketTimeout(MyJdbcHandler.java:721) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQueryInner(MyJdbcHandler.java:1173) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQuery(MyJdbcHandler.java:990) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.doInit(MyPhyQueryCursor.java:83) at com.alibaba.polardbx.executor.cursor.AbstractCursor.init(AbstractCursor.java:53) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.<init>(MyPhyQueryCursor.java:67) at com.alibaba.polardbx.repo.mysql.spi.CursorFactoryMyImpl.repoCursor(CursorFactoryMyImpl.java:42) at com.alibaba.polardbx.repo.mysql.handler.MyPhyQueryHandler.handle(MyPhyQueryHandler.java:24) at com.alibaba.polardbx.executor.handler.HandlerCommon.handlePlan(HandlerCommon.java:102) at com.alibaba.polardbx.executor.AbstractGroupExecutor.executeInner(AbstractGroupExecutor.java:58) at com.alibaba.polardbx.executor.AbstractGroupExecutor.execByExecPlanNode(AbstractGroupExecutor.java:36) at com.alibaba.polardbx.executor.TopologyExecutor.execByExecPlanNode(TopologyExecutor.java:34) at com.alibaba.polardbx.transaction.TransactionExecutor.execByExecPlanNode(TransactionExecutor.java:120) at com.alibaba.polardbx.executor.ExecutorHelper.executeByCursor(ExecutorHelper.java:155) at com.alibaba.polardbx.executor.ExecutorHelper.execute(ExecutorHelper.java:70) at com.alibaba.polardbx.executor.PlanExecutor.execByExecPlanNodeByOne(PlanExecutor.java:130) at com.alibaba.polardbx.executor.PlanExecutor.execute(PlanExecutor.java:75) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeQuery(TConnection.java:682) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeSQL(TConnection.java:457) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.executeSQL(TPreparedStatement.java:65) at com.alibaba.polardbx.matrix.jdbc.TStatement.executeInternal(TStatement.java:133) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.execute(TPreparedStatement.java:50) at com.alibaba.polardbx.server.ServerConnection.innerExecute(ServerConnection.java:1131) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:883) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:850) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:844) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:82) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:31) at com.alibaba.polardbx.server.ServerQueryHandler.executeSql(ServerQueryHandler.java:155) at com.alibaba.polardbx.server.ServerQueryHandler.executeStatement(ServerQueryHandler.java:133) at com.alibaba.polardbx.server.ServerQueryHandler.queryRaw(ServerQueryHandler.java:118) at com.alibaba.polardbx.net.FrontendConnection.query(FrontendConnection.java:460) at com.alibaba.polardbx.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:49) at com.alibaba.polardbx.net.FrontendConnection.lambda$handleData$0(FrontendConnection.java:753) at com.alibaba.polardbx.common.utils.thread.RunnableWithCpuCollector.run(RunnableWithCpuCollector.java:36) at com.alibaba.polardbx.common.utils.thread.ServerThreadPool$RunnableAdapter.run(ServerThreadPool.java:793) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:874) at com.alibaba.wisp.engine.WispTask.runOutsideWisp(WispTask.java:277) at com.alibaba.wisp.engine.WispTask.runCommand(WispTask.java:252) at com.alibaba.wisp.engine.WispTask.access$100(WispTask.java:33) at com.alibaba.wisp.engine.WispTask$CacheableCoroutine.run(WispTask.java:223) at java.dyn.CoroutineBase.startInternal(CoroutineBase.java:60) 2022-06-01 12:10:00.179 [ServerExecutor-bucket-2-19-thread-181] WARN com.alibaba.polardbx.executor.ExecutorHelper - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] [TDDL] PhyQuery(node="BANK_000000_GROUP", sql="SELECT SLEEP(?) AS `sleep(236)`") , tddl version: 5.4.13-16522656 2022-06-01 12:10:00.180 [ServerExecutor-bucket-2-19-thread-181] WARN com.alibaba.polardbx.server.ServerConnection - [user=polardbx_root,host=10.101.32.6,port=43947,schema=bank] [TDDL] [ERROR-CODE: 3009][1461cdf8b2809000] SQL: /*+TDDL:node(0) and SOCKET_TIMEOUT=2000 */ select sleep(236), tddl version: 5.4.13-16522656 com.alibaba.polardbx.common.exception.TddlRuntimeException: ERR-CODE: [TDDL-4614][ERR_EXECUTE_ON_MYSQL] Error occurs when execute on GROUP 'BANK_000000_GROUP' ATOM 'dskey_bank_000000_group#pxc-xdb-s-pxcunrcbmk4g9lcpk0f24#172.16.40.215-3008#bank_000000': Communications link failure at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.handleException(MyJdbcHandler.java:1935) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.generalHandlerException(MyJdbcHandler.java:1911) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQueryInner(MyJdbcHandler.java:1168) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQuery(MyJdbcHandler.java:990) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.doInit(MyPhyQueryCursor.java:83) at com.alibaba.polardbx.executor.cursor.AbstractCursor.init(AbstractCursor.java:53) at com.alibaba.polardbx.repo.mysql.spi.MyPhyQueryCursor.<init>(MyPhyQueryCursor.java:67) at com.alibaba.polardbx.repo.mysql.spi.CursorFactoryMyImpl.repoCursor(CursorFactoryMyImpl.java:42) at com.alibaba.polardbx.repo.mysql.handler.MyPhyQueryHandler.handle(MyPhyQueryHandler.java:24) at com.alibaba.polardbx.executor.handler.HandlerCommon.handlePlan(HandlerCommon.java:102) at com.alibaba.polardbx.executor.AbstractGroupExecutor.executeInner(AbstractGroupExecutor.java:58) at com.alibaba.polardbx.executor.AbstractGroupExecutor.execByExecPlanNode(AbstractGroupExecutor.java:36) at com.alibaba.polardbx.executor.TopologyExecutor.execByExecPlanNode(TopologyExecutor.java:34) at com.alibaba.polardbx.transaction.TransactionExecutor.execByExecPlanNode(TransactionExecutor.java:120) at com.alibaba.polardbx.executor.ExecutorHelper.executeByCursor(ExecutorHelper.java:155) at com.alibaba.polardbx.executor.ExecutorHelper.execute(ExecutorHelper.java:70) at com.alibaba.polardbx.executor.PlanExecutor.execByExecPlanNodeByOne(PlanExecutor.java:130) at com.alibaba.polardbx.executor.PlanExecutor.execute(PlanExecutor.java:75) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeQuery(TConnection.java:682) at com.alibaba.polardbx.matrix.jdbc.TConnection.executeSQL(TConnection.java:457) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.executeSQL(TPreparedStatement.java:65) at com.alibaba.polardbx.matrix.jdbc.TStatement.executeInternal(TStatement.java:133) at com.alibaba.polardbx.matrix.jdbc.TPreparedStatement.execute(TPreparedStatement.java:50) at com.alibaba.polardbx.server.ServerConnection.innerExecute(ServerConnection.java:1131) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:883) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:850) at com.alibaba.polardbx.server.ServerConnection.execute(ServerConnection.java:844) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:82) at com.alibaba.polardbx.server.handler.SelectHandler.handle(SelectHandler.java:31) at com.alibaba.polardbx.server.ServerQueryHandler.executeSql(ServerQueryHandler.java:155) at com.alibaba.polardbx.server.ServerQueryHandler.executeStatement(ServerQueryHandler.java:133) at com.alibaba.polardbx.server.ServerQueryHandler.queryRaw(ServerQueryHandler.java:118) at com.alibaba.polardbx.net.FrontendConnection.query(FrontendConnection.java:460) at com.alibaba.polardbx.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:49) at com.alibaba.polardbx.net.FrontendConnection.lambda$handleData$0(FrontendConnection.java:753) at com.alibaba.polardbx.common.utils.thread.RunnableWithCpuCollector.run(RunnableWithCpuCollector.java:36) at com.alibaba.polardbx.common.utils.thread.ServerThreadPool$RunnableAdapter.run(ServerThreadPool.java:793) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:874) at com.alibaba.wisp.engine.WispTask.runOutsideWisp(WispTask.java:277) at com.alibaba.wisp.engine.WispTask.runCommand(WispTask.java:252) at com.alibaba.wisp.engine.WispTask.access$100(WispTask.java:33) at com.alibaba.wisp.engine.WispTask$CacheableCoroutine.run(WispTask.java:223) at java.dyn.CoroutineBase.startInternal(CoroutineBase.java:60) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure at sun.reflect.GeneratedConstructorAccessor72.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3749) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3649) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4090) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2658) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1281) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:782) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1367) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) at com.alibaba.polardbx.group.jdbc.TGroupDirectPreparedStatement.execute(TGroupDirectPreparedStatement.java:84) at com.alibaba.polardbx.repo.mysql.spi.MyJdbcHandler.executeQueryInner(MyJdbcHandler.java:1133) ... 44 common frames omitted Caused by: java.net.SocketTimeoutException: time out at sun.nio.ch.WispSocketImpl$1$1.read0(WispSocketImpl.java:244) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:208) at sun.nio.ch.WispSocketImpl$1$1.read(WispSocketImpl.java:201) at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101) at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144) at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174) at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3183) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3659) ... 53 common frames omitted |
應用和 DB 間丟包導致 keepalive 心跳失敗
應用使用了 Druid 連接池來維護到 DB 間的所有長連接
應用和 DB 間丟包導致 keepalive 心跳失敗,進而 OS會斷開這個連接
一個連接歸還給Druid連接池都要做清理動作,就是第一個紅框的rollback/autocommit=1
歸還後OS 層面會探活TCP 連接,DB(4381)多次後多次不響應後,OS 觸發reset tcp斷開連接,此時上次應用(比如Druid連接池、比如Tomcat)還不知道此連接在OS 層面已經斷開
1 2 3 4 | #sysctl -a |grep -i keepalive net.ipv4.tcp_keepalive_intvl = 3 net.ipv4.tcp_keepalive_probes = 60 net.ipv4.tcp_keepalive_time = 20 |
繼續過來一個新連接,業務取到這個連接執行查詢就會報如下錯誤:
1 2 3 4 5 6 7 | com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 162,776 milliseconds ago. The last packet sent successfully to the server was 162,776 milliseconds ago. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 162,776 milliseconds ago. The last packet sent successfully to the server was 162,776 milliseconds ago. |
這個錯誤就是因為OS層面連接斷開了,並且斷開了162秒(和截圖時間戳能對應上)
對應的錯誤堆棧:
1 2 3 4 5 6 7 8 | Caused by: java.net.SocketException: Connection timed out (Write failed) at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) at java.net.SocketOutputStream.write(SocketOutputStream.java:155) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3725) ... 46 common frames omitted |
kill 案例
kill mysql client
mysql client連cn執行一個很慢的SQL,然後kill掉mysql client
cn報錯: