[Groonga-commit] groonga/groonga at 778806a [master] logical_table_remove: add "dependent" option

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Mar 18 12:37:56 JST 2016


Kouhei Sutou	2016-03-18 12:37:56 +0900 (Fri, 18 Mar 2016)

  New Revision: 778806a0ff7a6c83d59dd71e88d47e9b9c067d76
  https://github.com/groonga/groonga/commit/778806a0ff7a6c83d59dd71e88d47e9b9c067d76

  Message:
    logical_table_remove: add "dependent" option
    
    You can also remove related tables with the option.

  Added files:
    test/command/suite/sharding/logical_table_remove/referenced/default.expected
    test/command/suite/sharding/logical_table_remove/referenced/default.test
    test/command/suite/sharding/logical_table_remove/referenced/dependent.expected
    test/command/suite/sharding/logical_table_remove/referenced/dependent.test
  Modified files:
    plugins/sharding/logical_enumerator.rb
    plugins/sharding/logical_table_remove.rb

  Modified: plugins/sharding/logical_enumerator.rb (+8 -0)
===================================================================
--- plugins/sharding/logical_enumerator.rb    2016-03-18 12:35:46 +0900 (d08bfaa)
+++ plugins/sharding/logical_enumerator.rb    2016-03-18 12:37:56 +0900 (16a84d3)
@@ -143,6 +143,14 @@ module Groonga
           @month = month
           @day = day
         end
+
+        def to_suffix
+          if****@day*****?
+            "_%02d%02d" % [@year, @month]
+          else
+            "_%02d%02d%02d" % [@year, @month, @day]
+          end
+        end
       end
 
       class DayShardRange

  Modified: plugins/sharding/logical_table_remove.rb (+36 -6)
===================================================================
--- plugins/sharding/logical_table_remove.rb    2016-03-18 12:35:46 +0900 (8aed3ef)
+++ plugins/sharding/logical_table_remove.rb    2016-03-18 12:37:56 +0900 (b29437e)
@@ -9,20 +9,23 @@ module Groonga
                  "min_border",
                  "max",
                  "max_border",
+                 "dependent",
                ])
 
       def run_body(input)
+        @dependent = (input[:dependent] == "yes")
+
         enumerator = LogicalEnumerator.new("logical_table_remove", input)
 
         success = true
         enumerator.each do |shard, shard_range|
-          remove_table(shard, shard_range, enumerator.target_range)
+          remove_shard(shard, shard_range, enumerator.target_range)
         end
         writer.write(success)
       end
 
       private
-      def remove_table(shard, shard_range, target_range)
+      def remove_shard(shard, shard_range, target_range)
         cover_type = target_range.cover_type(shard_range)
         return if cover_type == :none
 
@@ -40,22 +43,49 @@ module Groonga
 
         case cover_type
         when :all
-          table.remove
+          remove_table(shard)
         when :partial_min
           remove_records(table) do |expression|
             expression_builder.build_partial_min(expression)
           end
-          table.remove if table.empty?
+          remove_table(shard) if table.empty?
         when :partial_max
           remove_records(table) do |expression|
             expression_builder.build_partial_max(expression)
           end
-          table.remove if table.empty?
+          remove_table(shard) if table.empty?
         when :partial_min_and_max
           remove_records(table) do |expression|
             expression_builder.build_partial_min_and_max(expression)
           end
