redis_failover 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changes.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.1
2
+ -----------
3
+ - More logging around exceptions
4
+ - Handle re-watching on client session expirations / disconnections
5
+ - Use an ephemeral node for the list of redis servers
6
+
1
7
  0.5.0
2
8
  -----------
3
9
  - redis_failover is now built on top of ZooKeeper! This means redis_failover enjoys all of the reliability, redundancy, and data consistency offered by ZooKeeper. The old fragile HTTP-based approach has been removed and will no longer be supported in favor of ZooKeeper. This does mean that in order to use redis_failover, you must have ZooKeeper installed and running. Please see the README for steps on how to do this if you don't already have ZooKeeper running in your production environment.
@@ -110,20 +110,27 @@ module RedisFailover
110
110
  def setup_zookeeper_client
111
111
  @zkclient = ZkClient.new(@zkservers)
112
112
 
113
- # when session expires / we are disconnected, purge client list
113
+ # when session expires, purge client list
114
114
  @zkclient.on_session_expiration do
115
115
  @lock.synchronize { purge_clients }
116
116
  end
117
+
118
+ # when we are disconnected, purge client list
117
119
  @zkclient.event_handler.register_state_handler(:connecting) do
118
120
  @lock.synchronize { purge_clients }
119
121
  end
120
122
 
123
+ # when session is recovered, watch again
124
+ @zkclient.on_session_recovered do
125
+ @zkclient.stat(@znode, :watch => true)
126
+ end
127
+
121
128
  # register a watcher for future changes
122
129
  @zkclient.watcher.register(@znode) do |event|
123
130
  if event.node_created? || event.node_changed?
124
131
  build_clients
125
132
  elsif event.node_deleted?
126
- @zkclient.stat( @znode, :watch => true)
133
+ @zkclient.stat(@znode, :watch => true)
127
134
  @lock.synchronize { purge_clients }
128
135
  else
129
136
  logger.error("Unknown ZK node event: #{event.inspect}")
@@ -149,6 +156,8 @@ module RedisFailover
149
156
  end
150
157
  rescue *ALL_ERRORS => ex
151
158
  logger.error("Error while handling operation `#{method}` - #{ex.message}")
159
+ logger.error(ex.backtrace.join("\n"))
160
+
152
161
  if tries < @max_retries
153
162
  tries += 1
154
163
  build_clients
@@ -187,18 +187,17 @@ module RedisFailover
187
187
  end
188
188
 
189
189
  def delete_path
190
- if @zkclient.stat(@znode).exists?
191
- @zkclient.delete(@znode)
192
- logger.info("Deleted zookeeper node #{@znode}")
193
- end
190
+ @zkclient.delete(@znode)
191
+ logger.info("Deleted zookeeper node #{@znode}")
192
+ rescue ZK::Exceptions::NoNode => ex
193
+ logger.info("Tried to delete missing znode: #{ex.message}")
194
194
  end
195
195
 
196
196
  def create_path
197
- # create nodes path if it doesn't already exist in ZK
198
- unless @zkclient.stat(@znode).exists?
199
- @zkclient.create(@znode, encode(current_nodes))
200
- logger.info("Created zookeeper node #{@znode}")
201
- end
197
+ @zkclient.create(@znode, encode(current_nodes), :ephemeral => true)
198
+ logger.info("Created zookeeper node #{@znode}")
199
+ rescue ZK::Exceptions::NodeExists
200
+ # best effort
202
201
  end
203
202
 
204
203
  def initialize_path
@@ -1,3 +1,3 @@
1
1
  module RedisFailover
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -17,6 +17,11 @@ module RedisFailover
17
17
  @on_session_expiration = block
18
18
  end
19
19
 
20
+ def on_session_recovered(&block)
21
+ @client.on_connected { block.call }
22
+ @on_session_recovered = block
23
+ end
24
+
20
25
  def get(*args, &block)
21
26
  perform_with_reconnect { @client.get(*args, &block) }
22
27
  end
@@ -55,8 +60,9 @@ module RedisFailover
55
60
  logger.info("Zookeeper client session expired, rebuilding client.")
56
61
  if tries < MAX_RECONNECTS
57
62
  tries += 1
58
- build_client
59
63
  @on_session_expiration.call if @on_session_expiration
64
+ build_client
65
+ @on_session_recovered.call if @on_session_recovered
60
66
  sleep(2) && retry
61
67
  end
62
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70300698370600 !ruby/object:Gem::Requirement
16
+ requirement: &70319722640420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70300698370600
24
+ version_requirements: *70319722640420
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70300698370180 !ruby/object:Gem::Requirement
27
+ requirement: &70319722640000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70300698370180
35
+ version_requirements: *70319722640000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &70300698369740 !ruby/object:Gem::Requirement
38
+ requirement: &70319722639560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70300698369740
46
+ version_requirements: *70319722639560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: zk
49
- requirement: &70300698369320 !ruby/object:Gem::Requirement
49
+ requirement: &70319722639140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70300698369320
57
+ version_requirements: *70319722639140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70300698368900 !ruby/object:Gem::Requirement
60
+ requirement: &70319722638720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70300698368900
68
+ version_requirements: *70319722638720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70300698368480 !ruby/object:Gem::Requirement
71
+ requirement: &70319722638300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70300698368480
79
+ version_requirements: *70319722638300
80
80
  description: Redis Failover is a ZooKeeper-based automatic master/slave failover solution
81
81
  for Ruby
82
82
  email:
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: -1870245960706248512
132
+ hash: 2520193948527829563
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  none: false
135
135
  requirements:
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: -1870245960706248512
141
+ hash: 2520193948527829563
142
142
  requirements: []
143
143
  rubyforge_project:
144
144
  rubygems_version: 1.8.16