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

refactor: add internal data structures for transactional connection state #3321

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Sep 6, 2024

TLDR:

  1. This change adds a data structure for transactional session state (i.e. running set retryAbortsInternally=false in a transaction will make that statement become part of the transaction, and the change will only be persisted if the transaction is committed).
  2. The new data structure also reduces the boilerplate code needed for new connection variables.
  3. The feature for transactional state is not enabled. Only one property (retryAbortsInternally) makes use of the data structure in order to show how it works end to end.

This change adds internal data structures that can be used for transactional connection state. These data structures also reduces the amount of code that is needed for each connection property that is added. Connection properties are currently represented as actual variables in the ConnectionImpl class. These new data structures removes the need for that.

Only the connection property retryAbortsInternally is refactored to use the new data structure. All other connection properties will be refactored in a following change, in order to keep each change as small as possible.

The data structure supports both transactional and non-transactional connection state. Transactional state is disabled in the current version in order to be consistent with the current behavior. It will be enabled in a later change when all connection properties have been refactored to use the new data structure.

Added [DO NOT MERGE], as we don't want this included in the current ongoing release.

@olavloite olavloite requested a review from a team as a code owner September 6, 2024 09:15
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: spanner Issues related to the googleapis/java-spanner API. labels Sep 6, 2024
@olavloite olavloite force-pushed the transactional-connection-state branch 4 times, most recently from 929466b to b2022c0 Compare September 7, 2024 13:39
…tate

This change adds internal data structures that can be used for transactional
connection state. These data structures also reduces the amount of code that
is needed for each connection property that is added. Connection properties
are currently represented as actual variables in the ConnectionImpl class.
These new data structures removes the need for that.

Only the connection property retryAbortsInternally is refactored to use
the new data structure. All other connection properties will be refactored
in a following change, in order to keep each change as small as possible.

The data structure supports both transactional and non-transactional
connection state. Transactional state is disabled in the current version
in order to be consistent with the current behavior. It will be enabled
in a later change when all connection properties have been refactored
to use the new data structure.
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2024
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 10, 2024
* refactor: add internal data structures for transactional connection state

This change adds internal data structures that can be used for transactional
connection state. These data structures also reduces the amount of code that
is needed for each connection property that is added. Connection properties
are currently represented as actual variables in the ConnectionImpl class.
These new data structures removes the need for that.

Only the connection property retryAbortsInternally is refactored to use
the new data structure. All other connection properties will be refactored
in a following change, in order to keep each change as small as possible.

The data structure supports both transactional and non-transactional
connection state. Transactional state is disabled in the current version
in order to be consistent with the current behavior. It will be enabled
in a later change when all connection properties have been refactored
to use the new data structure.

* refactor: replace individual variables with ConnectionProperty

Replace individual variables in ConnectionOptions and ConnectionImpl with
references to ConnectionProperties. This reduces the amount of code bloat,
especially in ConnectionOptions, as all connection property parsing is
now handled by the ConnectionState class in a generic way.

This setup also reduces the amount of code that is needed to add a new
connection property, as there is only one source of truth: the list of
properties in the ConnectionProperties class.

Following steps that will reduce the amount of code bloat further are:
1. Replace all the regular expressions for SET and SHOW statements with
   a simple token-based parser.
2. Cleaning up ConnectionOptions further by removing the duplicate list
   of ConnectionProperties there. These can be removed once the JDBC
   driver has been updated to use the new list of properties.
@rahul2393 rahul2393 requested a review from a team as a code owner September 12, 2024 08:48
@olavloite olavloite added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. do not merge Indicates a pull request not ready for merge, due to either quality or timing. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants