koyo-postgres-replication 0.1.0.pre → 0.1.3.pre

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: 78e654e0e390dedac52210540c5dafdb1c189b1bbb01968c8bd09b5bf5ee250f
4
- data.tar.gz: 9dfdec20a290ae9d30ac91f7cfb404530053f883c9f12a57f678dd3665f4be8a
3
+ metadata.gz: 1cc8e3d452d94177ba7d15d098bbb38b949c45a4e25c22562b358f2858b8d541
4
+ data.tar.gz: f844b6eb897ab00c079be8e09a45398532657938ab9e2ae762ddd07c67f685be
5
5
  SHA512:
6
- metadata.gz: 97987ad66fbed7a4c14124de1776e771c3e54fb1c70b8f7fca6f588fc054dd858af38b753d2578e65aaefc25e9c048d86af49d6d3f6822ccbdadc7a76d42fbb9
7
- data.tar.gz: d3fd6f95478bbf33830f7f8c85fcc3b99d9599987fea81cdd639f997d625bfd8fdfc99e9b4881da9ee6f703665d2019f9824ffc5ce38474828918c457abf82c6
6
+ metadata.gz: b7e17ddc565bcc1badd81dd6520506578e9eaf09be4598ace88b1336b8c8d797ea01e48724bad5217faf2442bcd04b5cce23a48f5feb048adc00d055e7c912d7
7
+ data.tar.gz: df0fd55f7909c6c401fbef598e618cd4837b22634400931b9942c50b650cde64b275c61ecdb7b0f82ab5f620a0b82b3851d9c4e40c20e9ecf7303b9e3628282c
data/.rubocop.yml CHANGED
@@ -17,6 +17,7 @@ Layout/LineLength:
17
17
  Max: 90
18
18
 
19
19
  AllCops:
20
+ TargetRubyVersion: 3.2.2
20
21
  DisplayCopNames: true
21
22
  Exclude:
22
23
  - 'spec/dummy/config/**/*'
data/.yardoc/checksums CHANGED
@@ -4,11 +4,11 @@ lib/koyo/repl/mod.rb 92b54b56643b06fdc74adc65dc04460f631d4036
4
4
  lib/koyo/repl/data.rb cb847585c0f439b9f645b5ebd7fa3b96e08b94ff
5
5
  lib/koyo/repl/install.rb 9b19b7bb74d084882a1f726693bac2d693015daa
6
6
  lib/koyo/repl/railtie.rb acb36cbbe1b386ece7567990945adecb6b6e5b80
7
- lib/koyo/repl/version.rb 94239a7a9719294e13a38b878da1d328b44fb3f5
7
+ lib/koyo/repl/version.rb 45af9c57eb86c840d6c0756f1cd0b8a2f4b00ac0
8
8
  lib/koyo/repl/data_row.rb 321caf0b080621f2d319fa152948cbe864c77294
9
9
  lib/koyo/repl/database.rb 39a304909ccf68d69d36c84e3036debd9f29f6ec
10
- lib/koyo/repl/diagnostics.rb 03b91c5ea3dbe1e337f4427d8f3261ebedb45a70
11
- lib/koyo/repl/configuration.rb 17858828602d696a584a9e3c239c0a5d94faa738
12
- lib/koyo/repl/postgres_server.rb 2569fa642e55f6032e6ea73e9ab8762018d3cd6c
10
+ lib/koyo/repl/diagnostics.rb 93226c47642c5e20f615425aff8a0c0ba988b07b
11
+ lib/koyo/repl/configuration.rb 8a32f819abf035340a3997d989ccafe0751d209e
12
+ lib/koyo/repl/postgres_server.rb c8f557e1eec5b9be51ebd48002a3986eddbd6634
13
13
  lib/koyo_postgres_replication.rb e3f4d905e3045b59f1f7c799d84cd9fde70eebd8
14
14
  lib/koyo/repl/event_handler_service.rb 99b67bdcf3e0e92a04cd01bf8d05a4569b45d218
Binary file
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --protected
2
+ --no-private
3
+ --embed-mixin ClassMethods
4
+ -
5
+ README.md
6
+ CHANGELOG.md
7
+ MIT-LICENSE
data/Gemfile CHANGED
@@ -6,9 +6,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
6
  # Specify your gem's dependencies in koyo_repl.gemspec
7
7
  gemspec
8
8
 
9
+ gem 'pg', '~> 1.1'
9
10
  gem 'rails', '~> 7.0'
10
11
  gem 'rake', '~> 13.0'
11
- gem 'pg', '~> 1.1'
12
12
 
13
13
  group :development, :test do
14
14
  gem 'debug', platforms: %i[mri mingw x64_mingw]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- koyo-postgres-replication (0.1.0.pre)
4
+ koyo-postgres-replication (0.1.2.pre)
5
5
  pg (~> 1.1)
6
6
  rack (~> 2.0, >= 2.0.0)
7
7
  rails (~> 7.0)
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Koyo::Postgres::Replication
2
2
 
3
+ 例 rei - Japanese for example
4
+ 効用 koyo - Japanese for utility
5
+
3
6
  ## Replcation slots
