Skip to content

Conversation

@xsgao-github
Copy link
Member

@xsgao-github xsgao-github commented Nov 13, 2024

Description

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## Section
* Fix JDBC `Connection.isValid(int)` which does not validate connection and/or credentials. ({issue}`22684`)
* Add `validateConnection` JDBC property that allows validating connection when making a JDBC connection. ({issue}`16504`)

@cla-bot cla-bot bot added the cla-signed label Nov 13, 2024
@github-actions github-actions bot added the jdbc Relates to Trino JDBC driver label Nov 13, 2024
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from 79d3243 to 639e787 Compare November 13, 2024 19:04
@github-actions github-actions bot added the docs label Nov 13, 2024
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch 2 times, most recently from 93a3aca to 499786a Compare November 13, 2024 20:49
@xsgao-github xsgao-github marked this pull request as draft November 13, 2024 20:51
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from 499786a to 693699c Compare November 13, 2024 21:14
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from 365474f to ba029a4 Compare November 14, 2024 03:56
@xsgao-github xsgao-github requested a review from aalbu November 14, 2024 04:04
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from ba029a4 to 23a00d0 Compare November 14, 2024 04:18
@wendigo wendigo self-requested a review November 14, 2024 05:37
@xsgao-github xsgao-github changed the title Support JDBC validate connection [WIP] Support JDBC validate connection Nov 14, 2024
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch 4 times, most recently from f3d16fb to 5615c84 Compare November 14, 2024 19:01
@xsgao-github xsgao-github requested a review from wendigo November 14, 2024 21:55
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from da5b8f5 to 3023767 Compare November 22, 2024 16:36
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch 2 times, most recently from 8806417 to a4976d5 Compare November 27, 2024 05:19
@xsgao-github xsgao-github requested a review from aalbu November 27, 2024 05:19
@xsgao-github xsgao-github force-pushed the sgao/support-validate-connection-3 branch from a4976d5 to d618ed0 Compare December 3, 2024 15:37
@wendigo
Copy link
Contributor

wendigo commented Dec 4, 2024

I'd prefer to not to add this to the StatementClientV1 itself - it's not needed there and the changes to remove the query from the constructor are wrong.

Instead, I'd just add it to JDBC only and use the fact that, TrinoConnection has the authenticated client already. With it, it's just a matter of:

        OkHttpClient.Builder builder = new OkHttpClient.Builder(client) // if you want some custom timeouts
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS);

        OkHttpClient timeoutClient = builder.build();
        timeoutClient.
                newCall(new Request.Builder().head()
                        .url(trinoUri.getUri() + "/v1/statement")
                        .build())
                .execute()
                .isSuccessful();

You can add this alone to isValid(int timeout) method. The only thing there is to handle 404 gracefully.

@xsgao-github
Copy link
Member Author

You can add this alone to isValid(int timeout) method.

But this undercut the pattern that JDBC delegates function calls to trino-client.

Given the fact that /v1/statement serves functions as two end-points, POST with a query body and a bunch of Trino headers, and HEAD without body or Trino headers, and you all disagree on making query optional, I am leaning to create a new AuthenticationClient object which connects to /v1/statement as well.

@xsgao-github xsgao-github requested a review from aalbu December 4, 2024 18:03
@aalbu
Copy link
Member

aalbu commented Jan 2, 2025

The reason to control this behavior through a property was indeed the extra round-trip. The argument was that since creating connections in Trino is basically free currently, there may be client applications that create connections for every query and in a scenario like that, adding an extra round-trip would introduce a performance regression. EXECUTE IMMEDIATE was introduced to address similar concerns.

@wendigo
Copy link
Contributor

wendigo commented Jan 2, 2025

@aalbu If the goal is to implement isValid than we can remove validation when connection is created (as the credentials will be validated when query is submitted) and leave it only for isValid. Since isValid is an explicit call, we will avoid this extra round trip and there will be no need for extra property.

@aalbu
Copy link
Member

aalbu commented Jan 2, 2025

The goal is to make Trino play nicer with BI tools. Most JDBC drivers ensure that connections are valid at creation time and also let you do a proper validity check). BI tools tend to misbehave when the behavior is different (i.e. you can create connections with wrong credentials or calling isValid() returns true when credentials are invalid).

@wendigo
Copy link
Contributor

wendigo commented Jan 2, 2025

Do we know whether isValid is enough or not?

@xsgao-github
Copy link
Member Author

Do we know whether isValid is enough or not?

Fixing isValid will help use case when connection pool is in place. But here we want to fix three things:

  1. Validate connection at getConnection.
  2. Return correct SQLState as getConnection.
  3. Validate connection at isValid.

@wendigo wendigo force-pushed the sgao/support-validate-connection-3 branch from d8f28d3 to 2e55865 Compare January 10, 2025 15:24
@wendigo
Copy link
Contributor

wendigo commented Jan 10, 2025

I've applied some structural changes and cleanups and squashed commits together.

@xsgao-github
Copy link
Member Author

I've applied some structural changes and cleanups and squashed commits together.

@wendigo is co-author now, @aalbu @electrum & @martint would you please review and approve this PR?

@wendigo wendigo requested a review from losipiuk January 10, 2025 17:00
@wendigo wendigo requested a review from mosabua January 10, 2025 17:03
@wendigo
Copy link
Contributor

wendigo commented Jan 10, 2025

@mosabua PTAL at jdbc.md change

@wendigo
Copy link
Contributor

wendigo commented Jan 10, 2025

@xsgao-github why have you added a merge commit here? We are not doing that

@wendigo wendigo force-pushed the sgao/support-validate-connection-3 branch from d67fed3 to 2e55865 Compare January 10, 2025 17:06
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Minor doc changes and then good to go.

@xsgao-github
Copy link
Member Author

@xsgao-github why have you added a merge commit here? We are not doing that

Yes, I clicked on Update branch button.
image

@mosabua
Copy link
Member

mosabua commented Jan 10, 2025

As part of docs fix also please rebase and squash commits .. and do that manually .. as you saw the GitHub UI messes that up with a merge commit ;-)

@wendigo
Copy link
Contributor

wendigo commented Jan 10, 2025

@xsgao-github it's not needed

@wendigo wendigo force-pushed the sgao/support-validate-connection-3 branch from 2e55865 to 7e01309 Compare January 10, 2025 17:17
@mosabua
Copy link
Member

mosabua commented Jan 10, 2025

Ship it @wendigo !

@wendigo wendigo merged commit 10bccd1 into trinodb:master Jan 10, 2025
97 checks passed
@github-actions github-actions bot added this to the 469 milestone Jan 10, 2025
@xsgao-github xsgao-github deleted the sgao/support-validate-connection-3 branch January 13, 2025 20:15
@xsgao-github
Copy link
Member Author

@mosabua
Copy link
Member

mosabua commented Jan 13, 2025

@xsgao-github there is no such thing as a Trino LTS release. Please keep questions relevant to Trino and related open source projects.

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

Labels

cla-signed docs jdbc Relates to Trino JDBC driver

Development

Successfully merging this pull request may close these issues.

JDBC Connection.isValid(int) should verify access token expiration

6 participants