redis_failover 0.9.0 → 0.9.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.9.1
2
+ -----------
3
+ - Improve nested exception handling.
4
+ - Fix manual failover support when znode does not exist first.
5
+ - Various fixes to work better with 1.8.7.
6
+
1
7
  0.9.0
2
8
  -----------
3
9
  - Make Node Manager's lock path vary with its main znode. (Bira)
data/README.md CHANGED
@@ -175,6 +175,7 @@ redis_failover uses YARD for its API documentation. Refer to the generated [API
175
175
  - To learn more about ZooKeeper, see the official [ZooKeeper](http://zookeeper.apache.org/) site.
176
176
  - See the [Quick ZooKeeper Guide](https://github.com/ryanlecompte/redis_failover/wiki/Quick-ZooKeeper-Guide) for a quick guide to getting ZooKeeper up and running with redis_failover.
177
177
  - To learn more about how ZooKeeper handles network partitions, see [ZooKeeper Failure Scenarios](http://wiki.apache.org/hadoop/ZooKeeper/FailureScenarios)
178
+ - Feel free to join #zk on the IRC freenode network. We're usually hanging out there talking about ZooKeeper and redis_failover.
178
179
 
179
180
 
180
181
  ## License
@@ -177,6 +177,8 @@ module RedisFailover
177
177
  else
178
178
  logger.error("Unknown ZK node event: #{event.inspect}")
179
179
  end
180
+ ensure
181
+ @zk.stat(@znode, :watch => true)
180
182
  end
181
183
 
182
184
  # Determines if a method is a known redis operation.
@@ -237,7 +239,7 @@ module RedisFailover
237
239
  # @raise [NoMasterError] if no master fallback is available
238
240
  def slave
239
241
  # pick a slave, if none available fallback to master
240
- if slave = @lock.synchronize { @slaves.sample }
242
+ if slave = @lock.synchronize { @slaves.shuffle.first }
241
243
  verify_role!(slave, :slave)
242
244
  return slave
243
245
  end
@@ -253,7 +255,7 @@ module RedisFailover
253
255
  return unless nodes_changed?(nodes)
254
256
 
255
257
  purge_clients
256
- logger.info("Building new clients for nodes #{nodes}")
258
+ logger.info("Building new clients for nodes #{nodes.inspect}")
257
259
  new_master = new_clients_for(nodes[:master]).first if nodes[:master]
258
260
  new_slaves = new_clients_for(*nodes[:slaves])
259
261
  @master = new_master
@@ -287,7 +289,7 @@ module RedisFailover
287
289
  def fetch_nodes
288
290
  data = @zk.get(@znode, :watch => true).first
289
291
  nodes = symbolize_keys(decode(data))
290
- logger.debug("Fetched nodes: #{nodes}")
292
+ logger.debug("Fetched nodes: #{nodes.inspect}")
291
293
 
292
294
  nodes
293
295
  rescue Zookeeper::Exceptions::InheritedConnectionError => ex
@@ -175,14 +175,14 @@ module RedisFailover
175
175
  redis = new_client
176
176
  yield redis
177
177
  end
178
- rescue
179
- raise NodeUnavailableError, self, caller
178
+ rescue => ex
179
+ raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
180
180
  ensure
181
181
  if redis
182
182
  begin
183
183
  redis.client.disconnect
184
- rescue
185
- raise NodeUnavailableError, self, caller
184
+ rescue => ex
185
+ raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
186
186
  end
187
187
  end
188
188
  end
@@ -87,8 +87,15 @@ module RedisFailover
87
87
 
88
88
  @zk.register(@manual_znode) do |event|
89
89
  @mutex.synchronize do
90
- if event.node_changed?
91
- schedule_manual_failover
90
+ begin
91
+ if event.node_created? || event.node_changed?
92
+ schedule_manual_failover
93
+ end
94
+ rescue => ex
95
+ logger.error("Error scheduling a manual failover: #{ex.inspect}")
96
+ logger.error(ex.backtrace.join("\n"))
97
+ ensure
98
+ @zk.stat(@manual_znode, :watch => true)
92
99
  end
93
100
  end
94
101
  end
@@ -340,15 +347,22 @@ module RedisFailover
340
347
  def schedule_manual_failover
341
348
  return unless @leader
342
349
  new_master = @zk.get(@manual_znode, :watch => true).first
350
+ return unless new_master && new_master.size > 0
343
351
  logger.info("Received manual failover request for: #{new_master}")
352
+ logger.info("Current nodes: #{current_nodes.inspect}")
344
353
 
345
354
  node = if new_master == ManualFailover::ANY_SLAVE
346
- @slaves.sample
355
+ @slaves.shuffle.first
347
356
  else
348
357
  host, port = new_master.split(':', 2)
349
358
  Node.new(:host => host, :port => port, :password => @options[:password])
350
359
  end
351
- notify_state(node, :manual_failover) if node
360
+
361
+ if node
362
+ notify_state(node, :manual_failover)
363
+ else
364
+ logger.error('Failed to perform manual failover, no candidate found.')
365
+ end
352
366
  end
353
367
  end
354
368
  end
@@ -1,3 +1,3 @@
1
1
  module RedisFailover
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
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.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2012-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -189,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  segments:
191
191
  - 0
192
- hash: 827412647750283458
192
+ hash: -610590228690809533
193
193
  required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  none: false
195
195
  requirements:
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  version: '0'
199
199
  segments:
200
200
  - 0
201
- hash: 827412647750283458
201
+ hash: -610590228690809533
202
202
  requirements: []
203
203
  rubyforge_project:
204
204
  rubygems_version: 1.8.23