[Groonga-commit] droonga/droonga-engine at 360e2bd [master] Accept only raw replicas volume

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Dec 11 16:32:37 JST 2014


YUKI Hiroshi	2014-12-11 16:32:37 +0900 (Thu, 11 Dec 2014)

  New Revision: 360e2bd59f39c0045ddbc2b2f3e6bc32fbfd5c42
  https://github.com/droonga/droonga-engine/commit/360e2bd59f39c0045ddbc2b2f3e6bc32fbfd5c42

  Merged e0f9f34: Merge pull request #30 from piroor/replicas-in-a-branch

  Message:
    Accept only raw replicas volume

  Modified files:
    lib/droonga/catalog/replicas_volume.rb

  Modified: lib/droonga/catalog/replicas_volume.rb (+26 -25)
===================================================================
--- lib/droonga/catalog/replicas_volume.rb    2014-12-11 16:25:09 +0900 (48abe58)
+++ lib/droonga/catalog/replicas_volume.rb    2014-12-11 16:32:37 +0900 (ea3433d)
@@ -20,21 +20,11 @@ module Droonga
 
       def initialize(dataset, raw_volume)
         @dataset = dataset
-
-        if raw_volume.is_a?(Hash) and raw_volume.key?("replicas")
-          @raw_volume = raw_volume
-          @volumes = @raw_volume["replicas"].collect do |raw_volume|
-            Catalog::Volume.create(dataset, raw_volume)
-          end
-        elsif raw_volume.is_a?(Array)
-          @volumes = raw_volume
-        else
-          raise ArgumentError.new(raw_volume)
-        end
+        @raw_volume = raw_volume
       end
 
       def each(&block)
-        @volumes.each(&block)
+        replicas.each(&block)
       end
 
       def ==(other)
@@ -51,27 +41,32 @@ module Droonga
       end
 
       def select(how=nil, live_nodes=nil)
-        volumes = live_volumes(live_nodes)
         case how
         when :top
-          [volumes.first]
+          replicas = live_replicas(live_nodes)
+          [replicas.first]
         when :random
-          [volumes.sample]
+          replicas = live_replicas(live_nodes)
+          [replicas.sample]
         when :all
-          @volumes
+          replicas
         else
           super
         end
       end
 
+      def replicas
+        @replicas ||= create_replicas
+      end
+
       def all_nodes
         @all_nodes ||= collect_all_nodes
       end
 
-      def live_volumes(live_nodes=nil)
-        return @volumes unless live_nodes
+      def live_replicas(live_nodes=nil)
+        return replicas unless live_nodes
 
-        @volumes.select do |volume|
+        replicas.select do |volume|
           dead_nodes = volume.all_nodes - live_nodes
           dead_nodes.empty?
         end
@@ -81,13 +76,13 @@ module Droonga
         routes = []
         case message["type"]
         when "broadcast"
-          volumes = select(message["replica"].to_sym, live_nodes)
-          volumes.each do |volume|
+          replicas = select(message["replica"].to_sym, live_nodes)
+          replicas.each do |volume|
             routes.concat(volume.compute_routes(message, live_nodes))
           end
         when "scatter"
-          volumes = select(message["replica"].to_sym, live_nodes)
-          volumes.each do |volume|
+          replicas = select(message["replica"].to_sym, live_nodes)
+          replicas.each do |volume|
             routes.concat(volume.compute_routes(message, live_nodes))
           end
         end
@@ -95,15 +90,21 @@ module Droonga
       end
 
       def sliced?
-        @volumes.any? do |volume|
+        replicas.any? do |volume|
           volume.sliced?
         end
       end
 
       private
+      def create_replicas
+        @raw_volume["replicas"].collect do |raw_replica|
+          Catalog::Volume.create(@dataset, raw_replica)
+        end
+      end
+
       def collect_all_nodes
         nodes = []
-        @volumes.each do |volume|
+        replicas.each do |volume|
           nodes += volume.all_nodes
         end
         nodes.sort.uniq
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index