ar-octopus-replication-tracking 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/ar-octopus-replication-tracking.gemspec +27 -0
- data/lib/ar-octopus-replication-tracking.rb +2 -0
- data/lib/octopus/replication_tracking.rb +7 -0
- data/lib/octopus/replication_tracking/base_methods.rb +23 -0
- data/lib/octopus/replication_tracking/proxy_methods.rb +41 -0
- data/lib/octopus/replication_tracking/version.rb +5 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e302c007223d36c21c7d0c553ae2f59eed99322
|
4
|
+
data.tar.gz: dd1cfed6cca7de5eaadfbeed2345bf3702deb1c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bb86883c6bdb9f8b85fe5926e2a0f25743ff55766dd92a09569ef9a99955f46022c43846de23889d8c87995915cf26aadbe5ee46346f1ce435227d82bcd60f0
|
7
|
+
data.tar.gz: 943c551c98cecd209f2ed11da828acb9d7e896557b0fef525a14294fc7ed65fdebd3b84469420ce814870fa8b1c2b4003a06a042ae079cc28f43b27ee097fcc5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jong Ha
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Octopus Replication Tracking
|
2
|
+
This Gem is extension of ar-octopus to help to find replication file and position number for each shard.
|
3
|
+
|
4
|
+
## Notes
|
5
|
+
* Currently only working for mysql2 adapter
|
6
|
+
* DB user requires to have access `show master status;` and `show slave status;`
|
7
|
+
|
8
|
+
## Install
|
9
|
+
Add this line to Gemfile:
|
10
|
+
|
11
|
+
gem 'ar-octopus-replication-tracking', git: 'git://github.com/jongmyung/octopus-replication-tracking.git'
|
12
|
+
|
13
|
+
## How to Use
|
14
|
+
Setup `shards.yml` and ready to use.
|
15
|
+
|
16
|
+
```yaml
|
17
|
+
octopus:
|
18
|
+
environments:
|
19
|
+
- development
|
20
|
+
development:
|
21
|
+
earth:
|
22
|
+
captain_america:
|
23
|
+
adapter: mysql2
|
24
|
+
database: captain_america_db
|
25
|
+
hulk:
|
26
|
+
adapter: mysql2
|
27
|
+
database: hulk_db
|
28
|
+
ironman:
|
29
|
+
adapter: mysql2
|
30
|
+
database: ironman_db
|
31
|
+
galaxy:
|
32
|
+
i_am_groot:
|
33
|
+
adapter: mysql2
|
34
|
+
database: i_am_grout_db
|
35
|
+
```
|
36
|
+
|
37
|
+
### Syntax
|
38
|
+
Replication status from asia shard
|
39
|
+
|
40
|
+
> Octopus.replication_position(:captain_america)
|
41
|
+
=> {:file_name=>"mysql-bin.000001", :position=>36668586}
|
42
|
+
|
43
|
+
Replication status from europe shard
|
44
|
+
|
45
|
+
Octopus.replication_position(:ironman)
|
46
|
+
=> {:file_name=>"mysql-bin.000001", :position=>36668583}
|
47
|
+
|
48
|
+
Replication status from slave group
|
49
|
+
|
50
|
+
Octopus.replication_position(slave_group: :galaxy)
|
51
|
+
=> {:file_name=>"mysql-bin.000001", :position=>36668586}
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
|
+
|
3
|
+
require 'octopus/replication_tracking/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'ar-octopus-replication-tracking'
|
7
|
+
s.version = Octopus::ReplicationTracking::VERSION
|
8
|
+
s.authors = ['Jongmyung Ha']
|
9
|
+
s.email = ['jongmyung@stayntouch.com']
|
10
|
+
s.homepage = 'https://github.com/jongmyung/octopus-replication-tracking'
|
11
|
+
s.summary = 'Check master/slave replication position with Octopus'
|
12
|
+
s.description = 'This gem allows you to find replication position with Octopus'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
|
17
|
+
s.required_ruby_version = '>= 2.1.0'
|
18
|
+
|
19
|
+
s.add_dependency 'ar-octopus', '~> 0.8.6'
|
20
|
+
|
21
|
+
s.add_development_dependency 'pry-byebug', '~> 0'
|
22
|
+
s.add_development_dependency 'rake', '~> 0'
|
23
|
+
s.add_development_dependency 'rspec', '~> 3'
|
24
|
+
s.add_development_dependency 'rubocop', '~> 0'
|
25
|
+
|
26
|
+
s.license = 'MIT'
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Octopus
|
2
|
+
module ReplicationTracking
|
3
|
+
# Extension of Octopus
|
4
|
+
module BaseMethods
|
5
|
+
def self.extended(base)
|
6
|
+
base.extend(ModuleMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Define Module methods
|
10
|
+
module ModuleMethods
|
11
|
+
def replication_position(shard)
|
12
|
+
conn = ActiveRecord::Base.connection
|
13
|
+
|
14
|
+
return unless conn.is_a?(Octopus::Proxy)
|
15
|
+
|
16
|
+
using(shard) { conn.replication_position }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Octopus.extend(Octopus::ReplicationTracking::BaseMethods)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Octopus
|
2
|
+
module ReplicationTracking
|
3
|
+
# Extension of Octopus::Proxy
|
4
|
+
module ProxyMethods
|
5
|
+
def self.extended(base)
|
6
|
+
base.send(:include, InstanceMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Define Instance methods
|
10
|
+
module InstanceMethods
|
11
|
+
def master_shard?
|
12
|
+
current_shard == Octopus.master_shard
|
13
|
+
end
|
14
|
+
|
15
|
+
def replication_position
|
16
|
+
master_shard? ? master_replication_status : slave_replication_status
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def master_replication_status
|
22
|
+
status_result = execute('SHOW MASTER STATUS;').first
|
23
|
+
{
|
24
|
+
file_name: status_result.try(:[], 0),
|
25
|
+
position: status_result.try(:[], 1)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def slave_replication_status
|
30
|
+
status_result = execute('SHOW SLAVE STATUS;').first
|
31
|
+
{
|
32
|
+
file_name: status_result.try(:[], 5),
|
33
|
+
position: status_result.try(:[], 6)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Octopus::Proxy.extend(Octopus::ReplicationTracking::ProxyMethods)
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar-octopus-replication-tracking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jongmyung Ha
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ar-octopus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem allows you to find replication position with Octopus
|
84
|
+
email:
|
85
|
+
- jongmyung@stayntouch.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- ar-octopus-replication-tracking.gemspec
|
97
|
+
- lib/ar-octopus-replication-tracking.rb
|
98
|
+
- lib/octopus/replication_tracking.rb
|
99
|
+
- lib/octopus/replication_tracking/base_methods.rb
|
100
|
+
- lib/octopus/replication_tracking/proxy_methods.rb
|
101
|
+
- lib/octopus/replication_tracking/version.rb
|
102
|
+
homepage: https://github.com/jongmyung/octopus-replication-tracking
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 2.1.0
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.8
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Check master/slave replication position with Octopus
|
126
|
+
test_files: []
|