redis_failover 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changes.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.2
2
+ -----------
3
+ - Always try to create path before setting current state in Node Manager.
4
+ - More explicit rescuing of exceptions.
5
+
1
6
  0.5.1
2
7
  -----------
3
8
  - More logging around exceptions
data/README.md CHANGED
@@ -96,7 +96,7 @@ The full set of options that can be passed to RedisFailover::Client are:
96
96
  ## Requirements
97
97
 
98
98
  - redis_failover is actively tested against MRI 1.9.2/1.9.3. Other rubies may work, although I don't actively test against them. 1.8 is not supported.
99
- - redis_failover requires a ZooKeeper service cluster to ensure reliability and data consistency. ZooKeeper is very simple and easy to get up and running. Please refer to this [Zookeper Guide](http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html) to get up and running quickly if you don't already have ZooKeeper as a part of your environment.
99
+ - redis_failover requires a ZooKeeper service cluster to ensure reliability and data consistency. ZooKeeper is very simple and easy to get up and running. Please refer to this [Quick ZooKeeper Guide](https://github.com/ryanlecompte/redis_failover/wiki/Quick-ZooKeeper-Guide) to get up and running quickly if you don't already have ZooKeeper as a part of your environment.
100
100
 
101
101
  ## Considerations
102
102
 
@@ -107,11 +107,13 @@ The full set of options that can be passed to RedisFailover::Client are:
107
107
  ## TODO
108
108
 
109
109
  - Rework specs to work against a set of real Redis/ZooKeeper nodes as opposed to stubs.
110
+ - Add support for running more than one Node Manager.
110
111
 
111
112
  ## Resources
112
113
 
113
114
  - To learn more about Redis master/slave replication, see the [Redis documentation](http://redis.io/topics/replication).
114
115
  - To learn more about ZooKeeper, see the official [ZooKeeper](http://zookeeper.apache.org/) site.
116
+ - 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.
115
117
 
116
118
  ## License
117
119
 
@@ -71,7 +71,7 @@ module RedisFailover
71
71
  # :namespace - namespace for redis nodes (optional)
72
72
  # :logger - logger override (optional)
73
73
  # :retry_failure - indicate if failures should be retried (default true)
74
- # :max_retries - max retries for a failure (default 5)
74
+ # :max_retries - max retries for a failure (default 3)
75
75
  #
76
76
  def initialize(options = {})
77
77
  Util.logger = options[:logger] if options[:logger]
@@ -80,10 +80,10 @@ module RedisFailover
80
80
  @namespace = options[:namespace]
81
81
  @password = options[:password]
82
82
  @retry = options[:retry_failure] || true
83
- @max_retries = @retry ? options.fetch(:max_retries, 3) : 0
83
+ @max_retries = @retry ? options.fetch(:max_retries, 3) : 1
84
84
  @master = nil
85
85
  @slaves = []
86
- @lock = Mutex.new
86
+ @lock = Monitor.new
87
87
  setup_zookeeper_client
88
88
  build_clients
89
89
  end
@@ -112,12 +112,12 @@ module RedisFailover
112
112
 
113
113
  # when session expires, purge client list
114
114
  @zkclient.on_session_expiration do
115
- @lock.synchronize { purge_clients }
115
+ purge_clients
116
116
  end
117
117
 
118
118
  # when we are disconnected, purge client list
119
119
  @zkclient.event_handler.register_state_handler(:connecting) do
120
- @lock.synchronize { purge_clients }
120
+ purge_clients
121
121
  end
122
122
 
123
123
  # when session is recovered, watch again
@@ -131,7 +131,7 @@ module RedisFailover
131
131
  build_clients
132
132
  elsif event.node_deleted?
133
133
  @zkclient.stat(@znode, :watch => true)
134
- @lock.synchronize { purge_clients }
134
+ purge_clients
135
135
  else
136
136
  logger.error("Unknown ZK node event: #{event.inspect}")
137
137
  end
@@ -154,7 +154,7 @@ module RedisFailover
154
154
  # direct everything else to master
155
155
  master.send(method, *args, &block)
156
156
  end
157
- rescue *ALL_ERRORS => ex
157
+ rescue *CONNECTIVITY_ERRORS => ex
158
158
  logger.error("Error while handling operation `#{method}` - #{ex.message}")
159
159
  logger.error(ex.backtrace.join("\n"))
160
160
 
@@ -200,7 +200,7 @@ module RedisFailover
200
200
  new_slaves = new_clients_for(*nodes[:slaves])
201
201
  @master = new_master
202
202
  @slaves = new_slaves
203
- rescue *ALL_ERRORS => ex
203
+ rescue StandardError, *CONNECTIVITY_ERRORS => ex
204
204
  purge_clients
205
205
  logger.error("Failed to fetch nodes from #{@zkservers} - #{ex.message}")
206
206
  logger.error(ex.backtrace.join("\n"))
@@ -285,10 +285,12 @@ module RedisFailover
285
285
  end
286
286
 
287
287
  def purge_clients
288
- logger.info("Purging current redis clients")
289
- disconnect(@master, *@slaves)
290
- @master = nil
291
- @slaves = []
288
+ @lock.synchronize do
289
+ logger.info("Purging current redis clients")
290
+ disconnect(@master, *@slaves)
291
+ @master = nil
292
+ @slaves = []
293
+ end
292
294
  end
293
295
  end
294
296
  end
@@ -41,7 +41,7 @@ module RedisFailover
41
41
 
42
42
  # flush current state
43
43
  write_state
44
- rescue *ALL_ERRORS => ex
44
+ rescue StandardError, *CONNECTIVITY_ERRORS => ex
45
45
  logger.error("Error while handling #{state_change.inspect}: #{ex.message}")
46
46
  logger.error(ex.backtrace.join("\n"))
47
47
  end
@@ -206,6 +206,7 @@ module RedisFailover
206
206
  end
207
207
 
208
208
  def write_state
209
+ create_path
209
210
  @zkclient.set(@znode, encode(current_nodes))
210
211
  end
211
212
  end
@@ -5,13 +5,13 @@ module RedisFailover
5
5
  module Util
6
6
  extend self
7
7
 
8
- DEFAULT_ZNODE_PATH = '/redis_failover_nodes'
9
- REDIS_ERRORS = Errno.constants.map { |c| Errno.const_get(c) }
10
- ALL_ERRORS = [
8
+ DEFAULT_ZNODE_PATH = '/redis_failover_nodes'.freeze
9
+ REDIS_ERRORS = Errno.constants.map { |c| Errno.const_get(c) }.freeze
10
+ CONNECTIVITY_ERRORS = [
11
11
  RedisFailover::Error,
12
+ ZK::Exceptions::KeeperException,
12
13
  ZookeeperExceptions::ZookeeperException,
13
- REDIS_ERRORS,
14
- StandardError].flatten
14
+ REDIS_ERRORS].flatten.freeze
15
15
 
16
16
  def symbolize_keys(hash)
17
17
  Hash[hash.map { |k, v| [k.to_sym, v] }]
@@ -1,3 +1,3 @@
1
1
  module RedisFailover
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
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.5.1
4
+ version: 0.5.2
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: &70319722640420 !ruby/object:Gem::Requirement
16
+ requirement: &70127944589860 !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: *70319722640420
24
+ version_requirements: *70127944589860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70319722640000 !ruby/object:Gem::Requirement
27
+ requirement: &70127944589440 !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: *70319722640000
35
+ version_requirements: *70127944589440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &70319722639560 !ruby/object:Gem::Requirement
38
+ requirement: &70127944589000 !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: *70319722639560
46
+ version_requirements: *70127944589000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: zk
49
- requirement: &70319722639140 !ruby/object:Gem::Requirement
49
+ requirement: &70127944588580 !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: *70319722639140
57
+ version_requirements: *70127944588580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70319722638720 !ruby/object:Gem::Requirement
60
+ requirement: &70127944588160 !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: *70319722638720
68
+ version_requirements: *70127944588160
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70319722638300 !ruby/object:Gem::Requirement
71
+ requirement: &70127944587740 !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: *70319722638300
79
+ version_requirements: *70127944587740
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: 2520193948527829563
132
+ hash: -3828155279649118741
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: 2520193948527829563
141
+ hash: -3828155279649118741
142
142
  requirements: []
143
143
  rubyforge_project:
144
144
  rubygems_version: 1.8.16