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

failover2 on connect #1133

Merged
merged 1 commit into from
Oct 3, 2024
Merged

failover2 on connect #1133

merged 1 commit into from
Oct 3, 2024

Conversation

sergiyvamz
Copy link
Contributor

Summary

Allows failover2 plugin to perform a failover during opening a new connection.

Additional Reviewers

@karenc-bq
@aaron-congo

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

github-actions bot commented Sep 27, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

  1. Register at Qodana Cloud and configure the action
  2. Use GitHub Code Scanning with Qodana
  3. Host Qodana report at GitHub Pages
  4. Inspect and use qodana.sarif.json (see the Qodana SARIF format for details)

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2023.3.1
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

boolean isInitialConnection, JdbcCallable<Connection, SQLException> connectFunc, boolean isForceConnect)
throws SQLException {

if (props.containsKey(INTERNAL_CONNECT_PROPERTY_NAME)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work to change this condition to the following so that we don't have to add the INTERNAL_CONNECT_PROPERTY_NAME? I think calling forceConnect probably always indicates we just want to connect directly without any special additional logic. If this works, we can probably just get rid of connectInternal and have different implementations for connect vs forceConnect.

Suggested change
if (props.containsKey(INTERNAL_CONNECT_PROPERTY_NAME)) {
if (isForceConnect)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

forceConnect() is for direct connection but it's not used in failover2. So forceConnect() makes not much sense to this case. Also, failover2 uses regular connect() because MonitoringHostListProvider already verified topology so no need to force direct connect. And with a regular connect(), the call comes to failover2 plugin again and our intention is to skip it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Using the INTERNAL_CONNECT_PROPERTY_NAME property as a flag seems a bit hacky/strange to me but I can't think of an alternative at the moment.

@sergiyvamz sergiyvamz force-pushed the failover2-on-connect branch 2 times, most recently from 3b0e0fd to b84d66c Compare October 1, 2024 17:34
throws SQLException {

if (!ENABLE_CONNECT_FAILOVER.getBoolean(props)) {
return connectFunc.call();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be connecting using getVerifiedConnection in this case?

Suggested change
return connectFunc.call();
return this.staleDnsHelper.getVerifiedConnection(isInitialConnection, this.hostListProviderService,
driverProtocol, hostSpec, props, connectFunc);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getVerifiedConnection() call already been made of a caller of connect() that is the same failover2 plugin. I don't think we need to execute it again.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry are you saying that getVerifiedConnection has been previously called by another plugin or previously called by failover2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

failover2 connect() is called, then getVerifiedConnection() is called.

conn = this.staleDnsHelper.getVerifiedConnection(isInitialConnection, this.hostListProviderService,

After that, if connection isn't established, a failover starts.

And eventually it calls pluginService.connect()

writerCandidateConn = this.pluginService.connect(writerCandidate, copyProp);

that will call failover2 connect() again. This call can be passed through to the next plugin since it's already been handled earlier.

Copy link
Contributor

@aaron-congo aaron-congo Oct 3, 2024

Choose a reason for hiding this comment

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

If I understand correctly that explains why we should use connectFunc.call instead of getVerifiedConnection when the props contain the INTERNAL_CONNECT_PROPERTY_NAME property, but this particular line is covering a different scenario: it is hit when connect failover is disabled. When connect failover is disabled we will never enter the failover logic below, so as the code currently is written, getVerifiedConnection will never be called in this scenario

@sergiyvamz sergiyvamz merged commit 31436c5 into main Oct 3, 2024
6 checks passed
@sergiyvamz sergiyvamz deleted the failover2-on-connect branch October 3, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants