google-cloud-spanner 2.26.0 → 2.28.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.
@@ -43,19 +43,28 @@ module Google
43
43
  # no operations are sent for more than an hour.
44
44
  #
45
45
  class Session
46
- ##
47
- # @private The `Google::Cloud::Spanner::V1::Session` object
46
+ # The wrapped `V1::Session` protobuf session object.
47
+ # @return [::Google::Cloud::Spanner::V1::Session]
48
+ # @private
48
49
  attr_accessor :grpc
49
50
 
50
- ##
51
- # @private The gRPC Service object.
51
+ # The `Spanner::Service` object.
52
+ # @private
53
+ # @return [::Google::Cloud::Spanner::Service]
52
54
  attr_accessor :service
53
55
 
54
- ##
55
- # @private The hash of query options.
56
+ # A hash of values to specify the custom query options for executing SQL query.
57
+ # Example option: `:optimizer_version`.
58
+ # @private
59
+ # @return [::Hash, nil]
56
60
  attr_accessor :query_options
57
61
 
58
- # @private Creates a new Session instance.
62
+ # Creates a new Session instance.
63
+ # @param grpc [::Google::Cloud::Spanner::V1::Session] Underlying `V1::Session` object.
64
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` object.
65
+ # @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
66
+ # query options for executing SQL query. Example option: `:optimizer_version`.
67
+ # @private
59
68
  def initialize grpc, service, query_options: nil
60
69
  @grpc = grpc
61
70
  @service = service
@@ -63,33 +72,38 @@ module Google
63
72
  end
64
73
 
65
74
  # The unique identifier for the project.
66
- # @return [String]
75
+ # @private
76
+ # @return [::String]
67
77
  def project_id
68
78
  @grpc.name.split("/")[1]
69
79
  end
70
80
 
71
81
  # The unique identifier for the instance.
72
- # @return [String]
82
+ # @private
83
+ # @return [::String]
73
84
  def instance_id
74
85
  @grpc.name.split("/")[3]
75
86
  end
76
87
 
77
88
  # The unique identifier for the database.
78
- # @return [String]
89
+ # @private
90
+ # @return [::String]
79
91
  def database_id
80
92
  @grpc.name.split("/")[5]
81
93
  end
82
94
 
83
95
  # The unique identifier for the session.
84
- # @return [String]
96
+ # @private
97
+ # @return [::String]
85
98
  def session_id
86
99
  @grpc.name.split("/")[7]
87
100
  end
88
101
 
89
- ##
90
- # The full path for the session resource. Values are of the form
102
+ # Full session name.
103
+ # Values are of the form:
91
104
  # `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
92
- # @return [String]
105
+ # @private
106
+ # @return [::String]
93
107
  def path
94
108
  @grpc.name
95
109
  end
@@ -360,7 +374,7 @@ module Google
360
374
  response = service.execute_streaming_sql path, sql, **execute_query_options
361
375
 
362
376
  results = Results.from_execute_query_response response, service, path, sql, execute_query_options
363
- @last_updated_at = Time.now
377
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
364
378
  results
365
379
  end
366
380
 
@@ -430,7 +444,7 @@ module Google
430
444
  batch.statements, seqno,
431
445
  request_options: request_options,
432
446
  call_options: call_options
433
- @last_updated_at = Time.now
447
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
434
448
  results
435
449
  end
436
450
 
@@ -483,6 +497,14 @@ module Google
483
497
  # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
484
498
  # * `:retry_codes` (`Array<String>`) - The error codes that should
485
499
  # trigger a retry.
500
+ # @param [::Google::Cloud::Spanner::V1::ReadRequest::OrderBy] order_by An option to control the order in which
501
+ # rows are returned from a read.
502
+ # To see the available options refer to
503
+ # ['Google::Cloud::Spanner::V1::ReadRequest::OrderBy'](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-OrderBy)
504
+ # @param [::Google::Cloud::Spanner::V1::ReadRequest::LockHint] lock_hint A lock hint mechanism for reads done
505
+ # within a transaction.
506
+ # To see the available options refer to
507
+ # ['Google::Cloud::Spanner::V1::ReadRequest::LockHint'](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-LockHint)
486
508
  #
487
509
  # @return [Google::Cloud::Spanner::Results] The results of the read
488
510
  # operation.
@@ -503,7 +525,7 @@ module Google
503
525
  def read table, columns, keys: nil, index: nil, limit: nil,
504
526
  transaction: nil, partition_token: nil, request_options: nil,
