Skip to content

google-cloud-spanner: Add alternate r/w txn API that doesn't require use of callback #1627

Description

@archiecobbs

In the Google Cloud Spanner Java API, the only way to perform read/write transactions is by providing a callback, via the TransactionRunner interface.

I understand that the API is trying to hide the details of the need to automatically retry transactions as a convenience to the programmer, but this limitation is a serious problem, at least for me. I need to be able to manage the transaction lifecycle myself, even if that means I have to perform my own retries (e.g., based on catching some sort of "retryable" exception, in this case AbortedException).

To make this problem more concrete, suppose one wanted to implement Spring's PlatformTransactionManager for Google Cloud Spanner, so as to fit in with one's existing code, and use one's existing retry logic. It would not be possible with the current API.

It would be easy to augment the API in a backward compatible way, by adding a method returning a TransactionContext directly to the user, and let the user handle the retries. Of course this new method could be documented as "more dangerous and less convenient" to scare away noobs, etc.

Can this alternate (more traditional) transaction API style be added to the Java API?

Thanks.

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the Spanner API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions