google-cloud-spanner 2.31.0 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 747996c4ee90317631f8648dbc5abefec1ef5dec80ab4e867475dfc465671cf6
4
- data.tar.gz: 7316c929b5c69c3595e35780fe13ced837091de64de0da2ad13e41c2ccab065e
3
+ metadata.gz: 8e4f1e2c9ad4832aa5ade2d7f086d0e9fd3f8f7c01a48147f0160ab8d4ed774a
4
+ data.tar.gz: a2f84a797e638ad1fb7538a861cd8b153dea2d0aaab0e6a89138c9592b37edf8
5
5
  SHA512:
6
- metadata.gz: c5f2caed803fc1883c743c34b45a54383259d20749628d01af88cd94d6ac2b89195af9597d763a199b597066a1bee5999fa3b2c3e34b89b59d78c5e86a7cdee1
7
- data.tar.gz: 8d40b705e2b0fa7b93f2aa334b8b034ad8cb320833d32d6c0bf7a1073966d6cc9d9b40192a86bd1d3fcacce64c020a60f7b4b4fa6b2b9ffdefbc6f308428b711
6
+ metadata.gz: f5e6a8a01519dc8bf7c87d81c1fd162c5297f5067c2fc7f42904aad8f59c13c322630841d20fc5433175c8cf3d4ef7afa52e01e0bf1171c35d27984e20d75d42
7
+ data.tar.gz: da60a3a4874ac6a695715f567baadd09de69c8691269a9dfd7c0f5011af80ff700feef8396fc79e97c22491b307c8f7e9b37742ba8bffc04706ee5560f80bbf8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.32.0 (2025-12-04)
4
+
5
+ #### Features
6
+
7
+ * Add support for ReadLockMode ([#171](https://github.com/googleapis/ruby-spanner/issues/171))
8
+
3
9
  ### 2.31.0 (2025-12-02)
4
10
 
5
11
  #### Features
@@ -1105,6 +1105,13 @@ module Google
1105
1105
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1106
1106
  # trigger a retry.
1107
1107
  #
1108
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1109
+ # The read lock mode for the transaction.
1110
+ # Can be one of the following:
1111
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1112
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1113
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1114
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1108
1115
  #
1109
1116
  # @return [Time, CommitResponse] The timestamp at which the operation
1110
1117
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1161,7 +1168,7 @@ module Google
1161
1168
  def upsert table, rows,
1162
1169
  exclude_txn_from_change_streams: false,
1163
1170
  isolation_level: nil, commit_options: nil, request_options: nil,
1164
- call_options: nil
1171
+ call_options: nil, read_lock_mode: nil
1165
1172
  request_options = Convert.to_request_options \
1166
1173
  request_options, tag_type: :transaction_tag
1167
1174
 
@@ -1171,7 +1178,8 @@ module Google
1171
1178
  isolation_level: isolation_level,
1172
1179
  commit_options: commit_options,
1173
1180
  request_options: request_options,
1174
- call_options: call_options
1181
+ call_options: call_options,
1182
+ read_lock_mode: read_lock_mode
1175
1183
  end
1176
1184
  end
1177
1185
  alias save upsert
@@ -1257,6 +1265,15 @@ module Google
1257
1265
  # trigger a retry.
1258
1266
  #
1259
1267
  #
1268
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1269
+ # The read lock mode for the transaction.
1270
+ # Can be one of the following:
1271
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1272
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1273
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1274
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1275
+ #
1276
+ #
1260
1277
  # @return [Time, CommitResponse] The timestamp at which the operation
1261
1278
  # committed. If commit options are set it returns {CommitResponse}.
1262
1279
  #
@@ -1312,7 +1329,7 @@ module Google
1312
1329
  def insert table, rows,
1313
1330
  exclude_txn_from_change_streams: false,
1314
1331
  isolation_level: nil, commit_options: nil, request_options: nil,
1315
- call_options: nil
1332
+ call_options: nil, read_lock_mode: nil
1316
1333
  request_options = Convert.to_request_options \
1317
1334
  request_options, tag_type: :transaction_tag
1318
1335
 
@@ -1322,7 +1339,8 @@ module Google
1322
1339
  isolation_level: isolation_level,
1323
1340
  commit_options: commit_options,
1324
1341
  request_options: request_options,
1325
- call_options: call_options
1342
+ call_options: call_options,
1343
+ read_lock_mode: read_lock_mode
1326
1344
  end
1327
1345
  end
1328
1346
 
@@ -1406,6 +1424,14 @@ module Google
1406
1424
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1407
1425
  # trigger a retry.
1408
1426
  #
1427
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1428
+ # The read lock mode for the transaction.
1429
+ # Can be one of the following:
1430
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1431
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1432
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1433
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1434
+ #
1409
1435
  #
1410
1436
  # @return [Time, CommitResponse] The timestamp at which the operation
1411
1437
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1461,7 +1487,7 @@ module Google
1461
1487
  def update table, rows,
1462
1488
  exclude_txn_from_change_streams: false,
1463
1489
  isolation_level: nil, commit_options: nil, request_options: nil,
1464
- call_options: nil
1490
+ call_options: nil, read_lock_mode: nil
1465
1491
  request_options = Convert.to_request_options \
1466
1492
  request_options, tag_type: :transaction_tag
1467
1493
 
@@ -1471,7 +1497,8 @@ module Google
1471
1497
  isolation_level: isolation_level,
1472
1498
  commit_options: commit_options,
1473
1499
  request_options: request_options,
1474
- call_options: call_options
1500
+ call_options: call_options,
1501
+ read_lock_mode: read_lock_mode
1475
1502
  end
1476
1503
  end
1477
1504
 
@@ -1557,6 +1584,14 @@ module Google
1557
1584
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1558
1585
  # trigger a retry.
1559
1586
  #
1587
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1588
+ # The read lock mode for the transaction.
1589
+ # Can be one of the following:
1590
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1591
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1592
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1593
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1594
+ #
1560
1595
  #
1561
1596
  # @return [Time, CommitResponse] The timestamp at which the operation
1562
1597
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1612,14 +1647,15 @@ module Google
1612
1647
  def replace table, rows,
1613
1648
  exclude_txn_from_change_streams: false,
1614
1649
  isolation_level: nil, commit_options: nil, request_options: nil,
1615
- call_options: nil
1650
+ call_options: nil, read_lock_mode: nil
1616
1651
  @pool.with_session do |session|
1617
1652
  session.replace table, rows,
1618
1653
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1619
1654
  isolation_level: isolation_level,
1620
1655
  commit_options: commit_options,
1621
1656
  request_options: request_options,
1622
- call_options: call_options
1657
+ call_options: call_options,
1658
+ read_lock_mode: read_lock_mode
1623
1659
  end
1624
1660
  end
1625
1661
 
@@ -1684,6 +1720,15 @@ module Google
1684
1720
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1685
1721
  # trigger a retry.
1686
1722
  #
1723
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1724
+ # The read lock mode for the transaction.
1725
+ # Can be one of the following:
1726
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1727
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1728
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1729
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1730
+ #
1731
+ #
1687
1732
  # @return [Time, CommitResponse] The timestamp at which the operation
1688
1733
  # committed. If commit options are set it returns {CommitResponse}.
1689
1734
  #
@@ -1732,7 +1777,7 @@ module Google
1732
1777
  def delete table, keys = [],
1733
1778
  exclude_txn_from_change_streams: false,
1734
1779
  isolation_level: nil, commit_options: nil, request_options: nil,
1735
- call_options: nil
1780
+ call_options: nil, read_lock_mode: nil
1736
1781
  request_options = Convert.to_request_options \
1737
1782
  request_options, tag_type: :transaction_tag
1738
1783
 
@@ -1742,7 +1787,8 @@ module Google
1742
1787
  isolation_level: isolation_level,
1743
1788
  commit_options: commit_options,
1744
1789
  request_options: request_options,
1745
- call_options: call_options
1790
+ call_options: call_options,
1791
+ read_lock_mode: read_lock_mode
1746
1792
  end
1747
1793
  end
1748
1794
 
@@ -1805,6 +1851,15 @@ module Google
1805
1851
  # @yield [commit] The block for mutating the data.
1806
1852
  # @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
1807
1853
  #
1854
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1855
+ # The read lock mode for the transaction.
1856
+ # Can be one of the following:
1857
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1858
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1859
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1860
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1861
+ #
1862
+ #
1808
1863
  # @return [Time, CommitResponse] The timestamp at which the operation
1809
1864
  # committed. If commit options are set it returns {CommitResponse}.
1810
1865
  #
@@ -1863,7 +1918,7 @@ module Google
1863
1918
  #
1864
1919
  def commit exclude_txn_from_change_streams: false,
1865
1920
  isolation_level: nil, commit_options: nil, request_options: nil,
1866
- call_options: nil, &block
1921
+ call_options: nil, read_lock_mode: nil, &block
1867
1922
  raise ArgumentError, "Must provide a block" unless block_given?
1868
1923
 
1869
1924
  request_options = Convert.to_request_options \
@@ -1876,6 +1931,7 @@ module Google
1876
1931
  commit_options: commit_options,
1877
1932
  request_options: request_options,
1878
1933
  call_options: call_options,
1934
+ read_lock_mode: read_lock_mode,
1879
1935
  &block
1880
1936
  )
1881
1937
  end
@@ -2042,6 +2098,15 @@ module Google
2042
2098
  # * `:retry_codes` (`Array<String>`) - The error codes that should
2043
2099
  # trigger a retry.
2044
2100
  #
2101
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
2102
+ # The read lock mode for the transaction.
2103
+ # Can be one of the following:
2104
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
2105
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
2106
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
2107
+ # but instead on a commit to validate that the data has not changed since the transaction started.
2108
+ #
2109
+ #
2045
2110
  # @yield [transaction] The block for reading and writing data.
2046
2111
  # @yieldparam [Google::Cloud::Spanner::Transaction] transaction The
2047
2112
  # Transaction object.
@@ -2144,7 +2209,7 @@ module Google
2144
2209
  # end
2145
2210
  #
2146
2211
  def transaction deadline: 120, exclude_txn_from_change_streams: false,
2147
- commit_options: nil, request_options: nil, call_options: nil
2212
+ commit_options: nil, request_options: nil, call_options: nil, read_lock_mode: nil
2148
2213
  ensure_service!
2149
2214
  unless Thread.current[IS_TRANSACTION_RUNNING_KEY].nil?
2150
2215
  raise "Nested transactions are not allowed"
@@ -2158,7 +2223,8 @@ module Google
2158
2223
  request_options, tag_type: :transaction_tag
2159
2224
 
2160
2225
  @pool.with_session do |session|
2161
- tx = session.create_empty_transaction exclude_txn_from_change_streams: exclude_txn_from_change_streams
2226
+ tx = session.create_empty_transaction \
2227
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams, read_lock_mode: read_lock_mode
2162
2228
  if request_options
2163
2229
  tx.transaction_tag = request_options[:transaction_tag]
2164
2230
  end
@@ -2175,7 +2241,8 @@ module Google
2175
2241
  tx.safe_begin_transaction!(
2176
2242
  exclude_from_change_streams: exclude_txn_from_change_streams,
2177
2243
  request_options: request_options,
2178
- call_options: call_options
2244
+ call_options: call_options,
2245
+ read_lock_mode: read_lock_mode
2179
2246
  )
2180
2247
  end
2181
2248
 
@@ -2195,7 +2262,8 @@ module Google
2195
2262
  commit_options: commit_options,
2196
2263
  request_options: request_options,
2197
2264
  call_options: call_options,
2198
- precommit_token: tx.precommit_token
2265
+ precommit_token: tx.precommit_token,
2266
+ read_lock_mode: read_lock_mode
2199
2267
  )
