Class: RedisFailover::NodeWatcher

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/redis_failover/node_watcher.rb

Overview

NodeWatcher periodically monitors a specific redis node for its availability. NodeWatcher instances periodically report a redis node's current state to the NodeManager for proper handling.

Constant Summary collapse

WATCHER_SLEEP_TIME =

Time to sleep before checking on the monitored node's status.

2

Constants included from Util

Util::CONNECTIVITY_ERRORS, Util::DEFAULT_ROOT_ZNODE_PATH, Util::REDIS_ERRORS, Util::REDIS_READ_OPS, Util::UNSUPPORTED_OPS, Util::ZK_ERRORS

Instance Method Summary collapse

Methods included from Util

#decode, #different?, #encode, logger, #logger, logger=, #symbolize_keys

Constructor Details

#initialize(manager, node, max_failures) ⇒ NodeWatcher

Creates a new instance.

Parameters:

  • manager (NodeManager)

    the node manager

  • node (Node)

    the node to watch

  • max_failures (Integer)

    the max failues before reporting node as down



16
17
18
19
20
21
22
# File 'lib/redis_failover/node_watcher.rb', line 16

def initialize(manager, node, max_failures)
  @manager = manager
  @node = node
  @max_failures = max_failures
  @monitor_thread = nil
  @done = false
end

Instance Method Details

#shutdownObject

Performs a graceful shutdown of this watcher.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/redis_failover/node_watcher.rb', line 34

def shutdown
  @done = true
  begin
    @node.wakeup
  rescue
    # best effort
  end
  @monitor_thread.join
rescue => ex
  logger.warn("Failed to gracefully shutdown watcher for #{@node}")
end

#watchObject

Note:

this method returns immediately and causes monitoring to be performed in a new background thread

Starts the node watcher.



28
29
30
31
# File 'lib/redis_failover/node_watcher.rb', line 28

def watch
  @monitor_thread ||= Thread.new { monitor_node }
  self
end