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.

Methods

Included Modules

Logging RedisMasterFile

Attributes

current_master  [R]  the current redis master
current_token  [R]  the current token used to detect correct message order

Public Instance methods

Beetle::Client instance for communication with the RedisConfigurationServer

[Source]

    # 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

[Source]

    # 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

called from RedisWatcher when watched redis is available

[Source]

     # File lib/beetle/redis_configuration_server.rb, line 106
106:     def master_available!
107:       publish_master(current_master)
108:       configure_slaves(current_master)
109:     end

check whether the current master is still online and still a master

[Source]

     # 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

[Source]

     # 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

test if redis is currently being watched

[Source]

    # File lib/beetle/redis_configuration_server.rb, line 59
59:     def paused?
60:       master_watcher.paused?
61:     end

called by the message dispatcher when a "pong" message from a RedisConfigurationClient is received

[Source]

    # 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)

[Source]

    # File lib/beetle/redis_configuration_server.rb, line 33
33:     def redis
34:       @redis ||= RedisServerInfo.new(config, :timeout => 3)
35:     end

start watching redis

[Source]

    # File lib/beetle/redis_configuration_server.rb, line 47
47:     def start
48:       verify_redis_master_file_string
49:       check_redis_configuration
50:       redis.refresh
51:       determine_initial_master
52:       log_start
53:       beetle.listen do
54:         master_watcher.watch
55:       end
56:     end

[Validate]