google-cloud-spanner 2.35.0 → 2.36.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: 7f2092db61c2ca6c7797176db72845ee4889255ed94d641d27ea8b5ac42f62b7
4
- data.tar.gz: 3430361284c44739652f9ca1785a902cfccafc813e9b7833df854f0836df98c4
3
+ metadata.gz: c29026317ec1d049671bb84fe53bb524d37c47d193273e7833476c7910f973ff
4
+ data.tar.gz: b1f38f9d6ee9b1f6f943285e75bab33d33f5cbe7da56e56c4e44f5a4e39e98c0
5
5
  SHA512:
6
- metadata.gz: 4edac28e59ec12727331f7810325de889c71154d28a3fb1dc155ec8d92f2f3b0a5a3e1168cc7a7949befd72bb13da25194107041021872778486ea8744a49c00
7
- data.tar.gz: '018fba01b2d4dd8b16483a4a752c7768e8f512637973bdaf080cf7da8e14e20db8cae51ca0843de1b51dffdadfc4c0e5867bbbd94402d12cc8ecb9373416e1fa'
6
+ metadata.gz: 318b3243859a85c920190de101f5426873eb7bf573ed0bd8e9afbce931f6b8faf4c0b25406a69aad77b2c4ef1f93fd5751f00a9127b07a05fbf58a69c4db0ce3
7
+ data.tar.gz: eb54fca70387011e9718590c81a4249f5e681a43e6e6fa640aa032e801433c414769e2a255f270dde193994655455cee3344db9e67717a2adda12e176d5334b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release History
2
2
 
