google-cloud-spanner 2.22.0 → 2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/google/cloud/spanner/admin/database.rb +9 -11
- data/lib/google/cloud/spanner/admin/instance.rb +9 -11
- data/lib/google/cloud/spanner/backup/job/list.rb +1 -2
- data/lib/google/cloud/spanner/backup/job.rb +1 -2
- data/lib/google/cloud/spanner/backup/list.rb +1 -3
- data/lib/google/cloud/spanner/backup/restore/job.rb +1 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +6 -5
- data/lib/google/cloud/spanner/batch_update.rb +1 -2
- data/lib/google/cloud/spanner/batch_write.rb +72 -0
- data/lib/google/cloud/spanner/batch_write_results.rb +142 -0
- data/lib/google/cloud/spanner/client.rb +232 -24
- data/lib/google/cloud/spanner/database/job/list.rb +1 -2
- data/lib/google/cloud/spanner/database/job.rb +1 -2
- data/lib/google/cloud/spanner/database/list.rb +2 -3
- data/lib/google/cloud/spanner/instance/config/list.rb +2 -3
- data/lib/google/cloud/spanner/instance/job.rb +2 -3
- data/lib/google/cloud/spanner/instance/list.rb +2 -3
- data/lib/google/cloud/spanner/lar_headers.rb +4 -0
- data/lib/google/cloud/spanner/mutation_group.rb +288 -0
- data/lib/google/cloud/spanner/project.rb +9 -27
- data/lib/google/cloud/spanner/service.rb +32 -6
- data/lib/google/cloud/spanner/session.rb +161 -17
- data/lib/google/cloud/spanner/transaction.rb +9 -3
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +32 -15
@@ -25,6 +25,7 @@ require "google/cloud/spanner/column_value"
|
|
25
25
|
require "google/cloud/spanner/convert"
|
26
26
|
require "google/cloud/spanner/commit_response"
|
27
27
|
require "google/cloud/spanner/lar_headers"
|
28
|
+
require "google/cloud/spanner/batch_write_results"
|
28
29
|
|
29
30
|
module Google
|
30
31
|
module Cloud
|
@@ -624,6 +625,9 @@ module Google
|
|
624
625
|
# `[:INT64]`.
|
625
626
|
# * {Fields} - Nested Structs are specified by providing a Fields
|
626
627
|
# object.
|
628
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
629
|
+
# mutations will not be recorded in change streams with DDL option
|
630
|
+
# `allow_txn_exclusion=true`.
|
627
631
|
# @param [Hash] query_options A hash of values to specify the custom
|
628
632
|
# query options for executing SQL query. Query options are optional.
|
629
633
|
# The following settings can be provided:
|
@@ -735,6 +739,7 @@ module Google
|
|
735
739
|
# request_options: request_options
|
736
740
|
#
|
737
741
|
def execute_partition_update sql, params: nil, types: nil,
|
742
|
+
exclude_txn_from_change_streams: false,
|
738
743
|
query_options: nil, request_options: nil,
|
739
744
|
call_options: nil
|
740
745
|
ensure_service!
|
@@ -745,9 +750,10 @@ module Google
|
|
745
750
|
route_to_leader = LARHeaders.partition_query
|
746
751
|
results = nil
|
747
752
|
@pool.with_session do |session|
|
753
|
+
transaction = pdml_transaction session, exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
748
754
|
results = session.execute_query \
|
749
755
|
sql, params: params, types: types,
|
750
|
-
transaction:
|
756
|
+
transaction: transaction,
|
751
757
|
query_options: query_options, request_options: request_options,
|
752
758
|
call_options: call_options, route_to_leader: route_to_leader
|
753
759
|
end
|
@@ -1020,6 +1026,9 @@ module Google
|
|
1020
1026
|
# See [Data
|
1021
1027
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1022
1028
|
#
|
1029
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1030
|
+
# mutations will not be recorded in change streams with DDL option
|
1031
|
+
# `allow_txn_exclusion=true`.
|
1023
1032
|
# @param [Hash] commit_options A hash of commit options.
|
1024
1033
|
# e.g., return_commit_stats. Commit options are optional.
|
1025
1034
|
# The following options can be provided:
|
@@ -1042,6 +1051,20 @@ module Google
|
|
1042
1051
|
# * `:tag` (String) A tag used for statistics collection
|
1043
1052
|
# about transaction. A tag must be a valid identifier of the format:
|
1044
1053
|
# `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1054
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1055
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1056
|
+
# optional. The following settings can be provided:
|
1057
|
+
#
|
1058
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1059
|
+
# that overrides the default setting.
|
1060
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1061
|
+
# setting of retry policy with the following keys:
|
1062
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1063
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1064
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1065
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1066
|
+
# trigger a retry.
|
1067
|
+
#
|
1045
1068
|
#
|
1046
1069
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1047
1070
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1095,13 +1118,18 @@ module Google
|
|
1095
1118
|
# { id: 2, name: "Harvey", active: true }],
|
1096
1119
|
# request_options: request_options
|
1097
1120
|
#
|
1098
|
-
def upsert table, rows,
|
1121
|
+
def upsert table, rows,
|
1122
|
+
exclude_txn_from_change_streams: false,
|
1123
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1099
1124
|
request_options = Convert.to_request_options \
|
1100
1125
|
request_options, tag_type: :transaction_tag
|
1101
1126
|
|
1102
1127
|
@pool.with_session do |session|
|
1103
|
-
session.upsert table, rows,
|
1104
|
-
|
1128
|
+
session.upsert table, rows,
|
1129
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1130
|
+
commit_options: commit_options,
|
1131
|
+
request_options: request_options,
|
1132
|
+
call_options: call_options
|
1105
1133
|
end
|
1106
1134
|
end
|
1107
1135
|
alias save upsert
|
@@ -1144,6 +1172,9 @@ module Google
|
|
1144
1172
|
#
|
1145
1173
|
# See [Data
|
1146
1174
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1175
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1176
|
+
# mutations will not be recorded in change streams with DDL option
|
1177
|
+
# `allow_txn_exclusion=true`.
|
1147
1178
|
# @param [Hash] commit_options A hash of commit options.
|
1148
1179
|
# e.g., return_commit_stats. Commit options are optional.
|
1149
1180
|
# The following options can be provided:
|
@@ -1166,6 +1197,20 @@ module Google
|
|
1166
1197
|
# * `:tag` (String) A tag used for statistics collection
|
1167
1198
|
# about transaction. A tag must be a valid identifier of the
|
1168
1199
|
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1200
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1201
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1202
|
+
# optional. The following settings can be provided:
|
1203
|
+
#
|
1204
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1205
|
+
# that overrides the default setting.
|
1206
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1207
|
+
# setting of retry policy with the following keys:
|
1208
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1209
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1210
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1211
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1212
|
+
# trigger a retry.
|
1213
|
+
#
|
1169
1214
|
#
|
1170
1215
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1171
1216
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1219,13 +1264,18 @@ module Google
|
|
1219
1264
|
# { id: 2, name: "Harvey", active: true }],
|
1220
1265
|
# request_options: request_options
|
1221
1266
|
#
|
1222
|
-
def insert table, rows,
|
1267
|
+
def insert table, rows,
|
1268
|
+
exclude_txn_from_change_streams: false,
|
1269
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1223
1270
|
request_options = Convert.to_request_options \
|
1224
1271
|
request_options, tag_type: :transaction_tag
|
1225
1272
|
|
1226
1273
|
@pool.with_session do |session|
|
1227
|
-
session.insert table, rows,
|
1228
|
-
|
1274
|
+
session.insert table, rows,
|
1275
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1276
|
+
commit_options: commit_options,
|
1277
|
+
request_options: request_options,
|
1278
|
+
call_options: call_options
|
1229
1279
|
end
|
1230
1280
|
end
|
1231
1281
|
|
@@ -1267,6 +1317,9 @@ module Google
|
|
1267
1317
|
#
|
1268
1318
|
# See [Data
|
1269
1319
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1320
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1321
|
+
# mutations will not be recorded in change streams with DDL option
|
1322
|
+
# `allow_txn_exclusion=true`.
|
1270
1323
|
# @param [Hash] commit_options A hash of commit options.
|
1271
1324
|
# e.g., return_commit_stats. Commit options are optional.
|
1272
1325
|
# The following options can be provided:
|
@@ -1289,6 +1342,20 @@ module Google
|
|
1289
1342
|
# * `:tag` (String) A tag used for statistics collection
|
1290
1343
|
# about transaction. A tag must be a valid identifier of the
|
1291
1344
|
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1345
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1346
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1347
|
+
# optional. The following settings can be provided:
|
1348
|
+
#
|
1349
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1350
|
+
# that overrides the default setting.
|
1351
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1352
|
+
# setting of retry policy with the following keys:
|
1353
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1354
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1355
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1356
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1357
|
+
# trigger a retry.
|
1358
|
+
#
|
1292
1359
|
#
|
1293
1360
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1294
1361
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1341,13 +1408,18 @@ module Google
|
|
1341
1408
|
# { id: 2, name: "Harvey", active: true }],
|
1342
1409
|
# request_options: request_options
|
1343
1410
|
#
|
1344
|
-
def update table, rows,
|
1411
|
+
def update table, rows,
|
1412
|
+
exclude_txn_from_change_streams: false,
|
1413
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1345
1414
|
request_options = Convert.to_request_options \
|
1346
1415
|
request_options, tag_type: :transaction_tag
|
1347
1416
|
|
1348
1417
|
@pool.with_session do |session|
|
1349
|
-
session.update table, rows,
|
1350
|
-
|
1418
|
+
session.update table, rows,
|
1419
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1420
|
+
commit_options: commit_options,
|
1421
|
+
request_options: request_options,
|
1422
|
+
call_options: call_options
|
1351
1423
|
end
|
1352
1424
|
end
|
1353
1425
|
|
@@ -1391,6 +1463,9 @@ module Google
|
|
1391
1463
|
#
|
1392
1464
|
# See [Data
|
1393
1465
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1466
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1467
|
+
# mutations will not be recorded in change streams with DDL option
|
1468
|
+
# `allow_txn_exclusion=true`.
|
1394
1469
|
# @param [Hash] commit_options A hash of commit options.
|
1395
1470
|
# e.g., return_commit_stats. Commit options are optional.
|
1396
1471
|
# The following options can be provided:
|
@@ -1413,6 +1488,20 @@ module Google
|
|
1413
1488
|
# * `:tag` (String) A tag used for statistics collection
|
1414
1489
|
# about transaction. A tag must be a valid identifier of the
|
1415
1490
|
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1491
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1492
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1493
|
+
# optional. The following settings can be provided:
|
1494
|
+
#
|
1495
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1496
|
+
# that overrides the default setting.
|
1497
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1498
|
+
# setting of retry policy with the following keys:
|
1499
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1500
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1501
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1502
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1503
|
+
# trigger a retry.
|
1504
|
+
#
|
1416
1505
|
#
|
1417
1506
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1418
1507
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1465,10 +1554,15 @@ module Google
|
|
1465
1554
|
# { id: 2, name: "Harvey", active: true }],
|
1466
1555
|
# request_options: request_options
|
1467
1556
|
#
|
1468
|
-
def replace table, rows,
|
1557
|
+
def replace table, rows,
|
1558
|
+
exclude_txn_from_change_streams: false,
|
1559
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1469
1560
|
@pool.with_session do |session|
|
1470
|
-
session.replace table, rows,
|
1471
|
-
|
1561
|
+
session.replace table, rows,
|
1562
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1563
|
+
commit_options: commit_options,
|
1564
|
+
request_options: request_options,
|
1565
|
+
call_options: call_options
|
1472
1566
|
end
|
1473
1567
|
end
|
1474
1568
|
|
@@ -1492,6 +1586,9 @@ module Google
|
|
1492
1586
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
1493
1587
|
# ranges to match returned data to. Values should have exactly as many
|
1494
1588
|
# elements as there are columns in the primary key.
|
1589
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1590
|
+
# mutations will not be recorded in change streams with DDL option
|
1591
|
+
# `allow_txn_exclusion=true`.
|
1495
1592
|
# @param [Hash] commit_options A hash of commit options.
|
1496
1593
|
# e.g., return_commit_stats. Commit options are optional.
|
1497
1594
|
# The following options can be provided:
|
@@ -1573,13 +1670,16 @@ module Google
|
|
1573
1670
|
# request_options = { tag: "BulkDelete-Users" }
|
1574
1671
|
# db.delete "users", [1, 2, 3], request_options: request_options
|
1575
1672
|
#
|
1576
|
-
def delete table, keys = [],
|
1577
|
-
|
1673
|
+
def delete table, keys = [],
|
1674
|
+
exclude_txn_from_change_streams: false,
|
1675
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1578
1676
|
request_options = Convert.to_request_options \
|
1579
1677
|
request_options, tag_type: :transaction_tag
|
1580
1678
|
|
1581
1679
|
@pool.with_session do |session|
|
1582
|
-
session.delete table, keys,
|
1680
|
+
session.delete table, keys,
|
1681
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1682
|
+
commit_options: commit_options,
|
1583
1683
|
request_options: request_options,
|
1584
1684
|
call_options: call_options
|
1585
1685
|
end
|
@@ -1600,6 +1700,9 @@ module Google
|
|
1600
1700
|
# this method may be appropriate for latency sensitive and/or high
|
1601
1701
|
# throughput blind changes.
|
1602
1702
|
#
|
1703
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1704
|
+
# mutations will not be recorded in change streams with DDL option
|
1705
|
+
# `allow_txn_exclusion=true`.
|
1603
1706
|
# @param [Hash] commit_options A hash of commit options.
|
1604
1707
|
# e.g., return_commit_stats. Commit options are optional.
|
1605
1708
|
# The following options can be provided:
|
@@ -1695,8 +1798,9 @@ module Google
|
|
1695
1798
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1696
1799
|
# end
|
1697
1800
|
#
|
1698
|
-
def commit
|
1699
|
-
call_options: nil,
|
1801
|
+
def commit exclude_txn_from_change_streams: false,
|
1802
|
+
commit_options: nil, request_options: nil, call_options: nil,
|
1803
|
+
&block
|
1700
1804
|
raise ArgumentError, "Must provide a block" unless block_given?
|
1701
1805
|
|
1702
1806
|
request_options = Convert.to_request_options \
|
@@ -1704,12 +1808,111 @@ module Google
|
|
1704
1808
|
|
1705
1809
|
@pool.with_session do |session|
|
1706
1810
|
session.commit(
|
1811
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1707
1812
|
commit_options: commit_options, request_options: request_options,
|
1708
1813
|
call_options: call_options, &block
|
1709
1814
|
)
|
1710
1815
|
end
|
1711
1816
|
end
|
1712
1817
|
|
1818
|
+
##
|
1819
|
+
# Batches the supplied mutation groups in a collection of efficient
|
1820
|
+
# transactions.
|
1821
|
+
#
|
1822
|
+
# All mutations in a group are committed atomically. However, mutations
|
1823
|
+
# across groups can be committed non-atomically in an unspecified order
|
1824
|
+
# and thus they must be independent of each other. Partial failure is
|
1825
|
+
# possible, i.e., some groups may have been committed successfully,
|
1826
|
+
# while others may have failed. The results of individual batches are
|
1827
|
+
# streamed into the response as the batches are applied.
|
1828
|
+
#
|
1829
|
+
# BatchWrite requests are not replay protected, meaning that each mutation
|
1830
|
+
# group may be applied more than once. Replays of non-idempotent mutations
|
1831
|
+
# may have undesirable effects. For example, replays of an insert mutation
|
1832
|
+
# may produce an already exists error or if you use generated or commit
|
1833
|
+
# timestamp-based keys, it may result in additional rows being added to the
|
1834
|
+
# mutation's table. We recommend structuring your mutation groups to be
|
1835
|
+
# idempotent to avoid this issue.
|
1836
|
+
#
|
1837
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1838
|
+
# mutations will not be recorded in change streams with DDL option
|
1839
|
+
# `allow_txn_exclusion=true`.
|
1840
|
+
# @param [Hash] request_options Common request options.
|
1841
|
+
#
|
1842
|
+
# * `:priority` (String) The relative priority for requests.
|
1843
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1844
|
+
# and does not guarantee priority or order of execution.
|
1845
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1846
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1847
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1848
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
1849
|
+
# queries or reads, used for statistics collection. Tag must be a
|
1850
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
1851
|
+
# and 64 characters in length.
|
1852
|
+
#
|
1853
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1854
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1855
|
+
# optional. The following settings can be provided:
|
1856
|
+
#
|
1857
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1858
|
+
# that overrides the default setting.
|
1859
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1860
|
+
# setting of retry policy with the following keys:
|
1861
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1862
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1863
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1864
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1865
|
+
# trigger a retry.
|
1866
|
+
#
|
1867
|
+
# @yield [batch_write] a batch write object
|
1868
|
+
# @yieldparam [Google::Cloud::Spanner::BatchWrite] batch_write a batch
|
1869
|
+
# write object used to add mutaion groups through {MutationGroup}.
|
1870
|
+
#
|
1871
|
+
# @return [Google::Cloud::Spanner::BatchWriteResults] The results of
|
1872
|
+
# the batch write operation. This is a stream of responses, each
|
1873
|
+
# covering a set of the mutation groups that were either applied or
|
1874
|
+
# failed together.
|
1875
|
+
#
|
1876
|
+
# @example
|
1877
|
+
# require "google/cloud/spanner"
|
1878
|
+
#
|
1879
|
+
# spanner = Google::Cloud::Spanner.new
|
1880
|
+
#
|
1881
|
+
# db = spanner.client "my-instance", "my-database"
|
1882
|
+
#
|
1883
|
+
# results = db.batch_write do |b|
|
1884
|
+
# # First mutation group
|
1885
|
+
# b.mutation_group do |mg|
|
1886
|
+
# mg.upsert "Singers", [{ SingerId: 16, FirstName: "Charlie", LastName: "Terry" }]
|
1887
|
+
# end
|
1888
|
+
#
|
1889
|
+
# # Second mutation group
|
1890
|
+
# b.mutation_group do |mg|
|
1891
|
+
# mg.upsert "Singers", [{ SingerId: 17, FirstName: "Catalina", LastName: "Smith" }]
|
1892
|
+
# mg.update "Albums", [{ SingerId: 17, AlbumId: 1, AlbumTitle: "Go Go Go" }]
|
1893
|
+
# end
|
1894
|
+
# end
|
1895
|
+
#
|
1896
|
+
# results.each do |response|
|
1897
|
+
# puts "groups applied: #{response.indexes}" if response.ok?
|
1898
|
+
# end
|
1899
|
+
#
|
1900
|
+
def batch_write exclude_txn_from_change_streams: false,
|
1901
|
+
request_options: nil,
|
1902
|
+
call_options: nil,
|
1903
|
+
&block
|
1904
|
+
raise ArgumentError, "Must provide a block" unless block_given?
|
1905
|
+
|
1906
|
+
@pool.with_session do |session|
|
1907
|
+
session.batch_write(
|
1908
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1909
|
+
request_options: request_options,
|
1910
|
+
call_options: call_options,
|
1911
|
+
&block
|
1912
|
+
)
|
1913
|
+
end
|
1914
|
+
end
|
1915
|
+
|
1713
1916
|
# rubocop:disable Metrics/AbcSize
|
1714
1917
|
# rubocop:disable Metrics/MethodLength
|
1715
1918
|
# rubocop:disable Metrics/BlockLength
|
@@ -1731,6 +1934,9 @@ module Google
|
|
1731
1934
|
#
|
1732
1935
|
# @param [Numeric] deadline The total amount of time in seconds the
|
1733
1936
|
# transaction has to succeed. The default is `120`.
|
1937
|
+
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
1938
|
+
# mutations will not be recorded in change streams with DDL option
|
1939
|
+
# `allow_txn_exclusion=true`.
|
1734
1940
|
# @param [Hash] commit_options A hash of commit options.
|
1735
1941
|
# e.g., return_commit_stats. Commit options are optional.
|
1736
1942
|
# The following options can be provided:
|
@@ -1870,8 +2076,8 @@ module Google
|
|
1870
2076
|
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1871
2077
|
# end
|
1872
2078
|
#
|
1873
|
-
def transaction deadline: 120,
|
1874
|
-
request_options: nil, call_options: nil
|
2079
|
+
def transaction deadline: 120, exclude_txn_from_change_streams: false,
|
2080
|
+
commit_options: nil, request_options: nil, call_options: nil
|
1875
2081
|
ensure_service!
|
1876
2082
|
unless Thread.current[IS_TRANSACTION_RUNNING_KEY].nil?
|
1877
2083
|
raise "Nested transactions are not allowed"
|
@@ -1885,7 +2091,7 @@ module Google
|
|
1885
2091
|
request_options, tag_type: :transaction_tag
|
1886
2092
|
|
1887
2093
|
@pool.with_session do |session|
|
1888
|
-
tx = session.create_empty_transaction
|
2094
|
+
tx = session.create_empty_transaction exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
1889
2095
|
if request_options
|
1890
2096
|
tx.transaction_tag = request_options[:transaction_tag]
|
1891
2097
|
end
|
@@ -1898,6 +2104,7 @@ module Google
|
|
1898
2104
|
commit_resp = @project.service.commit \
|
1899
2105
|
tx.session.path, tx.mutations,
|
1900
2106
|
transaction_id: transaction_id,
|
2107
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
1901
2108
|
commit_options: commit_options,
|
1902
2109
|
request_options: request_options,
|
1903
2110
|
call_options: call_options
|
@@ -1911,7 +2118,7 @@ module Google
|
|
1911
2118
|
# Sleep the amount from RetryDelay, or incremental backoff
|
1912
2119
|
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1913
2120
|
# Create new transaction on the session and retry the block
|
1914
|
-
tx = session.create_transaction
|
2121
|
+
tx = session.create_transaction exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
1915
2122
|
retry
|
1916
2123
|
rescue StandardError => e
|
1917
2124
|
# Rollback transaction when handling unexpected error
|
@@ -2306,8 +2513,9 @@ module Google
|
|
2306
2513
|
}.compact)))
|
2307
2514
|
end
|
2308
2515
|
|
2309
|
-
def pdml_transaction session
|
2310
|
-
pdml_tx_grpc = @project.service.create_pdml session.path
|
2516
|
+
def pdml_transaction session, exclude_txn_from_change_streams: false
|
2517
|
+
pdml_tx_grpc = @project.service.create_pdml session.path,
|
2518
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams
|
2311
2519
|
V1::TransactionSelector.new id: pdml_tx_grpc.id
|
2312
2520
|
end
|
2313
2521
|
|
@@ -30,8 +30,7 @@ module Google
|
|
30
30
|
# operations.
|
31
31
|
#
|
32
32
|
# @deprecated Use the result of
|
33
|
-
#
|
34
|
-
# instead.
|
33
|
+
# {Google::Cloud::Spanner::Admin::Database.database_admin}.list_database_operations instead.
|
35
34
|
#
|
36
35
|
class List < DelegateClass(::Array)
|
37
36
|
# @private
|
@@ -36,8 +36,7 @@ module Google
|
|
36
36
|
# Long-running Operation
|
37
37
|
#
|
38
38
|
# @deprecated Use the long-running operation returned by
|
39
|
-
#
|
40
|
-
# instead.
|
39
|
+
# {Google::Cloud::Spanner::Admin::Database.database_admin}.create_database instead.
|
41
40
|
#
|
42
41
|
# @example
|
43
42
|
# require "google/cloud/spanner"
|
@@ -26,9 +26,8 @@ module Google
|
|
26
26
|
# Database::List is a special case Array with additional
|
27
27
|
# values.
|
28
28
|
#
|
29
|
-
# @deprecated Use the result of
|
30
|
-
#
|
31
|
-
# instead.
|
29
|
+
# @deprecated Use the result of {Google::Cloud::Spanner::Admin::Database.database_admin}.list_databases
|
30
|
+
# instead.
|
32
31
|
class List < DelegateClass(::Array)
|
33
32
|
##
|
34
33
|
# If not empty, indicates that there are more records that match
|
@@ -27,9 +27,8 @@ module Google
|
|
27
27
|
# Instance::Config::List is a special case Array with additional
|
28
28
|
# values.
|
29
29
|
#
|
30
|
-
# @deprecated Use the result of
|
31
|
-
#
|
32
|
-
# instead.
|
30
|
+
# @deprecated Use the result of the
|
31
|
+
# {Google::Cloud::Spanner::Admin::Instance.instance_admin}.list_instance_configs instead.
|
33
32
|
class List < DelegateClass(::Array)
|
34
33
|
##
|
35
34
|
# If not empty, indicates that there are more records that match
|
@@ -34,9 +34,8 @@ module Google
|
|
34
34
|
# @see https://cloud.google.com/spanner/reference/rpc/google.longrunning#google.longrunning.Operation
|
35
35
|
# Long-running Operation
|
36
36
|
#
|
37
|
-
# @deprecated Use the long-running operation returned by
|
38
|
-
#
|
39
|
-
# instead.
|
37
|
+
# @deprecated Use the long-running operation returned by the
|
38
|
+
# {Google::Cloud::Spanner::Admin::Instance.instance_admin}.create_instance instead.
|
40
39
|
#
|
41
40
|
# @example
|
42
41
|
# require "google/cloud/spanner"
|
@@ -26,9 +26,8 @@ module Google
|
|
26
26
|
# Instance::List is a special case Array with additional
|
27
27
|
# values.
|
28
28
|
#
|
29
|
-
# @deprecated Use the result of
|
30
|
-
#
|
31
|
-
# instead.
|
29
|
+
# @deprecated Use the result of {Google::Cloud::Spanner::Admin::Instance.instance_admin}.list_instances
|
30
|
+
# instead.
|
32
31
|
class List < DelegateClass(::Array)
|
33
32
|
##
|
34
33
|
# If not empty, indicates that there are more records that match
|