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

Long sessions #517

Merged
Merged

Conversation

rcypher-databricks
Copy link
Collaborator

Resolves #

Description

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

Added USE_LONG_SESSIONS flag.
Extended Connection with DatabricksDBTConnection.  Added properties acquire_release_count and last_used_time.
Updated DatabricksConnectionManager.set_connection_name to create instance of DatabricksDBTConnection and update new properties.
Override ConnectionManager.release to not close the session and to update the new connection properties.
Signed-off-by: Raymond Cypher <[email protected]>
Added new connection pool (threads_compute_connections) to DatabricksConnectionManager. It is a map of thread ID to map of compute name to DatabricksDBTConnection.
Updated DatabricksConnectionManager.set_connection_name() to look for existing connections in the new pool and then update the existing thread_connections connection pool.
Overrode cleanup_all in DatabricksConnectionManager to fire events based on the connection acquire/release count, rather than the connection state.

Signed-off-by: Raymond Cypher <[email protected]>
Added _start_using and _stop_using to DatabricksDBTConnection.  These handle logging, last_used_time, and acquire_release_count.
Moved long session specific code from DatabricksConnectionManager.set_connection_name to its own method.
Refactoring and renaming of the long session code.

Signed-off-by: Raymond Cypher <[email protected]>
Signed-off-by: Raymond Cypher <[email protected]>
Signed-off-by: Raymond Cypher <[email protected]>
Copy link
Collaborator

@benc-db benc-db 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, overall looks good.

dbt/adapters/databricks/connections.py Outdated Show resolved Hide resolved
dbt/adapters/databricks/connections.py Show resolved Hide resolved
dbt/adapters/databricks/connections.py Outdated Show resolved Hide resolved
dbt/adapters/databricks/connections.py Outdated Show resolved Hide resolved
Use ConnectionState constants instead of string literals.
Use assert instead of throwing an exception if in unexpected code path when USE_LONG_SESSIONS=False
Added long session test with warehouse per model
Signed-off-by: Raymond Cypher <[email protected]>
Added default max idle time of 600 seconds.  Added code to read user specified max idle time from profile or from alternate compute definitions.
Updated DatabricksDBTConnection with connect_max_idle property and helper functions to determine if the connection should be cleaned up.
In DatabricksConnectionManager added _cleanup_idle_connections(). This is called whenever a connection is acquired for use.
Added a new class method _open2() to DatabricksConnectionManager.  This is used with USE_LONG_SESSIONS is true and uses the http_path property of DatabricksDBTConnection.
Signed-off-by: Raymond Cypher <[email protected]>
@rcypher-databricks rcypher-databricks marked this pull request as ready for review December 6, 2023 00:22
Copy link
Collaborator

@benc-db benc-db left a comment

Choose a reason for hiding this comment

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

Please review comments. Overall looks good, but would like clarification on the counter, and consider refactor the open functionality to be injectable.

@rcypher-databricks rcypher-databricks merged commit 04d04a8 into databricks:main Dec 6, 2023
18 checks passed
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.

2 participants