4
7
 
5
8
  This gem tries to simplify dealing with a `replication slot` in Postgres.
@@ -33,9 +36,7 @@ wiki](https://github.com/wiseleyb/koyo-postgres-replication/wiki/Configuring-Pos
33
36
  Add to Gemfile:
34
37
 
35
38
  ```
36
- gem 'koyo-postgres-replication',
37
- git: 'https://github.com/wiseleyb/koyo-postgres-replication',
38
- require: 'koyo'
39
+ gem 'koyo-postgres-replication', require: 'koyo'
39
40
  ```
40
41
 
41
42
  Then:
@@ -185,6 +186,16 @@ TODO: update
185
186
  * run rubocop
186
187
  * add/run yard
187
188
 
189
+ # Working with gem
190
+
191
+ ## Gem Build
192
+
193
+ ```
194
+ rm koyo-postgres-replication-{current version}.gem
195
+ git add .
196
+ gem build
197
+ ```
198
+
188
199
  # TODO
189
200
 
190
201
  * add monitoring helpers
data/changelog.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Koyo Postgres Replication Changelog
2
2
 
3
+ ## 0.1.3.pre
4
+
5
+ - republishing yanked gem
6
+
7
+ ## 0.1.2.pre
8
+
9
+ - bump TargetRubyVersion for Rubocop to 3.2.2
10
+ - fix [Issue
11
+ 2](https://github.com/wiseleyb/koyo-postgres-replication/issues/2) - gemspec
12
+ config around Yard doc
13
+ - Enter retry loop instead of crashing when db connection goes away
14
+
15
+ ## 0.1.1.pre
16
+
17
+ - remove deprecated has_rdoc from gem spec
18
+ - fix [Issue 1](https://github.com/wiseleyb/koyo-postgres-replication/issues/1)
19
+ - remove recursive run, replace with simple loop
20
+
3
21
  ## 0.1.0.pre
4
22
 
5
23
  - rails 7 plugin
@@ -17,10 +17,13 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.required_ruby_version = '>= 2.7.0'
19
19
 
20
- # spec.metadata["allowed_push_host"] = ''
21
- spec.metadata['changelog_uri'] = "#{url}/changelog.md"
22
- spec.metadata['homepage_uri'] = spec.homepage
23
- spec.metadata['source_code_uri'] = url
20
+ spec.metadata = {
21
+ 'bug_tracker_uri' => "#{url}/issues",
22
+ 'changelog_uri' => "#{url}/blob/main/changelog.md",
23
+ 'documentation' => 'https://www.rubydoc.info/github/wiseleyb/koyo-postgres-replication/main',
24
+ 'homepage_uri' => spec.homepage,
25
+ 'source_code_uri' => burl
26
+ }
24
27
 
25
28
  spec.files = Dir.chdir(__dir__) do
26
29
  `git ls-files -z`.split("\x0").reject do |f|
@@ -38,6 +41,4 @@ Gem::Specification.new do |spec|
38
41
  spec.add_dependency 'rake', '~> 13.0'
39
42
  spec.add_development_dependency 'rspec-rails', '~> 3.1'
40
43
  spec.add_development_dependency 'yard', '~> 0.9'
41
-
42
- spec.has_rdoc = 'yard'
43
44
  end
@@ -92,12 +92,12 @@ module Koyo
92
92
  # Helper method that converts config settings into a hash
93
93
  def to_h
94
94
  {
95
- auto_create_replication_slot: auto_create_replication_slot,
96
- config_prefix: config_prefix,
97
- database_name: database_name,
98
- slot: slot,
99
- sql_delay: sql_delay,
100
- test_mode: test_mode
95
+ auto_create_replication_slot:,
96
+ config_prefix:,
97
+ database_name:,
98
+ slot:,
99
+ sql_delay:,
100
+ test_mode:
101
101
  }
102
102
  end
103
103
 
@@ -19,6 +19,7 @@ module Koyo
19
19
  conn_name = Koyo::Repl.config.database_name
20
20
 
21
21
  unless conn_name
22
+ ActiveRecord::Base.establish_connection
22
23
  @conn = ActiveRecord::Base.connection
23
24
  return @conn
24
25
  end
@@ -35,6 +36,14 @@ module Koyo
35
36
  @conn
36
37
  end
37
38
 
39
+ # Attempts to re-establish db connection
40
+ # This would be used when something happens like the postgres
41
+ # server restarts
42
+ def re_establish_conn
43
+ @conn = nil
44
+ conn
45
+ end
46
+
38
47
  # Reads from the replication slot.
39
48
  # Reading from this marks the rows read (so you won't see them again)
40
49
  # For testing you can use `peek_slot` if you want to - which will keep
@@ -72,7 +72,7 @@ module Koyo
72
72
 
73
73
  # Returns configured database name
74
74
  def adapter_name
75
- Koyo::Repl::Datasbase.conn.adapter_name
75
+ Koyo::Repl::Database.conn.adapter_name
76
76
  rescue StandardError => e
77
77
  "Error: #{e.message}"
78
78
  end
@@ -45,38 +45,70 @@ module Koyo
45
45
  # Runs the server. You should only be running ONE of these
46
46
  # servers at a time.
47
47
  def run!
48
- # This allows us to catch ctrl-c and exit
49
- trap('SIGINT') { throw :done }
50
-
51
- catch(:done) do
52
- check
53
- sleep Koyo::Repl.config.sql_delay
54
- tick_tock
55
- run!
56
- # Possibly fatal errors
57
- rescue ActiveRecord::StatementInvalid => e
58
- if e.cause.exception.is_a?(PG::ConnectionBad)
48
+ loop do
49
+ begin
50
+ check
51
+ tick_tock
52
+ # Possibly fatal errors
53
+ rescue ActiveRecord::StatementInvalid => e
59
54
  Koyo::Repl::EventHandlerService.koyo_error(e)
60
- msg = "SHUTTING DOWN. Fatal Error in ReplPostgresServer: #{e.message}"
61
- log_repl_fatal(msg, err: e)
62
- else
55
+ @retry = 0
56
+ break unless attempt_reconnect(e)
57
+ rescue StandardError => e
63
58
  log_recoverable_error(e)
64
- run!
65
59
  end
66
- rescue StandardError => e
67
- log_recoverable_error(e)
68
- run!
60
+
61
+ break unless sleep_success?
69
62
  end
70
63
  end
71
64
 
65
+ # Attempts to re-establish DB connection. If it finds any other
66
+ # error this is fatal and server crashes at this point
67
+ # @param [StandardError] err Error that kicked off this retry loop
68
+ def attempt_reconnect(err)
69
+ @retry ||= 0
70
+ msg = "Error: Attempting to reconnect to DB. Retry: #{@retry}."
71
+ log_recoverable_error(err)
72
+
73
+ return false unless sleep_success?
74
+
75
+ Koyo::Repl::Database.re_establish_conn
76
+ msg = 'Re-established DB connection'
77
+ log_repl_info(msg)
78
+ true
79
+ rescue StandardError => e
80
+ unless bad_connection_error?(e)
81
+ msg = 'Fatal: Found erorr unrelated to PG::ConnectionBad while '\
82
+ "trying to reconnect: Error: #{e.message}"
83
+ log_repl_fatal(msg, err: e)
84
+ return false
85
+ end
86
+
87
+ @retry += 1
88
+ retry
89
+ end
90
+
91
+ # Test error to see if it's db:connection related
92
+ # Mostly here for specs
93
+ # @param [StandardError] err Error to check
94
+ def bad_connection_error?(err)
95
+ err.cause.exception.is_a?(PG::ConnectionBad)
96
+ end
97
+
98
+ # Did sleep succeed... this fails when you do something like hit
99
+ # ctrl-c on the server
100
+ # Mostly here for specs
101
+ def sleep_success?
102
+ system("sleep #{Koyo::Repl.config.sql_delay}")
103
+ end
104
+
72
105
  # Handles erros that aren't fatal. Calls back to
73
106
  # Koyo::Repl::Log@log_repl_error which calls back
74
107
  # to KoyoReplHandlerServer@log_repl_error
75
108
  def log_recoverable_error(err)
76
109
  Koyo::Repl::EventHandlerService.koyo_error(err)
77
110
  msg = "Error in ReplPostgresServer: #{err.message}"
78
- log_repl_error(msg, err: err)
79
- sleep Koyo::Repl.config.sql_delay
111
+ log_repl_error(msg, err:)
80
112
  end
81
113
 
82
114
  # Basic heart beat ping to allow you to see the server is still
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Koyo
4
4
  module Repl
5
- VERSION = '0.1.0.pre'
5
+ VERSION = '0.1.3.pre'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koyo-postgres-replication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
4
+ version: 0.1.3.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wiseley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-17 00:00:00.000000000 Z
11
+ date: 2023-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -115,6 +115,7 @@ files:
115
115
  - ".yardoc/object_types"
116
116
  - ".yardoc/objects/root.dat"
117
117
  - ".yardoc/proxy_types"
118
+ - ".yardopts"
118
119
  - Gemfile
119
120
  - Gemfile.lock
120
121
  - MIT-LICENSE
@@ -143,9 +144,11 @@ homepage: https://github.com/wiseleyb
143
144
  licenses:
144
145
  - MIT
145
146
  metadata:
146
- changelog_uri: https://github.com/wiseleyb/koyo-postgres-replication/changelog.md
147
+ bug_tracker_uri: https://github.com/wiseleyb/koyo-postgres-replication/issues
148
+ changelog_uri: https://github.com/wiseleyb/koyo-postgres-replication/blob/main/changelog.md
149
+ documentation: https://www.rubydoc.info/github/wiseleyb/koyo-postgres-replication/main
147
150
  homepage_uri: https://github.com/wiseleyb
148
- source_code_uri: https://github.com/wiseleyb/koyo-postgres-replication
151
+ source_code_uri: https://github.com/wiseleyb
149
152
  post_install_message:
150
153
  rdoc_options: []
151
154
  require_paths: