|
| 1 | +/* |
| 2 | + * Copyright Debezium Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 |
| 5 | + */ |
| 6 | +package io.debezium.connector.sqlserver; |
| 7 | + |
| 8 | +import io.debezium.connector.base.ChangeEventQueue; |
| 9 | +import io.debezium.pipeline.ErrorHandler; |
| 10 | + |
| 11 | +/** |
| 12 | + * Error handler for SQL Server. |
| 13 | + * |
| 14 | + * @author Chris Cranford |
| 15 | + */ |
| 16 | +public class SqlServerErrorHandler extends ErrorHandler { |
| 17 | + // This class is copied from debezium. driverClassLoader variable is added to the |
| 18 | + // original class. This class loader is the jdbc plugin class loader and is required |
| 19 | + // to load the SQLServerException class from the user uploaded jdbc jar rather than looking |
| 20 | + // into the debezium connector jar. |
| 21 | + public static ClassLoader driverClassLoader; |
| 22 | + public SqlServerErrorHandler(String logicalName, ChangeEventQueue<?> queue) { |
| 23 | + super(SqlServerConnector.class, logicalName, queue); |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + protected boolean isRetriable(Throwable throwable) { |
| 28 | + try { |
| 29 | + Class<?> sqlServerExceptionClass = driverClassLoader.loadClass("com.microsoft.sqlserver.jdbc.SQLServerException"); |
| 30 | + return sqlServerExceptionClass.isInstance(throwable) |
| 31 | + && (throwable.getMessage().contains("Connection timed out (Read failed)") |
| 32 | + || throwable.getMessage().contains("The connection has been closed.") |
| 33 | + || throwable.getMessage().contains("Connection reset") |
| 34 | + || throwable.getMessage().contains("SHUTDOWN is in progress")); |
| 35 | + |
| 36 | + } catch (ClassNotFoundException e) { |
| 37 | + throw new RuntimeException("Failed to load the SQLServerException class.", e); |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments