From ee7c51f4de54709c07837295d644f3c033ab1a30 Mon Sep 17 00:00:00 2001 From: Viliam Durina Date: Wed, 14 Oct 2020 14:54:18 +0200 Subject: [PATCH] Fix JDBC driver initialization deadlock (#2604) Fixes #2603 --- .../src/main/java/com/hazelcast/jet/cdc/impl/CdcSource.java | 3 +++ .../java/com/hazelcast/jet/impl/MasterSnapshotContext.java | 2 +- .../main/java/com/hazelcast/jet/impl/connector/ReadJdbcP.java | 2 ++ .../main/java/com/hazelcast/jet/impl/connector/WriteJdbcP.java | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/extensions/cdc-debezium/src/main/java/com/hazelcast/jet/cdc/impl/CdcSource.java b/extensions/cdc-debezium/src/main/java/com/hazelcast/jet/cdc/impl/CdcSource.java index c6b0d7c875e..8e7dc079a2a 100644 --- a/extensions/cdc-debezium/src/main/java/com/hazelcast/jet/cdc/impl/CdcSource.java +++ b/extensions/cdc-debezium/src/main/java/com/hazelcast/jet/cdc/impl/CdcSource.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.sql.DriverManager; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -74,6 +75,8 @@ public abstract class CdcSource { private SourceTask task; CdcSource(Processor.Context context, Properties properties) { + // workaround for https://github.com/hazelcast/hazelcast-jet/issues/2603 + DriverManager.getDrivers(); this.logger = context.logger(); this.properties = properties; this.reconnectTracker = new RetryTracker(getRetryStrategy(properties)); diff --git a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/MasterSnapshotContext.java b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/MasterSnapshotContext.java index a3b2eb4e37d..912f1c1ca52 100644 --- a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/MasterSnapshotContext.java +++ b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/MasterSnapshotContext.java @@ -250,7 +250,7 @@ private void onSnapshotPhase1Complete( stats.duration(), stats.numBytes(), stats.numKeys(), stats.numChunks(), snapshotMapName)); } if (!isSuccess) { - logger.warning(mc.jobIdString() + " snapshot " + snapshotId + " failed on some member(s), " + + logger.warning(mc.jobIdString() + " snapshot " + snapshotId + " phase 1 failed on some member(s), " + "one of the failures: " + mergedResult.getError()); try { snapshotMap.clear(); diff --git a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/ReadJdbcP.java b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/ReadJdbcP.java index a1ee036f781..ae78d372fa5 100644 --- a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/ReadJdbcP.java +++ b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/ReadJdbcP.java @@ -107,6 +107,8 @@ public static ProcessorMetaSupplier supplier( @Override protected void init(@Nonnull Context context) { + // workaround for https://github.com/hazelcast/hazelcast-jet/issues/2603 + DriverManager.getDrivers(); this.connection = newConnectionFn.get(); this.parallelism = context.totalParallelism(); this.index = context.globalProcessorIndex(); diff --git a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/WriteJdbcP.java b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/WriteJdbcP.java index 603dceb1719..725b88b6aea 100644 --- a/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/WriteJdbcP.java +++ b/hazelcast-jet-core/src/main/java/com/hazelcast/jet/impl/connector/WriteJdbcP.java @@ -37,6 +37,7 @@ import javax.sql.XAConnection; import javax.sql.XADataSource; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.SQLNonTransientException; @@ -115,6 +116,8 @@ public Collection get(int count) { @Override public void init(@Nonnull Outbox outbox, @Nonnull Context context) throws Exception { super.init(outbox, context); + // workaround for https://github.com/hazelcast/hazelcast-jet/issues/2603 + DriverManager.getDrivers(); logger = context.logger(); connectAndPrepareStatement(); }