google-cloud-spanner 2.18.0 → 2.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37f9332aedaf9d53b1eb13596dafa4b3571393449b85ce5e63750b5c57381e3f
4
- data.tar.gz: b137394c7819e4795a98727e626772ece2404ef40bc7ef84153014768ddbfb89
3
+ metadata.gz: 86e6ca163f96c37fa118d05ecf481289318c707f1de83ffb401c20b40afacb69
4
+ data.tar.gz: 12cbaad3945956e2da31862d23d0ef66658539fc30daee432879650d2ab3d028
5
5
  SHA512:
6
- metadata.gz: 0ea41265627415904e066549390d59ad72a2be577c3b6f7ac67d8a47197e4f2df4a79f9c2c14735bcd383989b2f3bfa602fe68e3ebde1d7cc055252d8644f36f
7
- data.tar.gz: 2cc9bf3bbe521e85c72ad2dd255eedf09225c0bbcc67bc4c319a4036aa7beac01c18f73a0fb6ff1fd203b96b15ff2b3bcbb82f2f8ddfd0f2aa72e1d2f31f03e9
6
+ metadata.gz: b866a7a87beb50165b5b1593a4e92a1e0a4684f7a5e7210647aae4ecbe05fcf9f61b1309b00d37deb94e592bc98e541ea1f1104e411a32f6ed9bc4bbde1ee624
7
+ data.tar.gz: d8c40babae83b334f95e15ea242f7b1271ecf510cd19722619e759b2a3082df04400b1fc3e78f572a0708ecca76ee68a71192fab92a425d1c27f3c8d58a58aca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.18.1 (2023-09-19)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Use hash to track the sessions in use ([#60](https://github.com/googleapis/ruby-spanner/issues/60))
8
+
3
9
  ### 2.18.0 (2023-09-05)
4
10
 
5
11
  #### Features
@@ -29,7 +29,11 @@ module Google
29
29
  # {Google::Cloud::Spanner::Session} instances.
30
30
  #
31
31
  class Pool
32
+ # @return [Array<Session>] A stack of `Session` objects.
32
33
  attr_accessor :sessions_available
34
+
35
+ # @return [Hash{String => Session}] A hash with session_id as keys,
36
+ # and `Session` objects as values.
33
37
  attr_accessor :sessions_in_use
34
38
 
35
39
  def initialize client, min: 10, max: 100, keepalive: 1800,
@@ -65,10 +69,10 @@ module Google
65
69
 
66
70
  # Use LIFO to ensure sessions are used from backend caches, which
67
71
  # will reduce the read / write latencies on user requests.
68
- read_session = sessions_available.pop # LIFO
69
- if read_session
70
- sessions_in_use << read_session
71
- return read_session
72
+ session = sessions_available.pop # LIFO
73
+ if session
74
+ sessions_in_use[session.session_id] = session
75
+ return session
72
76
  end
73
77
 
74
78
  if can_allocate_more_sessions?
@@ -85,7 +89,7 @@ module Google
85
89
  if action == :new
86
90
  session = new_session!
87
91
  @mutex.synchronize do
88
- sessions_in_use << session
92
+ sessions_in_use[session.session_id] = session
89
93
  end
90
94
  return session
91
95
  end
@@ -95,12 +99,12 @@ module Google
95
99
 
96
100
  def checkin_session session
97
101
  @mutex.synchronize do
98
- unless sessions_in_use.include? session
102
+ unless sessions_in_use.key? session.session_id
99
103
  raise ArgumentError, "Cannot checkin session"
100
104
  end
101
105
 
102
106
  sessions_available.push session
103
- sessions_in_use.delete_if { |s| s.session_id == session.session_id }
107
+ sessions_in_use.delete session.session_id
104
108
 
105
109
  @resource.signal
106
110
  end
@@ -163,7 +167,7 @@ module Google
163
167
  create_keepalive_task!
164
168
  # init session stack
165
169
  @sessions_available = @client.batch_create_new_sessions @min
166
- @sessions_in_use = []
170
+ @sessions_in_use = {}
167
171
  end
168
172
 
169
173
  def shutdown
@@ -176,9 +180,9 @@ module Google
176
180
  # Delete all sessions
177
181
  @mutex.synchronize do
178
182
  sessions_available.each { |s| future { s.release! } }
179
- sessions_in_use.each { |s| future { s.release! } }
183
+ sessions_in_use.each_value { |s| future { s.release! } }
180
184
  @sessions_available = []
181
- @sessions_in_use = []
185
+ @sessions_in_use = {}
182
186
  end
183
187
  # shutdown existing thread pool
184
188
  @thread_pool.shutdown
@@ -640,20 +640,12 @@ module Google
640
640
 
641
641
  request_options = build_request_options request_options
642
642
  safe_execute do |seqno|
643
- batch_update_results = nil
644
- begin
645
- response = session.batch_update tx_selector, seqno,
646
- request_options: request_options,
647
- call_options: call_options, &block
648
- batch_update_results = BatchUpdateResults.new response
649
- row_counts = batch_update_results.row_counts
650
- @grpc ||= batch_update_results.transaction
651
- return row_counts
652
- rescue Google::Cloud::Spanner::BatchUpdateError
653
- @grpc ||= batch_update_results.transaction
654
- # Re-raise after extracting transaction
655
- raise
656
- end
643
+ response = session.batch_update tx_selector, seqno,
644
+ request_options: request_options,
645
+ call_options: call_options, &block
646
+ batch_update_results = BatchUpdateResults.new response
647
+ @grpc ||= batch_update_results.transaction
648
+ batch_update_results.row_counts
657
649
  end
658
650
  end
659
651
 
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.18.0".freeze
19
+ VERSION = "2.18.1".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.18.0
4
+ version: 2.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-06 00:00:00.000000000 Z
12
+ date: 2023-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core