This is an automated email from the ASF dual-hosted git repository.
markap14 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new c1890a5bb8 NIFI-5501: Fixed classloader issue leading to multiple
abandoned threads (#7031)
c1890a5bb8 is described below
commit c1890a5bb813c64aca6c3c9684ceef01f43f9e86
Author: Matt Burgess <[email protected]>
AuthorDate: Fri Mar 10 15:37:32 2023 -0500
NIFI-5501: Fixed classloader issue leading to multiple abandoned threads
(#7031)
---
.../nifi/cdc/mysql/processors/CaptureChangeMySQL.java | 18 ++++--------------
.../cdc/mysql/processors/CaptureChangeMySQLTest.groovy | 3 ++-
2 files changed, 6 insertions(+), 15 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/main/java/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQL.java
b/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/main/java/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQL.java
index d2665fa231..0badd08aa8 100644
---
a/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/main/java/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQL.java
+++
b/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/main/java/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQL.java
@@ -29,6 +29,7 @@ import com.github.shyiko.mysql.binlog.network.SSLMode;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.annotation.behavior.InputRequirement;
import org.apache.nifi.annotation.behavior.PrimaryNodeOnly;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
import org.apache.nifi.annotation.behavior.Stateful;
import org.apache.nifi.annotation.behavior.TriggerSerially;
import org.apache.nifi.annotation.behavior.WritesAttribute;
@@ -92,13 +93,11 @@ import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.security.util.TlsConfiguration;
import org.apache.nifi.ssl.SSLContextService;
-import org.apache.nifi.util.file.classloader.ClassLoaderUtils;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
@@ -161,6 +160,7 @@ import static
org.apache.nifi.cdc.event.io.FlowFileEventWriteStrategy.MAX_EVENTS
@WritesAttribute(attribute = "mime.type", description = "The processor
outputs flow file content in JSON format, and sets the mime.type attribute to "
+ "application/json")
})
+@RequiresInstanceClassLoading
public class CaptureChangeMySQL extends AbstractSessionFactoryProcessor {
// Random invalid constant used as an indicator to not set the binlog
position on the client (thereby using the latest available)
@@ -257,6 +257,7 @@ public class CaptureChangeMySQL extends
AbstractSessionFactoryProcessor {
.required(false)
.identifiesExternalResource(ResourceCardinality.MULTIPLE,
ResourceType.FILE, ResourceType.DIRECTORY, ResourceType.URL)
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .dynamicallyModifiesClasspath(true)
.build();
public static final PropertyDescriptor USERNAME = new
PropertyDescriptor.Builder()
@@ -1403,16 +1404,7 @@ public class CaptureChangeMySQL extends
AbstractSessionFactoryProcessor {
protected void registerDriver(String locationString, String drvName)
throws InitializationException {
if (locationString != null && locationString.length() > 0) {
try {
- // Split and trim the entries
- final ClassLoader classLoader =
ClassLoaderUtils.getCustomClassLoader(
- locationString,
- this.getClass().getClassLoader(),
- (dir, name) -> name != null && name.endsWith(".jar")
- );
-
- // Workaround which allows to use URLClassLoader for JDBC
driver loading.
- // (Because the DriverManager will refuse to use a driver not
loaded by the system ClassLoader.)
- final Class<?> clazz = Class.forName(drvName, true,
classLoader);
+ final Class<?> clazz = Class.forName(drvName);
if (clazz == null) {
throw new InitializationException("Can't load Database
Driver " + drvName);
}
@@ -1421,8 +1413,6 @@ public class CaptureChangeMySQL extends
AbstractSessionFactoryProcessor {
} catch (final InitializationException e) {
throw e;
- } catch (final MalformedURLException e) {
- throw new InitializationException("Invalid Database Driver Jar
Url", e);
} catch (final Exception e) {
throw new InitializationException("Can't load Database
Driver", e);
}
diff --git
a/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/test/groovy/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQLTest.groovy
b/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/test/groovy/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQLTest.groovy
index f67567bfa5..becd21a5f9 100644
---
a/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/test/groovy/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQLTest.groovy
+++
b/nifi-nar-bundles/nifi-cdc/nifi-cdc-mysql-bundle/nifi-cdc-mysql-processors/src/test/groovy/org/apache/nifi/cdc/mysql/processors/CaptureChangeMySQLTest.groovy
@@ -31,6 +31,7 @@ import com.github.shyiko.mysql.binlog.event.WriteRowsEventData
import com.github.shyiko.mysql.binlog.network.SSLMode
import groovy.json.JsonSlurper
import org.apache.commons.io.output.WriterOutputStream
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading
import org.apache.nifi.cdc.event.ColumnDefinition
import org.apache.nifi.cdc.event.TableInfo
import org.apache.nifi.cdc.event.TableInfoCacheKey
@@ -1459,7 +1460,7 @@ class CaptureChangeMySQLTest {
/********************************
* Mock and helper classes below
********************************/
-
+ @RequiresInstanceClassLoading
class MockCaptureChangeMySQL extends CaptureChangeMySQL {
Map<TableInfoCacheKey, TableInfo> cache = new HashMap<>()