google-cloud-spanner 2.8.1 → 2.11.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 +39 -49
- data/OVERVIEW.md +69 -50
- data/lib/google/cloud/spanner/admin/database.rb +321 -0
- data/lib/google/cloud/spanner/admin/instance.rb +321 -0
- data/lib/google/cloud/spanner/backup/job/list.rb +7 -0
- data/lib/google/cloud/spanner/backup/job.rb +7 -0
- data/lib/google/cloud/spanner/backup/list.rb +7 -0
- data/lib/google/cloud/spanner/backup/restore/job.rb +7 -0
- data/lib/google/cloud/spanner/backup.rb +14 -0
- data/lib/google/cloud/spanner/client.rb +236 -34
- data/lib/google/cloud/spanner/convert.rb +22 -2
- data/lib/google/cloud/spanner/database/backup_info.rb +5 -0
- data/lib/google/cloud/spanner/database/job/list.rb +7 -0
- data/lib/google/cloud/spanner/database/job.rb +7 -0
- data/lib/google/cloud/spanner/database/list.rb +7 -0
- data/lib/google/cloud/spanner/database/restore_info.rb +5 -0
- data/lib/google/cloud/spanner/database.rb +13 -0
- data/lib/google/cloud/spanner/instance/config/list.rb +7 -0
- data/lib/google/cloud/spanner/instance/config.rb +7 -0
- data/lib/google/cloud/spanner/instance/job.rb +7 -0
- data/lib/google/cloud/spanner/instance/list.rb +7 -0
- data/lib/google/cloud/spanner/instance.rb +14 -0
- data/lib/google/cloud/spanner/project.rb +35 -0
- data/lib/google/cloud/spanner/service.rb +7 -2
- data/lib/google/cloud/spanner/session.rb +153 -0
- data/lib/google/cloud/spanner/transaction.rb +37 -1
- data/lib/google/cloud/spanner/version.rb +1 -1
- data/lib/google/cloud/spanner.rb +2 -0
- metadata +4 -2
@@ -236,6 +236,10 @@ module Google
|
|
236
236
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
237
237
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
238
238
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
239
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
240
|
+
# queries or reads, used for statistics collection. Tag must be a
|
241
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
242
|
+
# and 64 characters in length.
|
239
243
|
# @param [Hash] call_options A hash of values to specify the custom
|
240
244
|
# call options, e.g., timeout, retries, etc. Call options are
|
241
245
|
# optional. The following settings can be provided:
|
@@ -403,6 +407,21 @@ module Google
|
|
403
407
|
# puts "User #{row[:id]} is #{row[:name]}"
|
404
408
|
# end
|
405
409
|
#
|
410
|
+
# @example Query using tag for request query statistics collection.
|
411
|
+
# require "google/cloud/spanner"
|
412
|
+
#
|
413
|
+
# spanner = Google::Cloud::Spanner.new
|
414
|
+
#
|
415
|
+
# db = spanner.client "my-instance", "my-database"
|
416
|
+
#
|
417
|
+
# request_options = { tag: "Read-Users" }
|
418
|
+
# results = db.execute_query "SELECT * FROM users",
|
419
|
+
# request_options: request_options
|
420
|
+
#
|
421
|
+
# results.rows.each do |row|
|
422
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
423
|
+
# end
|
424
|
+
#
|
406
425
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
407
426
|
query_options: nil, request_options: nil,
|
408
427
|
call_options: nil
|
@@ -410,7 +429,8 @@ module Google
|
|
410
429
|
ensure_service!
|
411
430
|
|
412
431
|
params, types = Convert.to_input_params_and_types params, types
|
413
|
-
|
432
|
+
request_options = Convert.to_request_options request_options,
|
433
|
+
tag_type: :request_tag
|
414
434
|
single_use_tx = single_use_transaction single_use
|
415
435
|
results = nil
|
416
436
|
@pool.with_session do |session|
|
@@ -580,6 +600,10 @@ module Google
|
|
580
600
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
581
601
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
582
602
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
603
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
604
|
+
# queries or reads, used for statistics collection. Tag must be a
|
605
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
606
|
+
# and 64 characters in length.
|
583
607
|
# @param [Hash] call_options A hash of values to specify the custom
|
584
608
|
# call options, e.g., timeout, retries, etc. Call options are
|
585
609
|
# optional. The following settings can be provided:
|
@@ -657,12 +681,27 @@ module Google
|
|
657
681
|
# "UPDATE users SET friends = NULL WHERE active = @active",
|
658
682
|
# params: { active: false }, request_options: request_options
|
659
683
|
#
|
684
|
+
# @example Query using tag for request query statistics collection.
|
685
|
+
#
|
686
|
+
# require "google/cloud/spanner"
|
687
|
+
#
|
688
|
+
# spanner = Google::Cloud::Spanner.new
|
689
|
+
# db = spanner.client "my-instance", "my-database"
|
690
|
+
#
|
691
|
+
# request_options = { tag: "Update-Users" }
|
692
|
+
# row_count = db.execute_partition_update \
|
693
|
+
# "UPDATE users SET friends = NULL WHERE active = false",
|
694
|
+
# request_options: request_options
|
695
|
+
#
|
660
696
|
def execute_partition_update sql, params: nil, types: nil,
|
661
697
|
query_options: nil, request_options: nil,
|
662
698
|
call_options: nil
|
663
699
|
ensure_service!
|
664
700
|
|
665
701
|
params, types = Convert.to_input_params_and_types params, types
|
702
|
+
request_options = Convert.to_request_options request_options,
|
703
|
+
tag_type: :request_tag
|
704
|
+
|
666
705
|
results = nil
|
667
706
|
@pool.with_session do |session|
|
668
707
|
results = session.execute_query \
|
@@ -761,6 +800,10 @@ module Google
|
|
761
800
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
762
801
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
763
802
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
803
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
804
|
+
# queries or reads, used for statistics collection. Tag must be a
|
805
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
806
|
+
# and 64 characters in length.
|
764
807
|
# @param [Hash] call_options A hash of values to specify the custom
|
765
808
|
# call options, e.g., timeout, retries, etc. Call options are
|
766
809
|
# optional. The following settings can be provided:
|
@@ -840,6 +883,22 @@ module Google
|
|
840
883
|
# puts "User #{row[:id]} is #{row[:name]}"
|
841
884
|
# end
|
842
885
|
#
|
886
|
+
# @example Read using tag for read statistics collection.
|
887
|
+
#
|
888
|
+
# require "google/cloud/spanner"
|
889
|
+
#
|
890
|
+
# spanner = Google::Cloud::Spanner.new
|
891
|
+
#
|
892
|
+
# db = spanner.client "my-instance", "my-database"
|
893
|
+
#
|
894
|
+
# request_options = { tag: "Read-Users-All" }
|
895
|
+
# results = db.read "users", [:id, :name],
|
896
|
+
# request_options: request_options
|
897
|
+
#
|
898
|
+
# results.rows.each do |row|
|
899
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
900
|
+
# end
|
901
|
+
#
|
843
902
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
844
903
|
single_use: nil, request_options: nil, call_options: nil
|
845
904
|
validate_single_use_args! single_use
|
@@ -847,8 +906,10 @@ module Google
|
|
847
906
|
|
848
907
|
columns = Array(columns).map(&:to_s)
|
849
908
|
keys = Convert.to_key_set keys
|
850
|
-
|
851
909
|
single_use_tx = single_use_transaction single_use
|
910
|
+
request_options = Convert.to_request_options request_options,
|
911
|
+
tag_type: :request_tag
|
912
|
+
|
852
913
|
results = nil
|
853
914
|
@pool.with_session do |session|
|
854
915
|
results = session.read \
|
@@ -914,6 +975,9 @@ module Google
|
|
914
975
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
915
976
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
916
977
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
978
|
+
# * `:tag` (String) A tag used for statistics collection
|
979
|
+
# about transaction. A tag must be a valid identifier of the format:
|
980
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
917
981
|
#
|
918
982
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
919
983
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -954,7 +1018,23 @@ module Google
|
|
954
1018
|
# db.upsert "users", [{ id: 1, name: "Charlie", active: false }],
|
955
1019
|
# request_options: request_options
|
956
1020
|
#
|
1021
|
+
# @example Upsert using tag for transaction statistics collection.
|
1022
|
+
#
|
1023
|
+
# require "google/cloud/spanner"
|
1024
|
+
#
|
1025
|
+
# spanner = Google::Cloud::Spanner.new
|
1026
|
+
#
|
1027
|
+
# db = spanner.client "my-instance", "my-database"
|
1028
|
+
#
|
1029
|
+
# request_options = { tag: "Bulk-Upsert" }
|
1030
|
+
# db.upsert "users", [{ id: 1, name: "Charlie", active: false },
|
1031
|
+
# { id: 2, name: "Harvey", active: true }],
|
1032
|
+
# request_options: request_options
|
1033
|
+
#
|
957
1034
|
def upsert table, rows, commit_options: nil, request_options: nil
|
1035
|
+
request_options = Convert.to_request_options \
|
1036
|
+
request_options, tag_type: :transaction_tag
|
1037
|
+
|
958
1038
|
@pool.with_session do |session|
|
959
1039
|
session.upsert table, rows, commit_options: commit_options,
|
960
1040
|
request_options: request_options
|
@@ -999,7 +1079,6 @@ module Google
|
|
999
1079
|
#
|
1000
1080
|
# See [Data
|
1001
1081
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1002
|
-
#
|
1003
1082
|
# @param [Hash] commit_options A hash of commit options.
|
1004
1083
|
# e.g., return_commit_stats. Commit options are optional.
|
1005
1084
|
# The following options can be provided:
|
@@ -1015,6 +1094,9 @@ module Google
|
|
1015
1094
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1016
1095
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1017
1096
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1097
|
+
# * `:tag` (String) A tag used for statistics collection
|
1098
|
+
# about transaction. A tag must be a valid identifier of the
|
1099
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1018
1100
|
#
|
1019
1101
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1020
1102
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1055,7 +1137,23 @@ module Google
|
|
1055
1137
|
# db.insert "users", [{ id: 1, name: "Charlie", active: false }],
|
1056
1138
|
# request_options: request_options
|
1057
1139
|
#
|
1140
|
+
# @example Insert using tag for transaction statistics collection.
|
1141
|
+
#
|
1142
|
+
# require "google/cloud/spanner"
|
1143
|
+
#
|
1144
|
+
# spanner = Google::Cloud::Spanner.new
|
1145
|
+
#
|
1146
|
+
# db = spanner.client "my-instance", "my-database"
|
1147
|
+
#
|
1148
|
+
# request_options = { tag: "BulkInsert-Users" }
|
1149
|
+
# db.insert "users", [{ id: 1, name: "Charlie", active: false },
|
1150
|
+
# { id: 2, name: "Harvey", active: true }],
|
1151
|
+
# request_options: request_options
|
1152
|
+
#
|
1058
1153
|
def insert table, rows, commit_options: nil, request_options: nil
|
1154
|
+
request_options = Convert.to_request_options \
|
1155
|
+
request_options, tag_type: :transaction_tag
|
1156
|
+
|
1059
1157
|
@pool.with_session do |session|
|
1060
1158
|
session.insert table, rows, commit_options: commit_options,
|
1061
1159
|
request_options: request_options
|
@@ -1099,7 +1197,6 @@ module Google
|
|
1099
1197
|
#
|
1100
1198
|
# See [Data
|
1101
1199
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1102
|
-
#
|
1103
1200
|
# @param [Hash] commit_options A hash of commit options.
|
1104
1201
|
# e.g., return_commit_stats. Commit options are optional.
|
1105
1202
|
# The following options can be provided:
|
@@ -1115,6 +1212,9 @@ module Google
|
|
1115
1212
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1116
1213
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1117
1214
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1215
|
+
# * `:tag` (String) A tag used for statistics collection
|
1216
|
+
# about transaction. A tag must be a valid identifier of the
|
1217
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1118
1218
|
#
|
1119
1219
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1120
1220
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1155,7 +1255,22 @@ module Google
|
|
1155
1255
|
# db.update "users", [{ id: 1, name: "Charlie", active: false }],
|
1156
1256
|
# request_options: request_options
|
1157
1257
|
#
|
1258
|
+
# @example Updte using tag for transaction statistics collection.
|
1259
|
+
# require "google/cloud/spanner"
|
1260
|
+
#
|
1261
|
+
# spanner = Google::Cloud::Spanner.new
|
1262
|
+
#
|
1263
|
+
# db = spanner.client "my-instance", "my-database"
|
1264
|
+
#
|
1265
|
+
# request_options = { tag: "BulkUpdate-Users" }
|
1266
|
+
# db.update "users", [{ id: 1, name: "Charlie", active: false },
|
1267
|
+
# { id: 2, name: "Harvey", active: true }],
|
1268
|
+
# request_options: request_options
|
1269
|
+
#
|
1158
1270
|
def update table, rows, commit_options: nil, request_options: nil
|
1271
|
+
request_options = Convert.to_request_options \
|
1272
|
+
request_options, tag_type: :transaction_tag
|
1273
|
+
|
1159
1274
|
@pool.with_session do |session|
|
1160
1275
|
session.update table, rows, commit_options: commit_options,
|
1161
1276
|
request_options: request_options
|
@@ -1201,7 +1316,6 @@ module Google
|
|
1201
1316
|
#
|
1202
1317
|
# See [Data
|
1203
1318
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1204
|
-
#
|
1205
1319
|
# @param [Hash] commit_options A hash of commit options.
|
1206
1320
|
# e.g., return_commit_stats. Commit options are optional.
|
1207
1321
|
# The following options can be provided:
|
@@ -1217,6 +1331,9 @@ module Google
|
|
1217
1331
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1218
1332
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1219
1333
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1334
|
+
# * `:tag` (String) A tag used for statistics collection
|
1335
|
+
# about transaction. A tag must be a valid identifier of the
|
1336
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1220
1337
|
#
|
1221
1338
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1222
1339
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1257,6 +1374,18 @@ module Google
|
|
1257
1374
|
# db.replace "users", [{ id: 1, name: "Charlie", active: false }],
|
1258
1375
|
# request_options: request_options
|
1259
1376
|
#
|
1377
|
+
# @example Replace using tag for transaction statistics collection.
|
1378
|
+
# require "google/cloud/spanner"
|
1379
|
+
#
|
1380
|
+
# spanner = Google::Cloud::Spanner.new
|
1381
|
+
#
|
1382
|
+
# db = spanner.client "my-instance", "my-database"
|
1383
|
+
#
|
1384
|
+
# request_options = { tag: "BulkReplace-Users" }
|
1385
|
+
# db.replace "users", [{ id: 1, name: "Charlie", active: false },
|
1386
|
+
# { id: 2, name: "Harvey", active: true }],
|
1387
|
+
# request_options: request_options
|
1388
|
+
#
|
1260
1389
|
def replace table, rows, commit_options: nil, request_options: nil
|
1261
1390
|
@pool.with_session do |session|
|
1262
1391
|
session.replace table, rows, commit_options: commit_options,
|
@@ -1299,6 +1428,9 @@ module Google
|
|
1299
1428
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1300
1429
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1301
1430
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1431
|
+
# * `:tag` (String) A tag used for statistics collection
|
1432
|
+
# about transaction. A tag must be a valid identifier of the
|
1433
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1302
1434
|
# @param [Hash] call_options A hash of values to specify the custom
|
1303
1435
|
# call options, e.g., timeout, retries, etc. Call options are
|
1304
1436
|
# optional. The following settings can be provided:
|
@@ -1348,8 +1480,21 @@ module Google
|
|
1348
1480
|
# request_options = { priority: :PRIORITY_MEDIUM }
|
1349
1481
|
# db.delete "users", [1, 2, 3], request_options: request_options
|
1350
1482
|
#
|
1483
|
+
# @example Delete using tag for transaction statistics collection.
|
1484
|
+
# require "google/cloud/spanner"
|
1485
|
+
#
|
1486
|
+
# spanner = Google::Cloud::Spanner.new
|
1487
|
+
#
|
1488
|
+
# db = spanner.client "my-instance", "my-database"
|
1489
|
+
#
|
1490
|
+
# request_options = { tag: "BulkDelete-Users" }
|
1491
|
+
# db.delete "users", [1, 2, 3], request_options: request_options
|
1492
|
+
#
|
1351
1493
|
def delete table, keys = [], commit_options: nil, request_options: nil,
|
1352
1494
|
call_options: nil
|
1495
|
+
request_options = Convert.to_request_options \
|
1496
|
+
request_options, tag_type: :transaction_tag
|
1497
|
+
|
1353
1498
|
@pool.with_session do |session|
|
1354
1499
|
session.delete table, keys, commit_options: commit_options,
|
1355
1500
|
request_options: request_options,
|
@@ -1387,6 +1532,9 @@ module Google
|
|
1387
1532
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1388
1533
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1389
1534
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1535
|
+
# * `:tag` (String) A tag used for statistics collection
|
1536
|
+
# about transaction. A tag must be a valid identifier of the
|
1537
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1390
1538
|
# @param [Hash] call_options A hash of values to specify the custom
|
1391
1539
|
# call options, e.g., timeout, retries, etc. Call options are
|
1392
1540
|
# optional. The following settings can be provided:
|
@@ -1447,10 +1595,26 @@ module Google
|
|
1447
1595
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1448
1596
|
# end
|
1449
1597
|
#
|
1598
|
+
# @example Commit using tag for transaction statistics collection.
|
1599
|
+
# require "google/cloud/spanner"
|
1600
|
+
#
|
1601
|
+
# spanner = Google::Cloud::Spanner.new
|
1602
|
+
#
|
1603
|
+
# db = spanner.client "my-instance", "my-database"
|
1604
|
+
#
|
1605
|
+
# request_options = { tag: "BulkManipulate-Users" }
|
1606
|
+
# db.commit request_options: request_options do |c|
|
1607
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1608
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1609
|
+
# end
|
1610
|
+
#
|
1450
1611
|
def commit commit_options: nil, request_options: nil,
|
1451
1612
|
call_options: nil, &block
|
1452
1613
|
raise ArgumentError, "Must provide a block" unless block_given?
|
1453
1614
|
|
1615
|
+
request_options = Convert.to_request_options \
|
1616
|
+
request_options, tag_type: :transaction_tag
|
1617
|
+
|
1454
1618
|
@pool.with_session do |session|
|
1455
1619
|
session.commit(
|
1456
1620
|
commit_options: commit_options, request_options: request_options,
|
@@ -1494,6 +1658,11 @@ module Google
|
|
1494
1658
|
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1495
1659
|
# `:PRIORITY_HIGH`. If priority not set then default is
|
1496
1660
|
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1661
|
+
# * `:tag` (String)A tag used for statistics collection
|
1662
|
+
# about transaction. The value of a transaction tag should be the
|
1663
|
+
# same for all requests belonging to the same transaction. A tag must
|
1664
|
+
# be a valid identifier of the format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`
|
1665
|
+
#
|
1497
1666
|
# @param [Hash] call_options A hash of values to specify the custom
|
1498
1667
|
# call options, e.g., timeout, retries, etc. Call options are
|
1499
1668
|
# optional. The following settings can be provided:
|
@@ -1585,6 +1754,30 @@ module Google
|
|
1585
1754
|
# request_options: request_options
|
1586
1755
|
# end
|
1587
1756
|
#
|
1757
|
+
# @example Tags for request and transaction statistics collection.
|
1758
|
+
#
|
1759
|
+
# require "google/cloud/spanner"
|
1760
|
+
#
|
1761
|
+
# spanner = Google::Cloud::Spanner.new
|
1762
|
+
# db = spanner.client "my-instance", "my-database"
|
1763
|
+
#
|
1764
|
+
# # Transaction tag will be set to "Users-Txn"
|
1765
|
+
# db.transaction request_options: { tag: "Users-Txn" } do |tx|
|
1766
|
+
# # The transaction tag set as "Users-Txn"
|
1767
|
+
# # The request tag set as "Users-Txn-1"
|
1768
|
+
# request_options = { tag: "Users-Txn-1" }
|
1769
|
+
# results = tx.execute_query "SELECT * FROM users",
|
1770
|
+
# request_options: request_options
|
1771
|
+
#
|
1772
|
+
# results.rows.each do |row|
|
1773
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
1774
|
+
# end
|
1775
|
+
#
|
1776
|
+
# # The transaction tag set as "Users-Txn"
|
1777
|
+
# tx.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1778
|
+
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1779
|
+
# end
|
1780
|
+
#
|
1588
1781
|
def transaction deadline: 120, commit_options: nil,
|
1589
1782
|
request_options: nil, call_options: nil
|
1590
1783
|
ensure_service!
|
@@ -1596,39 +1789,48 @@ module Google
|
|
1596
1789
|
backoff = 1.0
|
1597
1790
|
start_time = current_time
|
1598
1791
|
|
1792
|
+
request_options = Convert.to_request_options \
|
1793
|
+
request_options, tag_type: :transaction_tag
|
1794
|
+
|
1599
1795
|
@pool.with_transaction do |tx|
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1796
|
+
if request_options
|
1797
|
+
tx.transaction_tag = request_options[:transaction_tag]
|
1798
|
+
end
|
1799
|
+
|
1800
|
+
begin
|
1801
|
+
Thread.current[:transaction_id] = tx.transaction_id
|
1802
|
+
yield tx
|
1803
|
+
commit_resp = @project.service.commit \
|
1804
|
+
tx.session.path, tx.mutations,
|
1805
|
+
transaction_id: tx.transaction_id,
|
1806
|
+
commit_options: commit_options,
|
1807
|
+
request_options: request_options,
|
1808
|
+
call_options: call_options
|
1809
|
+
resp = CommitResponse.from_grpc commit_resp
|
1810
|
+
commit_options ? resp : resp.timestamp
|
1811
|
+
rescue GRPC::Aborted, Google::Cloud::AbortedError => e
|
1812
|
+
# Re-raise if deadline has passed
|
1813
|
+
if current_time - start_time > deadline
|
1814
|
+
if e.is_a? GRPC::BadStatus
|
1815
|
+
e = Google::Cloud::Error.from_error e
|
1816
|
+
end
|
1817
|
+
raise e
|
1615
1818
|
end
|
1819
|
+
# Sleep the amount from RetryDelay, or incremental backoff
|
1820
|
+
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1821
|
+
# Create new transaction on the session and retry the block
|
1822
|
+
tx = tx.session.create_transaction
|
1823
|
+
retry
|
1824
|
+
rescue StandardError => e
|
1825
|
+
# Rollback transaction when handling unexpected error
|
1826
|
+
tx.session.rollback tx.transaction_id
|
1827
|
+
# Return nil if raised with rollback.
|
1828
|
+
return nil if e.is_a? Rollback
|
1829
|
+
# Re-raise error.
|
1616
1830
|
raise e
|
1831
|
+
ensure
|
1832
|
+
Thread.current[:transaction_id] = nil
|
1617
1833
|
end
|
1618
|
-
# Sleep the amount from RetryDelay, or incremental backoff
|
1619
|
-
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1620
|
-
# Create new transaction on the session and retry the block
|
1621
|
-
tx = tx.session.create_transaction
|
1622
|
-
retry
|
1623
|
-
rescue StandardError => e
|
1624
|
-
# Rollback transaction when handling unexpected error
|
1625
|
-
tx.session.rollback tx.transaction_id
|
1626
|
-
# Return nil if raised with rollback.
|
1627
|
-
return nil if e.is_a? Rollback
|
1628
|
-
# Re-raise error.
|
1629
|
-
raise e
|
1630
|
-
ensure
|
1631
|
-
Thread.current[:transaction_id] = nil
|
1632
1834
|
end
|
1633
1835
|
end
|
1634
1836
|
|
@@ -99,8 +99,7 @@ module Google
|
|
99
99
|
if field.is_a? Fields
|
100
100
|
field.struct(obj).to_grpc_value
|
101
101
|
else
|
102
|
-
|
103
|
-
"A hash value cannot be set to type #{field}."
|
102
|
+
Google::Protobuf::Value.new string_value: obj.to_json
|
104
103
|
end
|
105
104
|
else
|
106
105
|
if obj.respond_to?(:read) && obj.respond_to?(:rewind)
|
@@ -223,6 +222,8 @@ module Google
|
|
223
222
|
Data.from_grpc value.list_value.values, type.struct_type.fields
|
224
223
|
when :NUMERIC
|
225
224
|
BigDecimal value.string_value
|
225
|
+
when :JSON
|
226
|
+
JSON.parse value.string_value
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
@@ -324,6 +325,25 @@ module Google
|
|
324
325
|
|
325
326
|
[input_params, input_param_types]
|
326
327
|
end
|
328
|
+
|
329
|
+
##
|
330
|
+
# Build request options by replacing tag to respecitve statistics
|
331
|
+
# collection tag type.
|
332
|
+
#
|
333
|
+
# @param [Hash] options Common request options.
|
334
|
+
# * `:tag` (String) A tag used for statistics collection.
|
335
|
+
#
|
336
|
+
# @param [Symbol] tag_type Request tag type.
|
337
|
+
# Possible values are `request_tag`, `transaction_tag`
|
338
|
+
# @return [Hash, nil]
|
339
|
+
#
|
340
|
+
def to_request_options options, tag_type: nil
|
341
|
+
return unless options
|
342
|
+
|
343
|
+
return options unless options.key? :tag
|
344
|
+
|
345
|
+
options.transform_keys { |k| k == :tag ? tag_type : k }
|
346
|
+
end
|
327
347
|
end
|
328
348
|
|
329
349
|
# rubocop:enable all
|
@@ -12,11 +12,16 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
module Google
|
17
20
|
module Cloud
|
18
21
|
module Spanner
|
19
22
|
class Database
|
23
|
+
# @deprecated Use
|
24
|
+
# {Google::Cloud::Spanner::Admin::Database::V1::BackupInfo} instead.
|
20
25
|
class BackupInfo
|
21
26
|
##
|
22
27
|
# @private Creates a new Database::BackupInfo instance.
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "delegate"
|
17
20
|
|
@@ -26,6 +29,10 @@ module Google
|
|
26
29
|
# List is a special case Array with additional values for database
|
27
30
|
# operations.
|
28
31
|
#
|
32
|
+
# @deprecated Use the result of
|
33
|
+
# {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_database_operations}
|
34
|
+
# instead.
|
35
|
+
#
|
29
36
|
class List < DelegateClass(::Array)
|
30
37
|
# @private
|
31
38
|
# The gRPC Service object.
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "google/cloud/spanner/status"
|
17
20
|
require "google/cloud/spanner/database/job/list"
|
@@ -32,6 +35,10 @@ module Google
|
|
32
35
|
# @see https://cloud.google.com/spanner/reference/rpc/google.longrunning#google.longrunning.Operation
|
33
36
|
# Long-running Operation
|
34
37
|
#
|
38
|
+
# @deprecated Use the long-running operation returned by
|
39
|
+
# {Google::Cloud::Spanner::Admin::Database#database_admin Client#create_database}
|
40
|
+
# instead.
|
41
|
+
#
|
35
42
|
# @example
|
36
43
|
# require "google/cloud/spanner"
|
37
44
|
#
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "delegate"
|
17
20
|
|
@@ -22,6 +25,10 @@ module Google
|
|
22
25
|
##
|
23
26
|
# Database::List is a special case Array with additional
|
24
27
|
# values.
|
28
|
+
#
|
29
|
+
# @deprecated Use the result of
|
30
|
+
# {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_databases}
|
31
|
+
# instead.
|
25
32
|
class List < DelegateClass(::Array)
|
26
33
|
##
|
27
34
|
# If not empty, indicates that there are more records that match
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "google/cloud/spanner/database/backup_info"
|
17
20
|
|
@@ -19,6 +22,8 @@ module Google
|
|
19
22
|
module Cloud
|
20
23
|
module Spanner
|
21
24
|
class Database
|
25
|
+
# @deprecated Use
|
26
|
+
# {Google::Cloud::Spanner::Admin::Database::V1::RestoreInfo} instead.
|
22
27
|
class RestoreInfo
|
23
28
|
##
|
24
29
|
# @private Creates a new Database::RestoreInfo instance.
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "google/cloud/spanner/database/job"
|
17
20
|
require "google/cloud/spanner/database/list"
|
@@ -25,6 +28,13 @@ module Google
|
|
25
28
|
##
|
26
29
|
# # Database
|
27
30
|
#
|
31
|
+
# NOTE: From `google-cloud-spanner/v2.11.0` onwards, new features for
|
32
|
+
# mananging databases will only be available through the
|
33
|
+
# [google-cloud-spanner-admin-database-v1](https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-spanner-admin-database-v1)
|
34
|
+
# client. See the
|
35
|
+
# [README](https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-spanner#google-cloud-spanner)
|
36
|
+
# for further details.
|
37
|
+
#
|
28
38
|
# Represents a Cloud Spanner database. To use Cloud Spanner's read and
|
29
39
|
# write operations, you must first create a database. A database belongs
|
30
40
|
# to a {Instance} and contains tables and indexes. You may create multiple
|
@@ -38,6 +48,9 @@ module Google
|
|
38
48
|
# of {Google::Cloud::Spanner::Client}. See
|
39
49
|
# {Google::Cloud::Spanner::Project#client}.
|
40
50
|
#
|
51
|
+
# @deprecated Use
|
52
|
+
# {Google::Cloud::Spanner::Admin::Database#database_admin} instead.
|
53
|
+
#
|
41
54
|
# @example
|
42
55
|
# require "google/cloud"
|
43
56
|
#
|
@@ -12,6 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
# DO NOT EDIT: Unless you're fixing a P0/P1 and/or a security issue. This class
|
16
|
+
# is frozen to all new features from `google-cloud-spanner/v2.11.0` onwards.
|
17
|
+
|
15
18
|
|
16
19
|
require "delegate"
|
17
20
|
|
@@ -23,6 +26,10 @@ module Google
|
|
23
26
|
##
|
24
27
|
# Instance::Config::List is a special case Array with additional
|
25
28
|
# values.
|
29
|
+
#
|
30
|
+
# @deprecated Use the result of
|
31
|
+
# {Google::Cloud::Spanner::Admin::Instance#instance_admin Client#list_instance_configs}
|
32
|
+
# instead.
|
26
33
|
class List < DelegateClass(::Array)
|
27
34
|
##
|
28
35
|
# If not empty, indicates that there are more records that match
|