[Groonga-commit] droonga/droonga-engine at 8556050 [master] Output difference of updated new state for logs

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Apr 23 10:17:35 JST 2015


YUKI Hiroshi	2015-04-23 10:17:35 +0900 (Thu, 23 Apr 2015)

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

  Message:
    Output difference of updated new state for logs

  Added files:
    lib/droonga/differ.rb
  Modified files:
    lib/droonga/cluster.rb
    lib/droonga/command/droonga_engine.rb

  Modified: lib/droonga/cluster.rb (+3 -1)
===================================================================
--- lib/droonga/cluster.rb    2015-04-23 10:05:17 +0900 (b70b812)
+++ lib/droonga/cluster.rb    2015-04-23 10:17:35 +0900 (6b0c243)
@@ -18,6 +18,7 @@ require "droonga/changable"
 require "droonga/path"
 require "droonga/file_observer"
 require "droonga/engine_node"
+require "droonga/differ"
 
 module Droonga
   class Cluster
@@ -122,7 +123,8 @@ module Droonga
       else
         logger.info("cluster state changed",
                     :before => old_state,
-                    :after  => @state)
+                    :after  => @state,
+                    :diff   => Differ.diff(old_state, @state))
         clear_cache
         engine_nodes.each(&:resume)
         on_change

  Modified: lib/droonga/command/droonga_engine.rb (+5 -1)
===================================================================
--- lib/droonga/command/droonga_engine.rb    2015-04-23 10:05:17 +0900 (e55a9a7)
+++ lib/droonga/command/droonga_engine.rb    2015-04-23 10:17:35 +0900 (0b82abf)
@@ -32,6 +32,7 @@ require "droonga/serf"
 require "droonga/cluster"
 require "droonga/file_observer"
 require "droonga/process_supervisor"
+require "droonga/differ"
 
 module Droonga
   module Command
@@ -621,7 +622,10 @@ module Droonga
               my_previous_state = previous_state[my_name].dup
               my_previous_state.delete("internal_name")
               if my_new_state != my_previous_state
-                logger.info("restart by updated cluster-state.json")
+                logger.info("restart by updated cluster-state.json",
+                            :previous => my_previous_state,
+                            :new      => my_new_state,
+                            :diff     => Differ.diff(my_previous_state, my_new_state))
                 restart_graceful
               end
             end

  Added: lib/droonga/differ.rb (+47 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/differ.rb    2015-04-23 10:17:35 +0900 (ede4b6c)
@@ -0,0 +1,47 @@
+# Copyright (C) 2015 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+module Droonga
+  module Differ
+    class << self
+      def diff(a, b)
+        case a
+        when Hash
+          difference = {}
+          (a.keys + b.keys).uniq.each do |key|
+            unless a[key] == b[key]
+              difference[key] = diff(a[key], b[key])
+            end
+          end
+          difference
+        when Array
+          difference = {}
+          [a.size, b.size].max.times do |index|
+            unless a[index] == b[index]
+              difference[index] = diff(a[index], b[index])
+            end
+          end
+          difference
+        else
+          if a == b
+            nil
+          else
+            "#{a.inspect} <=> #{b.inspect}"
+          end
+        end
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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