active_record_mysql_xverify 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +80 -3
- data/.travis.yml +13 -14
- data/Appraisals +4 -0
- data/Dockerfile +13 -0
- data/README.md +19 -9
- data/bin/console +1 -1
- data/docker-compose.yml +8 -4
- data/gemfiles/ar60.gemfile +7 -0
- data/lib/active_record_mysql_xverify/config.rb +1 -1
- data/lib/active_record_mysql_xverify/verifiers/aurora_master.rb +1 -1
- data/lib/active_record_mysql_xverify/version.rb +1 -1
- data/seq.wsd +38 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247cfa1e88c414475aedb0a0da825d5860bfa0bac37557ff7c635fb7dec70ea8
|
4
|
+
data.tar.gz: e5a2e3ecf2448e82d8cbd5cdaae403f37ce780b4e0ab4edea5f620a37ba27731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b140b35801f33cc584ba71283329a7ac79eeacd7b5db5ccc217b6a903b254d3a64f0a03138a3a437f44f7d23d9b0c8b6555274f2a0b710c6929ff0aaa92aa106
|
7
|
+
data.tar.gz: ae7d6b6d69c781ff0558d47d8f62e39d1f524585ee7bf31ae912b38f6eaeccabc81e13272ed5971986412590ab9b5259da5b12208bdfdad8ab0b95ad2be7b4b9
|
data/.rubocop.yml
CHANGED
@@ -1,16 +1,93 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
-
|
4
|
-
TargetRubyVersion: 2.
|
3
|
+
- "gemfiles/**/*"
|
4
|
+
TargetRubyVersion: 2.4
|
5
5
|
Metrics/BlockLength:
|
6
6
|
Enabled: false
|
7
7
|
Metrics/LineLength:
|
8
8
|
Enabled: false
|
9
9
|
Metrics/MethodLength:
|
10
10
|
Enabled: false
|
11
|
-
Naming/
|
11
|
+
Naming/MethodParameterName:
|
12
12
|
Enabled: false
|
13
13
|
Style/Documentation:
|
14
14
|
Enabled: false
|
15
15
|
Style/TrailingCommaInHashLiteral:
|
16
16
|
EnforcedStyleForMultiline: consistent_comma
|
17
|
+
Gemspec/RequiredRubyVersion:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
21
|
+
Enabled: true
|
22
|
+
Layout/SpaceAroundMethodCallOperator:
|
23
|
+
Enabled: true
|
24
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
25
|
+
Enabled: true
|
26
|
+
Lint/DeprecatedOpenSSLConstant:
|
27
|
+
Enabled: true
|
28
|
+
Lint/DuplicateElsifCondition:
|
29
|
+
Enabled: true
|
30
|
+
Lint/DuplicateRescueException:
|
31
|
+
Enabled: true
|
32
|
+
Lint/EmptyConditionalBody:
|
33
|
+
Enabled: true
|
34
|
+
Lint/FloatComparison:
|
35
|
+
Enabled: true
|
36
|
+
Lint/MissingSuper:
|
37
|
+
Enabled: true
|
38
|
+
Lint/MixedRegexpCaptureTypes:
|
39
|
+
Enabled: true
|
40
|
+
Lint/OutOfRangeRegexpRef:
|
41
|
+
Enabled: true
|
42
|
+
Lint/RaiseException:
|
43
|
+
Enabled: true
|
44
|
+
Lint/SelfAssignment:
|
45
|
+
Enabled: true
|
46
|
+
Lint/StructNewOverride:
|
47
|
+
Enabled: true
|
48
|
+
Lint/TopLevelReturnWithArgument:
|
49
|
+
Enabled: true
|
50
|
+
Lint/UnreachableLoop:
|
51
|
+
Enabled: true
|
52
|
+
Style/AccessorGrouping:
|
53
|
+
Enabled: true
|
54
|
+
Style/ArrayCoercion:
|
55
|
+
Enabled: true
|
56
|
+
Style/BisectedAttrAccessor:
|
57
|
+
Enabled: true
|
58
|
+
Style/CaseLikeIf:
|
59
|
+
Enabled: true
|
60
|
+
Style/ExplicitBlockArgument:
|
61
|
+
Enabled: true
|
62
|
+
Style/ExponentialNotation:
|
63
|
+
Enabled: true
|
64
|
+
Style/GlobalStdStream:
|
65
|
+
Enabled: true
|
66
|
+
Style/HashAsLastArrayItem:
|
67
|
+
Enabled: true
|
68
|
+
Style/HashEachMethods:
|
69
|
+
Enabled: true
|
70
|
+
Style/HashLikeCase:
|
71
|
+
Enabled: true
|
72
|
+
Style/HashTransformKeys:
|
73
|
+
Enabled: true
|
74
|
+
Style/HashTransformValues:
|
75
|
+
Enabled: true
|
76
|
+
Style/OptionalBooleanParameter:
|
77
|
+
Enabled: true
|
78
|
+
Style/RedundantAssignment:
|
79
|
+
Enabled: true
|
80
|
+
Style/RedundantFetchBlock:
|
81
|
+
Enabled: true
|
82
|
+
Style/RedundantFileExtensionInRequire:
|
83
|
+
Enabled: true
|
84
|
+
Style/RedundantRegexpCharacterClass:
|
85
|
+
Enabled: true
|
86
|
+
Style/RedundantRegexpEscape:
|
87
|
+
Enabled: true
|
88
|
+
Style/SingleArgumentDig:
|
89
|
+
Enabled: true
|
90
|
+
Style/SlicingWithRange:
|
91
|
+
Enabled: true
|
92
|
+
Style/StringConcatenation:
|
93
|
+
Enabled: true
|
data/.travis.yml
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
---
|
2
|
-
dist: xenial
|
3
|
-
sudo: required
|
4
2
|
language: ruby
|
5
3
|
cache: bundler
|
6
4
|
rvm:
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
|
5
|
+
- 2.5.8
|
6
|
+
- 2.6.6
|
7
|
+
- 2.7.1
|
8
|
+
env:
|
9
|
+
- DATABASE_HOST=localhost DATABASE_USER=travis
|
11
10
|
before_install:
|
12
|
-
-
|
13
|
-
- function mysql_ping { mysqladmin -u root -h 127.0.0.1 -P 6033 ping > /dev/null 2> /dev/null; }
|
14
|
-
- for i in {1..60}; do mysql_ping && break; sleep 1; done
|
11
|
+
- for i in {1..60}; do mysqladmin -u travis ping && break; sleep 1; done
|
15
12
|
script:
|
16
13
|
- bundle exec rake
|
17
14
|
gemfile:
|
@@ -19,8 +16,10 @@ gemfile:
|
|
19
16
|
- gemfiles/ar50.gemfile
|
20
17
|
- gemfiles/ar51.gemfile
|
21
18
|
- gemfiles/ar52.gemfile
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
- gemfiles/ar60.gemfile
|
20
|
+
services:
|
21
|
+
- mysql
|
22
|
+
jobs:
|
23
|
+
exclude:
|
24
|
+
- rvm: 2.7.1
|
25
|
+
gemfile: gemfiles/ar42.gemfile
|
data/Appraisals
CHANGED
data/Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
FROM rubylang/ruby:2.5-bionic
|
2
|
+
|
3
|
+
RUN apt-get update && \
|
4
|
+
apt-get install -y \
|
5
|
+
mysql-client \
|
6
|
+
libmysqlclient-dev \
|
7
|
+
rubygems
|
8
|
+
|
9
|
+
COPY ./ /mnt/
|
10
|
+
WORKDIR /mnt
|
11
|
+
RUN gem update bundler -f && \
|
12
|
+
bundle install && \
|
13
|
+
bundle exec appraisal install
|
data/README.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
# active_record_mysql_xverify
|
2
2
|
|
3
|
-
It is a library
|
3
|
+
It is a library to solve Amazon RDS failover problems.
|
4
|
+
|
5
|
+
cf. https://github.com/brianmario/mysql2/issues/948
|
6
|
+
|
7
|
+
**Note: This library does not retry queries. Just reconnect.**
|
4
8
|
|
5
9
|
[![Gem Version](https://badge.fury.io/rb/active_record_mysql_xverify.svg)](http://badge.fury.io/rb/active_record_mysql_xverify)
|
6
10
|
[![Build Status](https://travis-ci.org/winebarrel/active_record_mysql_xverify.svg?branch=master)](https://travis-ci.org/winebarrel/active_record_mysql_xverify)
|
7
11
|
|
12
|
+
## How it works
|
13
|
+
|
14
|
+
![](https://user-images.githubusercontent.com/117768/59007604-19a61c80-8862-11e9-9f4b-515527b33ded.png)
|
15
|
+
|
8
16
|
## Installation
|
9
17
|
|
10
18
|
Add this line to your application's Gemfile:
|
@@ -49,9 +57,6 @@ ActiveRecordMysqlXverify.handle_if = ->(config) do
|
|
49
57
|
end
|
50
58
|
# Default: ->(_) { true }
|
51
59
|
|
52
|
-
ActiveRecordMysqlXverify.only_on_error = false
|
53
|
-
# Default: true
|
54
|
-
|
55
60
|
# CREATE DATABASE IF NOT EXISTS bookshelf;
|
56
61
|
# CREATE TABLE bookshelf.books (id INT PRIMARY KEY);
|
57
62
|
class Book < ActiveRecord::Base; end
|
@@ -74,7 +79,7 @@ In `config/environments/production.rb`:
|
|
74
79
|
|
75
80
|
```ruby
|
76
81
|
ActiveRecordMysqlXverify.verify = ->(conn) do
|
77
|
-
conn.ping && conn.query('
|
82
|
+
conn.ping && conn.query('select @@innodb_read_only').first.fetch('@@innodb_read_only').zero?
|
78
83
|
end
|
79
84
|
# Same as below:
|
80
85
|
# ActiveRecordMysqlXverify.verify = ActiveRecordMysqlXverify::Verifiers::AURORA_MASTER
|
@@ -131,8 +136,13 @@ Completed 302 Found in 150ms (ActiveRecord: 145.2ms)
|
|
131
136
|
|
132
137
|
## Test
|
133
138
|
|
139
|
+
## Test
|
140
|
+
|
141
|
+
```sh
|
142
|
+
docker-compose build
|
143
|
+
docker-compose run client bundle exec appraisal ar60 rake
|
134
144
|
```
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
145
|
+
|
146
|
+
## Related links
|
147
|
+
|
148
|
+
* https://github.com/winebarrel/active_record_postgresql_xverify
|
data/bin/console
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'bundler/setup'
|
5
|
-
require '
|
5
|
+
require 'active_record_mysql_xverify'
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
data/docker-compose.yml
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
version:
|
1
|
+
version: "3.8"
|
2
2
|
services:
|
3
|
+
client:
|
4
|
+
build: .
|
5
|
+
volumes:
|
6
|
+
- ./:/mnt
|
7
|
+
depends_on:
|
8
|
+
- mysql
|
3
9
|
mysql:
|
4
10
|
image: mysql:5.7
|
5
|
-
ports:
|
6
|
-
- 6033:3306
|
7
11
|
environment:
|
8
|
-
MYSQL_ALLOW_EMPTY_PASSWORD:
|
12
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module ActiveRecordMysqlXverify
|
4
4
|
module Verifiers
|
5
5
|
AURORA_MASTER = lambda do |conn|
|
6
|
-
conn.ping && conn.query('
|
6
|
+
conn.ping && conn.query('select @@innodb_read_only').first.fetch('@@innodb_read_only').zero?
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/seq.wsd
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
@startuml{seq.png}
|
2
|
+
|
3
|
+
actor Client
|
4
|
+
participant Rails
|
5
|
+
participant "Connection pool" as cp
|
6
|
+
participant "<size:10>active_recode_mysql_xverify</size>" as armx
|
7
|
+
participant MySQL
|
8
|
+
|
9
|
+
Client -> Rails : Request
|
10
|
+
activate Rails
|
11
|
+
Rails -> MySQL : Query
|
12
|
+
activate MySQL
|
13
|
+
group neg
|
14
|
+
Rails <-- MySQL : <font color=red>"read-only" error happen!</font>
|
15
|
+
deactivate MySQL
|
16
|
+
Client <-- Rails : <font color=red>Error</font>
|
17
|
+
deactivate Rails
|
18
|
+
end
|
19
|
+
|
20
|
+
Client -> Rails : Request
|
21
|
+
activate Rails
|
22
|
+
Rails -> cp : checkout
|
23
|
+
activate cp
|
24
|
+
cp -> armx : active?
|
25
|
+
activate armx
|
26
|
+
armx -> MySQL : Fetch "innodb_read_only"
|
27
|
+
activate MySQL
|
28
|
+
armx <-- MySQL : "ON"
|
29
|
+
deactivate MySQL
|
30
|
+
cp <-- armx : false
|
31
|
+
deactivate armx
|
32
|
+
cp --> MySQL : reconnect!
|
33
|
+
activate MySQL
|
34
|
+
deactivate MySQL
|
35
|
+
Rails <-- cp : Connection
|
36
|
+
deactivate cp
|
37
|
+
|
38
|
+
@enduml
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_mysql_xverify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- ".rubocop.yml"
|
122
122
|
- ".travis.yml"
|
123
123
|
- Appraisals
|
124
|
+
- Dockerfile
|
124
125
|
- Gemfile
|
125
126
|
- LICENSE.txt
|
126
127
|
- README.md
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- gemfiles/ar50.gemfile
|
135
136
|
- gemfiles/ar51.gemfile
|
136
137
|
- gemfiles/ar52.gemfile
|
138
|
+
- gemfiles/ar60.gemfile
|
137
139
|
- lib/active_record_mysql_xverify.rb
|
138
140
|
- lib/active_record_mysql_xverify/config.rb
|
139
141
|
- lib/active_record_mysql_xverify/constants.rb
|
@@ -143,6 +145,7 @@ files:
|
|
143
145
|
- lib/active_record_mysql_xverify/verifier.rb
|
144
146
|
- lib/active_record_mysql_xverify/verifiers/aurora_master.rb
|
145
147
|
- lib/active_record_mysql_xverify/version.rb
|
148
|
+
- seq.wsd
|
146
149
|
homepage: https://github.com/winebarrel/active_record_mysql_xverify
|
147
150
|
licenses:
|
148
151
|
- MIT
|
@@ -162,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
165
|
- !ruby/object:Gem::Version
|
163
166
|
version: '0'
|
164
167
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.7.6.2
|
168
|
+
rubygems_version: 3.0.3
|
167
169
|
signing_key:
|
168
170
|
specification_version: 4
|
169
171
|
summary: It is a library that performs extended verification when an error occurs
|