Skip to content

KAFKA-18215: KIP-891 Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters)#17741

Merged
gharris1727 merged 99 commits intoapache:trunkfrom
snehashisp:mvn-validation
Dec 11, 2024
Merged

KAFKA-18215: KIP-891 Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters)#17741
gharris1727 merged 99 commits intoapache:trunkfrom
snehashisp:mvn-validation

Conversation

@snehashisp
Copy link
Copy Markdown
Contributor

@snehashisp snehashisp commented Nov 10, 2024

The is one of a set of PRs for KIP-891. The list of total PRs given below all build one the previous one in the list. They can be reviewed individually, or if the complete set of changes is preferrable, please refer to the last PR.

This is PR#2 and contains changes to connector-config and connector validation endpoints to do appropriate validation considering the version provided and provide accurate defaults. This is primarily for connectors and converter PR#3 is for transformations.

  1. KAFKA-18182: KIP-891 Connect Multiversion Support (Base PR with Plugin Loading Isolation Changes) #16984 - Plugins Loading Isolation Changes
  2. KAFKA-18215: KIP-891 Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters) #17741 - Versioned Configs and Validation for Connector and Converters
  3. KAFKA-18419: KIP-891 Connect Multiversion Support (Transformation and Predicate Changes) #17742 - Transformation and Predicate Support
  4. KAFKA-18863: Connect Multiversion Support (Versioned Connector Creation and related changes) #17743 - Versioned Connector Creation
  5. KAFKA-18988: Connect Multiversion Support (Updates to status and metrics) #17988 - Updates to status and metrics

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

return plugins;
}

public PluginsRecommenders recommender() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep this as part of Plugins, then we can avoid the new PluginsRecommendors(plugins) call on every validate. Since the plugins information, once scanned remains static we don't really need to initialize all the recommenders again and again.

This is premature optimization, please don't do it. When someone has a benchmark that shows the benefit of this, it is trivial to implement.

The constructor of PluginsRecommenders does not perform any substantial pre-computation.
Validation already constructs hundreds of objects (ConfigValues, etc) each time it is called.

Also, if the plugins can be improved to be mutable in future it would be easier to revoke the current instance of recommenders in plugins and generate the new recommender, and have it reflected across all the uses.

YAGNI. When/if we get around to mutable Plugins, this class will look very different.

