Class: SolidRedis::ClusterState
- Inherits:
-
Object
- Object
- SolidRedis::ClusterState
- Defined in:
- lib/solid_redis/cluster_state.rb
Overview
Per-Ractor Cluster runtime: the slot table, the node configurations and the mutex protecting them. Never shared between Ractors.
Instance Method Summary collapse
- #any_node ⇒ Object
- #discovered? ⇒ Boolean
-
#initialize(specification) ⇒ ClusterState
constructor
A new instance of ClusterState.
-
#move(slot, host, port) ⇒ Object
Applies a MOVED redirection locally without a full topology refresh.
- #node(host, port) ⇒ Object
-
#node_for_slot(slot) ⇒ Object
Returns the master Config owning
slot, discovering the topology when it is not known yet. - #nodes ⇒ Object
- #refresh ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(specification) ⇒ ClusterState
Returns a new instance of ClusterState.
7 8 9 10 11 12 13 |
# File 'lib/solid_redis/cluster_state.rb', line 7 def initialize(specification) @specification = specification @mutex = Mutex.new @slots = Array.new(Cluster::KeySlot::SLOTS) @nodes = {} @discovered = false end |
Instance Method Details
#any_node ⇒ Object
40 41 42 |
# File 'lib/solid_redis/cluster_state.rb', line 40 def any_node nodes.first end |
#discovered? ⇒ Boolean
15 16 17 |
# File 'lib/solid_redis/cluster_state.rb', line 15 def discovered? @mutex.synchronize { @discovered } end |
#move(slot, host, port) ⇒ Object
Applies a MOVED redirection locally without a full topology refresh.
45 46 47 48 49 50 51 52 |
# File 'lib/solid_redis/cluster_state.rb', line 45 def move(slot, host, port) @mutex.synchronize do key = node_key(host, port) @nodes[key] ||= node_config(host, port) @slots[slot] = key @nodes[key] end end |
#node(host, port) ⇒ Object
54 55 56 |
# File 'lib/solid_redis/cluster_state.rb', line 54 def node(host, port) @mutex.synchronize { @nodes[node_key(host, port)] ||= node_config(host, port) } end |
#node_for_slot(slot) ⇒ Object
Returns the master Config owning slot, discovering the topology when
it is not known yet.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/solid_redis/cluster_state.rb', line 21 def node_for_slot(slot) @mutex.synchronize do discover unless @discovered key = @slots[slot] if key.nil? discover key = @slots[slot] end @nodes[key] || raise(ConnectionError, "No cluster node serves slot #{slot}") end end |
#nodes ⇒ Object
33 34 35 36 37 38 |
# File 'lib/solid_redis/cluster_state.rb', line 33 def nodes @mutex.synchronize do discover unless @discovered @nodes.values end end |
#refresh ⇒ Object
66 67 68 |
# File 'lib/solid_redis/cluster_state.rb', line 66 def refresh @mutex.synchronize { discover } end |
#reset ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/solid_redis/cluster_state.rb', line 58 def reset @mutex.synchronize do @discovered = false @slots.fill(nil) @nodes.clear end end |