3
+ ### 2.36.0 (2026-05-08)
4
+
5
+ #### Features
6
+
7
+ * set txn opts at client level ([#234](https://github.com/googleapis/ruby-spanner/issues/234))
8
+ #### Bug Fixes
9
+
10
+ * lift up and fix circular requires ([#226](https://github.com/googleapis/ruby-spanner/issues/226))
11
+
3
12
  ### 2.35.0 (2026-02-23)
4
13
 
5
14
  #### Features
@@ -14,7 +14,6 @@
14
14
 
15
15
 
16
16
  require "google/cloud/spanner/errors"
17
- require "google/cloud/spanner/project"
18
17
  require "google/cloud/spanner/data"
19
18
  require "google/cloud/spanner/session_cache"
20
19
  require "google/cloud/spanner/session_creation_options"
@@ -72,10 +71,25 @@ module Google
72
71
  # @param directed_read_options [::Hash, nil] Optional. Client options used to set
73
72
  # the `directed_read_options` for all ReadRequests and ExecuteSqlRequests.
74
73
  # Converts to `V1::DirectedReadOptions`. Example option: `:exclude_replicas`.
74
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transactions.
75
+ # Can be overridden by the isolation level set on the transaction.
76
+ # Can be one of the following:
77
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
78
+ # * `:SERIALIZABLE` : The serializable isolation level.
79
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
80
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transactions.
81
+ # Can be overridden by the read lock mode set on the transaction.
82
+ # Can be one of the following:
83
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
84
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
85
+ # requested, locks are acquired on read.
86
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
87
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
88
+ # changed since the transaction started.
75
89
  # @private
76
90
  def initialize project, instance_id, database_id, session_labels: nil,
77
91
  pool_opts: {}, query_options: nil, database_role: nil,
78
- directed_read_options: nil
92
+ directed_read_options: nil, isolation_level: nil, read_lock_mode: nil
79
93
  @project = project
80
94
  @instance_id = instance_id
81
95
  @database_id = database_id
@@ -83,6 +97,8 @@ module Google
83
97
  @session_labels = session_labels
84
98
  @query_options = query_options
85
99
  @directed_read_options = directed_read_options
100
+ @isolation_level = isolation_level
101
+ @read_lock_mode = read_lock_mode
86
102
 
87
103
  _pool_opts = pool_opts # unused. Here only to avoid having to disable Rubocop's Lint/UnusedMethodArgument
88
104
 
@@ -1071,8 +1087,6 @@ module Google
1071
1087
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1072
1088
  # mutations will not be recorded in change streams with DDL option
1073
1089
  # `allow_txn_exclusion=true`.
1074
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1075
- # isolation level for the transaction.
1076
1090
  # @param [Hash] commit_options A hash of commit options.
1077
1091
  # e.g., return_commit_stats. Commit options are optional.
1078
1092
  # The following options can be provided:
@@ -1110,12 +1124,22 @@ module Google
1110
1124
  # trigger a retry.
1111
1125
  #
1112
1126
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1113
- # The read lock mode for the transaction.
1127
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1128
+ # mode will be used.
1114
1129
  # Can be one of the following:
1115
1130
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1116
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1117
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1118
- # but instead on a commit to validate that the data has not changed since the transaction started.
1131
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1132
+ # requested, locks are acquired on read.
1133
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1134
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1135
+ # changed since the transaction started.
1136
+ #
1137
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1138
+ # If not specified, the client-level isolation level will be used.
1139
+ # Can be one of the following:
1140
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1141
+ # * `:SERIALIZABLE` : The serializable isolation level.
1142
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1119
1143
  #
1120
1144
  # @return [Time, CommitResponse] The timestamp at which the operation
1121
1145
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1179,11 +1203,11 @@ module Google
1179
1203
  @pool.with_session do |session|
1180
1204
  session.upsert table, rows,
1181
1205
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1182
- isolation_level: isolation_level,
1206
+ isolation_level: isolation_level || @isolation_level,
1183
1207
  commit_options: commit_options,
1184
1208
  request_options: request_options,
1185
1209
  call_options: call_options,
1186
- read_lock_mode: read_lock_mode
1210
+ read_lock_mode: read_lock_mode || @read_lock_mode
1187
1211
  end
1188
1212
  end
1189
1213
  alias save upsert
@@ -1230,8 +1254,6 @@ module Google
1230
1254
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1231
1255
  # mutations will not be recorded in change streams with DDL option
1232
1256
  # `allow_txn_exclusion=true`.
1233
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1234
- # isolation level for the transaction.
1235
1257
  # @param [Hash] commit_options A hash of commit options.
1236
1258
  # e.g., return_commit_stats. Commit options are optional.
1237
1259
  # The following options can be provided:
@@ -1270,13 +1292,22 @@ module Google
1270
1292
  #
1271
1293
  #
1272
1294
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1273
- # The read lock mode for the transaction.
1295
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1296
+ # mode will be used.
1274
1297
  # Can be one of the following:
1275
1298
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1276
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1277
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1278
- # but instead on a commit to validate that the data has not changed since the transaction started.
1279
- #
1299
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1300
+ # requested, locks are acquired on read.
1301
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1302
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1303
+ # changed since the transaction started.
1304
+ #
1305
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1306
+ # If not specified, the client-level isolation level will be used.
1307
+ # Can be one of the following:
1308
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1309
+ # * `:SERIALIZABLE` : The serializable isolation level.
1310
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1280
1311
  #
1281
1312
  # @return [Time, CommitResponse] The timestamp at which the operation
1282
1313
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1340,11 +1371,11 @@ module Google
1340
1371
  @pool.with_session do |session|
1341
1372
  session.insert table, rows,
1342
1373
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1343
- isolation_level: isolation_level,
1374
+ isolation_level: isolation_level || @isolation_level,
1344
1375
  commit_options: commit_options,
1345
1376
  request_options: request_options,
1346
1377
  call_options: call_options,
1347
- read_lock_mode: read_lock_mode
1378
+ read_lock_mode: read_lock_mode || @read_lock_mode
1348
1379
  end
1349
1380
  end
1350
1381
 
@@ -1390,8 +1421,6 @@ module Google
1390
1421
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1391
1422
  # mutations will not be recorded in change streams with DDL option
1392
1423
  # `allow_txn_exclusion=true`.
1393
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1394
- # isolation level for the transaction.
1395
1424
  # @param [Hash] commit_options A hash of commit options.
1396
1425
  # e.g., return_commit_stats. Commit options are optional.
1397
1426
  # The following options can be provided:
@@ -1429,13 +1458,22 @@ module Google
1429
1458
  # trigger a retry.
1430
1459
  #
1431
1460
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1432
- # The read lock mode for the transaction.
1461
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1462
+ # mode will be used.
1433
1463
  # Can be one of the following:
1434
1464
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1435
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1436
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1437
- # but instead on a commit to validate that the data has not changed since the transaction started.
1438
- #
1465
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1466
+ # requested, locks are acquired on read.
1467
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1468
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1469
+ # changed since the transaction started.
1470
+ #
1471
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1472
+ # If not specified, the client-level isolation level will be used.
1473
+ # Can be one of the following:
1474
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1475
+ # * `:SERIALIZABLE` : The serializable isolation level.
1476
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1439
1477
  #
1440
1478
  # @return [Time, CommitResponse] The timestamp at which the operation
1441
1479
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1498,11 +1536,11 @@ module Google
1498
1536
  @pool.with_session do |session|
1499
1537
  session.update table, rows,
1500
1538
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1501
- isolation_level: isolation_level,
1539
+ isolation_level: isolation_level || @isolation_level,
1502
1540
  commit_options: commit_options,
1503
1541
  request_options: request_options,
1504
1542
  call_options: call_options,
1505
- read_lock_mode: read_lock_mode
1543
+ read_lock_mode: read_lock_mode || @read_lock_mode
1506
1544
  end
1507
1545
  end
1508
1546
 
@@ -1550,8 +1588,6 @@ module Google
1550
1588
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1551
1589
  # mutations will not be recorded in change streams with DDL option
1552
1590
  # `allow_txn_exclusion=true`.
1553
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1554
- # isolation level for the transaction.
1555
1591
  # @param [Hash] commit_options A hash of commit options.
1556
1592
  # e.g., return_commit_stats. Commit options are optional.
1557
1593
  # The following options can be provided:
@@ -1589,13 +1625,22 @@ module Google
1589
1625
  # trigger a retry.
1590
1626
  #
1591
1627
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1592
- # The read lock mode for the transaction.
1628
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1629
+ # mode will be used.
1593
1630
  # Can be one of the following:
1594
1631
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1595
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1596
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1597
- # but instead on a commit to validate that the data has not changed since the transaction started.
1598
- #
1632
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1633
+ # requested, locks are acquired on read.
1634
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1635
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1636
+ # changed since the transaction started.
1637
+ #
1638
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1639
+ # If not specified, the client-level isolation level will be used.
1640
+ # Can be one of the following:
1641
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1642
+ # * `:SERIALIZABLE` : The serializable isolation level.
1643
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1599
1644
  #
1600
1645
  # @return [Time, CommitResponse] The timestamp at which the operation
1601
1646
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1655,11 +1700,11 @@ module Google
1655
1700
  @pool.with_session do |session|
1656
1701
  session.replace table, rows,
1657
1702
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1658
- isolation_level: isolation_level,
1703
+ isolation_level: isolation_level || @isolation_level,
1659
1704
  commit_options: commit_options,
1660
1705
  request_options: request_options,
1661
1706
  call_options: call_options,
1662
- read_lock_mode: read_lock_mode
1707
+ read_lock_mode: read_lock_mode || @read_lock_mode
1663
1708
  end
1664
1709
  end
1665
1710
 
@@ -1686,8 +1731,6 @@ module Google
1686
1731
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1687
1732
  # mutations will not be recorded in change streams with DDL option
1688
1733
  # `allow_txn_exclusion=true`.
1689
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1690
- # isolation level for the transaction.
1691
1734
  # @param [Hash] commit_options A hash of commit options.
1692
1735
  # e.g., return_commit_stats. Commit options are optional.
1693
1736
  # The following options can be provided:
@@ -1725,13 +1768,22 @@ module Google
1725
1768
  # trigger a retry.
1726
1769
  #
1727
1770
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1728
- # The read lock mode for the transaction.
1771
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1772
+ # mode will be used.
1729
1773
  # Can be one of the following:
1730
1774
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1731
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1732
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1733
- # but instead on a commit to validate that the data has not changed since the transaction started.
1734
- #
1775
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1776
+ # requested, locks are acquired on read.
1777
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1778
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1779
+ # changed since the transaction started.
1780
+ #
1781
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1782
+ # If not specified, the client-level isolation level will be used.
1783
+ # Can be one of the following:
1784
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1785
+ # * `:SERIALIZABLE` : The serializable isolation level.
1786
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1735
1787
  #
1736
1788
  # @return [Time, CommitResponse] The timestamp at which the operation
1737
1789
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1788,11 +1840,11 @@ module Google
1788
1840
  @pool.with_session do |session|
1789
1841
  session.delete table, keys,
1790
1842
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1791
- isolation_level: isolation_level,
1843
+ isolation_level: isolation_level || @isolation_level,
1792
1844
  commit_options: commit_options,
1793
1845
  request_options: request_options,
1794
1846
  call_options: call_options,
1795
- read_lock_mode: read_lock_mode
1847
+ read_lock_mode: read_lock_mode || @read_lock_mode
1796
1848
  end
1797
1849
  end
1798
1850
 
@@ -1814,8 +1866,6 @@ module Google
1814
1866
  # @param [Boolean] exclude_txn_from_change_streams If set to true,
1815
1867
  # mutations will not be recorded in change streams with DDL option
1816
1868
  # `allow_txn_exclusion=true`.
1817
- # @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
1818
- # isolation level for the transaction.
1819
1869
  # @param [Hash] commit_options A hash of commit options.
1820
1870
  # e.g., return_commit_stats. Commit options are optional.
1821
1871
  # The following options can be provided:
@@ -1856,13 +1906,20 @@ module Google
1856
1906
  # @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
1857
1907
  #
1858
1908
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
1859
- # The read lock mode for the transaction.
1909
+ # The read lock mode for the transaction. If not specified, the client-level read lock
1910
+ # moce will be used.
1860
1911
  # Can be one of the following:
1861
1912
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1862
1913
  # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
1863
1914
  # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
1864
1915
  # but instead on a commit to validate that the data has not changed since the transaction started.
1865
1916
  #
1917
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1918
+ # If not specified, the client-level isolation level will be used.
1919
+ # Can be one of the following:
1920
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1921
+ # * `:SERIALIZABLE` : The serializable isolation level.
1922
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1866
1923
  #
1867
1924
  # @return [Time, CommitResponse] The timestamp at which the operation
1868
1925
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1931,11 +1988,11 @@ module Google
1931
1988
  @pool.with_session do |session|
1932
1989
  session.commit(
1933
1990
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1934
- isolation_level: isolation_level,
1991
+ isolation_level: isolation_level || @isolation_level,
1935
1992
  commit_options: commit_options,
1936
1993
  request_options: request_options,
1937
1994
  call_options: call_options,
1938
- read_lock_mode: read_lock_mode,
1995
+ read_lock_mode: read_lock_mode || @read_lock_mode,
1939
1996
  &block
1940
1997
  )
1941
1998
  end
@@ -2103,12 +2160,22 @@ module Google
2103
2160
  # trigger a retry.
2104
2161
  #
2105
2162
  # @param [Google::Cloud::Spanner::V1::TransactionOptions::ReadWrite::ReadLockMode] read_lock_mode
2106
- # The read lock mode for the transaction.
2163
+ # The read lock mode for the transaction. If not specified, the client-level read lock
2164
+ # mode will be used.
2107
2165
  # Can be one of the following:
2108
2166
  # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
2109
- # * `:PESSIMISTIC` : The pessimistic lock mode, where read locks are acquired immediately on read.
2110
- # * `:OPTIMISTIC` : The optimistic lock mode, where locks for reads are not acquired on read
2111
- # but instead on a commit to validate that the data has not changed since the transaction started.
2167
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
2168
+ # requested, locks are acquired on read.
2169
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
2170
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
2171
+ # changed since the transaction started.
2172
+ #
2173
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
2174
+ # If not specified, the client-level isolation level will be used.
2175
+ # Can be one of the following:
2176
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
2177
+ # * `:SERIALIZABLE` : The serializable isolation level.
2178
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
2112
2179
  #
2113
2180
  #
2114
2181
  # @yield [transaction] The block for reading and writing data.
@@ -2213,7 +2280,8 @@ module Google
2213
2280
  # end
2214
2281
  #
2215
2282
  def transaction deadline: 120, exclude_txn_from_change_streams: false,
2216
- commit_options: nil, request_options: nil, call_options: nil, read_lock_mode: nil
2283
+ commit_options: nil, request_options: nil, call_options: nil, read_lock_mode: nil,
2284
+ isolation_level: nil
2217
2285
  ensure_service!
2218
2286
  unless Thread.current[IS_TRANSACTION_RUNNING_KEY].nil?
2219
2287
  raise "Nested transactions are not allowed"
@@ -2230,8 +2298,9 @@ module Google
2230
2298
  transaction_tag = request_options[:transaction_tag] if request_options
2231
2299
  tx = session.create_empty_transaction \
2232
2300
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
2233
- read_lock_mode: read_lock_mode,
2234
- transaction_tag: transaction_tag
2301
+ read_lock_mode: read_lock_mode || @read_lock_mode,
2302
+ transaction_tag: transaction_tag,
2303
+ isolation_level: isolation_level || @isolation_level
2235
2304
 
2236
2305
  begin
2237
2306
  Thread.current[IS_TRANSACTION_RUNNING_KEY] = true
@@ -18,7 +18,6 @@ require "date"
18
18
  require "stringio"
19
19
  require "base64"
20
20
  require "bigdecimal"
21
- require "google/cloud/spanner/data"
22
21
  require "google/cloud/spanner/interval"
23
22
 
24
23
  module Google
@@ -14,9 +14,6 @@
14
14
 
15
15
 
16
16
  require "google/cloud/spanner/errors"
17
- require "google/cloud/spanner/service"
18
- require "google/cloud/spanner/client"
19
- require "google/cloud/spanner/batch_client"
20
17
  require "google/cloud/spanner/instance"
21
18
  require "google/cloud/spanner/database"
22
19
  require "google/cloud/spanner/range"
@@ -551,6 +548,22 @@ module Google
551
548
  # Spanner will wait for a replica in the list to become available,
552
549
  # requests may fail due to DEADLINE_EXCEEDED errors.
553
550
  #
551
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transactions. Can be
552
+ # overridden by the isolation level set on the transaction.
553
+ # Can be one of the following:
554
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
555
+ # * `:SERIALIZABLE` : The serializable isolation level.
556
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
557
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transactions. Can be
558
+ # overridden by the read lock mode set on the transaction.
559
+ # Can be one of the following:
560
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
561
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
562
+ # requested, locks are acquired on read.
563
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
564
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
565
+ # changed since the transaction started.
566
+ #
554
567
  # @return [::Google::Cloud::Spanner::Client] The newly created client.
555
568
  #
556
569
  # @example
@@ -569,7 +582,8 @@ module Google
569
582
  # end
570
583
  #
571
584
  def client instance_id, database_id, pool: {}, labels: nil,
572
- query_options: nil, database_role: nil, directed_read_options: nil
585
+ query_options: nil, database_role: nil, directed_read_options: nil,
586
+ isolation_level: nil, read_lock_mode: nil
573
587
  # Convert from possible Google::Protobuf::Map
574
588
  labels = labels.to_h { |k, v| [String(k), String(v)] } if labels
575
589
  # Configs set by environment variables take over client-level configs.
@@ -585,7 +599,9 @@ module Google
585
599
  session_labels: labels,
586
600
  query_options: query_options,
587
601
  database_role: database_role,
588
- directed_read_options: directed_read_options
602
+ directed_read_options: directed_read_options,
603
+ isolation_level: isolation_level,
604
+ read_lock_mode: read_lock_mode
589
605
  end
590
606
 
591
607
  ##
@@ -19,7 +19,6 @@ require "google/cloud/spanner/version"
19
19
  require "google/cloud/spanner/v1"
20
20
  require "google/cloud/spanner/admin/instance/v1"
21
21
  require "google/cloud/spanner/admin/database/v1"
22
- require "google/cloud/spanner/convert"
23
22
  require "google/cloud/spanner/lar_headers"
24
23
 
25
24
  module Google
@@ -641,6 +640,19 @@ module Google
641
640
  # An id of the previous transaction, if this new transaction wrapper is being created
642
641
  # as a part of a retry. Previous transaction id should be added to TransactionOptions
643
642
  # of a new ReadWrite transaction when retry is attempted.
643
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transaction.
644
+ # Can be one of the following:
645
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
646
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
647
+ # requested, locks are acquired on read.
648
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
649
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
650
+ # changed since the transaction started.
651
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
652
+ # Can be one of the following:
653
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
654
+ # * `:SERIALIZABLE` : The serializable isolation level.
655
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
644
656
  # @private
645
657
  # @return [::Google::Cloud::Spanner::V1::Transaction]
646
658
  def begin_transaction session_name,
@@ -650,7 +662,8 @@ module Google
650
662
  route_to_leader: nil,
651
663
  mutation_key: nil,
652
664
  previous_transaction_id: nil,
653
- read_lock_mode: nil
665
+ read_lock_mode: nil,
666
+ isolation_level: nil
654
667
  read_write = if previous_transaction_id.nil?
655
668
  V1::TransactionOptions::ReadWrite.new
656
669
  else
@@ -665,7 +678,8 @@ module Google
665
678
 
666
679
  tx_opts = V1::TransactionOptions.new(
667
680
  read_write: read_write,
668
- exclude_txn_from_change_streams: exclude_txn_from_change_streams
681
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
682
+ isolation_level: isolation_level
669
683
  )
670
684
 
671
685
  opts = default_options session_name: session_name,
@@ -1521,13 +1521,26 @@ module Google
1521
1521
  # of a new ReadWrite transaction when retry is attempted.
1522
1522
  # @param transaction_tag [::String, nil] Optional.
1523
1523
  # A tag used for statistics collection about this transaction.
1524
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transaction.
1525
+ # Can be one of the following:
1526
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1527
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1528
+ # requested, locks are acquired on read.
1529
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1530
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1531
+ # changed since the transaction started.
1532
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1533
+ # Can be one of the following:
1534
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1535
+ # * `:SERIALIZABLE` : The serializable isolation level.
1536
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1524
1537
  # @private
1525
1538
  # @return [::Google::Cloud::Spanner::Transaction] The new *empty-wrapper* transaction object.
1526
1539
  def create_empty_transaction exclude_txn_from_change_streams: false, previous_transaction_id: nil,
1527
- read_lock_mode: nil, transaction_tag: nil
1540
+ read_lock_mode: nil, transaction_tag: nil, isolation_level: nil
1528
1541
  Transaction.from_grpc nil, self, exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1529
1542
  previous_transaction_id: previous_transaction_id, read_lock_mode: read_lock_mode,
1530
- transaction_tag: transaction_tag
1543
+ transaction_tag: transaction_tag, isolation_level: isolation_level
1531
1544
  end
1532
1545
 
1533
1546
  # If the session is non-multiplexed, keeps the session alive by executing `"SELECT 1"`.
@@ -129,12 +129,13 @@ module Google
129
129
  # @private
130
130
  # @return [::Google::Cloud::Spanner::Transaction]
131
131
  def initialize grpc, session, exclude_txn_from_change_streams, previous_transaction_id: nil,
132
- read_lock_mode: nil, transaction_tag: nil
132
+ read_lock_mode: nil, transaction_tag: nil, isolation_level: nil
133
133
  @grpc = grpc
134
134
  @session = session
135
135
  @exclude_txn_from_change_streams = exclude_txn_from_change_streams
136
136
  @read_lock_mode = read_lock_mode
137
137
  @transaction_tag = transaction_tag
138
+ @isolation_level = isolation_level
138
139
 
139
140
  # throwing away empty strings for simplicity
140
141
  unless previous_transaction_id.nil? || previous_transaction_id.empty?
@@ -144,7 +145,6 @@ module Google
144
145
  @commit = Commit.new
145
146
  @seqno = 0
146
147
  @exclude_txn_from_change_streams = false
147
- @read_lock_mode = nil
148
148
 
149
149
  # Mutex to enfore thread safety for transaction creation and query executions.
150
150
  #
@@ -1259,12 +1259,25 @@ module Google
1259
1259
  # of a new ReadWrite transaction when retry is attempted.
1260
1260
  # @param transaction_tag [::String, nil] Optional.
1261
1261
  # A tag used for statistics collection about this transaction.
1262
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transaction.
1263
+ # Can be one of the following:
1264
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1265
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1266
+ # requested, locks are acquired on read.
1267
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1268
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1269
+ # changed since the transaction started.
1270
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1271
+ # Can be one of the following:
1272
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1273
+ # * `:SERIALIZABLE` : The serializable isolation level.
1274
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1262
1275
  # @private
1263
1276
  # @return [::Google::Cloud::Spanner::Transaction]
1264
1277
  def self.from_grpc grpc, session, exclude_txn_from_change_streams: false, previous_transaction_id: nil,
1265
- read_lock_mode: nil, transaction_tag: nil
1278
+ read_lock_mode: nil, transaction_tag: nil, isolation_level: nil
1266
1279
  new grpc, session, exclude_txn_from_change_streams, previous_transaction_id: previous_transaction_id,
1267
- read_lock_mode: read_lock_mode, transaction_tag: transaction_tag
1280
+ read_lock_mode: read_lock_mode, transaction_tag: transaction_tag, isolation_level: isolation_level
1268
1281
  end
1269
1282
 
1270
1283
  ##
@@ -1288,11 +1301,24 @@ module Google
1288
1301
  # Example option: `:priority`.
1289
1302
  # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
1290
1303
  # call options. Example option `:timeout`.
1304
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transaction.
1305
+ # Can be one of the following:
1306
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1307
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1308
+ # requested, locks are acquired on read.
1309
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1310
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1311
+ # changed since the transaction started.
1312
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction.
1313
+ # Can be one of the following:
1314
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1315
+ # * `:SERIALIZABLE` : The serializable isolation level.
1316
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1291
1317
  # @private
1292
1318
  # @return [::Google::Cloud::Spanner::V1::Transaction, nil] The new transaction
1293
1319
  # object, or `nil` if a transaction already exists.
1294
1320
  def safe_begin_transaction! exclude_from_change_streams: false, request_options: nil, call_options: nil,
1295
- read_lock_mode: nil
1321
+ read_lock_mode: nil, isolation_level: nil
1296
1322
  # If a read-write transaction on a multiplexed session commit mutations
1297
1323
  # without performing any reads or queries, one of the mutations from the mutation set
1298
1324
  # must be sent as a mutation key for `BeginTransaction`.
@@ -1315,7 +1341,8 @@ module Google
1315
1341
  route_to_leader: route_to_leader,
1316
1342
  mutation_key: mutation_key,
1317
1343
  previous_transaction_id: previous_transaction_id,
1318
- read_lock_mode: read_lock_mode
1344
+ read_lock_mode: read_lock_mode || @read_lock_mode,
1345
+ isolation_level: isolation_level || @isolation_level
1319
1346
  )
1320
1347
  end
1321
1348
  end
@@ -1357,9 +1384,24 @@ module Google
1357
1384
  # @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
1358
1385
  # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
1359
1386
  # or write transactions from being tracked in change streams.
1387
+ # @param read_lock_mode [::Symbol, nil] Optional. The read lock mode for the transaction. If not
1388
+ # specified, the client-level read lock mode will be used.
1389
+ # Can be one of the following:
1390
+ # * `:READ_LOCK_MODE_UNSPECIFIED` : The default unspecified read lock mode.
1391
+ # * `:PESSIMISTIC` : The pessimistic lock mode, where depending on the isolation level and/or lock
1392
+ # requested, locks are acquired on read.
1393
+ # * `:OPTIMISTIC` : The optimistic lock mode, where locks are not acquired on read. Depending on the
1394
+ # isolation level and/or lock requested on a read, data may be validated at commit time to be not
1395
+ # changed since the transaction started.
1396
+ # @param isolation_level [::Symbol, nil] Optional. The isolation level for the transaction. If not
1397
+ # specified, the client-level isolation level will be used.
1398
+ # Can be one of the following:
1399
+ # * `:ISOLATION_LEVEL_UNSPECIFIED` : The default unspecified isolation level.
1400
+ # * `:SERIALIZABLE` : The serializable isolation level.
1401
+ # * `:REPEATABLE_READ` : The repeatable read isolation level.
1360
1402
  # @private
1361
1403
  # @return [::Google::Cloud::Spanner::V1::TransactionSelector]
1362
- def tx_selector exclude_txn_from_change_streams: false, read_lock_mode: nil
1404
+ def tx_selector exclude_txn_from_change_streams: false, read_lock_mode: nil, isolation_level: nil
1363
1405
  return V1::TransactionSelector.new id: transaction_id if existing_transaction?
1364
1406
 
1365
1407
  read_write = if @previous_transaction_id.nil?
@@ -1370,14 +1412,16 @@ module Google
1370
1412
  )
1371
1413
  end
1372
1414
 
1373
- unless read_lock_mode.nil?
1374
- read_write.read_lock_mode = read_lock_mode
1415
+ read_lock = read_lock_mode || @read_lock_mode
1416
+ unless read_lock.nil?
1417
+ read_write.read_lock_mode = read_lock
1375
1418
  end
1376
1419
 
1377
1420
  V1::TransactionSelector.new(
1378
1421
  begin: V1::TransactionOptions.new(
1379
1422
  read_write: read_write,
1380
- exclude_txn_from_change_streams: exclude_txn_from_change_streams
1423
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1424
+ isolation_level: isolation_level || @isolation_level
1381
1425
  )
1382
1426
  )
1383
1427
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.35.0".freeze
19
+ VERSION = "2.36.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -14,7 +14,10 @@
14
14
 
15
15
 
16
16
  require "google-cloud-spanner"
17
+ require "google/cloud/spanner/batch_client"
18
+ require "google/cloud/spanner/client"
17
19
  require "google/cloud/spanner/project"
20
+ require "google/cloud/spanner/service"
18
21
  require "google/cloud/spanner/spanner_error"
19
22
  require "google/cloud/spanner/request_id_interceptor"
20
23
  require "google/cloud/config"
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.35.0
4
+ version: 2.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
181
  - - ">="
182
182
  - !ruby/object:Gem::Version
183
- version: '3.1'
183
+ version: '3.2'
184
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="