Class | Beetle::RedisConfigurationServer |
In: |
lib/beetle/redis_configuration_server.rb
|
Parent: | Object |
A RedisConfigurationServer is the supervisor part of beetle‘s redis failover solution
An single instance of RedisConfigurationServer works as a supervisor for several RedisConfigurationClient instances. It is responsible for watching the redis master and electing and publishing a new master in case of failure.
It will make sure that all configured RedisConfigurationClient instances do not use the old master anymore before making a switch, to prevent inconsistent data.
Usually started via beetle configuration_server command.
current_master | [R] | the current redis master |
current_token | [R] | the current token used to detect correct message order |
Beetle::Client instance for communication with the RedisConfigurationServer
# File lib/beetle/redis_configuration_server.rb, line 38 38: def beetle 39: @beetle ||= build_beetle 40: end
called by the message dispatcher when a "client_invalidated" message from a RedisConfigurationClient is received
# File lib/beetle/redis_configuration_server.rb, line 78 78: def client_invalidated(payload) 79: id = payload["id"] 80: token = payload["token"] 81: logger.info "Received client_invalidated message from id '#{id}' with token '#{token}'" 82: return unless redeem_token(token) 83: @client_invalidated_ids_received << id 84: if all_client_invalidated_ids_received? 85: logger.debug "All client invalidated messages received" 86: @invalidate_timer.cancel if @invalidate_timer 87: switch_master 88: end 89: end
check whether the current master is still online and still a master
# File lib/beetle/redis_configuration_server.rb, line 112 112: def master_available? 113: redis.masters.include?(current_master) 114: end
called from RedisWatcher when watched redis becomes unavailable
# File lib/beetle/redis_configuration_server.rb, line 92 92: def master_unavailable! 93: msg = "Redis master '#{current_master.server}' not available" 94: master_watcher.pause 95: logger.warn(msg) 96: beetle.publish(:system_notification, {"message" => msg}.to_json) 97: 98: if @client_ids.empty? 99: switch_master 100: else 101: start_invalidation 102: end 103: end
called by the message dispatcher when a "pong" message from a RedisConfigurationClient is received
# File lib/beetle/redis_configuration_server.rb, line 64 64: def pong(payload) 65: id = payload["id"] 66: token = payload["token"] 67: logger.info "Received pong message from id '#{id}' with token '#{token}'" 68: return unless redeem_token(token) 69: @client_pong_ids_received << id 70: if all_client_pong_ids_received? 71: logger.debug "All client pong messages received" 72: @available_timer.cancel if @available_timer 73: invalidate_current_master 74: end 75: end
Redis system status information (an instance of class RedisServerInfo)
# File lib/beetle/redis_configuration_server.rb, line 33 33: def redis 34: @redis ||= RedisServerInfo.new(config, :timeout => 3) 35: end