You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

 

Status

Current stateUnder discussion.

Discussion threadhere

JIRAKAFKA-3487

Released: 

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

Kafka Connect is a highly extensible framework, designed to run software modules that integrate a wide variety of data sources and destinations with Kafka and, by definition, are developed independently of the framework. Examples of such modules are connectorstransformations and data converters. Because such independent development, dependency conflicts might arise naturally, between the framework and the modules, as well as among the modules themselves. This happens when, for instance, one connector is using the latest version of a package that added a new feature, while another connector depends on a previous version of the same package where this feature is missing. 

The effect is not very severe because software packages appearing often as common dependencies are usually doing a good job in preserving software compatibility between versions. Thus, such issues can usually get resolved with appropriate ordering of packages in the classpath. Furthermore, enough flexibility has been demonstrated so far between framework and connector developers in syncing up with updates of commonly used dependencies. 

Nevertheless, as Kafka Connect adoption grows, runtime exceptions due to version mismatches might arise more often, and therefore present a burden in the development and deployment of connectors with Kafka Connect. 

In order to resolve the issue of conflicting dependencies, class loading isolation is suggested here as a remedy.

In this case, the framework will do the heavy lifting in terms of development, offering a transparent resolution of dependency conflicts and keeping the changes in Kafka Connect's public interfaces minimal. 

Public Interfaces

The only publicly visible changes that are proposed in order to implement class loading isolation in Kafka Connect is the addition of two new Connect worker config properties:

These are framework level configuration properties that will affect all the connectors running in a Connect worker. 

The new configuration option module.path will accept a list of locations, represented as strings and separated by commas. The strings representing locations should be able to be transformed into URLs, in order to offer maximum flexibility in terms of module discovery. Nevertheless, in the first implementation of class loading isolation such locations will be paths to the local filesystem, that, in turn, can be easily transformed into URLs. 

When a filesystem path is used as location for imported modules (connectors, transformations and converters), the convention is that each module is storing all its required dependencies in a single directory under the location path listed in module.pathFor instance, if the location /usr/local/share/java is given in module.path then modules such as my-kafka-source-connectormy-kafka-sink-connectormy-connect-smt and my-converter should store all of their dependencies (usually in the form of jar files, but possibly as raw class files with the appropriate java package structure) under directories as follows:

/usr/local/share/java

/my-kafka-source-connector/

/my-kafka-sink-connector/

/my-connect-smt/

/my-converter/

The new configuration option module.isolation.enabled will accept a boolean value that will turn the feature of class loading isolation on and off. 

While the introduction of these two new configuration properties are the only changes proposed to the public interfaces of Kafka Connect, next are also described the main implementation steps that will be carried out within the framework to support class loading isolation.

Proposed Changes

Add module.path and module.isolation.enabled configuration properties for workers running both in standalone and distributed mode. By default module.path is empty and module.isolation.enabled is set to false.

Based on those two configuration properties, when class loading isolation is enabled, the Connect framework will be able to instantiate a custom module classloader for each module under the list of locations supplied in the module.pathThe main characteristics of such a module classloader are that:

  • it filters out classes belonging to the java library and the Connect framework and delegates their loading to the appropriate classloader.
  • it applies a child-first policy for the rest of the classes, aiming to load module specific dependencies directly.

Furthermore, the framework will control which classloading policy is in effect every time, by setting appropriately the thread context classloader (TCCL). This is not expected to be an issue, even in environments that use OSGi or other module deployment frameworks for two reasons:

  • the Connect framework controls the threads that run module code (e.g. connector tasks).
  • module classes and dependencies are required to be supplied explicitly through module.path.

Compatibility, Deprecation, and Migration Plan

  • Existing users will not be impacted since isolation will be disabled by default. 
  • Users enabling class loading isolation might experience higher demands in memory usage due to additional loading of otherwise common classes. However this increase is not expected to be prohibitive in most cases.

Test Plan

  • Targeted Unit tests will be developed to test the components that will implement class isolation in the framework. Additionally, all other tests will be set to run with class loading isolation turned on. 
  • System tests will be written to test class loading isolation when explicitly conflicting dependencies are introduced by connectors. 
  • Microbenchmarks will be designed to make sure the effect of classloader context switching is negligible. 

Rejected Alternatives

  • Use OSGi. OSGi. Along with its much broader scope, an OSGi implementation would bring significant implementation complexity, both in the framework and the connector development. 

  • Design for project Jigsaw and wait. With this KIP we describe an implementation path whose execution is expected to be focused and efficient. Major upgrades, such as an upgrade to the next Java version are not expected to move faster than the proposed implementation.

 

  • No labels