Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,10 @@ public void startRWTransaction() throws Exception {
} else {
transactionOptions.add(Options.isolationLevel(IsolationLevel.SERIALIZABLE));
}
if (optimistic) {
if (!repeatableRead && optimistic) {
transactionOptions.add(Options.readLockMode(ReadLockMode.OPTIMISTIC));
} else {
}
if (repeatableRead && !optimistic) {
transactionOptions.add(Options.readLockMode(ReadLockMode.PESSIMISTIC));
}
Comment on lines +400 to 405

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for setting the transaction lock mode can be simplified. The default lock mode for read-write transactions in Spanner is PESSIMISTIC. Therefore, you only need to explicitly set the lock mode when OPTIMISTIC is required.

The current implementation has a redundant condition that explicitly sets the PESSIMISTIC lock mode, which is already the default.

You can simplify this block to a single if statement that handles the OPTIMISTIC case, making the code more concise and readable.

Suggested change
if (!repeatableRead && optimistic) {
transactionOptions.add(Options.readLockMode(ReadLockMode.OPTIMISTIC));
} else {
}
if (repeatableRead && !optimistic) {
transactionOptions.add(Options.readLockMode(ReadLockMode.PESSIMISTIC));
}
if (optimistic && !repeatableRead) {
transactionOptions.add(Options.readLockMode(ReadLockMode.OPTIMISTIC));
}

runner =
Expand Down
Loading