Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix][zeta] Fix the deadlock issue with JDBC driver loading #4878

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public HikariDataSource createPooledDataSource(JdbcSourceConfig sourceConfig) {
config.setMaximumPoolSize(sourceConfig.getConnectionPoolSize());
config.setConnectionTimeout(sourceConfig.getConnectTimeoutMillis());
config.addDataSourceProperty(SERVER_TIMEZONE_KEY, sourceConfig.getServerTimeZone());
config.setDriverClassName(sourceConfig.getDriverClassName());

// optional optimization configurations for pooled DataSource
config.addDataSourceProperty("cachePrepStmts", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.common.utils.JdbcUrlUtil;
import org.apache.seatunnel.common.utils.SeaTunnelException;
import org.apache.seatunnel.connectors.cdc.base.config.JdbcSourceConfig;
import org.apache.seatunnel.connectors.cdc.base.config.SourceConfig;
import org.apache.seatunnel.connectors.cdc.base.dialect.DataSourceDialect;
Expand Down Expand Up @@ -111,12 +112,16 @@ public DebeziumDeserializationSchema<T> createDebeziumDeserializationSchema(
(SqlServerSourceConfig) this.configFactory.create(0);
TableId tableId =
this.dataSourceDialect.discoverDataCollections(sqlServerSourceConfig).get(0);
SqlServerConnection sqlServerConnection =
createSqlServerConnection(sqlServerSourceConfig.getDbzConfiguration());
Table table =
((SqlServerDialect) dataSourceDialect)
.queryTableSchema(sqlServerConnection, tableId)
.getTable();
Table table;
try (SqlServerConnection sqlServerConnection =
createSqlServerConnection(sqlServerSourceConfig.getDbzConfiguration())) {
table =
((SqlServerDialect) dataSourceDialect)
.queryTableSchema(sqlServerConnection, tableId)
.getTable();
} catch (Exception e) {
throw new SeaTunnelException(e);
}
physicalRowType = convertFromTable(table);
} else {
physicalRowType = dataType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ public class SimpleJdbcConnectionProvider implements JdbcConnectionProvider, Ser
private transient Driver loadedDriver;
private transient Connection connection;

static {
// Load DriverManager first to avoid deadlock between DriverManager's
// static initialization block and specific driver class's static
// initialization block when two different driver classes are loading
// concurrently using Class.forName while DriverManager is uninitialized
// before.
//
// This could happen in JDK 8 but not above as driver loading has been
// moved out of DriverManager's static initialization block since JDK 9.
DriverManager.getDrivers();
}

public SimpleJdbcConnectionProvider(@NonNull JdbcConnectionConfig jdbcConfig) {
this.jdbcConfig = jdbcConfig;
}
Expand Down