[Groonga-commit] droonga/droonga-engine at 2125ecd [master] Extract cluster-specific features of EngineState to ClusterState

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Dec 25 16:20:04 JST 2014


YUKI Hiroshi	2014-12-25 16:20:04 +0900 (Thu, 25 Dec 2014)

  New Revision: 2125ecd807b12fe9364ce27961d90762f0bf3c67
  https://github.com/droonga/droonga-engine/commit/2125ecd807b12fe9364ce27961d90762f0bf3c67

  Message:
    Extract cluster-specific features of EngineState to ClusterState

  Modified files:
    lib/droonga/dispatcher.rb
    lib/droonga/engine_state.rb
    lib/droonga/plugins/system.rb
    test/unit/plugins/system/test_status.rb

  Modified: lib/droonga/dispatcher.rb (+2 -2)
===================================================================
--- lib/droonga/dispatcher.rb    2014-12-25 15:54:03 +0900 (054ec5c)
+++ lib/droonga/dispatcher.rb    2014-12-25 16:20:04 +0900 (4a1d419)
@@ -193,9 +193,9 @@ module Droonga
         dataset =****@catal*****(step["dataset"])
         if dataset
           if write_step?(step)
-            target_nodes = @engine_state.writable_nodes
+            target_nodes = @engine_state.cluster.writable_nodes
           else
-            target_nodes = @engine_state.forwardable_nodes
+            target_nodes = @engine_state.cluster.forwardable_nodes
           end
           routes = dataset.compute_routes(step, target_nodes)
           step["routes"] = routes

  Modified: lib/droonga/engine_state.rb (+12 -83)
===================================================================
--- lib/droonga/engine_state.rb    2014-12-25 15:54:03 +0900 (3f475a5)
+++ lib/droonga/engine_state.rb    2014-12-25 16:20:04 +0900 (8499e6a)
@@ -21,7 +21,7 @@ require "droonga/loggable"
 require "droonga/event_loop"
 require "droonga/forwarder"
 require "droonga/replier"
-require "droonga/node_metadata"
+require "droonga/cluster_state"
 
 module Droonga
   class EngineState
@@ -33,20 +33,26 @@ module Droonga
     attr_reader :forwarder
     attr_reader :replier
     attr_writer :on_ready
+    attr_reader :catalog
+    attr_reader :cluster
     attr_accessor :on_finish
-    attr_accessor :catalog
+
     def initialize(loop, name, internal_name)
       @loop = loop
       @name = name
       @internal_name = internal_name
       @sessions = {}
       @current_id = 0
+      @cluster = ClusterState.new
       @forwarder = Forwarder.new(@loop, :buffering => true)
       @replier = Replier.new(@forwarder)
       @on_ready = nil
       @on_finish = nil
       @catalog = nil
-      @live_nodes_list = nil
+    end
+
+    def catalog=(catalog)
+      @catalog =****@clust***** = catalog
     end
 
     def start
@@ -105,95 +111,18 @@ module Droonga
       not****@sessi*****?
     end
 
-    def all_nodes
-      @catalog.all_nodes
-    end
-
-    def dead_nodes
-      if @live_nodes_list
-        @live_nodes_list.dead_nodes
-      else
-        []
-      end
-    end
-
-    def service_provider_nodes
-      if @live_nodes_list
-        @live_nodes_list.service_provider_nodes
-      else
-        all_nodes
-      end
-    end
-
-    def absorb_source_nodes
-      if @live_nodes_list
-        @live_nodes_list.absorb_source_nodes
-      else
-        all_nodes
-      end
-    end
-
-    def absorb_destination_nodes
-      if @live_nodes_list
-        @live_nodes_list.absorb_destination_nodes
-      else
-        all_nodes
-      end
-    end
-
-    def forwardable_nodes
-      same_role_nodes = nil
-      case node_metadata.role
-      when NodeMetadata::Role::SERVICE_PROVIDER
-        same_role_nodes = all_nodes & service_provider_nodes
-      when NodeMetadata::Role::ABSORB_SOURCE
-        same_role_nodes = all_nodes & absorb_source_nodes
-      when NodeMetadata::Role::ABSORB_DESTINATION
-        same_role_nodes = all_nodes & absorb_destination_nodes
-      else
-        same_role_nodes = []
-      end
-      same_role_nodes - dead_nodes
-    end
-
-    def writable_nodes
-      case node_metadata.role
-      when NodeMetadata::Role::SERVICE_PROVIDER
-        all_nodes
-      when NodeMetadata::Role::ABSORB_SOURCE
-        all_nodes & absorb_source_nodes
-      when NodeMetadata::Role::ABSORB_DESTINATION
-        all_nodes & absorb_destination_nodes
-      else
-        []
-      end
-    end
-
-    def live_nodes_list=(new_nodes_list)
-      old_live_nodes_list = @live_nodes_list
-      @live_nodes_list = new_nodes_list
-      unless old_live_nodes_list == new_nodes_list
-        @forwarder.resume
-      end
-      @live_nodes_list
+    def on_ready
+      @on_ready.call if @on_ready
     end
 
     def select_responsive_routes(routes)
-      selected_nodes = forwardable_nodes
+      selected_nodes =****@clust*****_nodes
       routes.select do |route|
         selected_nodes.include?(farm_path(route))
       end
     end
 
-    def on_ready
-      @on_ready.call if @on_ready
-    end
-
     private
-    def node_metadata
-      @node_metadata ||= NodeMetadata.new
-    end
-
     def log_tag
       "engine_state"
     end

  Modified: lib/droonga/plugins/system.rb (+4 -4)
===================================================================
--- lib/droonga/plugins/system.rb    2014-12-25 15:54:03 +0900 (7e0f723)
+++ lib/droonga/plugins/system.rb    2014-12-25 16:20:04 +0900 (d5612ba)
@@ -25,11 +25,11 @@ module Droonga
         action.synchronous = true
 
         def handle(message)
-          engine_state =****@messe*****_state
-          active_nodes = engine_state.forwardable_nodes
-          dead_nodes = engine_state.dead_nodes
+          cluster =****@messe*****_state.cluster
+          active_nodes = cluster.forwardable_nodes
+          dead_nodes = cluster.dead_nodes
           nodes = {}
-          engine_state.all_nodes.collect do |identifier|
+          cluster.all_nodes.collect do |identifier|
             if active_nodes.include?(identifier)
               status = "active"
             elsif dead_nodes.include?(identifier)

  Modified: test/unit/plugins/system/test_status.rb (+5 -0)
===================================================================
--- test/unit/plugins/system/test_status.rb    2014-12-25 15:54:03 +0900 (e33865b)
+++ test/unit/plugins/system/test_status.rb    2014-12-25 16:20:04 +0900 (03f1fb8)
@@ -46,6 +46,11 @@ class SystemStatusHandlerTest < Test::Unit::TestCase
   end
 
   class StubEngineState
+    def cluster
+      @cluster ||= StubClusterState.new
+  end
+
+  class StubClusterState
     def all_nodes
       [
         "127.0.0.1:10031/droonga",
-------------- next part --------------
HTML����������������������������...
下載 



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