505
527
  call_options: nil, data_boost_enabled: nil, directed_read_options: nil,
506
- route_to_leader: nil
528
+ route_to_leader: nil, order_by: nil, lock_hint: nil
507
529
  ensure_service!
508
530
 
509
531
  read_options = {
@@ -512,7 +534,9 @@ module Google
512
534
  partition_token: partition_token,
513
535
  request_options: request_options,
514
536
  call_options: call_options,
515
- route_to_leader: route_to_leader
537
+ route_to_leader: route_to_leader,
538
+ order_by: order_by,
539
+ lock_hint: lock_hint
516
540
  }
517
541
  read_options[:data_boost_enabled] = data_boost_enabled unless data_boost_enabled.nil?
518
542
  read_options[:directed_read_options] = directed_read_options unless directed_read_options.nil?
@@ -522,7 +546,7 @@ module Google
522
546
 
523
547
  results = Results.from_read_response response, service, path, table, columns, read_options
524
548
 
525
- @last_updated_at = Time.now
549
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
526
550
 
527
551
  results
528
552
  end
@@ -538,7 +562,7 @@ module Google
538
562
  max_partitions: max_partitions,
539
563
  call_options: call_options
540
564
 
541
- @last_updated_at = Time.now
565
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
542
566
 
543
567
  results
544
568
  end
@@ -555,7 +579,7 @@ module Google
555
579
  max_partitions: max_partitions,
556
580
  call_options: call_options
557
581
 
558
- @last_updated_at = Time.now
582
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
559
583
 
560
584
  results
561
585
  end
@@ -657,7 +681,7 @@ module Google
657
681
  commit_options: commit_options,
658
682
  request_options: request_options,
659
683
  call_options: call_options
660
- @last_updated_at = Time.now
684
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
661
685
  resp = CommitResponse.from_grpc commit_resp
662
686
  commit_options ? resp : resp.timestamp
663
687
  end
@@ -755,7 +779,7 @@ module Google
755
779
  request_options: request_options,
756
780
  call_options: call_options
757
781
  results = BatchWriteResults.new response
758
- @last_updated_at = Time.now
782
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
759
783
  results
760
784
  end
761
785
 
@@ -1341,7 +1365,7 @@ module Google
1341
1365
  # Rolls back the transaction, releasing any locks it holds.
1342
1366
  def rollback transaction_id
1343
1367
  service.rollback path, transaction_id
1344
- @last_updated_at = Time.now
1368
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
1345
1369
  true
1346
1370
  end
1347
1371
 
@@ -1370,7 +1394,7 @@ module Google
1370
1394
  def reload!
1371
1395
  ensure_service!
1372
1396
  @grpc = service.get_session path
1373
- @last_updated_at = Time.now
1397
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
1374
1398
  self
1375
1399
  rescue Google::Cloud::NotFoundError
1376
1400
  labels = @grpc.labels.to_h unless @grpc.labels.to_h.empty?
@@ -1379,7 +1403,7 @@ module Google
1379
1403
  project: project_id, instance: instance_id, database: database_id
1380
1404
  ),
1381
1405
  labels: labels
1382
- @last_updated_at = Time.now
1406
+ @last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
1383
1407
  self
1384
1408
  end
1385
1409
 
@@ -1408,18 +1432,23 @@ module Google
1408
1432
  service.delete_session path
1409
1433
  end
1410
1434
 
1411
- ##
1412
- # @private
1413
1435
  # Determines if the session has been idle longer than the given
1414
1436
  # duration.
1415
- def idle_since? duration
1437
+ # @param duration_sec [::Numeric] interval in seconds
1438
+ # @private
1439
+ # @return [::Boolean]
1440
+ def idle_since? duration_sec
1416
1441
  return true if @last_updated_at.nil?
1417
- Time.now > @last_updated_at + duration
1442
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) > @last_updated_at + duration_sec
1418
1443
  end
1419
1444
 
