koyo-postgres-replication 0.1.1.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: 52f66b5b4c592753e8cb81e6291a035289cce3f58bc610e4d78de5a1c0bb6fa9
4
- data.tar.gz: bbb086947453e1937f052ed86e6dd68efd4797b5a2d2ecaaccb77de92185832a
3
+ metadata.gz: 1cc8e3d452d94177ba7d15d098bbb38b949c45a4e25c22562b358f2858b8d541
4
+ data.tar.gz: f844b6eb897ab00c079be8e09a45398532657938ab9e2ae762ddd07c67f685be
5
5
  SHA512:
6
- metadata.gz: cd86fc705158b786bb847522d25bcccd881c55758a5f0857d8696fa6cee60972c1ca8ff0bf2bced4ad6444c5891a32acc19ed586d738eaea0b8c3cd34dac2218
7
- data.tar.gz: 7c48ed00f79b044873fafbef2e9ced4828caa50d0804d2720d220c49052fe3db67a22230312db1de91cc4ddaad2d21f5cdda04dfaf6efcf13bcbca176184c737
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.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- koyo-postgres-replication (0.1.1.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
@@ -36,9 +36,7 @@ wiki](https://github.com/wiseleyb/koyo-postgres-replication/wiki/Configuring-Pos
36
36
  Add to Gemfile:
37
37
 
38
38
  ```
39
- gem 'koyo-postgres-replication',
40
- git: 'https://github.com/wiseleyb/koyo-postgres-replication',
41
- require: 'koyo'
39
+ gem 'koyo-postgres-replication', require: 'koyo'
42
40
  ```
43
41
 
44
42
  Then:
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
@@ -12,7 +30,3 @@
12
30
  - utility class for working with replication slots
13
31
  - functional - but not tested in real life yet
14
32
 
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) - remove recursive run, replace with simple loop
@@ -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'] = burl
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|
@@ -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
@@ -51,24 +51,57 @@ module Koyo
51
51
  tick_tock
52
52
  # Possibly fatal errors
53
53
  rescue ActiveRecord::StatementInvalid => e
54
- if e.cause.exception.is_a?(PG::ConnectionBad)
55
- Koyo::Repl::EventHandlerService.koyo_error(e)
56
- msg = "SHUTTING DOWN. Fatal Error in ReplPostgresServer: #{e.message}"
57
- log_repl_fatal(msg, err: e)
58
- break
59
- else
60
- log_recoverable_error(e)
61
- end
62
- # recoverable error
54
+ Koyo::Repl::EventHandlerService.koyo_error(e)
55
+ @retry = 0
56
+ break unless attempt_reconnect(e)
63
57
  rescue StandardError => e
64
58
  log_recoverable_error(e)
65
59
  end
66
60
 
67
- success = system("sleep #{Koyo::Repl.config.sql_delay}")
68
- break unless success
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Koyo
4
4
  module Repl
5
- VERSION = '0.1.1.pre'
5
+ VERSION = '0.1.3.pre'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koyo-postgres-replication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre
4
+ version: 0.1.3.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wiseley
@@ -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,7 +144,9 @@ 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
151
  source_code_uri: https://github.com/wiseleyb
149
152
  post_install_message: