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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 184f9367a55260f7b22c13d31ee8bb3ee39d5ece
4
- data.tar.gz: 2d5023b1cf3dff63cc77b08ead3b0dfc25277c33
3
+ metadata.gz: 77c8e355ea71e9f4eccfee4cd410733251ebc73f
4
+ data.tar.gz: a593201985a1b9f9c85921102a8d40b8498da2d6
5
5
  SHA512:
6
- metadata.gz: c8a3edbdf975c3a2e6a99a19766dfb3cb1bd008207f8eb5f31eb71998de5ac01170a1fd941dab0b2e1499bb737396120f4db8f248ccb17c1c437550d5d80a167
7
- data.tar.gz: 3d378d43a33d6babab0d587c334b8e003b1ceb59041168a927a3e9b4daf77082ad81a65a2ebea0de7483571e615ee88234ed556a40a8fecd7d85857510e36f71
6
+ metadata.gz: 32af56509abc4a23fdb48e83b3fa5401160e52a7a8e60f2c8b52faccde878cdfbaaf4395be121bc58baee5a74b2db06aa06175fe25261ca05ed29b261903d499
7
+ data.tar.gz: fe29a8ca07a06a7985d592af5131a43e748e848703c253d957b0eef2508c31839ff0d2af01d964e74d688d01040590caf2cb6ef8d603614fa6664b650c37096f
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sequel-replica-failover.gemspec
4
4
  gemspec
5
+
6
+ # for testing purposes until pull request is accepted
7
+ gem 'ruby-usdt', github: 'sax/ruby-usdt', ref: 'probe-introspection', submodules: true
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
@@ -1,5 +1,6 @@
1
1
  require 'sequel-replica-failover/version'
2
2
  require 'sequel/connection_pool/sharded_single_failover'
3
+ require 'sequel-replica-failover/dtrace_provider'
3
4
 
4
5
  module Sequel
5
6
  module ReplicaFailover
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module ReplicaFailover
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  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.3
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-04 00:00:00.000000000 Z
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