Skip to content
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

Allow JDBC connectors to retry on transient failures #19191

Merged
merged 3 commits into from
Oct 19, 2023

Conversation

dominikzalewski
Copy link
Member

@dominikzalewski dominikzalewski commented Sep 28, 2023

Description

RetryingConnectionFactory now has a pluggable JDBC-connector specific retry strategy. This PR applies this change only to Oracle.

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:
All JDBC-based connectors are now always retrying (5 times for 30 seconds with a backoff) if opening a connection fails. By default this happens only if SQLTransientException is encountered. For backward compatibility, for Oracle this is overridden to SQLRecoverableException.

@cla-bot cla-bot bot added the cla-signed label Sep 28, 2023
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch 3 times, most recently from caadc2e to 992a02b Compare September 29, 2023 15:28
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch 8 times, most recently from a04c427 to fd98944 Compare October 3, 2023 08:30
@dominikzalewski dominikzalewski changed the title [WiP] Refactor to use DI instead of constructor calls [WiP] RetryingConnectionFactory has strategy of retries externalized Oct 3, 2023
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from fd98944 to 4f040f7 Compare October 3, 2023 08:50
@dominikzalewski dominikzalewski changed the title [WiP] RetryingConnectionFactory has strategy of retries externalized RetryingConnectionFactory has strategy of retries externalized Oct 3, 2023
@dominikzalewski dominikzalewski marked this pull request as ready for review October 3, 2023 09:58
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 4f040f7 to f7ff814 Compare October 3, 2023 11:25
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

some comments

right now the refactors look larger than the actual change and I can't be sure what is refactor vs what is required for the functionality

Comment on lines 85 to 97
if (oracleConfig.isConnectionPoolEnabled()) {
return oraclePoolConnectionFactory;
}
return retryingConnectionFactory;
Copy link
Member

Choose a reason for hiding this comment

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

looks like pre-exisiting logic that we only use RCF with non-pooled connections.
I don't know if it was intentional or not, so either we should add RCF to pooled connection factory as well or add a comment explaining why we only use RCF with non-pooled connections.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, but this ask seems out of scope? This has only been revealed because I slightly refactor the existing code and how it is more evident what the logic is. The scope has been frozen before I started working. If there's a good reason that we should change it, then we will. But we need a good reason.

Acceptance criteria

  • no new regressions
  • unit tests for new framework that it actually retries
  • it is possible to implement retry for any connector in future that fails sometimes to open a connection
  • no custom retrying in any jdbc connector, all connectors use new framework

Let me know if I misunderstood AC laid out by @kokosing.

@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch 2 times, most recently from 5266786 to 0ae9875 Compare October 3, 2023 12:10
@dominikzalewski
Copy link
Member Author

right now the refactors look larger than the actual change and I can't be sure what is refactor vs what is required for the functionality

I have broken down the change into a few commits, so that it is clear where the refactor ends and where adding functionality starts. If this is still not helpful, let's have a call.

@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 0ae9875 to dce2564 Compare October 3, 2023 13:42
@electrum
Copy link
Member

electrum commented Oct 3, 2023

The commit titles are too long. Please see https://cbea.ms/git-commit/

@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from dce2564 to 2c62916 Compare October 4, 2023 10:14
@dominikzalewski
Copy link
Member Author

The commit titles are too long. Please see https://cbea.ms/git-commit/

Shortened commit messages and formatted the extended description to 72 chars column.

@kokosing
Copy link
Member

kokosing commented Oct 5, 2023

How about PR title:

Allow JDBC connectors to retry on transient failures

Please provide PR description too and fill RN (release notes) form.

@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 9ad8864 to f2c32b0 Compare October 11, 2023 07:18
@dominikzalewski
Copy link
Member Author

I have also forgot to mention to you before that there is also io.trino.plugin.jdbc.LazyConnectionFactory :) Just wanted to make sure this puzzle is not too simple for you and you remember about all puzzles.

Thanks. I spent some time analyzing this, as your previous hint from slack was actually tracking the JdbcClient chain, rather than ConnectionFactory. But I figured it out by myself and it made me so proud :)

Simplified the chain with Lazy and Stats. There's a separate commit.

@dominikzalewski dominikzalewski marked this pull request as ready for review October 11, 2023 07:25
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 8638db0 to 9244f8c Compare October 11, 2023 08:26
Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Just one comment.

@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch 5 times, most recently from 14167f5 to 24e316a Compare October 17, 2023 11:01
Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

minor comments

I would like @hashhar to take a look too.

@hashhar hashhar self-requested a review October 17, 2023 12:35
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 24e316a to 0f67a87 Compare October 17, 2023 15:46
Refactor TestRetryingConnectionFactory and TestLazyConnectionFactory
to use Dependency Injection Motivation behind this change is to be
able to later add dependent objects to tested class without a need
for major changes in the test class itself.
@dominikzalewski dominikzalewski force-pushed the retry_on_jdbc_open_connection branch from 0f67a87 to da3f8ec Compare October 17, 2023 15:54
Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

The impl looks very good. I have no comments about it.

The only comment I have is about inspecting how the Guice map looks after the 2nd commit. From what I can tell we seem to have introduced duplication.

@hashhar
Copy link
Member

hashhar commented Oct 18, 2023

For references here's the actual Guice map before and after change for both JdbcClient and ConnectionFactory

BEFORE:

DriverConnectionFactory (OracleClientModule#connectionFactory == @ForBaseJdbc)
RetryingConnectionFactory (RetryingConnectionFactory#ctor)
StatisticsAwareConnectionFactory (StatisticsAwareConnectionFactory#ctor)
LazyConnectionFactory (LazyConnectionFactory#ctor)
ReusableConnectionFactory (ResuableConnectionFactoryModule - conditional, if QueryConfig#isReuseEnabled is true)

------------------------------------------------------------

OracleClient (OracleClientModule#setup == @ForBaseJdbc)
ForwardingJdbcClient (JdbcDiagnosticModule#createJdbcClientWithStats)
StatisticsAwareJdbcClient (JdbcDiagnosticModule#createJdbcClientWithStats == @StatsCollecting)
CachingJdbcClient (CachingJdbcClient#ctor)

AFTER:

DriverConnectionFactory (OracleClientModule#connectionFactory == @ForBaseJdbc)
StatisticsAwareConnectionFactory (StatisticsAwareConnectionFactory#ctor)
RetryingConnectionFactory (RetryingConnectionFactory#ctor)
LazyConnectionFactory (LazyConnectionFactory#ctor)
ReusableConnectionFactory (ResuableConnectionFactoryModule - conditional, if QueryConfig#isReuseEnabled is true)

No change in JdbcClient tree after the change.

@hashhar hashhar dismissed electrum’s stale review October 19, 2023 12:35

comments have been addressed

@hashhar hashhar merged commit 74012e3 into trinodb:master Oct 19, 2023
60 checks passed
@hashhar
Copy link
Member

hashhar commented Oct 19, 2023

@dominikzalewski can you please fill in the release notes template in the PR description since this would be a user visible change (even if not directly configurable).

@github-actions github-actions bot added this to the 430 milestone Oct 19, 2023
@dominikzalewski dominikzalewski deleted the retry_on_jdbc_open_connection branch October 19, 2023 12:40
@mosabua
Copy link
Member

mosabua commented Oct 21, 2023

Fyi .. please check out the final release notes entry we added for future references and as an example.

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

Successfully merging this pull request may close these issues.

5 participants