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

Feat: Introduce support for 'pre ping' to detect stale or lost connections #2632

Merged
merged 1 commit into from
May 20, 2024

Conversation

izeigerman
Copy link
Member

@izeigerman izeigerman commented May 17, 2024

For long running plans, a state connection established at the beginning of a plan application might go stale by the end of it.

This update introduces a "pre-ping" mechanism, ensuring that the connection is not stale before initiating a new transaction. The ping implementation itself is dialect-specific but essentially comes down to executing a SELECT 1 query in all cases except MySQL, which has a first-class API for this purpose.

The new behavior is configurable and is turned off by default for all engines except for those likely to be used to store the SQLMesh state: MySQL, MSSQL, and Postgres. This is also only supported for engines with transaction support.

@izeigerman izeigerman requested a review from a team May 17, 2024 22:47
try:
self._execute(exp.select(exp.Literal.number(1)).sql(dialect=self.dialect))
finally:
self._connection_pool.close_cursor()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why close in all cases? If we just verified the connection is good, why not keep it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it because we are just validating the connection?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is closing a cursor (not connection) to discard the result of the SELECT 1 query which can technically be fetched.

@izeigerman izeigerman force-pushed the feat-connection-pre-ping branch 3 times, most recently from 7d4b454 to 5cbab01 Compare May 19, 2024 21:19
@sungchun12
Copy link
Contributor

Really glad to see this PR :)

@izeigerman izeigerman merged commit 972b60a into main May 20, 2024
15 checks passed
@izeigerman izeigerman deleted the feat-connection-pre-ping branch May 20, 2024 16:32
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.

None yet

4 participants