Skip to content

Commit 06152d5

Browse files
committed
review comments resolved
1 parent 9fd5cb1 commit 06152d5

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,24 @@ public static TransactionOption optimisticLock() {
173173
*
174174
* <ul>
175175
* <li>{@link ReadLockMode#PESSIMISTIC}: Read locks are acquired immediately on read. This mode
176-
* primarily applies to transactions with {@code SERIALIZABLE} isolation.
176+
* only applies to {@code SERIALIZABLE} isolation. This mode prevents concurrent
177+
* modifications by locking data throughout the transaction. This reduces commit-time aborts
178+
* due to conflicts but can increase how long transactions wait for locks and the overall
179+
* contention.
177180
* <li>{@link ReadLockMode#OPTIMISTIC}: Locks for reads within the transaction are not acquired
178-
* on read. Instead the locks are acquired on a commit to validate that read/queried data
179-
* has not changed since the transaction started. If a conflict is detected, the transaction
180-
* will fail. This mode applies to transactions with {@code SERIALIZABLE} isolation.
181+
* on read. Instead the locks are acquired on commit to validate that read/queried data has
182+
* not changed since the transaction started. If a conflict is detected, the transaction
183+
* will fail. This mode only applies to {@code SERIALIZABLE} isolation. This mode defers
184+
* locking until commit, which can reduce contention and improve throughput. However, be
185+
* aware that this increases the risk of transaction aborts if there's significant write
186+
* competition on the same data.
181187
* <li>{@link ReadLockMode#READ_LOCK_MODE_UNSPECIFIED}: This is the default if no mode is set.
182188
* The locking behavior depends on the isolation level:
183189
* <ul>
184190
* <li>For {@code REPEATABLE_READ} isolation: Locking semantics default to {@code
185-
* OPTIMISTIC}. However, validation checks at commit are only performed for reads
186-
* within queries using {@code SELECT FOR UPDATE}, statements with {@code
187-
* LOCK_SCANNED_RANGES} hints, or DML statements. <br>
191+
* OPTIMISTIC}. However, validation checks at commit are only performed for queries
192+
* using {@code SELECT FOR UPDATE}, statements with {@code LOCK_SCANNED_RANGES} hints,
193+
* and DML statements. <br>
188194
* Note: It is an error to explicitly set {@code ReadLockMode} when the isolation
189195
* level is {@code REPEATABLE_READ}.
190196
* <li>For all other isolation levels: If the read lock mode is not set, it defaults to

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.google.spanner.v1.RequestOptions;
4646
import com.google.spanner.v1.Transaction;
4747
import com.google.spanner.v1.TransactionOptions;
48-
import com.google.spanner.v1.TransactionOptions.ReadWrite;
4948
import java.time.Instant;
5049
import java.util.ArrayList;
5150
import java.util.Collection;
@@ -285,8 +284,7 @@ public CommitResponse writeAtLeastOnceWithOptions(
285284
transactionOptionsBuilder.setIsolationLevel(options.isolationLevel());
286285
}
287286
if (options.readLockMode() != null) {
288-
transactionOptionsBuilder.setReadWrite(
289-
ReadWrite.newBuilder().setReadLockMode(options.readLockMode()));
287+
transactionOptionsBuilder.getReadWriteBuilder().setReadLockMode(options.readLockMode());
290288
}
291289
requestBuilder.setSingleUseTransaction(
292290
defaultTransactionOptions().toBuilder().mergeFrom(transactionOptionsBuilder.build()));

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import com.google.spanner.v1.SpannerGrpc;
7070
import com.google.spanner.v1.TransactionOptions;
7171
import com.google.spanner.v1.TransactionOptions.IsolationLevel;
72-
import com.google.spanner.v1.TransactionOptions.ReadWrite;
7372
import com.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
7473
import io.grpc.CallCredentials;
7574
import io.grpc.CompressorRegistry;
@@ -1729,8 +1728,7 @@ public DefaultReadWriteTransactionOptionsBuilder setIsolationLevel(
17291728

17301729
public DefaultReadWriteTransactionOptionsBuilder setReadLockMode(
17311730
ReadLockMode readLockMode) {
1732-
transactionOptionsBuilder.setReadWrite(
1733-
ReadWrite.newBuilder().setReadLockMode(readLockMode));
1731+
transactionOptionsBuilder.getReadWriteBuilder().setReadLockMode(readLockMode);
17341732
return this;
17351733
}
17361734

0 commit comments

Comments
 (0)