Class: RedisFailover::NodeStrategy

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/redis_failover/node_strategy.rb,
lib/redis_failover/node_strategy/single.rb,
lib/redis_failover/node_strategy/majority.rb,
lib/redis_failover/node_strategy/consensus.rb

Overview

Base class for strategies that determine node availability.

Direct Known Subclasses

Consensus, Majority, Single

Defined Under Namespace

Classes: Consensus, Majority, Single

Constant Summary

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

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

Class Method Details

.for(name) ⇒ Object

Loads a strategy based on the given name.

Parameters:

  • name (String, Symbol)

    the strategy name

Returns:

  • (Object)

    a new strategy instance



10
11
12
13
14
15
# File 'lib/redis_failover/node_strategy.rb', line 10

def self.for(name)
  require "redis_failover/node_strategy/#{name.downcase}"
  const_get(name.capitalize).new
rescue LoadError, NameError
  raise "Failed to find node strategy: #{name}"
end

Instance Method Details

#determine_state(node, snapshots) ⇒ Symbol

Returns the state determined by this strategy.

Parameters:

  • the (Node)

    node to handle

  • snapshots (Hash<Node, NodeSnapshot>)

    the current set of snapshots

Returns:

  • (Symbol)

    the status

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/redis_failover/node_strategy.rb', line 22

def determine_state(node, snapshots)
  raise NotImplementedError
end

#log_unavailable(node, snapshot) ⇒ Object

Logs a node as being unavailable.

Parameters:



30
31
32
# File 'lib/redis_failover/node_strategy.rb', line 30

def log_unavailable(node, snapshot)
  logger.info("#{self.class} marking #{node} as unavailable. Snapshot: #{snapshot}")
end