sequel-replica-failover 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/lib/sequel-replica-failover.rb +1 -0
- data/lib/sequel-replica-failover/dtrace_provider.rb +29 -0
- data/lib/sequel-replica-failover/version.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single_failover.rb +12 -0
- data/sequel-replica-failover.gemspec +2 -0
- data/spec/sequel-replica-failover/dtrace_provider_spec.rb +53 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77c8e355ea71e9f4eccfee4cd410733251ebc73f
|
4
|
+
data.tar.gz: a593201985a1b9f9c85921102a8d40b8498da2d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32af56509abc4a23fdb48e83b3fa5401160e52a7a8e60f2c8b52faccde878cdfbaaf4395be121bc58baee5a74b2db06aa06175fe25261ca05ed29b261903d499
|
7
|
+
data.tar.gz: fe29a8ca07a06a7985d592af5131a43e748e848703c253d957b0eef2508c31839ff0d2af01d964e74d688d01040590caf2cb6ef8d603614fa6664b650c37096f
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'usdt'
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module ReplicaFailover
|
5
|
+
class DTraceProvider
|
6
|
+
attr_reader :provider
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@provider = USDT::Provider.create(:ruby, :sequel_replica_failover)
|
10
|
+
end
|
11
|
+
|
12
|
+
def stick
|
13
|
+
@stick_probe ||= provider.probe(:connection, :stick)
|
14
|
+
end
|
15
|
+
|
16
|
+
def unstick
|
17
|
+
@unstick_probe ||= provider.probe(:connection, :unstick, :string)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.provider
|
21
|
+
@provider ||= new.tap do |p|
|
22
|
+
p.stick
|
23
|
+
p.unstick
|
24
|
+
p.provider.enable
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -42,6 +42,7 @@ class Sequel::ShardedSingleFailoverConnectionPool < Sequel::ShardedSingleConnect
|
|
42
42
|
private
|
43
43
|
|
44
44
|
def unstick(server)
|
45
|
+
probe(server.to_s) { |p| p.unstick }
|
45
46
|
disconnect_server(server)
|
46
47
|
@conns[server] = nil
|
47
48
|
@stuck_at = nil
|
@@ -49,8 +50,19 @@ class Sequel::ShardedSingleFailoverConnectionPool < Sequel::ShardedSingleConnect
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def stick
|
53
|
+
probe { |p| p.stick }
|
52
54
|
@stuck_at ||= Time.now
|
53
55
|
@stuck_times ||= 0
|
54
56
|
@stuck_times += 1
|
55
57
|
end
|
58
|
+
|
59
|
+
def probe(*args)
|
60
|
+
p = yield(Sequel::ReplicaFailover::DTraceProvider.provider)
|
61
|
+
return unless p.enabled?
|
62
|
+
if args.any?
|
63
|
+
p.fire(*args)
|
64
|
+
else
|
65
|
+
p.fire
|
66
|
+
end
|
67
|
+
end
|
56
68
|
end
|
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "sequel", ">= 4.3.0"
|
22
|
+
spec.add_dependency "ruby-usdt"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "rspec"
|
26
27
|
spec.add_development_dependency "timecop"
|
28
|
+
spec.add_development_dependency "guard-rspec"
|
27
29
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sequel::ReplicaFailover::DTraceProvider do
|
4
|
+
describe 'initialize' do
|
5
|
+
it 'creates a new provider' do
|
6
|
+
USDT::Provider.should_receive(:create).with(:ruby, :sequel_replica_failover)
|
7
|
+
Sequel::ReplicaFailover::DTraceProvider.new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'probes' do
|
12
|
+
let(:provider) { Sequel::ReplicaFailover::DTraceProvider.new }
|
13
|
+
|
14
|
+
describe '#stick' do
|
15
|
+
it 'is a probe' do
|
16
|
+
expect(provider.stick).to be_a USDT::Probe
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has :replica_failover for its function' do
|
20
|
+
expect(provider.stick.function).to eq(:connection)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has :stick for its name' do
|
24
|
+
expect(provider.stick.name).to eq(:stick)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#unstick' do
|
29
|
+
it 'is a probe' do
|
30
|
+
expect(provider.unstick).to be_a USDT::Probe
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has :replica_failover for its function' do
|
34
|
+
expect(provider.unstick.function).to eq(:connection)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has :unstick for its name' do
|
38
|
+
expect(provider.unstick.name).to eq(:unstick)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'takes a string argument' do
|
42
|
+
expect(provider.unstick.arguments).to eq([:string])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '::provider' do
|
48
|
+
it 'returns a DTraceProvider' do
|
49
|
+
provider = Sequel::ReplicaFailover::DTraceProvider.provider
|
50
|
+
expect(provider).to be_a(Sequel::ReplicaFailover::DTraceProvider)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-replica-failover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Henry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-usdt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Automatically failover between replicas when they go down.
|
84
112
|
email:
|
85
113
|
- paul@wanelo.com
|
@@ -90,13 +118,16 @@ files:
|
|
90
118
|
- .gitignore
|
91
119
|
- .rspec
|
92
120
|
- Gemfile
|
121
|
+
- Guardfile
|
93
122
|
- LICENSE.txt
|
94
123
|
- README.md
|
95
124
|
- Rakefile
|
96
125
|
- lib/sequel-replica-failover.rb
|
126
|
+
- lib/sequel-replica-failover/dtrace_provider.rb
|
97
127
|
- lib/sequel-replica-failover/version.rb
|
98
128
|
- lib/sequel/connection_pool/sharded_single_failover.rb
|
99
129
|
- sequel-replica-failover.gemspec
|
130
|
+
- spec/sequel-replica-failover/dtrace_provider_spec.rb
|
100
131
|
- spec/sequel/connection_pool/sharded_single_failover_spec.rb
|
101
132
|
- spec/spec_helper.rb
|
102
133
|
homepage: ''
|
@@ -124,5 +155,6 @@ signing_key:
|
|
124
155
|
specification_version: 4
|
125
156
|
summary: Automatically failover when replicas go down.
|
126
157
|
test_files:
|
158
|
+
- spec/sequel-replica-failover/dtrace_provider_spec.rb
|
127
159
|
- spec/sequel/connection_pool/sharded_single_failover_spec.rb
|
128
160
|
- spec/spec_helper.rb
|