programing

Aurora 페일오버로 인해 연결이 읽기 전용 상태로 유지됨

yellowcard 2023. 6. 4. 10:24
반응형

Aurora 페일오버로 인해 연결이 읽기 전용 상태로 유지됨

우리는 오로라 클러스터에서 MySQL을 사용하고 있습니다. 우리는 마스터와 슬레이브 두 가지 인스턴스가 있습니다.우리는 c3po 연결 풀 위에서 스프링 거래를 진행하고 있습니다.mariadb jdbc 드라이버(버전 2.2.3)를 사용하고 있습니다.

우리의 URL은 다음과 같습니다 - jdbc:dll:dll:myclaster-cluster.cluster-xxxxxx.us-east-1.rds.amazonaws.com:3306/db?rewriteBatchedStatements=true

페일오버를 테스트할 때마다 읽기 전용 연결을 사용하는 상태가 됩니다.

Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO a (a1, a2, a3, a4) VALUES (?, ?, ?, ?) on duplicate key update ]; SQL state [HY000]; error code [1290]; (conn=7) The MySQL server is running with the --read-only option so it cannot execute this statement; nested exception is java.sql.SQLException: (conn=7) The MySQL server is running with the --read-only option so it cannot execute this statement
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937)
    at com.persistence.impl.MyDao.insert(MyDao.java:52)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
    ... 1 common frames omitted
Caused by: java.sql.SQLException: (conn=7) The MySQL server is running with the --read-only option so it cannot execute this statement
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:198)
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:110)
    at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:228)
    at org.mariadb.jdbc.MariaDbPreparedStatementClient.executeInternal(MariaDbPreparedStatementClient.java:216)
    at org.mariadb.jdbc.MariaDbPreparedStatementClient.execute(MariaDbPreparedStatementClient.java:150)
    at org.mariadb.jdbc.MariaDbPreparedStatementClient.executeUpdate(MariaDbPreparedStatementClient.java:183)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:410)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:873)
    at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:866)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:629)
    ... 9 common frames omitted

어떻게 하면 드라이버가 마스터 인스턴스에만 연결을 반환하도록 할 수 있습니까?페일오버 시 오로라가 열려 있는 모든 연결을 강제로 닫을 수 있는 방법이 있습니까?

감사해요.

예외를 구현하여 문제를 해결했습니다.인터셉트에서 연결을 닫아서 풀에서 새 연결을 생성하도록 했습니다.

이 해결 방법은 mysql-connector-java 5.1.47과 관련이 있습니다.

@Override
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    if (sqlEx.getErrorCode() == READ_ONLY_ERROR_CODE) {
        log.warn("Got read only exception closing the connection {} ", sqlEx.getMessage());
        closeConnection(conn);
    }
    return sqlEx;
}

언급URL : https://stackoverflow.com/questions/49748908/aurora-failover-leaves-connections-open-as-read-only-state

반응형