pgtk 0.31.7 → 0.31.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9620e5581d667750f82a36568c6b64fcb27c2c588b93fc433869f1a430159128
4
- data.tar.gz: 281908df6408d31c7ae69ff9ea4a4122881b7ae54c7906e87d10abf885d625d4
3
+ metadata.gz: 10ac49e5f5fa5ac3792edf7e62961f8d37f8937a645a878de4e15b3ced01e575
4
+ data.tar.gz: 51b1c1927f57ea50b181cda95dc6f0471237c4873a7e99482b35f980fd8294dd
5
5
  SHA512:
6
- metadata.gz: f633a5925cbf6f8ad61247c898a7d58a59d8a64dcf7e23597f625ddfad816e856ae00b6b4960839abec9d763b931a4c519bce49c3bd2724fef38854e7c316c7e
7
- data.tar.gz: a70e63d0772e40632333d382d4c8598a6a1ab60d72b3ce7bc8675ed12aced75acdc6117fbfccfc6fd9094e927136f7b9f983ba99491b673a392fd7fdb645597a
6
+ metadata.gz: 9d1f4a4d1247426d01caea364c9082e6dc9b81eb7428fb2da3f11764d9542ad7c99b35b1f0a1ed25c033e203d9ef253b48b061ce29eee07ca2048f9f82aa8f50
7
+ data.tar.gz: f713deaf5f0b8c2ba45a0d6fd8d6c46fb88f8ba153b1f1096aa69c351655cd7ce1daefb7d6e0e730609eb96b713c90ad5b3a50ccb08914a10ee4011b4ba3ef2b
data/Gemfile.lock CHANGED
@@ -42,7 +42,7 @@ GEM
42
42
  loog (0.8.0)
43
43
  ellipsized
44
44
  logger (~> 1.0)
45
- minitest (6.0.5)
45
+ minitest (6.0.6)
46
46
  drb (~> 2.0)
47
47
  prism (~> 1.5)
48
48
  minitest-mock (5.27.0)
data/README.md CHANGED
@@ -284,7 +284,9 @@ retry_pool.exec('INSERT INTO logs (message) VALUES ($1)', ['User logged in'])
284
284
  Key features:
285
285
 
286
286
  1. Only `SELECT` queries are retried (to prevent duplicate data modifications)
287
- 2. Retries happen immediately without delay
287
+ 2. Retries happen immediately, except on `PG::ConnectionBad`,
288
+ where an exponential backoff (50ms, 200ms, 1s) is applied
289
+ between attempts to avoid amplifying upstream login storms
288
290
  3. The original error is raised after all retry attempts are exhausted
289
291
  4. Works seamlessly with other decorators like `Pgtk::Spy` and `Pgtk::Impatient`
290
292
 
@@ -7,7 +7,7 @@ require 'nokogiri'
7
7
  require 'rake/tasklib'
8
8
  require_relative '../pgtk'
9
9
 
10
- # Liquicheck rake task for check Liquibase XML files.
10
+ # Liquicheck rake task to check Liquibase XML files.
11
11
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
12
12
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
13
13
  # License:: MIT
@@ -63,7 +63,7 @@ class Pgtk::LiquicheckTask < Rake::TaskLib
63
63
  context = node.attr('context')&.to_s
64
64
  on(errors, file) do
65
65
  demand(id, 'ID is empty')
66
- confirm(id, /[-a-z]+/, "ID #{id.inspect} has not suffix in #{context} context") if context
66
+ confirm(id, /[-a-z]+/, "ID #{id.inspect} has no suffix in #{context} context") if context
67
67
  end
68
68
  on(errors, file) do
69
69
  demand(author, 'author is empty')
data/lib/pgtk/pool.rb CHANGED
@@ -114,7 +114,7 @@ class Pgtk::Pool
114
114
  # puts 'Title: ' + row['title']
115
115
  # end
116
116
  #
117
- # All values in the retrieved hash are strings. No matter what types of
117
+ # All values in the retrieved hash are strings. No matter what types
118
118
  # of data you have in the database, you get strings here. It's your job