2200
2268
 
2201
2269
  tx.precommit_token = commit_resp.precommit_token
@@ -2216,7 +2284,8 @@ module Google
2216
2284
  previous_transaction_id = tx.transaction_id if tx.existing_transaction?
2217
2285
  tx = session.create_empty_transaction(
2218
2286
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
2219
- previous_transaction_id: previous_transaction_id
2287
+ previous_transaction_id: previous_transaction_id,
2288
+ read_lock_mode: read_lock_mode
2220
2289
  )
2221
2290
  if request_options
2222
2291
  tx.transaction_tag = request_options[:transaction_tag]
@@ -540,12 +540,14 @@ module Google
540
540
  def commit session_name, mutations = [],
541
541
  transaction_id: nil, exclude_txn_from_change_streams: false,
542
542
  isolation_level: nil, commit_options: nil, request_options: nil,
543
- call_options: nil, precommit_token: nil
543
+ call_options: nil, precommit_token: nil, read_lock_mode: nil
544
544
  route_to_leader = LARHeaders.commit
545
545
  tx_opts = nil
546
546
  if transaction_id.nil?
547
547
  tx_opts = V1::TransactionOptions.new(
548
- read_write: V1::TransactionOptions::ReadWrite.new,
548
+ read_write: V1::TransactionOptions::ReadWrite.new(
549
+ read_lock_mode: read_lock_mode
550
+ ),
549
551
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
550
552
  isolation_level: isolation_level
551
553
  )
