Class: RedisRing::Slave
- Inherits:
-
Object
- Object
- RedisRing::Slave
- Defined in:
- lib/redis_ring/slave.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#current_master_host ⇒ Object
Returns the value of attribute current_master_host.
-
#current_master_port ⇒ Object
Returns the value of attribute current_master_port.
-
#master_rpc ⇒ Object
readonly
Returns the value of attribute master_rpc.
-
#node_id ⇒ Object
Returns the value of attribute node_id.
-
#process_manager ⇒ Object
readonly
Returns the value of attribute process_manager.
-
#running_shards ⇒ Object
readonly
Returns the value of attribute running_shards.
Instance Method Summary collapse
- #available_shards ⇒ Object
-
#initialize(configuration, master_rpc, process_manager) ⇒ Slave
constructor
A new instance of Slave.
- #join ⇒ Object
- #joined? ⇒ Boolean
- #start_shard(shard_number) ⇒ Object
- #status ⇒ Object
- #stop_shard(shard_number) ⇒ Object
- #sync_shard_with(shard_number, host, port) ⇒ Object
Constructor Details
#initialize(configuration, master_rpc, process_manager) ⇒ Slave
Returns a new instance of Slave.
9 10 11 12 13 14 15 |
# File 'lib/redis_ring/slave.rb', line 9 def initialize(configuration, master_rpc, process_manager) @configuration = configuration @master_rpc = master_rpc @process_manager = process_manager @joined = false @running_shards = {} end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/redis_ring/slave.rb', line 6 def configuration @configuration end |
#current_master_host ⇒ Object
Returns the value of attribute current_master_host.
5 6 7 |
# File 'lib/redis_ring/slave.rb', line 5 def current_master_host @current_master_host end |
#current_master_port ⇒ Object
Returns the value of attribute current_master_port.
5 6 7 |
# File 'lib/redis_ring/slave.rb', line 5 def current_master_port @current_master_port end |
#master_rpc ⇒ Object (readonly)
Returns the value of attribute master_rpc.
6 7 8 |
# File 'lib/redis_ring/slave.rb', line 6 def master_rpc @master_rpc end |
#node_id ⇒ Object
Returns the value of attribute node_id.
5 6 7 |
# File 'lib/redis_ring/slave.rb', line 5 def node_id @node_id end |
#process_manager ⇒ Object (readonly)
Returns the value of attribute process_manager.
6 7 8 |
# File 'lib/redis_ring/slave.rb', line 6 def process_manager @process_manager end |
#running_shards ⇒ Object (readonly)
Returns the value of attribute running_shards.
7 8 9 |
# File 'lib/redis_ring/slave.rb', line 7 def running_shards @running_shards end |
Instance Method Details
#available_shards ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/redis_ring/slave.rb', line 21 def available_shards available_shards = {} configuration.ring_size.times do |shard_no| shard_conf = ShardConfig.new(shard_no, configuration) = [shard_conf.db_mtime, shard_conf.aof_mtime].compact.max available_shards[shard_no] = if end return available_shards end |
#join ⇒ Object
35 36 37 38 39 |
# File 'lib/redis_ring/slave.rb', line 35 def join puts "JOINING CLUSTER" @joined = true master_rpc.connection(current_master_host, current_master_port).node_loaded(node_id) end |
#joined? ⇒ Boolean
17 18 19 |
# File 'lib/redis_ring/slave.rb', line 17 def joined? @joined end |
#start_shard(shard_number) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/redis_ring/slave.rb', line 41 def start_shard(shard_number) puts "STARTING SHARD #{shard_number}" return if running_shards.include?(shard_number) shard_conf = ShardConfig.new(shard_number, configuration) shard = running_shards[shard_number] = Shard.new(shard_conf) process_manager.start_shard(shard) end |
#status ⇒ Object
31 32 33 |
# File 'lib/redis_ring/slave.rb', line 31 def status { :joined => joined?, :running_shards => running_shards.keys, :available_shards => available_shards } end |
#stop_shard(shard_number) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/redis_ring/slave.rb', line 49 def stop_shard(shard_number) puts "STOPPING SHARD #{shard_number}" shard = running_shards[shard_number] return unless shard process_manager.stop_shard(shard) running_shards.delete(shard_number) end |
#sync_shard_with(shard_number, host, port) ⇒ Object
57 58 |
# File 'lib/redis_ring/slave.rb', line 57 def sync_shard_with(shard_number, host, port) end |