Skip to content

Cloud Spanner Client should prevent nested transactions #2117

Closed

Description

@vkedia

Cloud Spanner does not support nested transactions. But the client library does allow users to call DatabaseClient.readWriteTransaction().run() inside of the callback that is provided to an outer DatabaseClient.readWriteTransaction().run(). This is misleading since users might believe that this will behave like a nested transaction but in reality these will be two independent transactions. This is confusing and a source of bugs. Specifically the inner transaction might succeed while the outer might ABORT, in which case the callback will be rerun thus rerunning the inner transaction.
We should prevent this from happening by detecting and raising an error if someone calls DatabaseClient.readWriteTransaction().run() inside the callback provided to DatabaseClient.readWriteTransaction().run(). Note that this needs to be done before GA since this is a known breaking change.
Also note that if we come across a use case where we do want to allow calling a nested run, we should be able to enable that in future without making a breaking change.

cc @jgeewax @bjwatson

Activity

  1. added
    api: spanner
    priority: p0
    on Jun 6, 2017
  2. self-assigned this
    on Jun 6, 2017
  3. garrettjonesgoogle commented on Jun 20, 2017

    @garrettjonesgoogle
    Contributor

    GA-blocking issues shouldn't be marked P0; P0 is for issues where the latest release is DOA. Downgrading to P1.

  4. added
    priority: p1
    and removed
    priority: p0
    on Jun 20, 2017
  5. added
    type: feature request
    on Jul 17, 2017
  6. bjwatson commented on Aug 29, 2017

    @bjwatson

    @vkedia @garrettjonesgoogle I added the Release Blocking label to ensure this is fixed before GA.

  7. bjwatson commented on Oct 16, 2017

    @bjwatson
  8. yihanzhen commented on Jan 11, 2018

    @yihanzhen
    Contributor

    This has been added to our feature backlog: https://github.com/GoogleCloudPlatform/google-cloud-java/wiki/Feature-backlog . This issue will be closed but is linked in the backlog and can continue to be used for comment and discussion.

  9. added a commit that references this issue on Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: spannerpriority: p1type: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions