[Groonga-commit] droonga/droonga-engine at c40d698 [master] Calculate engine node status by Cluster itself

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Jan 6 17:39:39 JST 2015


YUKI Hiroshi	2015-01-06 17:39:39 +0900 (Tue, 06 Jan 2015)

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

  Message:
    Calculate engine node status by Cluster itself

  Modified files:
    lib/droonga/cluster.rb
    lib/droonga/engine_node.rb
    lib/droonga/plugins/system.rb
    test/unit/plugins/system/test_status.rb

  Modified: lib/droonga/cluster.rb (+11 -3)
===================================================================
--- lib/droonga/cluster.rb    2015-01-06 17:23:55 +0900 (34ac48c)
+++ lib/droonga/cluster.rb    2015-01-06 17:39:39 +0900 (08360fa)
@@ -70,6 +70,14 @@ module Droonga
       @engine_nodes ||= create_engine_nodes
     end
 
+    def engine_nodes_status
+      engine_nodes.collect do |node|
+        nodes[node.name] = {
+          "status" => node.status,
+        }
+      end
+    end
+
     def forward(message, destination)
       receiver = destination["to"]
       receiver_node_name = receiver.match(/\A[^:]+:\d+\/[^.]+/).to_s
@@ -122,13 +130,13 @@ module Droonga
 
     def forwardable_nodes
       @forwardable_nodes ||= engine_nodes.select do |node|
-        node.live? and node.role == node_metadata.role
+        node.forwardable?
       end.collect(&:name)
     end
 
     def writable_nodes
       @writable_nodes ||= engine_nodes.select do |node|
-        node.writable_by?(node_metadata.role)
+        node.writable?
       end.collect(&:name)
     end
 
@@ -174,7 +182,7 @@ module Droonga
     def create_engine_nodes
       all_node_names.collect do |name|
         node_state = @state[name] || {}
-        EngineNode.new(name, node_state, @loop)
+        EngineNode.new(name, node_state, node_metadata.role, @loop)
       end
     end
 

  Modified: lib/droonga/engine_node.rb (+16 -4)
===================================================================
--- lib/droonga/engine_node.rb    2015-01-06 17:23:55 +0900 (3022a3f)
+++ lib/droonga/engine_node.rb    2015-01-06 17:39:39 +0900 (d7877b2)
@@ -20,9 +20,10 @@ module Droonga
   class EngineNode
     attr_reader :name, :forwarder
 
-    def initialize(name, state, loop)
+    def initialize(name, state, sender_role, loop)
       @name  = name
       @state = state
+      @sender_role = sender_role
 
       @forwarder = Forwarder.new(loop, :buffering => true)
     end
@@ -56,11 +57,12 @@ module Droonga
     end
 
     def forwardable?
-      not dead?
+      return false unless live?
+      role == @sender_role
     end
 
-    def writable_by?(sender_role)
-      case sender_role
+    def writable?
+      case @sender_role
       when NodeMetadata::Role::SERVICE_PROVIDER
         true
       when NodeMetadata::Role::ABSORB_SOURCE
@@ -72,6 +74,16 @@ module Droonga
       end
     end
 
+    def status
+      if forwardable?
+        "active"
+      elsif dead?
+        "dead"
+      else
+        "inactive"
+      end
+    end
+
     def on_change
       @forwarder.resume
     end

  Modified: lib/droonga/plugins/system.rb (+1 -17)
===================================================================
--- lib/droonga/plugins/system.rb    2015-01-06 17:23:55 +0900 (31d9945)
+++ lib/droonga/plugins/system.rb    2015-01-06 17:39:39 +0900 (7206f01)
@@ -26,24 +26,8 @@ module Droonga
 
         def handle(message)
           cluster =****@messe*****
-          active_nodes = cluster.forwardable_nodes
-          dead_nodes = cluster.dead_nodes
-          nodes = {}
-          cluster.all_nodes.collect do |identifier|
-            if active_nodes.include?(identifier)
-              status = "active"
-            elsif dead_nodes.include?(identifier)
-              status = "dead"
-            else
-              status = "inactive"
-            end
-            nodes[identifier] = {
-              "status" => status,
-            }
-          end
-
           {
-            "nodes" => nodes,
+            "nodes" => cluster.engine_nodes_status,
           }
         end
       end

  Modified: test/unit/plugins/system/test_status.rb (+12 -18)
===================================================================
--- test/unit/plugins/system/test_status.rb    2015-01-06 17:23:55 +0900 (ede77cd)
+++ test/unit/plugins/system/test_status.rb    2015-01-06 17:39:39 +0900 (1d0cb13)
@@ -46,24 +46,18 @@ class SystemStatusHandlerTest < Test::Unit::TestCase
   end
 
   class StubCluster
-    def all_nodes
-      [
-        "127.0.0.1:10031/droonga",
-        "127.0.0.1:10032/droonga",
-        "127.0.0.1:10033/droonga",
-      ]
-    end
-
-    def forwardable_nodes
-      [
-        "127.0.0.1:10031/droonga",
-      ]
-    end
-
-    def dead_nodes
-      [
-        "127.0.0.1:10033/droonga",
-      ]
+    def engine_nodes_status
+      {
+        "127.0.0.1:10031/droonga" => {
+          "status" => "active",
+        },
+        "127.0.0.1:10032/droonga" => {
+          "status" => "inactive",
+        },
+        "127.0.0.1:10033/droonga" => {
+          "status" => "dead",
+        },
+      }
     end
   end
 
-------------- next part --------------
HTML����������������������������...
Download 



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