[Groonga-commit] droonga/droonga-engine at 79805c0 [master] Move get_routes() from Catalog to Dataset

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri May 9 12:30:55 JST 2014


YUKI Hiroshi	2014-05-09 12:30:55 +0900 (Fri, 09 May 2014)

  New Revision: 79805c024f02f08e09a1de6b88a73f08f8f27796
  https://github.com/droonga/droonga-engine/commit/79805c024f02f08e09a1de6b88a73f08f8f27796

  Message:
    Move get_routes() from Catalog to Dataset

  Modified files:
    lib/droonga/catalog/dataset.rb
    lib/droonga/catalog/version1.rb
    lib/droonga/catalog/version2.rb
    lib/droonga/dispatcher.rb

  Modified: lib/droonga/catalog/dataset.rb (+21 -0)
===================================================================
--- lib/droonga/catalog/dataset.rb    2014-05-09 12:21:14 +0900 (62b79af)
+++ lib/droonga/catalog/dataset.rb    2014-05-09 12:30:55 +0900 (a07ea4e)
@@ -62,6 +62,27 @@ module Droonga
         replicas.all_nodes
       end
 
+      def get_routes(args)
+        routes = []
+        case args["type"]
+        when "broadcast"
+          volumes = replicas.select(args["replica"].to_sym)
+          volumes.each do |volume|
+            slices = volume.select_slices
+            slices.each do |slice|
+              routes << slice.volume.address
+            end
+          end
+        when "scatter"
+          volumes = replicas.select(args["replica"].to_sym)
+          volumes.each do |volume|
+            slice = volume.choose_slice(args["record"])
+            routes << slice.volume.address
+          end
+        end
+        routes
+      end
+
       private
       def create_volumes(raw_volumes)
         raw_volumes.collect do |raw_volume|

  Modified: lib/droonga/catalog/version1.rb (+36 -35)
===================================================================
--- lib/droonga/catalog/version1.rb    2014-05-09 12:21:14 +0900 (ec3fab7)
+++ lib/droonga/catalog/version1.rb    2014-05-09 12:30:55 +0900 (d1a1103)
@@ -66,41 +66,6 @@ module Droonga
         return results
       end
 
-      def get_routes(name, args)
-        routes = []
-        dataset = dataset(name)
-        case args["type"]
-        when "broadcast"
-          dataset["ring"].each do |key, partition|
-            select_range_and_replicas(partition, args, routes)
-          end
-        when "scatter"
-          name = get_partition(dataset, args["record"]["_key"])
-          partition = dataset["ring"][name]
-          select_range_and_replicas(partition, args, routes)
-        end
-        return routes
-      end
-
-      def get_partition(dataset, key)
-        continuum = dataset["continuum"]
-        return dataset["ring"].keys[0] unless continuum
-        hash = Zlib.crc32(key)
-        min = 0
-        max = continuum.size - 1
-        while (min < max) do
-          index = (min + max) / 2
-          value, key = continuum[index]
-          return key if value == hash
-          if value > hash
-            max = index
-          else
-            min = index + 1
-          end
-        end
-        return continuum[max][1]
-      end
-
       def select_range_and_replicas(partition, args, routes)
         date_range = args["date_range"] || 0..-1
         partition["partitions"].sort[date_range].each do |time, replicas|
@@ -429,6 +394,42 @@ module Droonga
           end
         end
       end
+
+      class Dataset < Catalog::Dataset
+        def get_routes(args)
+          routes = []
+          case args["type"]
+          when "broadcast"
+            self["ring"].each do |key, partition|
+              select_range_and_replicas(partition, args, routes)
+            end
+          when "scatter"
+            name = get_partition(args["record"]["_key"])
+            partition = self["ring"][name]
+            select_range_and_replicas(partition, args, routes)
+          end
+          return routes
+        end
+
+        def get_partition(key)
+          continuum = self["continuum"]
+          return self["ring"].keys[0] unless continuum
+          hash = Zlib.crc32(key)
+          min = 0
+          max = continuum.size - 1
+          while (min < max) do
+            index = (min + max) / 2
+            value, key = continuum[index]
+            return key if value == hash
+            if value > hash
+              max = index
+            else
+              min = index + 1
+            end
+          end
+          return continuum[max][1]
+        end
+      end
     end
   end
 end

  Modified: lib/droonga/catalog/version2.rb (+0 -22)
===================================================================
--- lib/droonga/catalog/version2.rb    2014-05-09 12:21:14 +0900 (b78fa02)
+++ lib/droonga/catalog/version2.rb    2014-05-09 12:30:55 +0900 (22f7425)
@@ -57,28 +57,6 @@ module Droonga
         results
       end
 
-      def get_routes(name, args)
-        routes = []
-        dataset = dataset(name)
-        case args["type"]
-        when "broadcast"
-          volumes = dataset.replicas.select(args["replica"].to_sym)
-          volumes.each do |volume|
-            slices = volume.select_slices
-            slices.each do |slice|
-              routes << slice.volume.address
-            end
-          end
-        when "scatter"
-          volumes = dataset.replicas.select(args["replica"].to_sym)
-          volumes.each do |volume|
-            slice = volume.choose_slice(args["record"])
-            routes << slice.volume.address
-          end
-        end
-        routes
-      end
-
       def all_nodes
         nodes = []
         @datasets.each do |name, dataset|

  Modified: lib/droonga/dispatcher.rb (+2 -2)
===================================================================
--- lib/droonga/dispatcher.rb    2014-05-09 12:21:14 +0900 (e27c35c)
+++ lib/droonga/dispatcher.rb    2014-05-09 12:30:55 +0900 (3b52117)
@@ -167,9 +167,9 @@ module Droonga
       id = @engine_state.generate_id
       destinations = {}
       steps.each do |step|
-        dataset = step["dataset"]
+        dataset =****@catal*****(step["dataset"])
         if dataset
-          routes =****@catal*****_routes(dataset, step)
+          routes = dataset.get_routes(step)
           step["routes"] = routes
         else
           step["routes"] ||= [id]
-------------- next part --------------
HTML����������������������������...
Télécharger 



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