@@ -640,7 +642,8 @@ module Google
640
642
  call_options: nil,
641
643
  route_to_leader: nil,
642
644
  mutation_key: nil,
643
- previous_transaction_id: nil
645
+ previous_transaction_id: nil,
646
+ read_lock_mode: nil
644
647
  read_write = if previous_transaction_id.nil?
645
648
  V1::TransactionOptions::ReadWrite.new
646
649
  else
@@ -649,6 +652,10 @@ module Google
649
652
  )
650
653
  end
651
654
 
655
+ unless read_lock_mode.nil?
656
+ read_write.read_lock_mode = read_lock_mode
657
+ end
658
+
652
659
  tx_opts = V1::TransactionOptions.new(
653
660
  read_write: read_write,
654
661
  exclude_txn_from_change_streams: exclude_txn_from_change_streams
@@ -648,6 +648,15 @@ module Google
648
648
  # * `:retry_codes` (`Array<String>`) - The error codes that should
649
649
  # trigger a retry.
650
650
  #
651
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
652
+ # The read lock mode for the transaction.
653
+ # Can be one of the following:
654
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
655
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
656
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
657
+ # but instead on a commit to validate that the data has not changed since the transaction started.
658
+ #
659
+ #
651
660
  # @yield [commit] The block for mutating the data.
652
661
  # @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
653
662
  #
@@ -684,7 +693,7 @@ module Google
684
693
  #
685
694
  def commit transaction_id: nil, exclude_txn_from_change_streams: false,
686
695
  isolation_level: nil, commit_options: nil, request_options: nil,
687
- call_options: nil
696
+ call_options: nil, read_lock_mode: nil
688
697
  ensure_service!
689
698
  commit = Commit.new
690
699
  yield commit
@@ -698,6 +707,7 @@ module Google
698
707
  transaction_id: transaction_id,
699
708
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
700
709
  isolation_level: isolation_level,
710
+ read_lock_mode: read_lock_mode,
701
711
  commit_options: commit_options,
702
712
  request_options: request_options,
703
713
  call_options: call_options,
@@ -888,6 +898,15 @@ module Google
888
898
  # * `:retry_codes` (`Array<String>`) - The error codes that should
889
899
  # trigger a retry.
890
900
  #
901
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
902
+ # The read lock mode for the transaction.
903
+ # Can be one of the following:
904
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
905
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
906
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
907
+ # but instead on a commit to validate that the data has not changed since the transaction started.
908
+ #
909
+ #
891
910
  # @return [Time, CommitResponse] The timestamp at which the operation
892
911
  # committed. If commit options are set it returns {CommitResponse}.
893
912
  #
@@ -919,14 +938,15 @@ module Google
919
938
  def upsert table, *rows,
920
939
  transaction_id: nil, exclude_txn_from_change_streams: false,
921
940
  isolation_level: nil, commit_options: nil, request_options: nil,
922
- call_options: nil
941
+ call_options: nil, read_lock_mode: nil
923
942
  opts = {
924
943
  transaction_id: transaction_id,
925
944
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
926
945
  isolation_level: isolation_level,
927
946
  commit_options: commit_options,
928
947
  request_options: request_options,
929
- call_options: call_options
948
+ call_options: call_options,
949
+ read_lock_mode: read_lock_mode
930
950
  }
931
951
  commit(**opts) do |c|
932
952
  c.upsert table, rows
@@ -1012,6 +1032,15 @@ module Google
1012
1032
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1013
1033
  # trigger a retry.
1014
1034
  #
1035
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1036
+ # The read lock mode for the transaction.
1037
+ # Can be one of the following:
1038
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1039
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1040
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1041
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1042
+ #
1043
+ #
1015
1044
  # @return [Time, CommitResponse] The timestamp at which the operation
1016
1045
  # committed. If commit options are set it returns {CommitResponse}.
1017
1046
  #
@@ -1043,14 +1072,15 @@ module Google
1043
1072
  def insert table, *rows,
1044
1073
  transaction_id: nil, exclude_txn_from_change_streams: false,
1045
1074
  isolation_level: nil, commit_options: nil, request_options: nil,
1046
- call_options: nil
1075
+ call_options: nil, read_lock_mode: nil
1047
1076
  opts = {
1048
1077
  transaction_id: transaction_id,
1049
1078
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1050
1079
  isolation_level: isolation_level,
1051
1080
  commit_options: commit_options,
1052
1081
  request_options: request_options,
1053
- call_options: call_options
1082
+ call_options: call_options,
1083
+ read_lock_mode: read_lock_mode
1054
1084
  }
1055
1085
  commit(**opts) do |c|
1056
1086
  c.insert table, rows
@@ -1135,6 +1165,15 @@ module Google
1135
1165
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1136
1166
  # trigger a retry.
1137
1167
  #
1168
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1169
+ # The read lock mode for the transaction.
1170
+ # Can be one of the following:
1171
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1172
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1173
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1174
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1175
+ #
1176
+ #
1138
1177
  # @return [Time, CommitResponse] The timestamp at which the operation
1139
1178
  # committed. If commit options are set it returns {CommitResponse}.
1140
1179
  #
@@ -1166,14 +1205,15 @@ module Google
1166
1205
  def update table, *rows,
1167
1206
  transaction_id: nil, exclude_txn_from_change_streams: false,
1168
1207
  isolation_level: nil, commit_options: nil, request_options: nil,
1169
- call_options: nil
1208
+ call_options: nil, read_lock_mode: nil
1170
1209
  opts = {
1171
1210
  transaction_id: transaction_id,
1172
1211
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1173
1212
  isolation_level: isolation_level,
1174
1213
  commit_options: commit_options,
1175
1214
  request_options: request_options,
1176
- call_options: call_options
1215
+ call_options: call_options,
1216
+ read_lock_mode: read_lock_mode
1177
1217
  }
1178
1218
  commit(**opts) do |c|
1179
1219
  c.update table, rows
@@ -1261,6 +1301,15 @@ module Google
1261
1301
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1262
1302
  # trigger a retry.
1263
1303
  #
1304
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1305
+ # The read lock mode for the transaction.
1306
+ # Can be one of the following:
1307
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1308
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1309
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1310
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1311
+ #
1312
+ #
1264
1313
  # @return [Time, CommitResponse] The timestamp at which the operation
1265
1314
  # committed. If commit options are set it returns {CommitResponse}.
1266
1315
  #
@@ -1291,14 +1340,16 @@ module Google
1291
1340
  #
1292
1341
  def replace table, *rows,
1293
1342
  transaction_id: nil, exclude_txn_from_change_streams: false,
1294
- isolation_level: nil, commit_options: nil, request_options: nil, call_options: nil
1343
+ isolation_level: nil, commit_options: nil, request_options: nil,
1344
+ call_options: nil, read_lock_mode: nil
1295
1345
  opts = {
1296
1346
  transaction_id: transaction_id,
1297
1347
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1298
1348
  isolation_level: isolation_level,
1299
1349
  commit_options: commit_options,
1300
1350
  request_options: request_options,
1301
- call_options: call_options
1351
+ call_options: call_options,
1352
+ read_lock_mode: read_lock_mode
1302
1353
  }
1303
1354
  commit(**opts) do |c|
1304
1355
  c.replace table, rows
@@ -1364,6 +1415,15 @@ module Google
1364
1415
  # * `:retry_codes` (`Array<String>`) - The error codes that should
1365
1416
  # trigger a retry.
1366
1417
  #
1418
+ # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1419
+ # The read lock mode for the transaction.
1420
+ # Can be one of the following:
1421
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1422
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1423
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1424
+ # but instead on a commit to validate that the data has not changed since the transaction started.
1425
+ #
1426
+ #
1367
1427
  # @return [Time, CommitResponse] The timestamp at which the operation
1368
1428
  # committed. If commit options are set it returns {CommitResponse}.
1369
1429
  #
@@ -1392,14 +1452,15 @@ module Google
1392
1452
  def delete table, keys = [],
1393
1453
  transaction_id: nil, exclude_txn_from_change_streams: false,
1394
1454
  isolation_level: nil, commit_options: nil, request_options: nil,
1395
- call_options: nil
1455
+ call_options: nil, read_lock_mode: nil
1396
1456
  opts = {
1397
1457
  transaction_id: transaction_id,
1398
1458
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1399
1459
  isolation_level: isolation_level,
1400
1460
  commit_options: commit_options,
1401
1461
  request_options: request_options,
1402
- call_options: call_options
1462
+ call_options: call_options,
1463
+ read_lock_mode: read_lock_mode
1403
1464
  }
1404
1465
  commit(**opts) do |c|
1405
1466
  c.delete table, keys
@@ -1423,12 +1484,15 @@ module Google
1423
1484
  # or write transactions from being tracked in change streams.
1424
1485
  # @private
1425
1486
  # @return [::Google::Cloud::Spanner::Transaction]
1426
- def create_transaction exclude_txn_from_change_streams: false
1487
+ def create_transaction exclude_txn_from_change_streams: false, read_lock_mode: nil
1427
1488
  route_to_leader = LARHeaders.begin_transaction true
1428
1489
  tx_grpc = service.begin_transaction path,
1429
1490
  route_to_leader: route_to_leader,
1430
- exclude_txn_from_change_streams: exclude_txn_from_change_streams
1431
- Transaction.from_grpc tx_grpc, self, exclude_txn_from_change_streams: exclude_txn_from_change_streams
1491
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1492
+ read_lock_mode: read_lock_mode
1493
+ Transaction.from_grpc \
1494
+ tx_grpc, self,
1495
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams, read_lock_mode: read_lock_mode
1432
1496
  end
1433
1497
 
1434
1498
  # Creates a new empty transaction wrapper without a server-side object.
@@ -1444,9 +1508,10 @@ module Google
1444
1508
  # of a new ReadWrite transaction when retry is attempted.
1445
1509
  # @private
1446
1510
  # @return [::Google::Cloud::Spanner::Transaction] The new *empty-wrapper* transaction object.
1447
- def create_empty_transaction exclude_txn_from_change_streams: false, previous_transaction_id: nil
1511
+ def create_empty_transaction exclude_txn_from_change_streams: false, previous_transaction_id: nil,
1512
+ read_lock_mode: nil
1448
1513
  Transaction.from_grpc nil, self, exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1449
- previous_transaction_id: previous_transaction_id
1514
+ previous_transaction_id: previous_transaction_id, read_lock_mode: read_lock_mode
1450
1515
  end
1451
1516
 
1452
1517
  # If the session is non-multiplexed, keeps the session alive by executing `"SELECT 1"`.
@@ -111,6 +111,9 @@ module Google
111
111
  # @return [::String, nil]
112
112
  attr_reader :previous_transaction_id
113
113
 
114
+ # @private Whether to add a read lock mode on the transaction.
115
+ attr_accessor :read_lock_mode
116
+
114
117
  # Creates a new `Spanner::Transaction` instance from a `V1::Transaction` object.
115
118
  # @param grpc [::Google::Cloud::Spanner::V1::Transaction] Underlying `V1::Transaction` object.
116
119
  # @param session [::Google::Cloud::Spanner::Session] The session this transaction is running in.
@@ -123,10 +126,11 @@ module Google
123
126
  # of a new ReadWrite transaction when retry is attempted.
124
127
  # @private
125
128
  # @return [::Google::Cloud::Spanner::Transaction]
126
- def initialize grpc, session, exclude_txn_from_change_streams, previous_transaction_id: nil
129
+ def initialize grpc, session, exclude_txn_from_change_streams, previous_transaction_id: nil, read_lock_mode: nil
127
130
  @grpc = grpc
128
131
  @session = session
129
132
  @exclude_txn_from_change_streams = exclude_txn_from_change_streams
133
+ @read_lock_mode = read_lock_mode
130
134
 
131
135
  # throwing away empty strings for simplicity
132
136
  unless previous_transaction_id.nil? || previous_transaction_id.empty?
@@ -136,6 +140,7 @@ module Google
136
140
  @commit = Commit.new
137
141
  @seqno = 0
138
142
  @exclude_txn_from_change_streams = false
143
+ @read_lock_mode = nil
139
144
 
140
145
  # Mutex to enfore thread safety for transaction creation and query executions.
141
146
  #
@@ -1250,8 +1255,10 @@ module Google
1250
1255
  # of a new ReadWrite transaction when retry is attempted.
1251
1256
  # @private
1252
1257
  # @return [::Google::Cloud::Spanner::Transaction]
1253
- def self.from_grpc grpc, session, exclude_txn_from_change_streams: false, previous_transaction_id: nil
1254
- new grpc, session, exclude_txn_from_change_streams, previous_transaction_id: previous_transaction_id
1258
+ def self.from_grpc grpc, session, exclude_txn_from_change_streams: false, previous_transaction_id: nil,
1259
+ read_lock_mode: nil
1260
+ new grpc, session, exclude_txn_from_change_streams, previous_transaction_id: previous_transaction_id,
1261
+ read_lock_mode: read_lock_mode
1255
1262
  end
1256
1263
 
1257
1264
  ##
@@ -1278,7 +1285,8 @@ module Google
1278
1285
  # @private
1279
1286
  # @return [::Google::Cloud::Spanner::V1::Transaction, nil] The new transaction
1280
1287
  # object, or `nil` if a transaction already exists.
1281
- def safe_begin_transaction! exclude_from_change_streams: false, request_options: nil, call_options: nil
1288
+ def safe_begin_transaction! exclude_from_change_streams: false, request_options: nil, call_options: nil,
1289
+ read_lock_mode: nil
1282
1290
  # If a read-write transaction on a multiplexed session commit mutations
1283
1291
  # without performing any reads or queries, one of the mutations from the mutation set
1284
1292
  # must be sent as a mutation key for `BeginTransaction`.
@@ -1299,7 +1307,8 @@ module Google
1299
1307
  call_options: call_options,
1300
1308
  route_to_leader: route_to_leader,
1301
1309
  mutation_key: mutation_key,
1302
- previous_transaction_id: previous_transaction_id
1310
+ previous_transaction_id: previous_transaction_id,
1311
+ read_lock_mode: read_lock_mode
1303
1312
  )
1304
1313
  end
1305
1314
  end
@@ -1343,7 +1352,7 @@ module Google
1343
1352
  # or write transactions from being tracked in change streams.
1344
1353
  # @private
1345
1354
  # @return [::Google::Cloud::Spanner::V1::TransactionSelector]
1346
- def tx_selector exclude_txn_from_change_streams: false
1355
+ def tx_selector exclude_txn_from_change_streams: false, read_lock_mode: nil
1347
1356
  return V1::TransactionSelector.new id: transaction_id if existing_transaction?
1348
1357
 
1349
1358
  read_write = if @previous_transaction_id.nil?
@@ -1354,6 +1363,10 @@ module Google
1354
1363
  )
1355
1364
  end
1356
1365
 
1366
+ unless read_lock_mode.nil?
1367
+ read_write.read_lock_mode = read_lock_mode
1368
+ end
1369
+
1357
1370
  V1::TransactionSelector.new(
1358
1371
  begin: V1::TransactionOptions.new(
1359
1372
  read_write: read_write,
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.31.0".freeze
19
+ VERSION = "2.32.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.31.0
4
+ version: 2.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore