[Groonga-commit] droonga/droonga-engine at 099f2c8 [master] Restructure classes around Volume.

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Dec 5 15:11:04 JST 2014


YUKI Hiroshi	2014-12-05 15:11:04 +0900 (Fri, 05 Dec 2014)

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

  Merged e0f9f34: Merge pull request #30 from piroor/replicas-in-a-branch

  Message:
    Restructure classes around Volume.
    
    Now, there are 3 type volumes:
    
     1. SingleVolume, is a physical computer.
     2. SlicesVolume, is a collection of <Slice>s.
     2. ReplicasVolume, is a collection of volumes.
    
    A Slice must have one of volumes.
    For example:
    
      datasets:{
        Default:{
         replicas:[
           {
             slices:[
               { volume: { address:... } },
               {
                 volume: {
                   replicas: [
                     { address: ... },
                     { address: ... }
                   ]
                 }
               },
               {
                 volume: {
                   slices: [
                     { volume: { address:... } },
                     { volume: { address:... } },
                     {
                       volume: {
                         replicas: [
                           { address:... },
                           { address:... }
                         ]
                       }
                    }
                  ]
                }
              }
            ]
          }
        ]
      }}
    
    It will be parsed as:
    
      ReplicasVolume:[
        Slices:[
          Slice:SingleVolume,
          Slice:ReplicasVolume:[
            SingleVolume,
            SingleVolume
          ],
          Slice:SlicesVolume:[
            Slice:SingleVolume,
            Slice:SingleVolume,
            Slice:ReplicasVolume:[
              SingleVolume,
              SingleVolume
            ]
          ]
        ]
      ]
    
    Note, currently the top level ReplicasVolume is the Dataset itself.
    It is dangerous, so we should change the structure like:
    
      datasets:{
        Default:{
          volume:{
            replicas:[...]
          }
        }
      }
    
    This breaks backward compatibility - v2 catalogs have to be migrated when they are parsed.
    So, after the change, catalog's spec version must be incremented to 3.

  Removed files:
    lib/droonga/catalog/replica.rb
  Modified files:
    lib/droonga/catalog/dataset.rb
    lib/droonga/catalog/slice.rb
    lib/droonga/catalog/volume.rb
    test/unit/catalog/test_dataset.rb
    test/unit/catalog/test_slice.rb
  Renamed files:
    lib/droonga/catalog/replicas_volume.rb
      (from lib/droonga/catalog/replicas.rb)
    lib/droonga/catalog/slices_volume.rb
      (from lib/droonga/catalog/slices.rb)
    test/unit/catalog/test_replicas_volume.rb
      (from test/unit/catalog/test_replicas.rb)
    test/unit/catalog/test_slices_volume.rb
      (from test/unit/catalog/test_slices.rb)

  Modified: lib/droonga/catalog/dataset.rb (+6 -2)
===================================================================
--- lib/droonga/catalog/dataset.rb    2014-12-05 14:34:23 +0900 (2d8b0e9)
+++ lib/droonga/catalog/dataset.rb    2014-12-05 15:11:04 +0900 (f3a9063)
@@ -14,7 +14,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require "droonga/catalog/schema"
-require "droonga/catalog/replicas"
+require "droonga/catalog/volume"
 
 module Droonga
   module Catalog
@@ -55,8 +55,12 @@ module Droonga
         @data["nWorkers"] || 0
       end
 
+      #XXX Currently, dataset has a property named "replicas" so
+      #    can be parsed as a ReplicasVolume.
+      #    We must introduce a new property "volume" to provide
+      #    ReplicasVolume safely.
       def replicas
-        @replicas ||= Replicas.create(self, @data["replicas"])
+        @replicas ||= ReplicasVolume.new(self, @data)
       end
 
       def all_nodes

  Deleted: lib/droonga/catalog/replica.rb (+0 -33) 100644
===================================================================
--- lib/droonga/catalog/replica.rb    2014-12-05 14:34:23 +0900 (a97270a)
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright (C) 2014 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
-
-require "droonga/catalog/slices"
-
-module Droonga
-  module Catalog
-    class Replica < Slices
-      def volume
-        return nil unles****@data*****?("volume")
-        @volume ||= Volume.create(@dataset, @data["volume"])
-      end
-
-      private
-      def collect_all_nodes
-        return volume.all_nodes if volume
-        super
-      end
-    end
-  end
-end

  Renamed: lib/droonga/catalog/replicas_volume.rb (+13 -14) 83%
===================================================================
--- lib/droonga/catalog/replicas.rb    2014-12-05 14:34:23 +0900 (da1d818)
+++ lib/droonga/catalog/replicas_volume.rb    2014-12-05 15:11:04 +0900 (46dc0b7)
@@ -13,25 +13,24 @@
 # 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 "droonga/catalog/volume"
-
 module Droonga
   module Catalog
-    class Replicas
-      class << self
-        def create(dataset, raw_replicas)
-          replicas = raw_replicas.collect do |raw_replica|
-            Replica.new(dataset, raw_replica)
-          end
-          new(dataset, replicas)
-        end
-      end
-
+    class ReplicasVolume
       include Enumerable
 
-      def initialize(dataset, replicas)
+      def initialize(dataset, data)
         @dataset = dataset
-        @replicas = replicas
+
+        if data.is_a?(Hash) and data.key?("replicas")
+          @data     = data
+          @replicas = @data["replicas"].collect do |raw_volume|
+            Catalog::Volume.create(dataset, raw_volume)
+          end
+        elsif data.is_a?(Array)
+          @replicas = data
+        else
+          raise ArgumentError.new(data)
+        end
       end
 
       def each(&block)

  Modified: lib/droonga/catalog/slice.rb (+14 -13)
===================================================================
--- lib/droonga/catalog/slice.rb    2014-12-05 14:34:23 +0900 (59ab1ef)
+++ lib/droonga/catalog/slice.rb    2014-12-05 15:11:04 +0900 (a4a0ad0)
@@ -34,27 +34,28 @@ module Droonga
       end
 
       def volume
-        return nil unles****@data*****?("volume")
-        @volume ||= Volume.create(@dataset, @data["volume"])
+        @volume ||= Catalog::Volume.create(@dataset, @data["volume"])
       end
 
       def replicas
-        return nil unles****@data*****?("replicas")
-        @replicas ||= Replicas.create(@dataset, @data["replicas"])
-      end
-
-      def all_nodes
-        @all_nodes ||= collect_all_nodes
+        if volume.is_a?(ReplicasVolume)
+          volume.replicas
+        else
+          nil
+        end
       end
 
-      private
-      def collect_all_nodes
-        if volume
-          volume.all_nodes
+      def slices
+        if volume.is_a?(SlicesVolume)
+          volume.slices
         else
-          replicas.all_nodes
+          nil
         end
       end
+
+      def all_nodes
+        @all_nodes ||= volume.all_nodes
+      end
     end
   end
 end

  Renamed: lib/droonga/catalog/slices_volume.rb (+2 -5) 95%
===================================================================
--- lib/droonga/catalog/slices.rb    2014-12-05 14:34:23 +0900 (8a7dbac)
+++ lib/droonga/catalog/slices_volume.rb    2014-12-05 15:11:04 +0900 (628446e)
@@ -20,13 +20,11 @@ require "droonga/catalog/slice"
 
 module Droonga
   module Catalog
-    class Slices
+    class SlicesVolume
       def initialize(dataset, data)
         @dataset = dataset
         @data = data
-        if slices and ratio_scaled_slicer?
-          compute_continuum
-        end
+        compute_continuum if ratio_scaled_slicer?
       end
 
       def dimension
@@ -38,7 +36,6 @@ module Droonga
       end
 
       def slices
-        return nil unles****@data*****?("slices")
         @slices ||= create_slices
       end
 

  Modified: lib/droonga/catalog/volume.rb (+19 -2)
===================================================================
--- lib/droonga/catalog/volume.rb    2014-12-05 14:34:23 +0900 (9262344)
+++ lib/droonga/catalog/volume.rb    2014-12-05 15:11:04 +0900 (0979bcf)
@@ -14,17 +14,34 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require "droonga/catalog/single_volume"
-require "droonga/catalog/replica"
+require "droonga/catalog/slices_volume"
+require "droonga/catalog/replicas_volume"
 
 module Droonga
   module Catalog
     module Volume
+      class UnknownTypeVolume < ArgumentError
+        attr_reader :raw_volume
+
+        def initialize(raw_volume)
+          @raw_volume = raw_volume
+        end
+
+        def message
+          @raw_volume.inspect
+        end
+      end
+
       class << self
         def create(dataset, raw_volume)
           if raw_volume.key?("address")
             SingleVolume.new(raw_volume)
+          elsif raw_volume.key?("slices")
+            SlicesVolume.new(dataset, raw_volume)
+          elsif raw_volume.key?("replicas")
+            ReplicasVolume.new(dataset, raw_volume)
           else
-            Replica.new(dataset, raw_volume)
+            raise UnknownTypeVolume.new(raw_volume)
           end
         end
       end

  Modified: test/unit/catalog/test_dataset.rb (+1 -1)
===================================================================
--- test/unit/catalog/test_dataset.rb    2014-12-05 14:34:23 +0900 (e49f1e7)
+++ test/unit/catalog/test_dataset.rb    2014-12-05 15:11:04 +0900 (756a1cb)
@@ -97,7 +97,7 @@ class CatalogDatasetTest < Test::Unit::TestCase
         "replicas" => [],
       }
       dataset = create_dataset(data)
-      assert_equal(Droonga::Catalog::Replicas.new(nil, []),
+      assert_equal(Droonga::Catalog::ReplicasVolume.new(nil, []),
                    dataset.replicas)
     end
   end

  Renamed: test/unit/catalog/test_replicas_volume.rb (+4 -3) 92%
===================================================================
--- test/unit/catalog/test_replicas.rb    2014-12-05 14:34:23 +0900 (75000fe)
+++ test/unit/catalog/test_replicas_volume.rb    2014-12-05 15:11:04 +0900 (a2db6e3)
@@ -13,12 +13,13 @@
 # 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 "droonga/catalog/replicas"
+require "droonga/catalog/volume"
+require "droonga/catalog/replicas_volume"
 
 class CatalogReplicasTest < Test::Unit::TestCase
   private
-  def create_replicas(replicas)
-    Droonga::Catalog::Replicas.new(nil, replicas)
+  def create_replicas(data_or_replicas)
+    Droonga::Catalog::ReplicasVolume.new(nil, data_or_replicas)
   end
 
   class SelectTest < self

  Modified: test/unit/catalog/test_slice.rb (+1 -5)
===================================================================
--- test/unit/catalog/test_slice.rb    2014-12-05 14:34:23 +0900 (e3ebedd)
+++ test/unit/catalog/test_slice.rb    2014-12-05 15:11:04 +0900 (9cf43a6)
@@ -106,11 +106,7 @@ class CatalogSliceTest < Test::Unit::TestCase
       data = {
         "volume" => {
           "replicas" => [
-            {
-              "volume" => {
-                "address" => "127.0.0.1:10047/volume.000",
-              },
-            },
+            { "address" => "127.0.0.1:10047/volume.000" },
           ],
         },
       }

  Renamed: test/unit/catalog/test_slices_volume.rb (+6 -5) 92%
===================================================================
--- test/unit/catalog/test_slices.rb    2014-12-05 14:34:23 +0900 (1df66a9)
+++ test/unit/catalog/test_slices_volume.rb    2014-12-05 15:11:04 +0900 (e7f51f0)
@@ -14,6 +14,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require "droonga/catalog/dataset"
+require "droonga/catalog/slices_volume"
 
 class CatalogSingleVolumeTest < Test::Unit::TestCase
   def create_slices(data)
@@ -22,7 +23,7 @@ class CatalogSingleVolumeTest < Test::Unit::TestCase
       },
     }
     dataset = Droonga::Catalog::Dataset.new("DatasetName", minimum_dataset_data)
-    Droonga::Catalog::Slices.new(dataset, data)
+    Droonga::Catalog::SlicesVolume.new(dataset, data)
   end
 
   class DimensionTest < self
@@ -122,16 +123,16 @@ class CatalogSingleVolumeTest < Test::Unit::TestCase
           {
             "volume" => {
               "replicas" => [
-                { "volume" => { "address" => "127.0.0.1:23003/droonga.000" } },
-                { "volume" => { "address" => "127.0.0.1:23003/droonga.001" } },
+                { "address" => "127.0.0.1:23003/droonga.000" },
+                { "address" => "127.0.0.1:23003/droonga.001" },
               ],
             },
           },
           {
             "volume" => {
               "replicas" => [
-                { "volume" => { "address" => "127.0.0.1:23004/droonga.100" } },
-                { "volume" => { "address" => "127.0.0.1:23004/droonga.101" } },
+                { "address" => "127.0.0.1:23004/droonga.100" },
+                { "address" => "127.0.0.1:23004/droonga.101" },
               ],
             },
           },
-------------- next part --------------
HTML����������������������������...
下载 



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