1420
- ##
1421
- # @private Creates a new Session instance from a
1422
- # `Google::Cloud::Spanner::V1::Session`.
1445
+ # Creates a new Session instance from a `V1::Session`.
1446
+ # @param grpc [::Google::Cloud::Spanner::V1::Session] Underlying `V1::Session` object.
1447
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` ref.
1448
+ # @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
1449
+ # query options for executing SQL query. Example option: `:optimizer_version`.
1450
+ # @private
1451
+ # @return [::Google::Cloud::Spanner::Session]
1423
1452
  def self.from_grpc grpc, service, query_options: nil
1424
1453
  new grpc, service, query_options: query_options
1425
1454
  end
@@ -1439,6 +1468,11 @@ module Google
1439
1468
  raise "Must have active connection to service" unless service
1440
1469
  end
1441
1470
 
1471
+ # Merge two hashes
1472
+ # @param hash [::Hash, nil]
1473
+ # @param hash_to_merge [::Hash, nil]
1474
+ # @private
1475
+ # @return [::Hash, nil]
1442
1476
  def merge_if_present hash, hash_to_merge
1443
1477
  if hash.nil?
1444
1478
  hash_to_merge
@@ -76,19 +76,40 @@ module Google
76
76
  # end
77
77
  #
78
78
  class Transaction
79
- # @private The `Google::Cloud::Spanner::V1::Transaction` object.
79
+ # The underlying `V1::Transaction` protobuf object.
80
+ # @private
81
+ # @return [::Google::Cloud::Spanner::V1::Transaction]
80
82
  attr_reader :grpc
81
83
 
82
- # @private The Session object.
84
+ # The `Spanner::Session` session for this transaction.
85
+ # @private
86
+ # @return [::Google::Cloud::Spanner::Session]
83
87
  attr_accessor :session
84
88
 
85
- # @private Transaction tag for statistics collection.
89
+ # Transaction tag for statistics collection.
90
+ # Example: `"update_user_profile"`.
91
+ # @private
92
+ # @return [::String, nil]
86
93
  attr_accessor :transaction_tag
87
94
 
88
- # @private Whether to exclude from change streams.
95
+ # Whether to exclude this transaction from change streams.
96
+ # @private
97
+ # @return [::Boolean]
89
98
  attr_accessor :exclude_txn_from_change_streams
90
99
 
91
- def initialize
100
+ # Creates a new `Spanner::Transaction` instance from a `V1::Transaction` object.
101
+ # @param grpc [::Google::Cloud::Spanner::V1::Transaction] Underlying `V1::Transaction` object.
102
+ # @param session [::Google::Cloud::Spanner::Session] The session this transaction is running in.
103
+ # @param exclude_txn_from_change_streams [::Boolean]
104
+ # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
105
+ # or write transactions from being tracked in change streams.
106
+ # @private
107
+ # @return [::Google::Cloud::Spanner::Transaction]
108
+ def initialize grpc, session, exclude_txn_from_change_streams
109
+ @grpc = grpc
110
+ @session = session
111
+ @exclude_txn_from_change_streams = exclude_txn_from_change_streams
112
+
92
113
  @commit = Commit.new
93
114
  @seqno = 0
94
115
  @exclude_txn_from_change_streams = false
@@ -116,7 +137,7 @@ module Google
116
137
  # @return [String] The transaction id.
117
138
  def transaction_id
118
139
  return @grpc.id if existing_transaction?
119
- safe_begin_transaction
140
+ safe_begin_transaction!
120
141
  @grpc.id
121
142
  end
122
143
 
@@ -1153,15 +1174,16 @@ module Google
1153
1174
  @commit.mutations
1154
1175
  end
1155
1176
 
1156
- ##
1157
- # @private Creates a new Transaction instance from a
1158
- # `Google::Cloud::Spanner::V1::Transaction`.
1177
+ # Creates a new `Spanner::Transaction` instance from a `V1::Transaction` object.
1178
+ # @param grpc [::Google::Cloud::Spanner::V1::Transaction] Underlying `V1::Transaction` object.
1179
+ # @param session [::Google::Cloud::Spanner::Session] The session this transaction is running in.
1180
+ # @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
1181
+ # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
1182
+ # or write transactions from being tracked in change streams.
1183
+ # @private
1184
+ # @return [::Google::Cloud::Spanner::Transaction]
1159
1185
  def self.from_grpc grpc, session, exclude_txn_from_change_streams: false
1160
- new.tap do |s|
1161
- s.instance_variable_set :@grpc, grpc
1162
- s.instance_variable_set :@session, session
1163
- s.exclude_txn_from_change_streams = exclude_txn_from_change_streams
1164
- end
1186
+ new grpc, session, exclude_txn_from_change_streams
1165
1187
  end
1166
1188
 
1167
1189
  ##
@@ -1176,6 +1198,33 @@ module Google
1176
1198
  @grpc.nil?
1177
1199
  end
1178
1200
 
1201
+ # Begins a new transaction in a thread-safe manner if one does not already exist.
1202
+ #
1203
+ # @param exclude_from_change_streams [::Boolean] Optional. Defaults to `false`.
1204
+ # When `exclude_from_change_streams` is set to `true`, it prevents read
1205
+ # or write transactions from being tracked in change streams.
1206
+ # @param request_options [::Hash, nil] Optional. Common request options.
1207
+ # Example option: `:priority`.
1208
+ # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
1209
+ # call options. Example option `:timeout`.
1210
+ # @private
1211
+ # @return [::Google::Cloud::Spanner::V1::Transaction, nil] The new transaction
1212
+ # object, or `nil` if a transaction already exists.
1213
+ def safe_begin_transaction! exclude_from_change_streams: false, request_options: nil, call_options: nil
1214
+ @mutex.synchronize do
1215
+ return if existing_transaction?
1216
+ ensure_session!
1217
+ route_to_leader = LARHeaders.begin_transaction true
1218
+ @grpc = service.begin_transaction(
1219
+ session.path,
1220
+ exclude_txn_from_change_streams: exclude_from_change_streams,
1221
+ request_options: request_options,
1222
+ call_options: call_options,
1223
+ route_to_leader: route_to_leader
1224
+ )
1225
+ end
1226
+ end
1227
+
1179
1228
  protected
1180
1229
 
1181
1230
  ##
@@ -1203,24 +1252,18 @@ module Google
1203
1252
  end
1204
1253
  end
1205
1254
 
1206
- ##
1207
- # Create a new transaction in a thread-safe manner.
1208
- def safe_begin_transaction
1209
- @mutex.synchronize do
1210
- return if existing_transaction?
1211
- ensure_session!
1212
- route_to_leader = LARHeaders.begin_transaction true
1213
- @grpc = service.begin_transaction session.path, route_to_leader: route_to_leader
1214
- end
1215
- end
1216
-
1217
- ##
1218
- # @private The TransactionSelector to be used for queries. This method must
1219
- # be called from within a synchronized block, since the value returned
1220
- # depends on the state of @grpc field.
1255
+ # The TransactionSelector to be used for queries. This method must
1256
+ # be called from within a synchronized block, since the value returned
1257
+ # depends on the state of @grpc field.
1221
1258
  #
1222
- # This method is expected to be called from within `safe_execute()` method's block,
1223
- # since it provides synchronization and gurantees thread safety.
1259
+ # This method is expected to be called from within `safe_execute()` method's block,
1260
+ # since it provides synchronization and gurantees thread safety.
1261
+ #
1262
+ # @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
1263
+ # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
1264
+ # or write transactions from being tracked in change streams.
1265
+ # @private
1266
+ # @return [::Google::Cloud::Spanner::V1::TransactionSelector]
1224
1267
  def tx_selector exclude_txn_from_change_streams: false
1225
1268
  return V1::TransactionSelector.new id: transaction_id if existing_transaction?
1226
1269
  V1::TransactionSelector.new(
@@ -1261,6 +1304,9 @@ module Google
1261
1304
  raise "Must have active connection to service" unless session
1262
1305
  end
1263
1306
 
1307
+ # The `Spanner::Service` object used by this transaction.
1308
+ # @private
1309
+ # @return [::Google::Cloud::Spanner::Service]
1264
1310
  def service
1265
1311
  session.service
1266
1312
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.26.0".freeze
19
+ VERSION = "2.28.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.26.0
4
+ version: 2.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  - Chris Smith
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-28 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -150,6 +150,7 @@ files:
150
150
  - lib/google/cloud/spanner/instance/config/list.rb
151
151
  - lib/google/cloud/spanner/instance/job.rb
152
152
  - lib/google/cloud/spanner/instance/list.rb
153
+ - lib/google/cloud/spanner/interval.rb
153
154
  - lib/google/cloud/spanner/lar_headers.rb
154
155
  - lib/google/cloud/spanner/mutation_group.rb
155
156
  - lib/google/cloud/spanner/partition.rb
@@ -175,14 +176,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
176
  requirements:
176
177
  - - ">="
177
178
  - !ruby/object:Gem::Version
178
- version: '3.0'
179
+ version: '3.1'
179
180
  required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  requirements:
181
182
  - - ">="
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.6.5
186
+ rubygems_version: 3.6.9
186
187
  specification_version: 4
187
188
  summary: API Client library for Google Cloud Spanner API
188
189
  test_files: []