[Groonga-commit] droonga/droonga-engine at 816585c [master] catalog-generator: fix a bug that --replicas generates invalid catalog.json

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jul 17 20:21:23 JST 2014


Kouhei Sutou	2014-07-17 20:21:23 +0900 (Thu, 17 Jul 2014)

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

  Message:
    catalog-generator: fix a bug that --replicas generates invalid catalog.json

  Modified files:
    lib/droonga/catalog_generator.rb
    test/unit/test_catalog_generator.rb

  Modified: lib/droonga/catalog_generator.rb (+25 -2)
===================================================================
--- lib/droonga/catalog_generator.rb    2014-07-17 20:19:56 +0900 (2b78dda)
+++ lib/droonga/catalog_generator.rb    2014-07-17 20:21:23 +0900 (b469e0c)
@@ -127,8 +127,7 @@ module Droonga
       end
 
       def replicas
-        return @options[:replicas] if @options[:replicas]
-        @generated_replicas ||= Replicas.new(@options)
+        @replicas ||= create_replicas
       end
 
       def to_catalog
@@ -143,6 +142,16 @@ module Droonga
       end
 
       private
+      def create_replicas
+        catalog_replicas = @options[:replicas]
+        if catalog_replicas
+          replicas = Replicas.new
+          replicas.load(catalog_replicas)
+          replicas
+        else
+          Replicas.new(@options)
+        end
+      end
     end
 
     class Replicas
@@ -156,6 +165,20 @@ module Droonga
         @n_slices   = options[:n_slices]
       end
 
+      def load(catalog_replicas)
+        dataset = Catalog::Dataset.new("temporary",
+                                       "replicas" => catalog_replicas)
+        collection_volume = dataset.replicas.first
+        slices = collection_volume.slices
+        @hosts = slices.collect do |slice|
+          slice.volume.host
+        end
+        @n_slices = slices.size
+        single_volume = slices.first.volume
+        @port = single_volume.port
+        @tag = single_volume.tag
+      end
+
       def to_catalog
         catalog_replicas = []
         @hosts.each do |host|

  Modified: test/unit/test_catalog_generator.rb (+27 -0)
===================================================================
--- test/unit/test_catalog_generator.rb    2014-07-17 20:19:56 +0900 (be8f8a1)
+++ test/unit/test_catalog_generator.rb    2014-07-17 20:21:23 +0900 (efde063)
@@ -90,4 +90,31 @@ class CatalogGeneratorTest < Test::Unit::TestCase
       assert_equal("Entries", generate["datasets"]["Droonga"]["fact"])
     end
   end
+
+  class ReplicasTest < self
+    def test_raw
+      replicas = [
+        {
+          "dimension" => "_key",
+          "slicer" => "hash",
+          "slices" => [
+            {
+              "volume" => {
+                "address" => "127.0.0.1:10031/droonga.000",
+              },
+              "weight" => 100,
+            },
+          ],
+        },
+      ]
+      @generator.add_dataset("Droonga", :replicas => replicas)
+      dataset = {
+        "nWorkers" => 4,
+        "plugins" => ["groonga", "search", "crud", "dump", "system"],
+        "schema" => {},
+        "replicas" => replicas,
+      }
+      assert_equal(dataset, generate["datasets"]["Droonga"])
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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