-          table.remove if table.empty?
+          remove_table(shard) if table.empty?
+        end
+      end
+
+      def remove_table(shard)
+        table = shard.table
+        shard_suffix = shard.range_data.to_suffix
+
+        referenced_table_ids = []
+        if @dependent
+          table.columns.each do |column|
+            range = column.range
+            referenced_table_ids << range.id if range.is_a?(Table)
+            column.indexes.each do |index_info|
+              referenced_table_ids << index_info.index.domain.id
+            end
+          end
+        end
+
+        table.remove(:dependent => @dependent)
+
+        context = Groonga::Context.instance
+        referenced_table_ids.each do |referenced_table_id|
+          referenced_table = context[referenced_table_id]
+          next if referenced_table.nil?
+          if referenced_table.name.end_with?(shard_suffix)
+            referenced_table.remove(:dependent => @dependent)
+          end
         end
       end
 

  Added: test/command/suite/sharding/logical_table_remove/referenced/default.expected (+92 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_table_remove/referenced/default.expected    2016-03-18 12:37:56 +0900 (b981a3a)
@@ -0,0 +1,92 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20150203 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+[[0,0.0,0.0],true]
+table_create Times_20150203 TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp
+[[0,0.0,0.0],true]
+table_create NotRelated_20150204 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+table_create Paths_20150204 TABLE_HASH_KEY|KEY_LARGE ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20150204 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20150204 path COLUMN_SCALAR Paths_20150204
+[[0,0.0,0.0],true]
+table_create Times_20150204 TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp
+[[0,0.0,0.0],true]
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-03 23:59:59", "path": "/var/"}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-04 13:49:00", "path": "/root/"},
+{"timestamp": "2015-02-04 13:50:00", "path": "/etc/aliases"}
+]
+[[0,0.0,0.0],3]
+logical_table_remove Logs timestamp   --min "2015-02-04 00:00:00"   --min_border "include"
+[[0,0.0,0.0],true]
+dump
+plugin_register sharding
+
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+
+table_create Times_20150203 TABLE_PAT_KEY Time
+
+table_create NotRelated_20150204 TABLE_NO_KEY
+
+table_create Paths_20150204 TABLE_HASH_KEY|KEY_LARGE ShortText
+
+table_create Times_20150204 TABLE_PAT_KEY Time
+
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+
+load --table Paths_20150203
+[
+["_key"],
+["/tmp/log"],
+["/var/"]
+]
+
+load --table Logs_20150203
+[
+["_id","path","timestamp"],
+[1,"/tmp/log",1422935340.0],
+[2,"/var/",1422975599.0]
+]
+
+load --table Paths_20150204
+[
+["_key"],
+["/tmp/log"],
+["/root/"],
+["/etc/aliases"]
+]
+
+load --table Times_20150204
+[
+["_key"],
+[1422975600.0],
+[1423025340.0],
+[1423025400.0]
+]
+
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp

  Added: test/command/suite/sharding/logical_table_remove/referenced/default.test (+38 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_table_remove/referenced/default.test    2016-03-18 12:37:56 +0900 (7dbbb96)
@@ -0,0 +1,38 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+table_create Times_20150203 TABLE_PAT_KEY Time
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp
+
+table_create NotRelated_20150204 TABLE_NO_KEY
+
+table_create Paths_20150204 TABLE_HASH_KEY|KEY_LARGE ShortText
+table_create Logs_20150204 TABLE_NO_KEY
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+column_create Logs_20150204 path COLUMN_SCALAR Paths_20150204
+table_create Times_20150204 TABLE_PAT_KEY Time
+column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp
+
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-03 23:59:59", "path": "/var/"}
+]
+
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-04 13:49:00", "path": "/root/"},
+{"timestamp": "2015-02-04 13:50:00", "path": "/etc/aliases"}
+]
+
+logical_table_remove Logs timestamp \
+  --min "2015-02-04 00:00:00" \
+  --min_border "include"
+
+dump

  Added: test/command/suite/sharding/logical_table_remove/referenced/dependent.expected (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_table_remove/referenced/dependent.expected    2016-03-18 12:37:56 +0900 (1c44d4f)
@@ -0,0 +1,72 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20150203 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+[[0,0.0,0.0],true]
+table_create Times_20150203 TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp
+[[0,0.0,0.0],true]
+table_create NotRelated_20150204 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+table_create Paths_20150204 TABLE_HASH_KEY|KEY_LARGE ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20150204 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20150204 path COLUMN_SCALAR Paths_20150204
+[[0,0.0,0.0],true]
+table_create Times_20150204 TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp
+[[0,0.0,0.0],true]
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-03 23:59:59", "path": "/var/"}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-04 13:49:00", "path": "/root/"},
+{"timestamp": "2015-02-04 13:50:00", "path": "/etc/aliases"}
+]
+[[0,0.0,0.0],3]
+logical_table_remove Logs timestamp   --min "2015-02-04 00:00:00"   --min_border "include"   --dependent yes
+[[0,0.0,0.0],true]
+dump
+plugin_register sharding
+
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+
+table_create Times_20150203 TABLE_PAT_KEY Time
+
+table_create NotRelated_20150204 TABLE_NO_KEY
+
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+
+load --table Paths_20150203
+[
+["_key"],
+["/tmp/log"],
+["/var/"]
+]
+
+load --table Logs_20150203
+[
+["_id","path","timestamp"],
+[1,"/tmp/log",1422935340.0],
+[2,"/var/",1422975599.0]
+]
+
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp

  Added: test/command/suite/sharding/logical_table_remove/referenced/dependent.test (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_table_remove/referenced/dependent.test    2016-03-18 12:37:56 +0900 (8f3c082)
@@ -0,0 +1,39 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203
+table_create Times_20150203 TABLE_PAT_KEY Time
+column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp
+
+table_create NotRelated_20150204 TABLE_NO_KEY
+
+table_create Paths_20150204 TABLE_HASH_KEY|KEY_LARGE ShortText
+table_create Logs_20150204 TABLE_NO_KEY
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+column_create Logs_20150204 path COLUMN_SCALAR Paths_20150204
+table_create Times_20150204 TABLE_PAT_KEY Time
+column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp
+
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-03 23:59:59", "path": "/var/"}
+]
+
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "path": "/tmp/log"},
+{"timestamp": "2015-02-04 13:49:00", "path": "/root/"},
+{"timestamp": "2015-02-04 13:50:00", "path": "/etc/aliases"}
+]
+
+logical_table_remove Logs timestamp \
+  --min "2015-02-04 00:00:00" \
+  --min_border "include" \
+  --dependent yes
+
+dump
-------------- next part --------------
HTML����������������������������...
Descargar 



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