2012-09-09 2 views
2

에서 내가 이동 경로 1.5 mysql Ver 14.14 Distrib 5.1.52, for unknown-linux-gnu (x86_64) using readline 5.1연결 시간 초과 이동 경로

를 사용하고 난 다음 마이그레이션을 썼다 : table1가 작고 table2가 283,018 행이

alter table table1 add column col_11 blob; 
alter table table1 add column col_12 varchar(255) DEFAULT NULL; 

alter table table2 add column col_21 blob; 
alter table table2 add column col_22 varchar(255) DEFAULT NULL; 

.

마이그레이션이 성공했지만 (열이 table1table2에 모두 추가되었지만 버전 업데이트에 실패했습니다 (com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.).

my.cnf 파일이 다음 줄 wait_timeout=30을 보유하고 내가 무슨 일하는 table2이 두 열을 추가하는 것은 이상 wait_timout 걸렸다라고 생각 - "실패"마이그레이션 - 지금은이 상황을을 : 마이그레이션이 성공했지만 버전은 업데이트되지 않습니다. 그러나 나는이 SQL 쿼리 실행 :

show variables like "%timeout%"; 

을 그리고이있어 :

wait_timeout은 약 8 시간이다 제안
+----------------------------+-------+ 
| Variable_name    | Value | 
+----------------------------+-------+ 
| connect_timeout   | 10 | 
| delayed_insert_timeout  | 300 | 
| innodb_lock_wait_timeout | 50 | 
| innodb_rollback_on_timeout | OFF | 
| interactive_timeout  | 28800 | 
| net_read_timeout   | 30 | 
| net_write_timeout   | 60 | 
| slave_net_timeout   | 3600 | 
| table_lock_wait_timeout | 50 | 
| wait_timeout    | 28800 | 
+----------------------------+-------+ 

...

그래서 내 질문에 입니다 왜이 연결 시간 초과가 발생합니까?

그리고 주로 어떻게 해결할 수 있습니까?

편집 : 앱과 데이터베이스 모두 동일한 컴퓨터에 있습니다.

Current schema version: 12.9.3 
Migrating to version 12.9.3.1 

Error while extracting database product name - falling back to empty error codes 
org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed. 
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:296) 
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:320) 
    at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:216) 
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:140) 
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:103) 
    at org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407) 
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:522) 
    at com.googlecode.flyway.core.metadatatable.MetaDataTable.insert(MetaDataTable.java:149) 
    at com.googlecode.flyway.core.migration.DbMigrator.applyMigration(DbMigrator.java:248) 
    at com.googlecode.flyway.core.migration.DbMigrator$1.doInTransaction(DbMigrator.java:148) 
    at com.googlecode.flyway.core.migration.DbMigrator$1.doInTransaction(DbMigrator.java:114) 
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128) 
    at com.googlecode.flyway.core.migration.DbMigrator.migrate(DbMigrator.java:113) 
    at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:619) 
    at com.googlecode.flyway.commandline.Main.main(Main.java:79) 
Caused by: 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:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.Util.getInstance(Util.java:386) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) 
    at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1205) 
    at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1197) 
    at com.mysql.jdbc.ConnectionImpl.getMetaData(ConnectionImpl.java:3061) 
    at com.mysql.jdbc.ConnectionImpl.getMetaData(ConnectionImpl.java:3056) 
    at org.springfra 
mework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:285) 
    ... 15 more 
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 
The last packet successfully received from the server was 654,699 milliseconds ago. The last packet sent successfully to the server was 17 milliseconds ago. 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3102) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666) 
    at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:512) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396) 
    ... 9 more 
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. 
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2552) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3002) 
    ... 18 more 
