Class: RedisFailover::ManualFailover
- Inherits:
-
Object
- Object
- RedisFailover::ManualFailover
- Defined in:
- lib/redis_failover/manual_failover.rb
Overview
Provides manual failover support to a new master.
Constant Summary collapse
- ZNODE_PATH =
Path for manual failover communication.
'manual_failover'.freeze
- ANY_SLAVE =
Denotes that any slave can be used as a candidate for promotion.
"ANY_SLAVE".freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(zk, root_znode, options = {}) ⇒ ManualFailover
constructor
Creates a new instance.
-
#perform ⇒ Object
Performs a manual failover.
Constructor Details
#initialize(zk, root_znode, options = {}) ⇒ ManualFailover
Note:
If options is empty, a random slave will be used as a failover candidate.
Creates a new instance.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/redis_failover/manual_failover.rb', line 24 def initialize(zk, root_znode, = {}) @zk = zk @root_znode = root_znode @options = unless @options.empty? port = Integer(@options[:port]) rescue nil raise ArgumentError, ':host not properly specified' if @options[:host].to_s.empty? raise ArgumentError, ':port not properly specified' if port.nil? end end |
Class Method Details
.path(root_znode) ⇒ Object
10 11 12 |
# File 'lib/redis_failover/manual_failover.rb', line 10 def self.path(root_znode) "#{root_znode}/#{ZNODE_PATH}" end |
Instance Method Details
#perform ⇒ Object
Performs a manual failover.
37 38 39 40 41 |
# File 'lib/redis_failover/manual_failover.rb', line 37 def perform create_path node = @options.empty? ? ANY_SLAVE : "#{@options[:host]}:#{@options[:port]}" @zk.set(self.class.path(@root_znode), node) end |