Class: RedisRing::ShardConfig
- Inherits:
-
Object
- Object
- RedisRing::ShardConfig
- Defined in:
- lib/redis_ring/shard_config.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#shard_number ⇒ Object
readonly
Returns the value of attribute shard_number.
Instance Method Summary collapse
- #aof_file_name ⇒ Object
- #aof_mtime ⇒ Object
- #common_config_path ⇒ Object
- #config_file_name ⇒ Object
- #db_file_name ⇒ Object
- #db_mtime ⇒ Object
- #host ⇒ Object
-
#initialize(shard_number, configuration) ⇒ ShardConfig
constructor
A new instance of ShardConfig.
- #log_file ⇒ Object
- #password ⇒ Object
- #port ⇒ Object
- #redis_path ⇒ Object
- #render ⇒ Object
- #save ⇒ Object
- #vm_max_memory ⇒ Object
- #vm_page_size ⇒ Object
- #vm_pages ⇒ Object
- #vm_swap_file ⇒ Object
- #working_directory ⇒ Object
Constructor Details
#initialize(shard_number, configuration) ⇒ ShardConfig
Returns a new instance of ShardConfig.
7 8 9 10 11 12 13 14 |
# File 'lib/redis_ring/shard_config.rb', line 7 def initialize(shard_number, configuration) unless shard_number >= 0 && shard_number < configuration.ring_size raise ArgumentError.new("shard number #{shard_number} must be between 0 and #{configuration.ring_size - 1}") end @shard_number = shard_number @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/redis_ring/shard_config.rb', line 5 def configuration @configuration end |
#shard_number ⇒ Object (readonly)
Returns the value of attribute shard_number.
5 6 7 |
# File 'lib/redis_ring/shard_config.rb', line 5 def shard_number @shard_number end |
Instance Method Details
#aof_file_name ⇒ Object
77 78 79 |
# File 'lib/redis_ring/shard_config.rb', line 77 def aof_file_name file('db_files', "shard-#{shard_number}.aof") end |
#aof_mtime ⇒ Object
85 86 87 |
# File 'lib/redis_ring/shard_config.rb', line 85 def aof_mtime mtime(aof_file_name) end |
#common_config_path ⇒ Object
93 94 95 |
# File 'lib/redis_ring/shard_config.rb', line 93 def common_config_path File.join(configuration.base_directory, "shared_config.conf") end |
#config_file_name ⇒ Object
33 34 35 |
# File 'lib/redis_ring/shard_config.rb', line 33 def config_file_name File.join(configuration.base_directory, 'configs', "shard-#{shard_number}.conf") end |
#db_file_name ⇒ Object
73 74 75 |
# File 'lib/redis_ring/shard_config.rb', line 73 def db_file_name file('db_files', "shard-#{shard_number}.rdb") end |
#db_mtime ⇒ Object
81 82 83 |
# File 'lib/redis_ring/shard_config.rb', line 81 def db_mtime mtime(db_file_name) end |
#host ⇒ Object
37 38 39 |
# File 'lib/redis_ring/shard_config.rb', line 37 def host configuration.host_name end |
#log_file ⇒ Object
49 50 51 |
# File 'lib/redis_ring/shard_config.rb', line 49 def log_file File.(file('logs', "shard-#{shard_number}.log"), working_directory) end |
#password ⇒ Object
89 90 91 |
# File 'lib/redis_ring/shard_config.rb', line 89 def password configuration.password end |
#port ⇒ Object
41 42 43 |
# File 'lib/redis_ring/shard_config.rb', line 41 def port configuration.base_port + shard_number + 1 end |
#redis_path ⇒ Object
45 46 47 |
# File 'lib/redis_ring/shard_config.rb', line 45 def redis_path configuration.redis_path end |
#render ⇒ Object
16 17 18 19 |
# File 'lib/redis_ring/shard_config.rb', line 16 def render template = ERB.new(File.read(configuration.redis_config_template_path)) return template.result(binding) end |
#save ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/redis_ring/shard_config.rb', line 21 def save FileUtils.mkdir_p(working_directory) ['configs', 'logs', 'vm_files', 'db_files'].each do |dir_name| FileUtils.mkdir_p(File.join(configuration.base_directory, dir_name)) end FileUtils.touch(common_config_path) unless File.exist?(common_config_path) File.open(config_file_name, 'w') { |f| f.write(render) } end |
#vm_max_memory ⇒ Object
61 62 63 |
# File 'lib/redis_ring/shard_config.rb', line 61 def vm_max_memory configuration.total_max_memory / configuration.ring_size end |
#vm_page_size ⇒ Object
69 70 71 |
# File 'lib/redis_ring/shard_config.rb', line 69 def vm_page_size configuration.vm_page_size end |
#vm_pages ⇒ Object
65 66 67 |
# File 'lib/redis_ring/shard_config.rb', line 65 def vm_pages configuration.total_vm_size / configuration.vm_page_size / configuration.ring_size end |
#vm_swap_file ⇒ Object
57 58 59 |
# File 'lib/redis_ring/shard_config.rb', line 57 def vm_swap_file file('vm_files', "shard-#{shard_number}.swap") end |
#working_directory ⇒ Object
53 54 55 |
# File 'lib/redis_ring/shard_config.rb', line 53 def working_directory "#{configuration.base_directory}/work/shard-#{shard_number}" end |