programing

MariaDB 커넥터 J: autoReconnect가 기본 페일오버에 대해 작동하지 않음

iphone6s 2023. 8. 10. 18:35
반응형

MariaDB 커넥터 J: autoReconnect가 기본 페일오버에 대해 작동하지 않음

autoReconnect 옵션에 대한 https://mariadb.com/kb/en/library/about-mariadb-connector-j/, 에서 페일오버 및 로드 밸런싱 모드를 사용하지 않을 때 이 매개 변수를 사용하도록 설정하면 커넥터는 장애가 발생한 후 호스트에 다시 연결을 시도하기만 합니다.이를 기본 페일오버라고 합니다.

하지만 문제는 서버 장애 후 다시 연결이 되지 않는다는 것입니다.테스트 코드는 다음과 같습니다.

@Test
public void waitTimeoutResultSetTest() throws SQLException, InterruptedException {

    try (Connection connection = setBlankConnection("&autoReconnect=true")) {
        Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT 1");
    assertTrue(rs.next());

    stmt.execute("set session wait_timeout=1");

    Thread.sleep(3000); // Wait for the server to kill the connection

    try {
       rs = stmt.executeQuery("show databases;");
       assertTrue(rs.next());

       System.out.println("position 1");
    } catch (SQLException e) {
      //normal exception
      System.out.println("position 2");
    }
    }
}

autoReconnect를 사용하면 예상 결과는 위치 1에 도달하지만 실제로는 위치 2에 도달합니다. 단, "peer에 의해 연결 재설정: 소켓 쓰기 오류"는 예외입니다.

제 질문은 기본 페일오버가 작동하지 않는지, 아니면 제 테스트 코드가 잘못되었는지 여부입니다.웹에서 다른 정보를 찾을 수가 없는데, 혹시 알고 계신다면 설명해주실 수 있나요?

언급URL : https://stackoverflow.com/questions/55758122/mariadb-connector-j-autoreconnect-does-not-wok-for-basic-faillover

반응형