[Groonga-commit] droonga/fluent-plugin-droonga at 7f5cff8 [master] Report error for broken relations of zones and farms

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Feb 13 14:18:57 JST 2014


YUKI Hiroshi	2014-02-13 14:18:57 +0900 (Thu, 13 Feb 2014)

  New Revision: 7f5cff8615d6d7098e9a45427f03743983a3beb9
  https://github.com/droonga/fluent-plugin-droonga/commit/7f5cff8615d6d7098e9a45427f03743983a3beb9

  Message:
    Report error for broken relations of zones and farms

  Modified files:
    lib/droonga/catalog/base.rb
    lib/droonga/catalog/errors.rb

  Modified: lib/droonga/catalog/base.rb (+27 -1)
===================================================================
--- lib/droonga/catalog/base.rb    2014-02-13 10:59:16 +0900 (4cd61d5)
+++ lib/droonga/catalog/base.rb    2014-02-13 14:18:57 +0900 (51bd865)
@@ -162,6 +162,9 @@ module Droonga
           validate_datasets
         end
         do_validation do
+          validate_zone_relations
+        end
+        do_validation do
           validate_database_relations
         end
       end
@@ -365,6 +368,29 @@ module Droonga
         validate_parameter_type(Array, plugins, "#{name}.plugins")
       end
 
+      def validate_zone_relations
+        return unless @data["zones"].is_a?(Array)
+        return unless @data["farms"].is_a?(Hash)
+
+        farms = @data["farms"]
+        zones = @data["zones"]
+
+        all_farms = farms.keys
+        all_zones = zones.flatten
+
+        all_farms.each do |farm|
+          unless all_zones.include?(farm)
+            raise FarmNotZoned.new(farm, zones, @path)
+          end
+        end
+
+        all_zones.each do |zone|
+          unless all_farms.include?(zone)
+            raise UnknownFarmInZones.new(farm, zones, @path)
+          end
+        end
+      end
+
       def validate_database_relations
         return unless @data["farms"]
 
@@ -386,7 +412,7 @@ module Droonga
                          "partitions.#{range}[#{index}]"
                 do_validation do
                   unless partition =~ valid_farms_matcher
-                    raise UnknownFarm.new(name, partition, @path)
+                    raise UnknownFarmForPartition.new(name, partition, @path)
                   end
                   do_validation do
                     directory_name = $POSTMATCH

  Modified: lib/droonga/catalog/errors.rb (+13 -1)
===================================================================
--- lib/droonga/catalog/errors.rb    2014-02-13 10:59:16 +0900 (f83fa21)
+++ lib/droonga/catalog/errors.rb    2014-02-13 14:18:57 +0900 (f8f7db6)
@@ -67,7 +67,19 @@ module Droonga
       end
     end
 
-    class UnknownFarm < ValidationError
+    class FarmNotZoned < ValidationError
+      def initialize(name, zones, path)
+        super("The farm \"#{name}\" does not appear in zones: #{zones}", path)
+      end
+    end
+
+    class UnknownFarmInZones < ValidationError
+      def initialize(name, zones, path)
+        super("Unknown farm \"#{name}\" appears in zones: #{zones}", path)
+      end
+    end
+
+    class UnknownFarmForPartition < ValidationError
       def initialize(name, partition, path)
         super("The partition #{partition} at \"#{name}\" seems to be bound to an unknown farm.", path)
       end
-------------- next part --------------
HTML����������������������������...
Download 



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