Kouhei Sutou
null+****@clear*****
Sat Jul 19 21:29:30 JST 2014
Kouhei Sutou 2014-07-19 21:29:30 +0900 (Sat, 19 Jul 2014) New Revision: 3b0e31ce23123fff4931db45f139a098d8c05662 https://github.com/droonga/droonga-engine/commit/3b0e31ce23123fff4931db45f139a098d8c05662 Message: Use Address internal Modified files: lib/droonga/catalog/single_volume.rb lib/droonga/catalog/version2.rb lib/droonga/catalog_generator.rb test/unit/catalog/test_single_volume.rb test/unit/catalog/test_slice.rb Modified: lib/droonga/catalog/single_volume.rb (+5 -36) =================================================================== --- lib/droonga/catalog/single_volume.rb 2014-07-19 21:29:12 +0900 (7ac4a78) +++ lib/droonga/catalog/single_volume.rb 2014-07-19 21:29:30 +0900 (4cebb33) @@ -13,55 +13,24 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +require "droonga/address" + module Droonga module Catalog class SingleVolume + attr_reader :address def initialize(data) @data = data - parse_address - end - - def address - @data["address"] - end - - def host - @host - end - - def port - @port - end - - def tag - @tag - end - - def name - @name + @address = Address.parse(@data["address"]) end def node - "#{host}:#{port}/#{tag}" + @address.node end def all_nodes @all_nodes ||= [node] end - - private - def parse_address - if /\A(.+):(\d+)\/([^.]+)\.(.+)\z/ =~ address - @host = $1 - @port = $2.to_i - @tag = $3 - @name = $4 - else - format = "${host_name}:${port_number}/${tag}.${name}" - message = "volume address must be <#{format}> format: <#{address}>" - raise ArgumentError, message - end - end end end end Modified: lib/droonga/catalog/version2.rb (+5 -5) =================================================================== --- lib/droonga/catalog/version2.rb 2014-07-19 21:29:12 +0900 (da1e42f) +++ lib/droonga/catalog/version2.rb 2014-07-19 21:29:30 +0900 (228c878) @@ -13,6 +13,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +require "droonga/address" require "droonga/catalog/base" require "droonga/catalog/dataset" require "droonga/catalog/version2_validator" @@ -30,9 +31,8 @@ module Droonga @datasets end - def slices(name) + def slices(node) device = "." - pattern = Regexp.new("^#{name}\.") results = {} @datasets.each do |dataset_name, dataset| n_workers = dataset.n_workers @@ -40,8 +40,8 @@ module Droonga dataset.replicas.each do |volume| volume.slices.each do |slice| volume_address = slice.volume.address - if pattern =~ volume_address - path = File.join([device, $POSTMATCH, "db"]) + if volume_address.node == node + path = File.join([device, volume_address.name, "db"]) path = File.expand_path(path, base_path) options = { :dataset => dataset_name, @@ -49,7 +49,7 @@ module Droonga :n_workers => n_workers, :plugins => plugins } - results[volume_address] = options + results[volume_address.to_s] = options end end end Modified: lib/droonga/catalog_generator.rb (+4 -4) =================================================================== --- lib/droonga/catalog_generator.rb 2014-07-19 21:29:12 +0900 (61e7734) +++ lib/droonga/catalog_generator.rb 2014-07-19 21:29:30 +0900 (1c6a112) @@ -183,12 +183,12 @@ module Droonga collection_volume = dataset.replicas.first slices = collection_volume.slices @hosts = slices.collect do |slice| - slice.volume.host + slice.volume.address.host end @n_slices = slices.size - single_volume = slices.first.volume - @port = single_volume.port - @tag = single_volume.tag + single_volume_address = slices.first.volume.address + @port = single_volume_address.port + @tag = single_volume_address.tag end def to_catalog Modified: test/unit/catalog/test_single_volume.rb (+8 -17) =================================================================== --- test/unit/catalog/test_single_volume.rb 2014-07-19 21:29:12 +0900 (68f377b) +++ test/unit/catalog/test_single_volume.rb 2014-07-19 21:29:30 +0900 (9306d1e) @@ -24,25 +24,16 @@ class CatalogSingleVolumeTest < Test::Unit::TestCase @volume = Droonga::Catalog::SingleVolume.new(data) end - def test_address - assert_equal("127.0.0.1:10047/tag.000", - @volume.address) - end - - def test_host - assert_equal("127.0.0.1", @volume.host) - end - - def test_port - assert_equal(10047, @volume.port) - end - - def test_tag - assert_equal("tag", @volume.tag) + def address(host, port, tag, name) + Droonga::Address.new(:host => host, + :port => port, + :tag => tag, + :name => name) end - def test_name - assert_equal("000", @volume.name) + def test_address + assert_equal(address("127.0.0.1", 10047, "tag", "000"), + @volume.address) end def test_node Modified: test/unit/catalog/test_slice.rb (+1 -1) =================================================================== --- test/unit/catalog/test_slice.rb 2014-07-19 21:29:12 +0900 (3e81390) +++ test/unit/catalog/test_slice.rb 2014-07-19 21:29:30 +0900 (6745eff) @@ -86,7 +86,7 @@ class CatalogSliceTest < Test::Unit::TestCase } slice = create_slice(data) assert_equal("127.0.0.1:10047/volume.000", - slice.volume.address) + slice.volume.address.to_s) end def test_all_nodes -------------- next part -------------- HTML����������������������������... 下载