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

Unbind transaction boundaries from connection open/close #44

Open
mwatts15 opened this issue May 8, 2022 · 0 comments
Open

Unbind transaction boundaries from connection open/close #44

mwatts15 opened this issue May 8, 2022 · 0 comments

Comments

@mwatts15
Copy link
Contributor

mwatts15 commented May 8, 2022

Problem

The connection boundaries in owmeta-core are tied to the transaction boundaries in owmeta-core through the use of traction.begin/abort/commit calls in the owmeta_core.data.Data methods. This presents problems when, for instance, we want to abort a transaction but closing the connection via Data.closeDatabase commits the ongoing transaction:

with transaction.manager, connect():
    result = do_something()
    if condition(result):
        raise Exception("nope")

contrariwise, we can just have unnecessary transactions which aren't clearly tied to our transaction manager, which is just confusing. In this piece of code, we have a transaction that's initiated but then implicitly aborted when the transaction manager does its thing:

with connect(), transaction.manager:
    result = do_something()
    if condition(result):
        raise Exception("nope")

Which could prove problematic when we're integrating with other schemes that may have to do some extra work in setting up a transaction.

Proposal

  • Add an explicit transaction manager to Data objects with "explicit" mode enabled by default.
  • Make use of the explicit transaction manager where we use transaction.manager now (mostly in owmeta_core.command.OWM and tests for that)
  • Allow replacing the transaction manager created automatically with one provided to allow for integration with transaction managers that are set up some other way.

Alternatives

Considered letting this alone, but it actually becomes a problem when trying to allow for retrying user actions within the scope of a transaction since the implicit commit commits partial work, even when we raise an exception when our connection boundary is within our transaction boundary and the retry starts a new transaction.

Just removing the transaction.begin/commit/abort calls doesn't completely solve the issue since it still leads to subtle bugs that are only solved by carefully rearranging when connections are started and ended, but that's really fragile, confusing, and harder to use in the long run than explicit transaction boundaries with standardized context managers.

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

No branches or pull requests

1 participant