Kouhei Sutou
null+****@clear*****
Fri Mar 21 15:49:57 JST 2014
Kouhei Sutou 2014-03-21 15:49:57 +0900 (Fri, 21 Mar 2014) New Revision: 784256126e410042db8c1aa71e83bca7601f7bcd https://github.com/droonga/fluent-plugin-droonga/commit/784256126e410042db8c1aa71e83bca7601f7bcd Message: Use volume objects Modified files: lib/droonga/catalog/collection_volume.rb lib/droonga/catalog/dataset.rb lib/droonga/catalog/version2.rb Modified: lib/droonga/catalog/collection_volume.rb (+5 -0) =================================================================== --- lib/droonga/catalog/collection_volume.rb 2014-03-21 15:43:34 +0900 (48fac53) +++ lib/droonga/catalog/collection_volume.rb 2014-03-21 15:49:57 +0900 (6f0718d) @@ -31,6 +31,11 @@ module Droonga def slices @data["slices"] end + + # Just for backward compatibility + def [](key) + @data[key] + end end end end Modified: lib/droonga/catalog/dataset.rb (+14 -1) =================================================================== --- lib/droonga/catalog/dataset.rb 2014-03-21 15:43:34 +0900 (55c14bd) +++ lib/droonga/catalog/dataset.rb 2014-03-21 15:49:57 +0900 (2bd09fc) @@ -14,6 +14,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require "droonga/catalog/schema" +require "droonga/catalog/single_volume" +require "droonga/catalog/collection_volume" require "droonga/catalog/volume_collection" module Droonga @@ -52,7 +54,18 @@ module Droonga end def replicas - @replicas ||= VolumeCollection.new(@data["replicas"]) + @replicas ||= VolumeCollection.new(create_volumes(@data["replicas"])) + end + + private + def create_volumes(raw_volumes) + raw_volumes.collect do |raw_volume| + if raw_volume.key?("address") + SingleVolume.new(raw_volume) + else + CollectionVolume.new(raw_volume) + end + end end end end Modified: lib/droonga/catalog/version2.rb (+12 -12) =================================================================== --- lib/droonga/catalog/version2.rb 2014-03-21 15:43:34 +0900 (b7d7630) +++ lib/droonga/catalog/version2.rb 2014-03-21 15:49:57 +0900 (d25d803) @@ -62,19 +62,19 @@ module Droonga dataset = dataset(name) case args["type"] when "broadcast" - replicas = dataset.replicas.select(args["replica"].to_sym) - replicas.each do |replica| - slices = select_slices(replica) + volumes = dataset.replicas.select(args["replica"].to_sym) + volumes.each do |volume| + slices = select_slices(volume) slices.each do |slice| routes << slice["volume"]["address"] end end when "scatter" - replicas = dataset.replicas.select(args["replica"].to_sym) - replicas.each do |replica| - dimension = replica["dimension"] || "_key" + volumes = dataset.replicas.select(args["replica"].to_sym) + volumes.each do |volume| + dimension = volume.dimension key = args["key"] || args["record"][dimension] - slice = select_slice(replica, key) + slice = select_slice(volume, key) routes << slice["volume"]["address"] end end @@ -123,16 +123,16 @@ module Droonga end end - def select_slices(replica, range=0..-1) - sorted_slices = replica["slices"].sort_by do |slice| + def select_slices(volume, range=0..-1) + sorted_slices = volume.slices.sort_by do |slice| slice["label"] end sorted_slices[range] end - def select_slice(replica, key) - continuum = replica["continuum"] - return replica["slices"].first unless continuum + def select_slice(volume, key) + continuum = volume["continuum"] + return volume.slices.first unless continuum hash = Zlib.crc32(key) min = 0 -------------- next part -------------- HTML����������������������������...Download