Skip to content

adding optimistic locking#16124

Draft
sahusanket wants to merge 2 commits into
release/6.11from
test_opti_deployskip
Draft

adding optimistic locking#16124
sahusanket wants to merge 2 commits into
release/6.11from
test_opti_deployskip

Conversation

@sahusanket
Copy link
Copy Markdown
Contributor

No description provided.

@sahusanket sahusanket self-assigned this May 12, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the SpannerTransactionRunner to enable optimistic locking for all read-write transactions. A review comment identifies that this global change in concurrency semantics could lead to increased transaction aborts and retries in high-contention scenarios, recommending that the behavior be made configurable or verified for compatibility with existing workloads.

public void run(TxRunnable runnable) throws TransactionException {
try {
admin.getDatabaseClient().readWriteTransaction().allowNestedTransaction().run(context -> {
admin.getDatabaseClient().readWriteTransaction(Options.optimisticLock()).allowNestedTransaction().run(context -> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Enabling optimistic locking globally for all transactions is a significant change in concurrency semantics. While it can improve performance for low-contention workloads by avoiding read locks, it may lead to a high rate of transaction aborts and retries in high-contention scenarios. This can result in increased latency and CPU usage on the Spanner nodes. It is recommended to make this behavior configurable or to verify that all existing workloads using this runner are compatible with optimistic concurrency control, as Cloud Spanner defaults to pessimistic locking for a reason.

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.

1 participant