google-cloud-spanner 2.29.0 → 2.31.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/backup/job.rb +3 -1
- data/lib/google/cloud/spanner/batch_client.rb +17 -8
- data/lib/google/cloud/spanner/batch_snapshot.rb +18 -4
- data/lib/google/cloud/spanner/batch_update_results.rb +7 -2
- data/lib/google/cloud/spanner/client.rb +135 -92
- data/lib/google/cloud/spanner/commit.rb +3 -0
- data/lib/google/cloud/spanner/commit_response.rb +11 -5
- data/lib/google/cloud/spanner/instance.rb +2 -2
- data/lib/google/cloud/spanner/pool.rb +65 -6
- data/lib/google/cloud/spanner/project.rb +8 -22
- data/lib/google/cloud/spanner/results.rb +51 -16
- data/lib/google/cloud/spanner/service.rb +76 -12
- data/lib/google/cloud/spanner/session.rb +121 -52
- data/lib/google/cloud/spanner/session_cache.rb +125 -0
- data/lib/google/cloud/spanner/session_creation_options.rb +70 -0
- data/lib/google/cloud/spanner/snapshot.rb +29 -9
- data/lib/google/cloud/spanner/transaction.rb +124 -36
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 747996c4ee90317631f8648dbc5abefec1ef5dec80ab4e867475dfc465671cf6
|
|
4
|
+
data.tar.gz: 7316c929b5c69c3595e35780fe13ced837091de64de0da2ad13e41c2ccab065e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5f2caed803fc1883c743c34b45a54383259d20749628d01af88cd94d6ac2b89195af9597d763a199b597066a1bee5999fa3b2c3e34b89b59d78c5e86a7cdee1
|
|
7
|
+
data.tar.gz: 8d40b705e2b0fa7b93f2aa334b8b034ad8cb320833d32d6c0bf7a1073966d6cc9d9b40192a86bd1d3fcacce64c020a60f7b4b4fa6b2b9ffdefbc6f308428b711
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 2.31.0 (2025-12-02)
|
|
4
|
+
|
|
5
|
+
#### Features
|
|
6
|
+
|
|
7
|
+
* Support isolation level in Transaction Options ([#206](https://github.com/googleapis/ruby-spanner/issues/206))
|
|
8
|
+
|
|
9
|
+
### 2.30.0 (2025-11-17)
|
|
10
|
+
|
|
11
|
+
#### Features
|
|
12
|
+
|
|
13
|
+
* implement support for Multiplexed Sessions ([#195](https://github.com/googleapis/ruby-spanner/issues/195))
|
|
14
|
+
|
|
3
15
|
### 2.29.0 (2025-11-06)
|
|
4
16
|
|
|
5
17
|
#### Features
|
|
@@ -71,7 +71,9 @@ module Google
|
|
|
71
71
|
##
|
|
72
72
|
# @private Creates a new Backup::Job instance.
|
|
73
73
|
def initialize
|
|
74
|
+
# @type [::Gapic::Operation, nil]
|
|
74
75
|
@grpc = nil
|
|
76
|
+
# @type [::Google::Cloud::Spanner::Service, nil]
|
|
75
77
|
@service = nil
|
|
76
78
|
end
|
|
77
79
|
|
|
@@ -268,7 +270,7 @@ module Google
|
|
|
268
270
|
end
|
|
269
271
|
|
|
270
272
|
# Create a new Backup::Job from a `Gapic::Operation` object.
|
|
271
|
-
# @param grpc [::Gapic::Operation`]
|
|
273
|
+
# @param grpc [::Gapic::Operation`] Underlying `Gapic::Operation` object.
|
|
272
274
|
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
|
|
273
275
|
# @private
|
|
274
276
|
# @return [::Google::Cloud::Spanner::Backup::Job]
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
require "google/cloud/spanner/errors"
|
|
17
17
|
require "google/cloud/spanner/project"
|
|
18
18
|
require "google/cloud/spanner/session"
|
|
19
|
+
require "google/cloud/spanner/session_cache"
|
|
20
|
+
require "google/cloud/spanner/session_creation_options"
|
|
19
21
|
require "google/cloud/spanner/batch_snapshot"
|
|
20
22
|
|
|
21
23
|
module Google
|
|
@@ -83,6 +85,16 @@ module Google
|
|
|
83
85
|
@session_labels = session_labels
|
|
84
86
|
@query_options = query_options
|
|
85
87
|
@directed_read_options = directed_read_options
|
|
88
|
+
|
|
89
|
+
session_creation_options = SessionCreationOptions.new(
|
|
90
|
+
database_path: Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
91
|
+
project: @project.service.project, instance: instance_id, database: database_id
|
|
92
|
+
),
|
|
93
|
+
session_labels: @session_labels,
|
|
94
|
+
query_options: @query_options
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@session_cache = SessionCache.new @project.service, session_creation_options
|
|
86
98
|
end
|
|
87
99
|
|
|
88
100
|
# The unique identifier for the project.
|
|
@@ -110,13 +122,15 @@ module Google
|
|
|
110
122
|
end
|
|
111
123
|
|
|
112
124
|
# The Spanner instance connected to.
|
|
113
|
-
# @
|
|
125
|
+
# @deprecated Use {Google::Cloud::Spanner::Admin::Instance#instance_admin} instead.
|
|
126
|
+
# @return [::Google::Cloud::Spanner::Instance]
|
|
114
127
|
def instance
|
|
115
128
|
@project.instance instance_id
|
|
116
129
|
end
|
|
117
130
|
|
|
118
131
|
# The Spanner database connected to.
|
|
119
|
-
# @
|
|
132
|
+
# @deprecated Use {Google::Cloud::Spanner::Admin::Database#database_admin} instead.
|
|
133
|
+
# @return [::Google::Cloud::Spanner::Database]
|
|
120
134
|
def database
|
|
121
135
|
@project.database instance_id, database_id
|
|
122
136
|
end
|
|
@@ -428,12 +442,7 @@ module Google
|
|
|
428
442
|
# @return [::Google::Cloud::Spanner::Session]
|
|
429
443
|
def session
|
|
430
444
|
ensure_service!
|
|
431
|
-
|
|
432
|
-
V1::Spanner::Paths.database_path(
|
|
433
|
-
project: project_id, instance: instance_id, database: database_id
|
|
434
|
-
),
|
|
435
|
-
labels: @session_labels
|
|
436
|
-
Session.from_grpc grpc, @project.service, query_options: @query_options
|
|
445
|
+
@session_cache.session
|
|
437
446
|
end
|
|
438
447
|
|
|
439
448
|
##
|
|
@@ -68,8 +68,15 @@ module Google
|
|
|
68
68
|
# @private Directed Read Options
|
|
69
69
|
attr_reader :directed_read_options
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
# @
|
|
71
|
+
# Creates a new `Spanner::BatchSnapshot` instance.
|
|
72
|
+
# @param grpc [::Google::Cloud::Spanner::V1::Transaction]
|
|
73
|
+
# Underlying `V1::Transaction` object.
|
|
74
|
+
# @param session [::Google::Cloud::Spanner::Session] A `Spanner::Session` reference.
|
|
75
|
+
# @param directed_read_options [::Hash, nil] Optional. Client options used to set
|
|
76
|
+
# the `directed_read_options` for all ReadRequests and ExecuteSqlRequests.
|
|
77
|
+
# Converts to `V1::DirectedReadOptions`. Example option: `:exclude_replicas`.
|
|
78
|
+
# @private
|
|
79
|
+
# @return [::Google::Cloud::Spanner::BatchSnapshot]
|
|
73
80
|
def initialize grpc, session, directed_read_options: nil
|
|
74
81
|
@grpc = grpc
|
|
75
82
|
@session = session
|
|
@@ -852,9 +859,16 @@ module Google
|
|
|
852
859
|
from_grpc transaction_grpc, Session.from_grpc(session_grpc, service, query_options: query_options)
|
|
853
860
|
end
|
|
854
861
|
|
|
855
|
-
|
|
856
|
-
# @private Creates a new BatchSnapshot instance from a
|
|
862
|
+
# Creates a new BatchSnapshot instance from a
|
|
857
863
|
# `Google::Cloud::Spanner::V1::Transaction`.
|
|
864
|
+
# @param grpc [::Google::Cloud::Spanner::V1::Transaction]
|
|
865
|
+
# Underlying `V1::Transaction` object.
|
|
866
|
+
# @param session [::Google::Cloud::Spanner::Session] A `Spanner::Session` reference.
|
|
867
|
+
# @param directed_read_options [::Hash, nil] Optional. Client options used to set
|
|
868
|
+
# the `directed_read_options` for all ReadRequests and ExecuteSqlRequests.
|
|
869
|
+
# Converts to `V1::DirectedReadOptions`. Example option: `:exclude_replicas`.
|
|
870
|
+
# @private
|
|
871
|
+
# @return [::Google::Cloud::Spanner::BatchSnapshot]
|
|
858
872
|
def self.from_grpc grpc, session, directed_read_options: nil
|
|
859
873
|
new grpc, session, directed_read_options: directed_read_options
|
|
860
874
|
end
|
|
@@ -19,10 +19,15 @@ module Google
|
|
|
19
19
|
##
|
|
20
20
|
# @private Helper class to process BatchDML response
|
|
21
21
|
class BatchUpdateResults
|
|
22
|
-
|
|
23
|
-
#
|
|
22
|
+
# The `V1::ExecuteBatchDmlResponse` object to process
|
|
23
|
+
# @private
|
|
24
|
+
# @return [::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse]
|
|
24
25
|
attr_reader :grpc
|
|
25
26
|
|
|
27
|
+
# Initializes the `BatchUpdateResults` helper
|
|
28
|
+
# @private
|
|
29
|
+
# @param grpc [::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse]
|
|
30
|
+
# The response from `ExecuteBatchDml` rpc to process in this helper.
|
|
26
31
|
def initialize grpc
|
|
27
32
|
@grpc = grpc
|
|
28
33
|
end
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
require "google/cloud/spanner/errors"
|
|
17
17
|
require "google/cloud/spanner/project"
|
|
18
18
|
require "google/cloud/spanner/data"
|
|
19
|
-
require "google/cloud/spanner/
|
|
19
|
+
require "google/cloud/spanner/session_cache"
|
|
20
|
+
require "google/cloud/spanner/session_creation_options"
|
|
20
21
|
require "google/cloud/spanner/session"
|
|
21
22
|
require "google/cloud/spanner/transaction"
|
|
22
23
|
require "google/cloud/spanner/snapshot"
|
|
@@ -61,8 +62,9 @@ module Google
|
|
|
61
62
|
# @param database_id [::String] Database id, e.g. `"my-database"`.
|
|
62
63
|
# @param session_labels [::Hash, nil] Optional. The labels to be applied to all sessions
|
|
63
64
|
# created by the client. Example: `"team" => "billing-service"`.
|
|
64
|
-
# @param pool_opts [::Hash] Optional. `
|
|
65
|
-
#
|
|
65
|
+
# @param pool_opts [::Hash] Optional. Defaults to `{}`. Deprecated.
|
|
66
|
+
# @deprecated This parameter is non-functional since the multiplexed SessionCache does not require
|
|
67
|
+
# pool options.
|
|
66
68
|
# @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
67
69
|
# query options for executing SQL query. Example parameter `:optimizer_version`.
|
|
68
70
|
# @param database_role [::String, nil] Optional. The Spanner session creator role.
|
|
@@ -79,9 +81,21 @@ module Google
|
|
|
79
81
|
@database_id = database_id
|
|
80
82
|
@database_role = database_role
|
|
81
83
|
@session_labels = session_labels
|
|
82
|
-
@directed_read_options = directed_read_options
|
|
83
|
-
@pool = Pool.new self, **pool_opts
|
|
84
84
|
@query_options = query_options
|
|
85
|
+
@directed_read_options = directed_read_options
|
|
86
|
+
|
|
87
|
+
_pool_opts = pool_opts # unused. Here only to avoid having to disable Rubocop's Lint/UnusedMethodArgument
|
|
88
|
+
|
|
89
|
+
session_creation_options = SessionCreationOptions.new(
|
|
90
|
+
database_path: Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
91
|
+
project: @project.service.project, instance: instance_id, database: database_id
|
|
92
|
+
),
|
|
93
|
+
session_labels: @session_labels,
|
|
94
|
+
session_creator_role: @database_role,
|
|
95
|
+
query_options: @query_options
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@pool = SessionCache.new @project.service, session_creation_options
|
|
85
99
|
end
|
|
86
100
|
|
|
87
101
|
# The unique identifier for the project.
|
|
@@ -1053,6 +1067,8 @@ module Google
|
|
|
1053
1067
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1054
1068
|
# mutations will not be recorded in change streams with DDL option
|
|
1055
1069
|
# `allow_txn_exclusion=true`.
|
|
1070
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1071
|
+
# isolation level for the transaction.
|
|
1056
1072
|
# @param [Hash] commit_options A hash of commit options.
|
|
1057
1073
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1058
1074
|
# The following options can be provided:
|
|
@@ -1144,13 +1160,15 @@ module Google
|
|
|
1144
1160
|
#
|
|
1145
1161
|
def upsert table, rows,
|
|
1146
1162
|
exclude_txn_from_change_streams: false,
|
|
1147
|
-
|
|
1163
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1164
|
+
call_options: nil
|
|
1148
1165
|
request_options = Convert.to_request_options \
|
|
1149
1166
|
request_options, tag_type: :transaction_tag
|
|
1150
1167
|
|
|
1151
1168
|
@pool.with_session do |session|
|
|
1152
1169
|
session.upsert table, rows,
|
|
1153
1170
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1171
|
+
isolation_level: isolation_level,
|
|
1154
1172
|
commit_options: commit_options,
|
|
1155
1173
|
request_options: request_options,
|
|
1156
1174
|
call_options: call_options
|
|
@@ -1200,6 +1218,8 @@ module Google
|
|
|
1200
1218
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1201
1219
|
# mutations will not be recorded in change streams with DDL option
|
|
1202
1220
|
# `allow_txn_exclusion=true`.
|
|
1221
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1222
|
+
# isolation level for the transaction.
|
|
1203
1223
|
# @param [Hash] commit_options A hash of commit options.
|
|
1204
1224
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1205
1225
|
# The following options can be provided:
|
|
@@ -1291,13 +1311,15 @@ module Google
|
|
|
1291
1311
|
#
|
|
1292
1312
|
def insert table, rows,
|
|
1293
1313
|
exclude_txn_from_change_streams: false,
|
|
1294
|
-
|
|
1314
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1315
|
+
call_options: nil
|
|
1295
1316
|
request_options = Convert.to_request_options \
|
|
1296
1317
|
request_options, tag_type: :transaction_tag
|
|
1297
1318
|
|
|
1298
1319
|
@pool.with_session do |session|
|
|
1299
1320
|
session.insert table, rows,
|
|
1300
1321
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1322
|
+
isolation_level: isolation_level,
|
|
1301
1323
|
commit_options: commit_options,
|
|
1302
1324
|
request_options: request_options,
|
|
1303
1325
|
call_options: call_options
|
|
@@ -1346,6 +1368,8 @@ module Google
|
|
|
1346
1368
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1347
1369
|
# mutations will not be recorded in change streams with DDL option
|
|
1348
1370
|
# `allow_txn_exclusion=true`.
|
|
1371
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1372
|
+
# isolation level for the transaction.
|
|
1349
1373
|
# @param [Hash] commit_options A hash of commit options.
|
|
1350
1374
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1351
1375
|
# The following options can be provided:
|
|
@@ -1436,13 +1460,15 @@ module Google
|
|
|
1436
1460
|
#
|
|
1437
1461
|
def update table, rows,
|
|
1438
1462
|
exclude_txn_from_change_streams: false,
|
|
1439
|
-
|
|
1463
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1464
|
+
call_options: nil
|
|
1440
1465
|
request_options = Convert.to_request_options \
|
|
1441
1466
|
request_options, tag_type: :transaction_tag
|
|
1442
1467
|
|
|
1443
1468
|
@pool.with_session do |session|
|
|
1444
1469
|
session.update table, rows,
|
|
1445
1470
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1471
|
+
isolation_level: isolation_level,
|
|
1446
1472
|
commit_options: commit_options,
|
|
1447
1473
|
request_options: request_options,
|
|
1448
1474
|
call_options: call_options
|
|
@@ -1493,6 +1519,8 @@ module Google
|
|
|
1493
1519
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1494
1520
|
# mutations will not be recorded in change streams with DDL option
|
|
1495
1521
|
# `allow_txn_exclusion=true`.
|
|
1522
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1523
|
+
# isolation level for the transaction.
|
|
1496
1524
|
# @param [Hash] commit_options A hash of commit options.
|
|
1497
1525
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1498
1526
|
# The following options can be provided:
|
|
@@ -1583,10 +1611,12 @@ module Google
|
|
|
1583
1611
|
#
|
|
1584
1612
|
def replace table, rows,
|
|
1585
1613
|
exclude_txn_from_change_streams: false,
|
|
1586
|
-
|
|
1614
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1615
|
+
call_options: nil
|
|
1587
1616
|
@pool.with_session do |session|
|
|
1588
1617
|
session.replace table, rows,
|
|
1589
1618
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1619
|
+
isolation_level: isolation_level,
|
|
1590
1620
|
commit_options: commit_options,
|
|
1591
1621
|
request_options: request_options,
|
|
1592
1622
|
call_options: call_options
|
|
@@ -1616,6 +1646,8 @@ module Google
|
|
|
1616
1646
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1617
1647
|
# mutations will not be recorded in change streams with DDL option
|
|
1618
1648
|
# `allow_txn_exclusion=true`.
|
|
1649
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1650
|
+
# isolation level for the transaction.
|
|
1619
1651
|
# @param [Hash] commit_options A hash of commit options.
|
|
1620
1652
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1621
1653
|
# The following options can be provided:
|
|
@@ -1699,13 +1731,15 @@ module Google
|
|
|
1699
1731
|
#
|
|
1700
1732
|
def delete table, keys = [],
|
|
1701
1733
|
exclude_txn_from_change_streams: false,
|
|
1702
|
-
|
|
1734
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1735
|
+
call_options: nil
|
|
1703
1736
|
request_options = Convert.to_request_options \
|
|
1704
1737
|
request_options, tag_type: :transaction_tag
|
|
1705
1738
|
|
|
1706
1739
|
@pool.with_session do |session|
|
|
1707
1740
|
session.delete table, keys,
|
|
1708
1741
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1742
|
+
isolation_level: isolation_level,
|
|
1709
1743
|
commit_options: commit_options,
|
|
1710
1744
|
request_options: request_options,
|
|
1711
1745
|
call_options: call_options
|
|
@@ -1730,6 +1764,8 @@ module Google
|
|
|
1730
1764
|
# @param [Boolean] exclude_txn_from_change_streams If set to true,
|
|
1731
1765
|
# mutations will not be recorded in change streams with DDL option
|
|
1732
1766
|
# `allow_txn_exclusion=true`.
|
|
1767
|
+
# @param [Google::Cloud::Spanner::V1::TransactionOptions::IsolationLevel] isolation_level Optional. The
|
|
1768
|
+
# isolation level for the transaction.
|
|
1733
1769
|
# @param [Hash] commit_options A hash of commit options.
|
|
1734
1770
|
# e.g., return_commit_stats. Commit options are optional.
|
|
1735
1771
|
# The following options can be provided:
|
|
@@ -1826,8 +1862,8 @@ module Google
|
|
|
1826
1862
|
# end
|
|
1827
1863
|
#
|
|
1828
1864
|
def commit exclude_txn_from_change_streams: false,
|
|
1829
|
-
|
|
1830
|
-
&block
|
|
1865
|
+
isolation_level: nil, commit_options: nil, request_options: nil,
|
|
1866
|
+
call_options: nil, &block
|
|
1831
1867
|
raise ArgumentError, "Must provide a block" unless block_given?
|
|
1832
1868
|
|
|
1833
1869
|
request_options = Convert.to_request_options \
|
|
@@ -1836,8 +1872,11 @@ module Google
|
|
|
1836
1872
|
@pool.with_session do |session|
|
|
1837
1873
|
session.commit(
|
|
1838
1874
|
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
1839
|
-
|
|
1840
|
-
|
|
1875
|
+
isolation_level: isolation_level,
|
|
1876
|
+
commit_options: commit_options,
|
|
1877
|
+
request_options: request_options,
|
|
1878
|
+
call_options: call_options,
|
|
1879
|
+
&block
|
|
1841
1880
|
)
|
|
1842
1881
|
end
|
|
1843
1882
|
end
|
|
@@ -1943,7 +1982,8 @@ module Google
|
|
|
1943
1982
|
# rubocop:disable Metrics/AbcSize
|
|
1944
1983
|
# rubocop:disable Metrics/MethodLength
|
|
1945
1984
|
# rubocop:disable Metrics/BlockLength
|
|
1946
|
-
|
|
1985
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
|
1986
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
1947
1987
|
|
|
1948
1988
|
##
|
|
1949
1989
|
# Creates a transaction for reads and writes that execute atomically at
|
|
@@ -2128,9 +2168,10 @@ module Google
|
|
|
2128
2168
|
yield tx
|
|
2129
2169
|
|
|
2130
2170
|
unless tx.existing_transaction?
|
|
2131
|
-
# This
|
|
2171
|
+
# This typically will happen if the yielded `tx` object was only used to add mutations.
|
|
2132
2172
|
# Then it never called any RPCs and didn't create a server-side Transaction object.
|
|
2133
2173
|
# In which case we should make an explicit BeginTransaction call here.
|
|
2174
|
+
|
|
2134
2175
|
tx.safe_begin_transaction!(
|
|
2135
2176
|
exclude_from_change_streams: exclude_txn_from_change_streams,
|
|
2136
2177
|
request_options: request_options,
|
|
@@ -2139,15 +2180,28 @@ module Google
|
|
|
2139
2180
|
end
|
|
2140
2181
|
|
|
2141
2182
|
transaction_id = tx.transaction_id
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2183
|
+
|
|
2184
|
+
# This "inner retry" mechanism is for Commit Response protocol.
|
|
2185
|
+
# Unlike the retry on `Aborted` errors it will not re-create a transaction.
|
|
2186
|
+
# This is intentional, as these retries are not related to e.g.
|
|
2187
|
+
# transactions deadlocking, so it's OK to retry "as-is".
|
|
2188
|
+
should_retry = true
|
|
2189
|
+
while should_retry
|
|
2190
|
+
commit_resp = @project.service.commit(
|
|
2191
|
+
tx.session.path,
|
|
2192
|
+
tx.mutations,
|
|
2193
|
+
transaction_id: transaction_id,
|
|
2194
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
2195
|
+
commit_options: commit_options,
|
|
2196
|
+
request_options: request_options,
|
|
2197
|
+
call_options: call_options,
|
|
2198
|
+
precommit_token: tx.precommit_token
|
|
2199
|
+
)
|
|
2200
|
+
|
|
2201
|
+
tx.precommit_token = commit_resp.precommit_token
|
|
2202
|
+
should_retry = !commit_resp.precommit_token.nil?
|
|
2203
|
+
end
|
|
2204
|
+
|
|
2151
2205
|
resp = CommitResponse.from_grpc commit_resp
|
|
2152
2206
|
commit_options ? resp : resp.timestamp
|
|
2153
2207
|
rescue GRPC::Aborted,
|
|
@@ -2157,8 +2211,16 @@ module Google
|
|
|
2157
2211
|
check_and_propagate_err! e, (current_time - start_time > deadline)
|
|
2158
2212
|
# Sleep the amount from RetryDelay, or incremental backoff
|
|
2159
2213
|
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
|
2214
|
+
|
|
2160
2215
|
# Create new transaction on the session and retry the block
|
|
2161
|
-
|
|
2216
|
+
previous_transaction_id = tx.transaction_id if tx.existing_transaction?
|
|
2217
|
+
tx = session.create_empty_transaction(
|
|
2218
|
+
exclude_txn_from_change_streams: exclude_txn_from_change_streams,
|
|
2219
|
+
previous_transaction_id: previous_transaction_id
|
|
2220
|
+
)
|
|
2221
|
+
if request_options
|
|
2222
|
+
tx.transaction_tag = request_options[:transaction_tag]
|
|
2223
|
+
end
|
|
2162
2224
|
retry
|
|
2163
2225
|
rescue StandardError => e
|
|
2164
2226
|
# Rollback transaction when handling unexpected error
|
|
@@ -2176,6 +2238,9 @@ module Google
|
|
|
2176
2238
|
# rubocop:enable Metrics/AbcSize
|
|
2177
2239
|
# rubocop:enable Metrics/MethodLength
|
|
2178
2240
|
# rubocop:enable Metrics/BlockLength
|
|
2241
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
|
2242
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
2243
|
+
|
|
2179
2244
|
|
|
2180
2245
|
##
|
|
2181
2246
|
# Creates a snapshot read-only transaction for reads that execute
|
|
@@ -2262,7 +2327,7 @@ module Google
|
|
|
2262
2327
|
staleness: staleness || exact_staleness,
|
|
2263
2328
|
call_options: call_options
|
|
2264
2329
|
Thread.current[IS_TRANSACTION_RUNNING_KEY] = true
|
|
2265
|
-
snp = Snapshot.from_grpc snp_grpc, session, @directed_read_options
|
|
2330
|
+
snp = Snapshot.from_grpc snp_grpc, session, directed_read_options: @directed_read_options
|
|
2266
2331
|
yield snp if block_given?
|
|
2267
2332
|
ensure
|
|
2268
2333
|
Thread.current[IS_TRANSACTION_RUNNING_KEY] = nil
|
|
@@ -2442,58 +2507,8 @@ module Google
|
|
|
2442
2507
|
##
|
|
2443
2508
|
# Reset the client sessions.
|
|
2444
2509
|
#
|
|
2445
|
-
def reset
|
|
2446
|
-
@pool.reset
|
|
2447
|
-
end
|
|
2448
|
-
|
|
2449
|
-
# Creates a new Session objece.
|
|
2450
|
-
# @param multiplexed [::Boolean] Optional. Default to `false`.
|
|
2451
|
-
# If `true`, specifies a multiplexed session.
|
|
2452
|
-
# @private
|
|
2453
|
-
# @return [::Google::Cloud::Spanner::Session]
|
|
2454
|
-
def create_new_session multiplexed: false
|
|
2455
|
-
ensure_service!
|
|
2456
|
-
grpc = @project.service.create_session \
|
|
2457
|
-
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
2458
|
-
project: project_id, instance: instance_id, database: database_id
|
|
2459
|
-
),
|
|
2460
|
-
labels: @session_labels,
|
|
2461
|
-
database_role: @database_role,
|
|
2462
|
-
multiplexed: multiplexed
|
|
2463
|
-
|
|
2464
|
-
Session.from_grpc grpc, @project.service, query_options: @query_options
|
|
2465
|
-
end
|
|
2466
|
-
|
|
2467
|
-
##
|
|
2468
|
-
# @private
|
|
2469
|
-
# Creates a batch of new session objects of size `total`.
|
|
2470
|
-
# Makes multiple RPCs if necessary. Returns empty array if total is 0.
|
|
2471
|
-
def batch_create_new_sessions total
|
|
2472
|
-
sessions = []
|
|
2473
|
-
remaining = total
|
|
2474
|
-
while remaining.positive?
|
|
2475
|
-
sessions += batch_create_sessions remaining
|
|
2476
|
-
remaining = total - sessions.count
|
|
2477
|
-
end
|
|
2478
|
-
sessions
|
|
2479
|
-
end
|
|
2480
|
-
|
|
2481
|
-
##
|
|
2482
|
-
# @private
|
|
2483
|
-
# The response may have fewer sessions than requested in the RPC.
|
|
2484
|
-
#
|
|
2485
|
-
def batch_create_sessions session_count
|
|
2486
|
-
ensure_service!
|
|
2487
|
-
resp = @project.service.batch_create_sessions \
|
|
2488
|
-
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
2489
|
-
project: project_id, instance: instance_id, database: database_id
|
|
2490
|
-
),
|
|
2491
|
-
session_count,
|
|
2492
|
-
labels: @session_labels,
|
|
2493
|
-
database_role: @database_role
|
|
2494
|
-
resp.session.map do |grpc|
|
|
2495
|
-
Session.from_grpc grpc, @project.service, query_options: @query_options
|
|
2496
|
-
end
|
|
2510
|
+
def reset!
|
|
2511
|
+
@pool.reset!
|
|
2497
2512
|
end
|
|
2498
2513
|
|
|
2499
2514
|
# @private
|
|
@@ -2516,23 +2531,51 @@ module Google
|
|
|
2516
2531
|
raise "Must have active connection to service" unless @project.service
|
|
2517
2532
|
end
|
|
2518
2533
|
|
|
2519
|
-
|
|
2520
|
-
#
|
|
2534
|
+
# Checks that the options hash contains exactly one valid single-use key.
|
|
2535
|
+
#
|
|
2536
|
+
# @param opts [::Hash, nil] The options hash to validate.
|
|
2537
|
+
# @private
|
|
2538
|
+
# @raise [ArgumentError] If the hash does not contain exactly one valid
|
|
2539
|
+
# single-use key.
|
|
2540
|
+
# @return [void]
|
|
2521
2541
|
def validate_single_use_args! opts
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2542
|
+
# An empty options hash is valid.
|
|
2543
|
+
return if opts.nil? || opts.empty?
|
|
2544
|
+
|
|
2545
|
+
keys = opts.keys
|
|
2546
|
+
|
|
2547
|
+
valid_keys = Set.new(%i[
|
|
2548
|
+
strong timestamp read_timestamp staleness exact_staleness
|
|
2549
|
+
bounded_timestamp min_read_timestamp bounded_staleness max_staleness
|
|
2550
|
+
]).freeze
|
|
2551
|
+
|
|
2552
|
+
# Raise an error unless there is exactly one key and it's in the valid set.
|
|
2553
|
+
return if keys.length == 1 && valid_keys.include?(keys.first)
|
|
2529
2554
|
raise ArgumentError,
|
|
2530
|
-
"
|
|
2531
|
-
"#{valid_keys}"
|
|
2555
|
+
"Options must contain exactly one of the following keys: " \
|
|
2556
|
+
"#{valid_keys.to_a.join ', '}"
|
|
2532
2557
|
end
|
|
2533
2558
|
|
|
2534
|
-
|
|
2535
|
-
#
|
|
2559
|
+
# Creates a selector for a single-use, read-only transaction.
|
|
2560
|
+
#
|
|
2561
|
+
# @param opts [::Hash] Options for creating the transaction selector.
|
|
2562
|
+
# If those are `nil` or empty, a `nil` will be returned instead of a `V1::TransactionSelector`.
|
|
2563
|
+
# @option opts [::Boolean] :strong
|
|
2564
|
+
# Executes a strong read.
|
|
2565
|
+
# @option opts [::Time, ::DateTime] :read_timestamp
|
|
2566
|
+
# Executes a read at the provided time. Alias: `:timestamp`.
|
|
2567
|
+
# @option opts [::Numeric] :exact_staleness
|
|
2568
|
+
# Executes a read at a time that is exactly this stale (in seconds).
|
|
2569
|
+
# Alias: `:staleness`.
|
|
2570
|
+
# @option opts [::Time, ::DateTime] :min_read_timestamp
|
|
2571
|
+
# Executes a read at a time that is at least this timestamp.
|
|
2572
|
+
# Alias: `:bounded_timestamp`.
|
|
2573
|
+
# @option opts [::Numeric] :max_staleness
|
|
2574
|
+
# Executes a read at a time that is at most this stale (in seconds).
|
|
2575
|
+
# Alias: `:bounded_staleness`.
|
|
2576
|
+
# @private
|
|
2577
|
+
# @return [V1::TransactionSelector, nil] The transaction selector object, or
|
|
2578
|
+
# `nil` if the `opts` hash is nil or empty.
|
|
2536
2579
|
def single_use_transaction opts
|
|
2537
2580
|
return nil if opts.nil? || opts.empty?
|
|
2538
2581
|
|
|
@@ -45,6 +45,7 @@ module Google
|
|
|
45
45
|
##
|
|
46
46
|
# @private
|
|
47
47
|
def initialize
|
|
48
|
+
# @type [Array<Google::Cloud::Spanner::V1::Mutation>]
|
|
48
49
|
@mutations = []
|
|
49
50
|
end
|
|
50
51
|
|
|
@@ -279,7 +280,9 @@ module Google
|
|
|
279
280
|
keys
|
|
280
281
|
end
|
|
281
282
|
|
|
283
|
+
# Return the current mutations added to this `Spanner::Commit` object.
|
|
282
284
|
# @private
|
|
285
|
+
# @return [Array<Google::Cloud::Spanner::V1::Mutation>]
|
|
283
286
|
def mutations
|
|
284
287
|
@mutations
|
|
285
288
|
end
|
|
@@ -53,8 +53,11 @@ module Google
|
|
|
53
53
|
# puts commit_resp.stats.mutation_count
|
|
54
54
|
#
|
|
55
55
|
class CommitResponse
|
|
56
|
-
|
|
57
|
-
#
|
|
56
|
+
# Creates a new CommitResponse instance.
|
|
57
|
+
#
|
|
58
|
+
# @param grpc [::Google::Cloud::Spanner::V1::CommitResponse]
|
|
59
|
+
# Underlying `V1::CommitResponse` object.
|
|
60
|
+
# @private
|
|
58
61
|
def initialize grpc
|
|
59
62
|
@grpc = grpc
|
|
60
63
|
end
|
|
@@ -74,10 +77,13 @@ module Google
|
|
|
74
77
|
CommitStats.from_grpc @grpc.commit_stats if @grpc.commit_stats
|
|
75
78
|
end
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
# @private
|
|
79
|
-
# Creates a new Commit responsee instance from a
|
|
80
|
+
# Creates a new `Spanner::CommitResponse` instance from a
|
|
80
81
|
# `Google::Cloud::Spanner::V1::CommitResponse`.
|
|
82
|
+
#
|
|
83
|
+
# @param grpc [::Google::Cloud::Spanner::V1::CommitResponse]
|
|
84
|
+
# Underlying `V1::CommitResponse` object.
|
|
85
|
+
# @private
|
|
86
|
+
# @return [::Google::Cloud::Spanner::CommitResponse]
|
|
81
87
|
def self.from_grpc grpc
|
|
82
88
|
new grpc
|
|
83
89
|
end
|
|
@@ -81,7 +81,7 @@ module Google
|
|
|
81
81
|
|
|
82
82
|
# Creates a new `Spanner::Instance` instance.
|
|
83
83
|
# @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
|
|
84
|
-
#
|
|
84
|
+
# Underlying `V1::Instance` object.
|
|
85
85
|
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
|
|
86
86
|
# @private
|
|
87
87
|
def initialize grpc, service
|
|
@@ -965,7 +965,7 @@ module Google
|
|
|
965
965
|
# Creates a new Instance instance from a
|
|
966
966
|
# `Google::Cloud::Spanner::Admin::Instance::V1::Instance`.
|
|
967
967
|
# @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
|
|
968
|
-
#
|
|
968
|
+
# Underlying `V1::Instance` object.
|
|
969
969
|
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
|
|
970
970
|
# @private
|
|
971
971
|
# @return [::Google::Cloud::Spanner::Instance]
|