Skip to content

[FLINK-36236] Fix overriding the connection provider in JdbcSourceBuilder #169

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

Merged
merged 5 commits into from
Jun 20, 2025

Conversation

rajucomp
Copy link
Contributor

FLINK-36236: Fix Overriding the Connection Provider in JdbcSourceBuilder

Summary

This PR fixes an issue where a custom JdbcConnectionProvider passed via JdbcSourceBuilder#setConnectionProvider was unintentionally overwritten during the build() process. This prevented users from injecting their own connection management logic (e.g., for testing or advanced connection pooling scenarios).

Changes

  • JdbcSourceBuilder

    • Modified build() method to only set a default SimpleJdbcConnectionProvider if no custom provider has been set.
  • JdbcSource

    • Exposed a getConnectionProvider() method with @VisibleForTesting to enable access from test code.
  • Test Coverage

    • Added a unit test testSetConnectionProvider() to:
      • Verify that null values are rejected.
      • Assert that the JdbcSource retains and uses the explicitly provided JdbcConnectionProvider.

Motivation

This change ensures the builder pattern behaves predictably: user-provided values should not be silently overridden. This is especially important when dependency injection or custom behavior is expected during source initialization.

Copy link

boring-cyborg bot commented May 25, 2025

Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)

@rajucomp
Copy link
Contributor Author

@eskabetxe Can I get a review please ? Thanks.

@rajucomp rajucomp changed the title FLINK-36236 Fix overriding the connection provider in JdbcSourceBuilder [FLINK-36236] Fix overriding the connection provider in JdbcSourceBuilder May 25, 2025
Copy link
Member

@eskabetxe eskabetxe left a comment

Choose a reason for hiding this comment

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

LGTM.

My only concern is the change in visibility of some methods in a @PublicEvolving class. I understand they're annotated with @VisibleForTesting, but we should be cautious with such changes.

@1996fanrui can you run CI/CD please

@rajucomp
Copy link
Contributor Author

@@eskabetxe the checks have passed. Could you merge the PR ? I don't think I have the permission to do so. Thanks!

Copy link

@ferenc-csaky ferenc-csaky left a comment

Choose a reason for hiding this comment

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

LGTM! Based on the definition (pasted below) @PublicEvolving I see no harm in restricting the visibility of those getters.

Classes and methods with this annotation are intended for public use and have stable behavior. However, their interfaces and signatures are not considered to be stable and might be changed across versions. 

@rajucomp this supersedes #150, right?

@ferenc-csaky
Copy link

Anyways, will merge this by the end of today if no objections until then, this is a fairly simple change and it is out there for quite a while already.

@ferenc-csaky ferenc-csaky merged commit f697986 into apache:main Jun 20, 2025
4 checks passed
Copy link

boring-cyborg bot commented Jun 20, 2025

Awesome work, congrats on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants