[Groonga-commit] droonga/fluent-plugin-droonga at 7ef4cae [master] Validate relations of datasets and farm

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Wed Feb 12 17:18:57 JST 2014


YUKI Hiroshi	2014-02-12 17:18:57 +0900 (Wed, 12 Feb 2014)

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

  Message:
    Validate relations of datasets and farm

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

  Modified: lib/droonga/catalog/base.rb (+29 -0)
===================================================================
--- lib/droonga/catalog/base.rb    2014-02-12 17:04:09 +0900 (0c1fea0)
+++ lib/droonga/catalog/base.rb    2014-02-12 17:18:57 +0900 (a73436b)
@@ -61,6 +61,12 @@ module Droonga
       end
     end
 
+    class UnknownFarm < ValidationError
+      def initialize(name, partition, path)
+        super("The partition #{partition} at \"#{name}\" seems to be bound to an unknown farm.", path)
+      end
+    end
+
     class Base
       attr_reader :path, :base_path
       def initialize(data, path)
@@ -191,6 +197,7 @@ module Droonga
         validate_zones
         validate_farms
         validate_datasets
+        validate_database_relations
       end
 
       def validate_parameter_type(expected, value, name)
@@ -315,6 +322,28 @@ module Droonga
           validate_parameter_type(String, value, "#{name}[#{index}]")
         end
       end
+
+      def validate_database_relations
+        farm_names = @data["farms"].keys.collect do |name|
+          Regexp.escape(name)
+        end
+        valid_farms_matcher = Regexp.new("^(#{farm_names.join("|")})\.")
+
+        datasets.each do |dataset_name, dataset|
+          ring = dataset["ring"]
+          ring.each do |ring_key, part|
+            part["partitions"].each do |range, partitions|
+              partitions.each_with_index do |partition, index|
+                unless partition =~ valid_farms_matcher
+                  name = "datasets.#{dataset_name}.ring.#{ring_key}." +
+                           "partitions.#{range}[#{index}]"
+                  raise UnknownFarm.new(name, partition, @path)
+                end
+              end
+            end
+          end
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る