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 +4 -4
- data/.rubocop.yml +1 -0
- data/.yardoc/checksums +4 -4
- data/.yardoc/objects/root.dat +0 -0
- data/.yardopts +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -3
- data/changelog.md +18 -0
- data/koyo-postgres-replication.gemspec +7 -6
- data/lib/koyo/repl/configuration.rb +6 -6
- data/lib/koyo/repl/database.rb +9 -0
- data/lib/koyo/repl/diagnostics.rb +1 -1
- data/lib/koyo/repl/postgres_server.rb +52 -20
- data/lib/koyo/repl/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cc8e3d452d94177ba7d15d098bbb38b949c45a4e25c22562b358f2858b8d541
|
4
|
+
data.tar.gz: f844b6eb897ab00c079be8e09a45398532657938ab9e2ae762ddd07c67f685be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7e17ddc565bcc1badd81dd6520506578e9eaf09be4598ace88b1336b8c8d797ea01e48724bad5217faf2442bcd04b5cce23a48f5feb048adc00d055e7c912d7
|
7
|
+
data.tar.gz: df0fd55f7909c6c401fbef598e618cd4837b22634400931b9942c50b650cde64b275c61ecdb7b0f82ab5f620a0b82b3851d9c4e40c20e9ecf7303b9e3628282c
|
data/.rubocop.yml
CHANGED
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
|
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
|
11
|
-
lib/koyo/repl/configuration.rb
|
12
|
-
lib/koyo/repl/postgres_server.rb
|
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
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/.yardopts
ADDED
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
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
96
|
-
config_prefix
|
97
|
-
database_name
|
98
|
-
slot
|
99
|
-
sql_delay
|
100
|
-
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
|
|
data/lib/koyo/repl/database.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
67
|
-
|
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:
|
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
|
data/lib/koyo/repl/version.rb
CHANGED
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.
|
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-
|
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
|
-
|
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
|
151
|
+
source_code_uri: https://github.com/wiseleyb
|
149
152
|
post_install_message:
|
150
153
|
rdoc_options: []
|
151
154
|
require_paths:
|