Comment on lines +547 to +554
VersionRange range = PluginUtils.connectorVersionRequirement(connectorVersion);
ClassLoader connectorLoader = plugins.pluginLoader(connectorClass, range);
try (LoaderSwap loaderSwap = plugins.withClassLoader(connectorLoader)) {
T plugin = (T) plugins.newPlugin(pluginName, pluginClass, null);
if (plugin instanceof Versioned) {
return ((Versioned) plugin).version();
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If two different version of the same plugin is bundled under the same plugin classloader

This is impossible from Connect's perspective. Once a ClassLoader returns a Class, it is cached and cannot be redefined. If two versions of a plugin are both present within the same ClassLoader, one will be picked arbitrarily, and it will always be picked (on the local machine). Effectively, Connect cant even know the second class file is there, which is why we don't try and detect it.

@snehashisp
Copy link
Copy Markdown
Contributor Author

snehashisp commented Dec 11, 2024

Hi @gharris1727. Please take another pass. I have made the requested changes, lmk if I have missed anything. Some tests are failing, will look into those soon.

There is another unrelated issue I came across while testing this PR. There might be a regression in #16604, which seems to break reflections based isolation for plugins that are already defined in the classpath. Looks like the new classgraph scanner is always loading the classpath plugins even if there is a another version in an isolated plugin.path. This is causing the runtime to ignore the plugin due to this check. In my setup, I have built the following plugin hierarchy for testing, and I found that the different versions of json converter are never identified due to the one being present in the classpath.

plugins3
├── connect-file-1.2.1-T-0.9.0-P-3.1
│   └── lib
│       └── connect-file-1.2.1-T-0.9.0-P-3.1.jar
├── connect-file-2.2.1-T-1.0.0-P-3.1-extra
│   └── lib
│       ├── connect-file-2.2.1-T-1.0.0-P-3.1-extra.jar
│       └── connect-json-11.jar
├── connect-file-2.2.1-T-1.1.0-P-3.1
│   └── lib
│       └── connect-file-2.2.1-T-1.1.0-P-3.1.jar
├── connect-file-2.2.11-T-2.1.0-P-3.5
│   └── lib
│       └── connect-file-2.2.11-T-2.1.0-P-3.5.jar
├── json-11
│   └── lib
│       └── connect-json-11.jar
└── json-17
    └── libs
        └── connect-json-17.jar

I changed the debug logs to error in the class and observed the following errors during scanning.

[2024-12-11 07:29:28,968] ERROR class org.apache.kafka.connect.json.JsonConverter from other classloader jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44 is visible from C:\Users\user\Desktop\confluent\testing\plugins3\connect-file-1.2.1-T-0.9.0-P-3.1, excluding to prevent isolated loading (org.apache.kafka.connect.runtime.isolation.ReflectionScanner:135)
[2024-12-11 07:29:28,969] ERROR class org.apache.kafka.connect.json.JsonConverter from other classloader jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44 is visible from C:\Users\user\Desktop\confluent\testing\plugins3\connect-file-1.2.1-T-0.9.0-P-3.1, excluding to prevent isolated loading (org.apache.kafka.connect.runtime.isolation.ReflectionScanner:135)

The fix I made was to use overrideClassLoaders(source.loaders() instead of addClassLoader here. Based on this code, addClassLoader by default includes the jdk classloaders first and only then scans the provided loader. I think overriding the loader here is the correct approach, but have not dug too deep here. This is probably not the correct place but wanted to bring it to your attention and see if I am missing something. LMK if I should create a bug ticket for this.

@gharris1727
Copy link
Copy Markdown
Contributor

There is another unrelated issue I came across while testing this PR. There might be a regression in #16604

Great catch! That regression hasn't been released yet and would definitely be a blocker for the release. Please open a blocker ticket for that we can fix it.

The fix I made was to use overrideClassLoaders(source.loaders() instead of addClassLoader

I think this is the right fix. It looks like Classgraph by default expects parent-first loaders, while our loaders are child-first. When the same class is defined multiple times, it masks all later copies, which would hide all of the other versions of the plugins.

Copy link
Copy Markdown
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also fix the build/tests.

@@ -1,149 +1,149 @@
/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: large diff.

How does this happen? I don't see what the change is...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was happening when I was rolling back changes via IDE. I think it somehow adding carriage returns to the lines since its on windows. Does not normally happen If I do operation with WSL.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah the line endings could cause a big diff. Thanks for looking into it!

Comment thread .gitignore Outdated
@snehashisp
Copy link
Copy Markdown
Contributor Author

Created https://issues.apache.org/jira/browse/KAFKA-18211 for the issue.

Copy link
Copy Markdown
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @snehashisp

@gharris1727 gharris1727 changed the title [WIP] KIP-891: Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters) KAFKA-18215: KIP-891 Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters) Dec 11, 2024
@gharris1727 gharris1727 merged commit f4fe606 into apache:trunk Dec 11, 2024
" or use \"FileStreamSink\" or \"FileStreamSinkConnector\" to make the configuration a bit shorter";
private static final String CONNECTOR_CLASS_DISPLAY = "Connector class";

public static final String CONNECTOR_VERSION = "connector." + WorkerConfig.PLUGIN_VERSION_SUFFIX;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snehashisp Thanks for this great patch. I have one small comment: It seems we are using connector.plugin.version instead of connector.version, correct? If so, could you please update the KIP accordingly?

peterxcli pushed a commit to peterxcli/kafka that referenced this pull request Dec 18, 2024
…idation changes for Connectors and Converters) (apache#17741)

Reviewers: Greg Harris <greg.harris@aiven.io>
tedyu pushed a commit to tedyu/kafka that referenced this pull request Jan 6, 2025
…idation changes for Connectors and Converters) (apache#17741)

Reviewers: Greg Harris <greg.harris@aiven.io>
snehashisp added a commit to snehashisp/kafka that referenced this pull request Jan 7, 2025
… and Validation changes for Connectors and Converters) (apache#17741)"

This reverts commit f4fe606.
gharris1727 pushed a commit that referenced this pull request Jan 7, 2025
These changes will be postponed to the 4.1 release.

* Revert "KAFKA-18215: KIP-891 Connect Multiversioning Support (Configs and Validation changes for Connectors and Converters) (#17741)"

This reverts commit f4fe606.

* Revert "KAFKA-18182: KIP-891 Add VersionRange to Plugins and DelegatingClassLoader APIs (#16984)"

This reverts commit af0054b.

Reviewers: Greg Harris <greg.harris@aiven.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions ci-approved connect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants