google-cloud-spanner 2.27.0 → 2.29.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.
@@ -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.27.0".freeze
19
+ VERSION = "2.29.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.27.0
4
+ version: 2.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore