google-cloud-spanner 2.30.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/google/cloud/spanner/client.rb +113 -19
- data/lib/google/cloud/spanner/service.rb +15 -5
- data/lib/google/cloud/spanner/session.rb +104 -16
- data/lib/google/cloud/spanner/transaction.rb +19 -6
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e4f1e2c9ad4832aa5ade2d7f086d0e9fd3f8f7c01a48147f0160ab8d4ed774a
|
|
4
|
+
data.tar.gz: a2f84a797e638ad1fb7538a861cd8b153dea2d0aaab0e6a89138c9592b37edf8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f5e6a8a01519dc8bf7c87d81c1fd162c5297f5067c2fc7f42904aad8f59c13c322630841d20fc5433175c8cf3d4ef7afa52e01e0bf1171c35d27984e20d75d42
|
|
7
|
+
data.tar.gz: da60a3a4874ac6a695715f567baadd09de69c8691269a9dfd7c0f5011af80ff700feef8396fc79e97c22491b307c8f7e9b37742ba8bffc04706ee5560f80bbf8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
9
|
+
### 2.31.0 (2025-12-02)
|
|
10
|
+
|
|
11
|
+
#### Features
|
|
12
|
+
|
|
13
|
+
* Support isolation level in Transaction Options ([#206](https://github.com/googleapis/ruby-spanner/issues/206))
|
|
14
|
+
|
|
3
15
|
### 2.30.0 (2025-11-17)
|
|
4
16
|
|
|
5
17
|
#### Features
|
|
@@ -1067,6 +1067,8 @@ module Google
|
|
|
1067
1067
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1068
1068
|
# mutations will not be recorded in change streams with DDL option
|
|
1069
1069
|
# `allow_txn_exclusion=true`.
|
|
1070
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1071
|
+
# isolation level for the transaction.
|
|
1070
1072
|
# @param [Hash] commit_options A hash of commit options.
|
|
1071
1073
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1072
1074
|
# The following options can be provided:
|
|
@@ -1103,6 +1105,13 @@ module Google
|
|
|
1103
1105
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1104
1106
|
# trigger a retry.
|
|
1105
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.
|
|
1106
1115
|
#
|
|
1107
1116
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1108
1117
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
@@ -1158,16 +1167,19 @@ module Google
|
|
|
1158
1167
|
#
|
|
1159
1168
|
def upsert table, rows,
|
|
1160
1169
|
exclude_txn_from_change_streams: false,
|
|
1161
|
-
|
|
1170
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1171
|
+
call_options: nil, read_lock_mode: nil
|
|
1162
1172
|
request_options = Convert.to_request_options \
|
|
1163
1173
|
request_options, tag_type: :transaction_tag
|
|
1164
1174
|
|
|
1165
1175
|
@pool.with_session do |session|
|
|
1166
1176
|
session.upsert table, rows,
|
|
1167
1177
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1178
|
+
isolation_level: isolation_level,
|
|
1168
1179
|
commit_options: commit_options,
|
|
1169
1180
|
request_options: request_options,
|
|
1170
|
-
call_options: call_options
|
|
1181
|
+
call_options: call_options,
|
|
1182
|
+
read_lock_mode: read_lock_mode
|
|
1171
1183
|
end
|
|
1172
1184
|
end
|
|
1173
1185
|
alias save upsert
|
|
@@ -1214,6 +1226,8 @@ module Google
|
|
|
1214
1226
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1215
1227
|
# mutations will not be recorded in change streams with DDL option
|
|
1216
1228
|
# `allow_txn_exclusion=true`.
|
|
1229
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1230
|
+
# isolation level for the transaction.
|
|
1217
1231
|
# @param [Hash] commit_options A hash of commit options.
|
|
1218
1232
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1219
1233
|
# The following options can be provided:
|
|
@@ -1251,6 +1265,15 @@ module Google
|
|
|
1251
1265
|
# trigger a retry.
|
|
1252
1266
|
#
|
|
1253
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
|
+
#
|
|
1254
1277
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1255
1278
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1256
1279
|
#
|
|
@@ -1305,16 +1328,19 @@ module Google
|
|
|
1305
1328
|
#
|
|
1306
1329
|
def insert table, rows,
|
|
1307
1330
|
exclude_txn_from_change_streams: false,
|
|
1308
|
-
|
|
1331
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1332
|
+
call_options: nil, read_lock_mode: nil
|
|
1309
1333
|
request_options = Convert.to_request_options \
|
|
1310
1334
|
request_options, tag_type: :transaction_tag
|
|
1311
1335
|
|
|
1312
1336
|
@pool.with_session do |session|
|
|
1313
1337
|
session.insert table, rows,
|
|
1314
1338
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1339
|
+
isolation_level: isolation_level,
|
|
1315
1340
|
commit_options: commit_options,
|
|
1316
1341
|
request_options: request_options,
|
|
1317
|
-
call_options: call_options
|
|
1342
|
+
call_options: call_options,
|
|
1343
|
+
read_lock_mode: read_lock_mode
|
|
1318
1344
|
end
|
|
1319
1345
|
end
|
|
1320
1346
|
|
|
@@ -1360,6 +1386,8 @@ module Google
|
|
|
1360
1386
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1361
1387
|
# mutations will not be recorded in change streams with DDL option
|
|
1362
1388
|
# `allow_txn_exclusion=true`.
|
|
1389
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1390
|
+
# isolation level for the transaction.
|
|
1363
1391
|
# @param [Hash] commit_options A hash of commit options.
|
|
1364
1392
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1365
1393
|
# The following options can be provided:
|
|
@@ -1396,6 +1424,14 @@ module Google
|
|
|
1396
1424
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1397
1425
|
# trigger a retry.
|
|
1398
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
|
+
#
|
|
1399
1435
|
#
|
|
1400
1436
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1401
1437
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
@@ -1450,16 +1486,19 @@ module Google
|
|
|
1450
1486
|
#
|
|
1451
1487
|
def update table, rows,
|
|
1452
1488
|
exclude_txn_from_change_streams: false,
|
|
1453
|
-
|
|
1489
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1490
|
+
call_options: nil, read_lock_mode: nil
|
|
1454
1491
|
request_options = Convert.to_request_options \
|
|
1455
1492
|
request_options, tag_type: :transaction_tag
|
|
1456
1493
|
|
|
1457
1494
|
@pool.with_session do |session|
|
|
1458
1495
|
session.update table, rows,
|
|
1459
1496
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1497
|
+
isolation_level: isolation_level,
|
|
1460
1498
|
commit_options: commit_options,
|
|
1461
1499
|
request_options: request_options,
|
|
1462
|
-
call_options: call_options
|
|
1500
|
+
call_options: call_options,
|
|
1501
|
+
read_lock_mode: read_lock_mode
|
|
1463
1502
|
end
|
|
1464
1503
|
end
|
|
1465
1504
|
|
|
@@ -1507,6 +1546,8 @@ module Google
|
|
|
1507
1546
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1508
1547
|
# mutations will not be recorded in change streams with DDL option
|
|
1509
1548
|
# `allow_txn_exclusion=true`.
|
|
1549
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1550
|
+
# isolation level for the transaction.
|
|
1510
1551
|
# @param [Hash] commit_options A hash of commit options.
|
|
1511
1552
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1512
1553
|
# The following options can be provided:
|
|
@@ -1543,6 +1584,14 @@ module Google
|
|
|
1543
1584
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1544
1585
|
# trigger a retry.
|
|
1545
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
|
+
#
|
|
1546
1595
|
#
|
|
1547
1596
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1548
1597
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
@@ -1597,13 +1646,16 @@ module Google
|
|
|
1597
1646
|
#
|
|
1598
1647
|
def replace table, rows,
|
|
1599
1648
|
exclude_txn_from_change_streams: false,
|
|
1600
|
-
|
|
1649
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1650
|
+
call_options: nil, read_lock_mode: nil
|
|
1601
1651
|
@pool.with_session do |session|
|
|
1602
1652
|
session.replace table, rows,
|
|
1603
1653
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1654
|
+
isolation_level: isolation_level,
|
|
1604
1655
|
commit_options: commit_options,
|
|
1605
1656
|
request_options: request_options,
|
|
1606
|
-
call_options: call_options
|
|
1657
|
+
call_options: call_options,
|
|
1658
|
+
read_lock_mode: read_lock_mode
|
|
1607
1659
|
end
|
|
1608
1660
|
end
|
|
1609
1661
|
|
|
@@ -1630,6 +1682,8 @@ module Google
|
|
|
1630
1682
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1631
1683
|
# mutations will not be recorded in change streams with DDL option
|
|
1632
1684
|
# `allow_txn_exclusion=true`.
|
|
1685
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1686
|
+
# isolation level for the transaction.
|
|
1633
1687
|
# @param [Hash] commit_options A hash of commit options.
|
|
1634
1688
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1635
1689
|
# The following options can be provided:
|
|
@@ -1666,6 +1720,15 @@ module Google
|
|
|
1666
1720
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1667
1721
|
# trigger a retry.
|
|
1668
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
|
+
#
|
|
1669
1732
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1670
1733
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1671
1734
|
#
|
|
@@ -1713,16 +1776,19 @@ module Google
|
|
|
1713
1776
|
#
|
|
1714
1777
|
def delete table, keys = [],
|
|
1715
1778
|
exclude_txn_from_change_streams: false,
|
|
1716
|
-
|
|
1779
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1780
|
+
call_options: nil, read_lock_mode: nil
|
|
1717
1781
|
request_options = Convert.to_request_options \
|
|
1718
1782
|
request_options, tag_type: :transaction_tag
|
|
1719
1783
|
|
|
1720
1784
|
@pool.with_session do |session|
|
|
1721
1785
|
session.delete table, keys,
|
|
1722
1786
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1787
|
+
isolation_level: isolation_level,
|
|
1723
1788
|
commit_options: commit_options,
|
|
1724
1789
|
request_options: request_options,
|
|
1725
|
-
call_options: call_options
|
|
1790
|
+
call_options: call_options,
|
|
1791
|
+
read_lock_mode: read_lock_mode
|
|
1726
1792
|
end
|
|
1727
1793
|
end
|
|
1728
1794
|
|
|
@@ -1744,6 +1810,8 @@ module Google
|
|
|
1744
1810
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1745
1811
|
# mutations will not be recorded in change streams with DDL option
|
|
1746
1812
|
# `allow_txn_exclusion=true`.
|
|
1813
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1814
|
+
# isolation level for the transaction.
|
|
1747
1815
|
# @param [Hash] commit_options A hash of commit options.
|
|
1748
1816
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1749
1817
|
# The following options can be provided:
|
|
@@ -1783,6 +1851,15 @@ module Google
|
|
|
1783
1851
|
# @yield [commit] The block for mutating the data.
|
|
1784
1852
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
|
1785
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
|
+
#
|
|
1786
1863
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1787
1864
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1788
1865
|
#
|
|
@@ -1840,8 +1917,8 @@ module Google
|
|
|
1840
1917
|
# end
|
|
1841
1918
|
#
|
|
1842
1919
|
def commit exclude_txn_from_change_streams: false,
|
|
1843
|
-
|
|
1844
|
-
&block
|
|
1920
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1921
|
+
call_options: nil, read_lock_mode: nil, &block
|
|
1845
1922
|
raise ArgumentError, "Must provide a block" unless block_given?
|
|
1846
1923
|
|
|
1847
1924
|
request_options = Convert.to_request_options \
|
|
@@ -1850,8 +1927,12 @@ module Google
|
|
|
1850
1927
|
@pool.with_session do |session|
|
|
1851
1928
|
session.commit(
|
|
1852
1929
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1853
|
-
|
|
1854
|
-
|
|
1930
|
+
isolation_level: isolation_level,
|
|
1931
|
+
commit_options: commit_options,
|
|
1932
|
+
request_options: request_options,
|
|
1933
|
+
call_options: call_options,
|
|
1934
|
+
read_lock_mode: read_lock_mode,
|
|
1935
|
+
&block
|
|
1855
1936
|
)
|
|
1856
1937
|
end
|
|
1857
1938
|
end
|
|
@@ -2017,6 +2098,15 @@ module Google
|
|
|
2017
2098
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
2018
2099
|
# trigger a retry.
|
|
2019
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
|
+
#
|
|
2020
2110
|
# @yield [transaction] The block for reading and writing data.
|
|
2021
2111
|
# @yieldparam [Google::Cloud::Spanner::Transaction] transaction The
|
|
2022
2112
|
# Transaction object.
|
|
@@ -2119,7 +2209,7 @@ module Google
|
|
|
2119
2209
|
# end
|
|
2120
2210
|
#
|
|
2121
2211
|
def transaction deadline: 120, exclude_txn_from_change_streams: false,
|
|
2122
|
-
commit_options: nil, request_options: nil, call_options: nil
|
|
2212
|
+
commit_options: nil, request_options: nil, call_options: nil, read_lock_mode: nil
|
|
2123
2213
|
ensure_service!
|
|
2124
2214
|
unless Thread.current[IS_TRANSACTION_RUNNING_KEY].nil?
|
|
2125
2215
|
raise "Nested transactions are not allowed"
|
|
@@ -2133,7 +2223,8 @@ module Google
|
|
|
2133
2223
|
request_options, tag_type: :transaction_tag
|
|
2134
2224
|
|
|
2135
2225
|
@pool.with_session do |session|
|
|
2136
|
-
tx = session.create_empty_transaction
|
|
2226
|
+
tx = session.create_empty_transaction \
|
|
2227
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams, read_lock_mode: read_lock_mode
|
|
2137
2228
|
if request_options
|
|
2138
2229
|
tx.transaction_tag = request_options[:transaction_tag]
|
|
2139
2230
|
end
|
|
@@ -2150,7 +2241,8 @@ module Google
|
|
|
2150
2241
|
tx.safe_begin_transaction!(
|
|
2151
2242
|
exclude_from_change_streams: exclude_txn_from_change_streams,
|
|
2152
2243
|
request_options: request_options,
|
|
2153
|
-
call_options: call_options
|
|
2244
|
+
call_options: call_options,
|
|
2245
|
+
read_lock_mode: read_lock_mode
|
|
2154
2246
|
)
|
|
2155
2247
|
end
|
|
2156
2248
|
|
|
@@ -2170,7 +2262,8 @@ module Google
|
|
|
2170
2262
|
commit_options: commit_options,
|
|
2171
2263
|
request_options: request_options,
|
|
2172
2264
|
call_options: call_options,
|
|
2173
|
-
precommit_token: tx.precommit_token
|
|
2265
|
+
precommit_token: tx.precommit_token,
|
|
2266
|
+
read_lock_mode: read_lock_mode
|
|
2174
2267
|
)
|
|
2175
2268
|
|
|
2176
2269
|
tx.precommit_token = commit_resp.precommit_token
|
|
@@ -2191,7 +2284,8 @@ module Google
|
|
|
2191
2284
|
previous_transaction_id = tx.transaction_id if tx.existing_transaction?
|
|
2192
2285
|
tx = session.create_empty_transaction(
|
|
2193
2286
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
2194
|
-
previous_transaction_id: previous_transaction_id
|
|
2287
|
+
previous_transaction_id: previous_transaction_id,
|
|
2288
|
+
read_lock_mode: read_lock_mode
|
|
2195
2289
|
)
|
|
2196
2290
|
if request_options
|
|
2197
2291
|
tx.transaction_tag = request_options[:transaction_tag]
|
|
@@ -524,6 +524,8 @@ module Google
|
|
|
524
524
|
# @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
|
|
525
525
|
# When `exclude_txn_from_change_streams` is set to `true`, it prevents read
|
|
526
526
|
# or write transactions from being tracked in change streams.
|
|
527
|
+
# @param isolation_level [::Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] Optional.
|
|
528
|
+
# The isolation level for the transaction.
|
|
527
529
|
# @param commit_options [::Hash, nil] Optional. A hash of commit options.
|
|
528
530
|
# Example option: `:return_commit_stats`.
|
|
529
531
|
# @param request_options [::Hash, nil] Optional. Common request options.
|
|
@@ -537,14 +539,17 @@ module Google
|
|
|
537
539
|
# @return [::Google::Cloud::Spanner::V1::CommitResponse]
|
|
538
540
|
def commit session_name, mutations = [],
|
|
539
541
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
540
|
-
|
|
541
|
-
precommit_token: nil
|
|
542
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
543
|
+
call_options: nil, precommit_token: nil, read_lock_mode: nil
|
|
542
544
|
route_to_leader = LARHeaders.commit
|
|
543
545
|
tx_opts = nil
|
|
544
546
|
if transaction_id.nil?
|
|
545
547
|
tx_opts = V1::TransactionOptions.new(
|
|
546
|
-
read_write: V1::TransactionOptions::ReadWrite.new
|
|
547
|
-
|
|
548
|
+
read_write: V1::TransactionOptions::ReadWrite.new(
|
|
549
|
+
read_lock_mode: read_lock_mode
|
|
550
|
+
),
|
|
551
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
552
|
+
isolation_level: isolation_level
|
|
548
553
|
)
|
|
549
554
|
end
|
|
550
555
|
opts = default_options session_name: session_name,
|
|
@@ -637,7 +642,8 @@ module Google
|
|
|
637
642
|
call_options: nil,
|
|
638
643
|
route_to_leader: nil,
|
|
639
644
|
mutation_key: nil,
|
|
640
|
-
previous_transaction_id: nil
|
|
645
|
+
previous_transaction_id: nil,
|
|
646
|
+
read_lock_mode: nil
|
|
641
647
|
read_write = if previous_transaction_id.nil?
|
|
642
648
|
V1::TransactionOptions::ReadWrite.new
|
|
643
649
|
else
|
|
@@ -646,6 +652,10 @@ module Google
|
|
|
646
652
|
)
|
|
647
653
|
end
|
|
648
654
|
|
|
655
|
+
unless read_lock_mode.nil?
|
|
656
|
+
read_write.read_lock_mode = read_lock_mode
|
|
657
|
+
end
|
|
658
|
+
|
|
649
659
|
tx_opts = V1::TransactionOptions.new(
|
|
650
660
|
read_write: read_write,
|
|
651
661
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
|
@@ -603,6 +603,8 @@ module Google
|
|
|
603
603
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
604
604
|
# mutations will not be recorded in change streams with DDL option
|
|
605
605
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
606
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
607
|
+
# isolation level for the transaction.
|
|
606
608
|
# @param [Hash] commit_options A hash of commit options.
|
|
607
609
|
# e.g., return_commit_stats. Commit options are optional.
|
|
608
610
|
# The following options can be provided:
|
|
@@ -646,6 +648,15 @@ module Google
|
|
|
646
648
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
647
649
|
# trigger a retry.
|
|
648
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
|
+
#
|
|
649
660
|
# @yield [commit] The block for mutating the data.
|
|
650
661
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
|
651
662
|
#
|
|
@@ -681,7 +692,8 @@ module Google
|
|
|
681
692
|
# puts commit_resp.stats.mutation_count
|
|
682
693
|
#
|
|
683
694
|
def commit transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
684
|
-
|
|
695
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
696
|
+
call_options: nil, read_lock_mode: nil
|
|
685
697
|
ensure_service!
|
|
686
698
|
commit = Commit.new
|
|
687
699
|
yield commit
|
|
@@ -694,6 +706,8 @@ module Google
|
|
|
694
706
|
commit.mutations,
|
|
695
707
|
transaction_id: transaction_id,
|
|
696
708
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
709
|
+
isolation_level: isolation_level,
|
|
710
|
+
read_lock_mode: read_lock_mode,
|
|
697
711
|
commit_options: commit_options,
|
|
698
712
|
request_options: request_options,
|
|
699
713
|
call_options: call_options,
|
|
@@ -840,6 +854,8 @@ module Google
|
|
|
840
854
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
841
855
|
# mutations will not be recorded in change streams with DDL option
|
|
842
856
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
857
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
858
|
+
# isolation level for the transaction.
|
|
843
859
|
# @param [Hash] commit_options A hash of commit options.
|
|
844
860
|
# e.g., return_commit_stats. Commit options are optional.
|
|
845
861
|
# The following options can be provided:
|
|
@@ -882,6 +898,15 @@ module Google
|
|
|
882
898
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
883
899
|
# trigger a retry.
|
|
884
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
|
+
#
|
|
885
910
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
886
911
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
887
912
|
#
|
|
@@ -912,13 +937,16 @@ module Google
|
|
|
912
937
|
#
|
|
913
938
|
def upsert table, *rows,
|
|
914
939
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
915
|
-
|
|
940
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
941
|
+
call_options: nil, read_lock_mode: nil
|
|
916
942
|
opts = {
|
|
917
943
|
transaction_id: transaction_id,
|
|
918
944
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
945
|
+
isolation_level: isolation_level,
|
|
919
946
|
commit_options: commit_options,
|
|
920
947
|
request_options: request_options,
|
|
921
|
-
call_options: call_options
|
|
948
|
+
call_options: call_options,
|
|
949
|
+
read_lock_mode: read_lock_mode
|
|
922
950
|
}
|
|
923
951
|
commit(**opts) do |c|
|
|
924
952
|
c.upsert table, rows
|
|
@@ -960,6 +988,8 @@ module Google
|
|
|
960
988
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
961
989
|
# mutations will not be recorded in change streams with DDL option
|
|
962
990
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
991
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
992
|
+
# isolation level for the transaction.
|
|
963
993
|
# @param [Hash] commit_options A hash of commit options.
|
|
964
994
|
# e.g., return_commit_stats. Commit options are optional.
|
|
965
995
|
# The following options can be provided:
|
|
@@ -1002,6 +1032,15 @@ module Google
|
|
|
1002
1032
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1003
1033
|
# trigger a retry.
|
|
1004
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
|
+
#
|
|
1005
1044
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1006
1045
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1007
1046
|
#
|
|
@@ -1032,13 +1071,16 @@ module Google
|
|
|
1032
1071
|
#
|
|
1033
1072
|
def insert table, *rows,
|
|
1034
1073
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
1035
|
-
|
|
1074
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1075
|
+
call_options: nil, read_lock_mode: nil
|
|
1036
1076
|
opts = {
|
|
1037
1077
|
transaction_id: transaction_id,
|
|
1038
1078
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1079
|
+
isolation_level: isolation_level,
|
|
1039
1080
|
commit_options: commit_options,
|
|
1040
1081
|
request_options: request_options,
|
|
1041
|
-
call_options: call_options
|
|
1082
|
+
call_options: call_options,
|
|
1083
|
+
read_lock_mode: read_lock_mode
|
|
1042
1084
|
}
|
|
1043
1085
|
commit(**opts) do |c|
|
|
1044
1086
|
c.insert table, rows
|
|
@@ -1079,6 +1121,8 @@ module Google
|
|
|
1079
1121
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1080
1122
|
# mutations will not be recorded in change streams with DDL option
|
|
1081
1123
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
1124
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1125
|
+
# isolation level for the transaction.
|
|
1082
1126
|
# @param [Hash] commit_options A hash of commit options.
|
|
1083
1127
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1084
1128
|
# The following options can be provided:
|
|
@@ -1121,6 +1165,15 @@ module Google
|
|
|
1121
1165
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1122
1166
|
# trigger a retry.
|
|
1123
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
|
+
#
|
|
1124
1177
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1125
1178
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1126
1179
|
#
|
|
@@ -1151,13 +1204,16 @@ module Google
|
|
|
1151
1204
|
#
|
|
1152
1205
|
def update table, *rows,
|
|
1153
1206
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
1154
|
-
|
|
1207
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1208
|
+
call_options: nil, read_lock_mode: nil
|
|
1155
1209
|
opts = {
|
|
1156
1210
|
transaction_id: transaction_id,
|
|
1157
1211
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1212
|
+
isolation_level: isolation_level,
|
|
1158
1213
|
commit_options: commit_options,
|
|
1159
1214
|
request_options: request_options,
|
|
1160
|
-
call_options: call_options
|
|
1215
|
+
call_options: call_options,
|
|
1216
|
+
read_lock_mode: read_lock_mode
|
|
1161
1217
|
}
|
|
1162
1218
|
commit(**opts) do |c|
|
|
1163
1219
|
c.update table, rows
|
|
@@ -1200,6 +1256,8 @@ module Google
|
|
|
1200
1256
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1201
1257
|
# mutations will not be recorded in change streams with DDL option
|
|
1202
1258
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
1259
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1260
|
+
# isolation level for the transaction.
|
|
1203
1261
|
# @param [Hash] commit_options A hash of commit options.
|
|
1204
1262
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1205
1263
|
# The following options can be provided:
|
|
@@ -1243,6 +1301,15 @@ module Google
|
|
|
1243
1301
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1244
1302
|
# trigger a retry.
|
|
1245
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
|
+
#
|
|
1246
1313
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1247
1314
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1248
1315
|
#
|
|
@@ -1273,13 +1340,16 @@ module Google
|
|
|
1273
1340
|
#
|
|
1274
1341
|
def replace table, *rows,
|
|
1275
1342
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
1276
|
-
|
|
1343
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1344
|
+
call_options: nil, read_lock_mode: nil
|
|
1277
1345
|
opts = {
|
|
1278
1346
|
transaction_id: transaction_id,
|
|
1279
1347
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1348
|
+
isolation_level: isolation_level,
|
|
1280
1349
|
commit_options: commit_options,
|
|
1281
1350
|
request_options: request_options,
|
|
1282
|
-
call_options: call_options
|
|
1351
|
+
call_options: call_options,
|
|
1352
|
+
read_lock_mode: read_lock_mode
|
|
1283
1353
|
}
|
|
1284
1354
|
commit(**opts) do |c|
|
|
1285
1355
|
c.replace table, rows
|
|
@@ -1301,6 +1371,8 @@ module Google
|
|
|
1301
1371
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1302
1372
|
# mutations will not be recorded in change streams with DDL option
|
|
1303
1373
|
# `allow_txn_exclusion=true`. Used if starting a new transaction.
|
|
1374
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1375
|
+
# isolation level for the transaction.
|
|
1304
1376
|
# @param [Hash] commit_options A hash of commit options.
|
|
1305
1377
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1306
1378
|
# The following options can be provided:
|
|
@@ -1343,6 +1415,15 @@ module Google
|
|
|
1343
1415
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1344
1416
|
# trigger a retry.
|
|
1345
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
|
+
#
|
|
1346
1427
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
|
1347
1428
|
# committed. If commit options are set it returns {CommitResponse}.
|
|
1348
1429
|
#
|
|
@@ -1370,13 +1451,16 @@ module Google
|
|
|
1370
1451
|
#
|
|
1371
1452
|
def delete table, keys = [],
|
|
1372
1453
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
1373
|
-
|
|
1454
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1455
|
+
call_options: nil, read_lock_mode: nil
|
|
1374
1456
|
opts = {
|
|
1375
1457
|
transaction_id: transaction_id,
|
|
1376
1458
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1459
|
+
isolation_level: isolation_level,
|
|
1377
1460
|
commit_options: commit_options,
|
|
1378
1461
|
request_options: request_options,
|
|
1379
|
-
call_options: call_options
|
|
1462
|
+
call_options: call_options,
|
|
1463
|
+
read_lock_mode: read_lock_mode
|
|
1380
1464
|
}
|
|
1381
1465
|
commit(**opts) do |c|
|
|
1382
1466
|
c.delete table, keys
|
|
@@ -1400,12 +1484,15 @@ module Google
|
|
|
1400
1484
|
# or write transactions from being tracked in change streams.
|
|
1401
1485
|
# @private
|
|
1402
1486
|
# @return [::Google::Cloud::Spanner::Transaction]
|
|
1403
|
-
def create_transaction exclude_txn_from_change_streams: false
|
|
1487
|
+
def create_transaction exclude_txn_from_change_streams: false, read_lock_mode: nil
|
|
1404
1488
|
route_to_leader = LARHeaders.begin_transaction true
|
|
1405
1489
|
tx_grpc = service.begin_transaction path,
|
|
1406
1490
|
route_to_leader: route_to_leader,
|
|
1407
|
-
exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
|
1408
|
-
|
|
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
|
|
1409
1496
|
end
|
|
1410
1497
|
|
|
1411
1498
|
# Creates a new empty transaction wrapper without a server-side object.
|
|
@@ -1421,9 +1508,10 @@ module Google
|
|
|
1421
1508
|
# of a new ReadWrite transaction when retry is attempted.
|
|
1422
1509
|
# @private
|
|
1423
1510
|
# @return [::Google::Cloud::Spanner::Transaction] The new *empty-wrapper* transaction object.
|
|
1424
|
-
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
|
|
1425
1513
|
Transaction.from_grpc nil, self, exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1426
|
-
previous_transaction_id: previous_transaction_id
|
|
1514
|
+
previous_transaction_id: previous_transaction_id, read_lock_mode: read_lock_mode
|
|
1427
1515
|
end
|
|
1428
1516
|
|
|
1429
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
|
-
|
|
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,
|