NuGet 패키지 Polly을 사용하여 장애 조치 (failover) SQL 예외를 트랩하는 재시도 논리를 구현하고 있습니다. Azure에서 SQL Server Always On High Availability를 설정했습니다.트랩 SQL 장애 조치 예외
모든 SQL 예외 (올바르지 않은)를 트랩하는 것이 아니라 장애 조치가 발생할 때 발생하는 특정 SQL 예외를 트랩하려고합니다.
SSMS에서 대시 보드를 보여준 다음 장애 조치를 인위적으로 트리거하여 내 코드를 테스트 할 수있었습니다. 처음에는 모든 예외가 버블 링되도록했습니다 (트래핑 없음). 그런 다음 장애 조치를 대기시키고 내 로그에서 SQL 예외가 발생했는지 확인합니다. 결과적으로 장애 조치로 인해 발생한 모든 SQL 예외를 잡을 수있게되었습니다.
제 질문은 포괄적 인 목록입니까? SQL Server Failover에서 재시도 논리를 구현 한 다른 사람들이 다른 SQL 예외를 잡아 두는가?
로직을 100 회 이상 페일 오버하려고 시도했지만 아무 것도 버블 링하지 않았습니다. 그렇다고해서 Failover SQL Exception 전체를 포착 한 것은 아닙니다.
재시도 논리에는 Policy.Handle (se => IsFailoverSqlException (se))이 있습니다. 장애 조치가 대기중인 코드의 위치에 따라 아래에 트랩하는 세 가지 SQL 예외가 표시됩니다.
private static bool IsFailoverSqlException(SqlException se)
{
return (
/*
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
*/
(se.Class == 20 && se.State == 0 && se.Number == 53) ||
/*
Failed while logging Fatal to MT Database: Unable to access availability database 'MedicusMT' because the database replica is not in the PRIMARY or SECONDARY role.
Connections to an availability database is permitted only when the database replica is in the PRIMARY or SECONDARY role.
Try the operation again later.
*/
(se.Class == 14 && se.State == 1 && se.Number == 983) ||
// A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)
(se.Class == 20 && se.State == 0 && se.Number == -1)
);
}