resilient_reads 0.1.3 → 0.1.4
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 +4 -4
- data/.idea/resilient_reads.iml +0 -2
- data/README.md +2 -2
- data/lib/resilient_reads/lag_checker.rb +17 -19
- data/lib/resilient_reads/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56b29303c6173728af9204eaa7b2b4c2ed73a5b6d7e6e3100d8e23bbc2afc2ae
|
|
4
|
+
data.tar.gz: 813d2268fd80a7835c2c4744eca2f4a6f879645049305ec02df71443b8329d47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32e222767e097b4735a534a2cf4f1be7edc4e15214e3ccdcb1135c277170023d134228fea85efe0068882ed6a9549e961f9d8cc8270dc71ca371c7ae7a83dc5e
|
|
7
|
+
data.tar.gz: 7e4da86bf77656e5b948446314f2841ce1aa64f4ef01cb980ad5b59eb678cf8291b335d6372d63cdf2a9f90dcb90f446a8caf91b6e7c692e1a2c9f0dcf4fd5b3
|
data/.idea/resilient_reads.iml
CHANGED
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
</content>
|
|
12
12
|
<orderEntry type="jdk" jdkName="RVM: ruby-3.4.2" jdkType="RUBY_SDK" />
|
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.7.2, RVM: ruby-3.4.2) [gem]" level="application" />
|
|
15
14
|
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.4, RVM: ruby-3.4.2) [gem]" level="application" />
|
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v13.3.1, RVM: ruby-3.4.2) [gem]" level="application" />
|
|
17
15
|
</component>
|
|
18
16
|
</module>
|
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Drop-in replacement for [distribute_reads](https://github.com/ankane/distribute_
|
|
|
19
19
|
Add to your Gemfile:
|
|
20
20
|
|
|
21
21
|
```ruby
|
|
22
|
-
gem "resilient_reads"
|
|
22
|
+
gem "resilient_reads"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Remove any previous read-distribution gems:
|
|
@@ -214,4 +214,4 @@ config.lag_check_interval = 10 # Cache lag result for 10 seconds
|
|
|
214
214
|
|
|
215
215
|
## License
|
|
216
216
|
|
|
217
|
-
MIT
|
|
217
|
+
MIT
|
|
@@ -47,32 +47,30 @@ module ResilientReads
|
|
|
47
47
|
def self.lag_for_mysql(conn)
|
|
48
48
|
# Prefer SHOW REPLICA STATUS (MySQL 8.0.22+, MariaDB 10.5.1+)
|
|
49
49
|
# and fall back to the deprecated SHOW SLAVE STATUS.
|
|
50
|
-
|
|
50
|
+
ResilientReads.log(:debug, "MySQL Replica Lag Start")
|
|
51
|
+
lag =
|
|
51
52
|
begin
|
|
52
|
-
conn.execute("SHOW REPLICA STATUS")
|
|
53
|
+
result = conn.execute("SHOW REPLICA STATUS")
|
|
54
|
+
if result.present? && result.rows.present?
|
|
55
|
+
result.rows.first[result.fields.index("Seconds_Behind_Source")]
|
|
56
|
+
else
|
|
57
|
+
nil
|
|
58
|
+
end
|
|
53
59
|
rescue ActiveRecord::StatementInvalid
|
|
54
|
-
conn.execute("SHOW SLAVE STATUS")
|
|
60
|
+
result = conn.execute("SHOW SLAVE STATUS")
|
|
61
|
+
if result.present? && result.rows.present?
|
|
62
|
+
result.rows.first[result.fields.index("Seconds_Behind_Master")]
|
|
63
|
+
else
|
|
64
|
+
nil
|
|
65
|
+
end
|
|
55
66
|
end
|
|
56
|
-
|
|
57
|
-
row = if result.respond_to?(:first)
|
|
58
|
-
result.first
|
|
59
|
-
elsif result.respond_to?(:to_a)
|
|
60
|
-
result.to_a.first
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
return nil unless row
|
|
64
|
-
|
|
65
|
-
# Seconds_Behind_Source (MySQL 8.0.22+) / Seconds_Behind_Master (legacy)
|
|
66
|
-
lag = if row.is_a?(Hash)
|
|
67
|
-
row["Seconds_Behind_Source"] || row["Seconds_Behind_Master"]
|
|
68
|
-
elsif row.respond_to?(:[])
|
|
69
|
-
row["Seconds_Behind_Source"] || row["Seconds_Behind_Master"]
|
|
70
|
-
end
|
|
67
|
+
ResilientReads.log(:debug, "MySQL Replica Lag: #{lag}")
|
|
71
68
|
|
|
72
69
|
lag&.to_f
|
|
73
70
|
rescue => e
|
|
74
71
|
ResilientReads.log(:debug, "MySQL lag check failed: #{e.message}")
|
|
75
72
|
nil
|
|
76
73
|
end
|
|
74
|
+
|
|
77
75
|
end
|
|
78
|
-
end
|
|
76
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resilient_reads
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jamie Puckett
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Distribute database reads across multiple replicas in Rails with automatic
|
|
13
13
|
load balancing, health checking, and graceful failover to primary.
|
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
60
|
version: '0'
|
|
61
61
|
requirements: []
|
|
62
|
-
rubygems_version: 3.6.
|
|
62
|
+
rubygems_version: 3.6.9
|
|
63
63
|
specification_version: 4
|
|
64
64
|
summary: Distribute database reads across multiple replicas in Rails with automatic
|
|
65
65
|
load balancing, health checking, and graceful failover to primary.
|