[Groonga-commit] droonga/droonga-engine at fcf7f91 [master] Detect role of myself based on serf tags file

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 21 14:17:09 JST 2015


YUKI Hiroshi	2015-04-21 14:17:09 +0900 (Tue, 21 Apr 2015)

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

  Message:
    Detect role of myself based on serf tags file

  Modified files:
    lib/droonga/command/remote.rb
    lib/droonga/node_role.rb
    lib/droonga/serf.rb

  Modified: lib/droonga/command/remote.rb (+0 -2)
===================================================================
--- lib/droonga/command/remote.rb    2015-04-21 14:16:40 +0900 (fccd384)
+++ lib/droonga/command/remote.rb    2015-04-21 14:17:09 +0900 (f0443bf)
@@ -18,7 +18,6 @@ require "json"
 require "droonga/path"
 require "droonga/serf"
 require "droonga/node_name"
-require "droonga/node_role"
 require "droonga/catalog/generator"
 require "droonga/catalog/modifier"
 require "droonga/catalog/fetcher"
@@ -119,7 +118,6 @@ module Droonga
         def process
           log("old role: #{@serf.role}")
           @serf.role = @params["role"]
-          NodeRole.mine =****@serf*****
           log("new role: #{@serf.role}")
         end
       end

  Modified: lib/droonga/node_role.rb (+11 -9)
===================================================================
--- lib/droonga/node_role.rb    2015-04-21 14:16:40 +0900 (6af0985)
+++ lib/droonga/node_role.rb    2015-04-21 14:17:09 +0900 (ca0ae2c)
@@ -13,6 +13,10 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "json"
+
+require "droonga/path"
+
 module Droonga
   class NodeRole
     SERVICE_PROVIDER   = "service-provider"
@@ -31,16 +35,14 @@ module Droonga
       end
 
       def mine
-        if @mine
-          @mine.to_s
-        else
-          SERVICE_PROVIDER
+        if Path.serf_tags_file.exist?
+          tags = Path.serf_tags_file.read
+          tags = JSON.parse(tags)
+          return tags["role"] if tags["role"]
         end
-      end
-
-      def mine=(new_role)
-        @mine = new(new_role)
-        @mine.to_s
+        SERVICE_PROVIDER
+      rescue Errno::ENOENT, JSON::ParserError
+        SERVICE_PROVIDER
       end
     end
 

  Modified: lib/droonga/serf.rb (+1 -3)
===================================================================
--- lib/droonga/serf.rb    2015-04-21 14:16:40 +0900 (a9e7c8d)
+++ lib/droonga/serf.rb    2015-04-21 14:17:09 +0900 (33e2932)
@@ -63,9 +63,7 @@ module Droonga
     def initialize_tags
       set_tag("type", "engine")
       set_tag("cluster_id", cluster_id)
-      current_role = role
-      set_tag("role", current_role)
-      NodeRole.mine = current_role
+      set_tag("role", role)
     end
 
     def leave
-------------- next part --------------
HTML����������������������������...
Download 



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