119
119
  # to convert them to the type you need.
120
120
  #
@@ -322,6 +322,7 @@ class Pgtk::Pool
322
322
  conn = renew(conn, reason)
323
323
  rescue StandardError => e
324
324
  @log.warn("Failed to renew dead connection (#{reason}): #{e.message}")
325
+ raise(e)
325
326
  end
326
327
  end
327
328
  begin
data/lib/pgtk/retry.rb CHANGED
@@ -54,6 +54,8 @@ class Pgtk::Retry
54
54
  # so its message and stack trace are preserved for debugging.
55
55
  class Exhausted < StandardError; end
56
56
 
57
+ BACKOFFS = [0.05, 0.2, 1.0].freeze
58
+
57
59
  # Constructor.
58
60
  #
59
61
  # @param [Pgtk::Pool] pool The pool to decorate
@@ -86,13 +88,15 @@ class Pgtk::Retry
86
88
  end
87
89
 
88
90
  # Execute a SQL query with automatic retry on transient failures.
89
- # SELECT queries are retried on any error, since reads are idempotent.
90
- # Non-SELECT queries are retried only on PG::ConnectionBad, since by
91
- # definition the query never reached the server, so retrying cannot
92
- # duplicate a write. Other errors on writes propagate immediately,
93
- # because a failure may occur after the server received the query but
94
- # before the acknowledgement reached the client, and retrying a
95
- # non-idempotent write could duplicate it.
91
+ # Only SELECT queries are retried, since reads are idempotent.
92
+ # Non-SELECT queries propagate the original error immediately, even
93
+ # on PG::ConnectionBad, because that error can be raised after the
94
+ # server already received the query but before the acknowledgement
95
+ # reached the client, and retrying a non-idempotent write could
96
+ # duplicate it. When the underlying error is PG::ConnectionBad, an
97
+ # exponential backoff (see BACKOFFS) is applied between attempts, so
98
+ # that a SELECT failing against an upstream pool that is in its
99
+ # login-failure cache window does not amplify the storm.
96
100
  #
97
101
  # @param [String] sql The SQL query with params inside (possibly)
98
102
  # @return [Array] Result rows
@@ -101,14 +105,11 @@ class Pgtk::Retry
101
105
  attempt = 0
102
106
  begin
103
107
  @pool.exec(sql, *)
104
- rescue PG::ConnectionBad => e
105
- attempt += 1
106
- raise(Exhausted, "Retry gave up after #{@attempts} attempts: #{e.message}") if attempt >= @attempts
107
- retry
108
108
  rescue StandardError, Pgtk::Impatient::TooSlow => e
109
109
  raise(e) unless query.strip.upcase.start_with?('SELECT')
110
110
  attempt += 1
111
111
  raise(Exhausted, "Retry gave up after #{@attempts} attempts: #{e.message}") if attempt >= @attempts
112
+ sleep(BACKOFFS[attempt - 1] || BACKOFFS.last) if e.is_a?(PG::ConnectionBad)
112
113
  retry
113
114
  end
114
115
  end
data/lib/pgtk/version.rb CHANGED
@@ -10,5 +10,5 @@ require_relative '../pgtk'
10
10
  # Copyright:: Copyright (c) 2019-2026 Yegor Bugayenko
11
11
  # License:: MIT
12
12
  module Pgtk
13
- VERSION = '0.31.7' unless defined?(VERSION)
13
+ VERSION = '0.31.8' unless defined?(VERSION)
14
14
  end
data/resources/pom.xml CHANGED
@@ -10,7 +10,7 @@
10
10
  <version>0.0.0</version>
11
11
  <packaging>pom</packaging>
12
12
  <properties>
13
- <postgresql.version>42.7.10</postgresql.version>
13
+ <postgresql.version>42.7.11</postgresql.version>
14
14
  <liquibase.version>5.0.2</liquibase.version>
15
15
  </properties>
16
16
  <dependencies>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.7
4
+ version: 0.31.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko