Class: RedisFailover::FailoverStrategy::Latency

Inherits:
RedisFailover::FailoverStrategy show all
Defined in:
lib/redis_failover/failover_strategy/latency.rb

Overview

Failover strategy that selects an available node that is both seen by all node managers and has the lowest reported health check latency.

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

Instance Method Summary collapse

Methods inherited from RedisFailover::FailoverStrategy

for

Methods included from Util

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

Instance Method Details

#find_candidate(snapshots) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/redis_failover/failover_strategy/latency.rb', line 7

def find_candidate(snapshots)
  candidates = {}
  snapshots.each do |node, snapshot|
    if snapshot.all_available?
      candidates[node] = snapshot.avg_latency
    end
  end

  if candidate = candidates.min_by(&:last)
    candidate.first
  end
end