Application exception overridden by rollback exception 
org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [UPDATE schema_version SET current_version=0]; Communications link failure 
The last packet successfully received from the server was 654,699 milliseconds ago. The last packet sent successfully to the server was 17 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 
The last packet successfully received from the server was 654,699 milliseconds ago. The last packet sent successfully to the server was 17 milliseconds ago. 
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:97) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407) 
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:522) 
    at com.googlecode.flyway.core.metadatatable.MetaDataTable.insert(MetaDataTable.java:149) 
    at com.googlecode.flyway.core.migration.DbMigrator.applyMigration(DbMigrator.java:248) 
    at com.googlecode.flyway.core.migration.DbMigrator$1.doInTransaction(DbMigrator.java:148) 
    at com.googlecode.flyway.core.migration.DbMigrator$1.doInTransaction(DbMigrator.java:114) 
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128) 
    at com.googlecode.flyway.core.migration.DbMigrator.migrate(DbMigrator.java:113) 
    at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:619) 
    at com.googlecode.flyway.commandline.Main.main(Main.java:79) 
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 
The last packet successfully received from the server was 654,699 milliseconds ago. The last packet sent successfully to the server was 17 milliseconds ago. 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) 
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3102) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749) 
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666) 
    at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:512) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396) 
    ... 9 more 
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. 
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2552) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3002) 
    ... 18 more 
FlywayException: Migration failed ! 
Occured in com.googlecode.flyway.core.migration.DbMigrator in method migrate, line number 164 
Caused by java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. 
Occured in com.mysql.jdbc.MysqlIO in method readFully, line number 2552 

답변

1

분석의 비트 : 시작할 때 도구는 두 개의 새로운 연결을 생성하는 철새 이동 경로 명령 줄로

이 연결 실효 배제 할 수 여기에

전체 스택 추적입니다 .

Flyway는 먼저 메타 데이터 테이블에 대한 연결을 열고 잠급니다.

그런 다음 두 번째 연결을 열고 마이그레이션을 실행합니다. 나는이 단계가 매우 오래 걸린다 고 가정하고있다. (로그에서 + 11 분).

마이그레이션이 완료되면 두 번째 연결의 트랜잭션이 커밋되고 새 행이 첫 번째 연결을 통해 메타 데이터 테이블에 추가됩니다.

이것은 폭탄을 터뜨리는 곳입니다.하지만 통신은 있지만 연결 시간 초과 또는 잠금 시간 초과 예외는 아닙니다.

앱과 DB 사이의 일부 네트워크 장비 (라우터/스위치/프록시)가 비활성 연결을 끊을 수 있습니까?

+0

답장을 보내 주셔서 감사합니다. 먼저 앱과 DB가 동일한 컴퓨터 (로컬 호스트)에 있습니다. 따라서 내가 제안한 것이 문제인지는 모르겠지만 생각하지 않습니다. 여기에 또 다른 것이 있습니다 - c3p0을 응용 프로그램으로 사용했을 때 동일한 예외가 발생했습니다. – Noam

2

우리는이 문제에 직면하여 우리에게 효과가있는 해결책을 찾을 수있었습니다. 이동 경로가 최소한 두 개의 연결을 사용하는 것 같습니다. 하나는 schema_version 테이블을 잠그고 다른 하나는 실제로 변경을 실행하는 것입니다.이 문제는 변경자가 schema_version 테이블을 제한 시간 동안 연결하지 못하게 할만큼 오래 걸릴 때 발생합니다. 이 문제를 해결하는 가장 쉬운 방법은 MySQL wait_timeout을 비교적 큰 것으로 끌어 올리는 것입니다. 이 경우 480 분 (또는 28800 초)으로 설정합니다.

set global wait_timeout=28800; 
+0

플라이웨이 연결을 위해 mysql 시간 초과 값을 변경할 수 있습니까? 나는 그 자신을 할 수있는 방법을 찾지 못했습니다. – Rob

+0

또한 global wait_timeout 및 wait_timeout을 다른 값으로 설정할 수 있습니다. 나는 동일한 문제를 겪었고, 'SELECT @@ global.wait_timeout, @@ session.wait_timeout;'을했을 때 알아 냈다. Mine session.wait_timeout은 28800이고, global.wait_timeout은 600이었다. – Marcelo