Kouhei Sutou
null+****@clear*****
Wed Aug 31 19:28:54 JST 2016
Kouhei Sutou 2016-08-31 19:28:54 +0900 (Wed, 31 Aug 2016) New Revision: beafe282efcba1d78d4115de332fdb4be6f13a69 https://github.com/groonga/groonga/commit/beafe282efcba1d78d4115de332fdb4be6f13a69 Message: logical_table_remove: support broken column's index Modified files: plugins/sharding/logical_table_remove.rb test/command/suite/sharding/logical_table_remove/broken/column/dependent.expected test/command/suite/sharding/logical_table_remove/broken/column/dependent_force.expected test/command/suite/sharding/logical_table_remove/broken/shard_key_column/dependent_force.expected test/command/suite/sharding/logical_table_remove/broken/table_and_column/dependent_force.expected Modified: plugins/sharding/logical_table_remove.rb (+62 -23) =================================================================== --- plugins/sharding/logical_table_remove.rb 2016-08-31 19:15:36 +0900 (4854321) +++ plugins/sharding/logical_table_remove.rb 2016-08-31 19:28:54 +0900 (5f146f8) @@ -83,43 +83,82 @@ module Groonga end end + def collect_referenced_table_ids_from_column_name(column_name, + referenced_table_ids) + database = context.database + column_id = database[column_name] + database.each_raw do |id, cursor| + next if ID.builtin?(id) + next if id == column_id + + context.open_temporary(id) do |object| + if object.nil? + context.clear_error + next + end + + case object + when IndexColumn + if object.source_ids.include?(column_id) + collect_referenced_table_ids_from_index_ids([id], + referenced_table_ids) + end + end + end + end + end + + def collect_referenced_table_ids_from_column(column, + referenced_table_ids) + range = column.range + case range + when nil + context.clear_error + when Table + referenced_table_ids << range.id + collect_referenced_table_ids_from_index_ids(range.index_ids, + referenced_table_ids) + end + collect_referenced_table_ids_from_index_ids(column.index_ids, + referenced_table_ids) + end + + def collect_referenced_table_ids_from_column_names(column_names) + referenced_table_ids = [] + column_names.each do |column_name| + column = context[column_name] + if column.nil? + context.clear_error + collect_referenced_table_ids_from_column_name(column_name, + referenced_table_ids) + else + collect_referenced_table_ids_from_column(column, + referenced_table_ids) + end + end + referenced_table_ids + end + def collect_referenced_table_ids(shard, table) return [] unless @dependent - columns = nil + column_names = nil if table begin - columns = table.columns + column_names = table.columns.collect(&:name) rescue context.clear_error end end - if columns.nil? + if column_names.nil? prefix = "#{shard.table_name}." - columns = [] + column_names = [] context.database.each_name(:prefix => prefix) do |column_name| - column = context[column_name] - columns << column - context.clear_error if column.nil? + column_names << column_name end end - referenced_table_ids = [] - columns.each do |column| - next if column.nil? - range = column.range - case range - when nil - context.clear_error - when Table - referenced_table_ids << range.id - collect_referenced_table_ids_from_index_ids(range.index_ids, - referenced_table_ids) - end - collect_referenced_table_ids_from_index_ids(column.index_ids, - referenced_table_ids) - end - referenced_table_ids + collect_referenced_table_ids_from_column_names(column_names) end def remove_table(shard, table) Modified: test/command/suite/sharding/logical_table_remove/broken/column/dependent.expected (+2 -0) =================================================================== --- test/command/suite/sharding/logical_table_remove/broken/column/dependent.expected 2016-08-31 19:15:36 +0900 (9e8203f) +++ test/command/suite/sharding/logical_table_remove/broken/column/dependent.expected 2016-08-31 19:28:54 +0900 (6b561af) @@ -61,6 +61,8 @@ logical_table_remove Logs timestamp --min "2015-02-04 00:00:00" --min_border #|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000112> #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) +#|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) +#|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| [object][remove] column is broken: <Logs_20150204.path>: [object][remove] column is broken: <Logs_20150204.path>: [io][open] file size is too small: <8>(required: >= 64): <db/db.000011 dump plugin_register sharding Modified: test/command/suite/sharding/logical_table_remove/broken/column/dependent_force.expected (+2 -0) =================================================================== --- test/command/suite/sharding/logical_table_remove/broken/column/dependent_force.expected 2016-08-31 19:15:36 +0900 (833e4a7) +++ test/command/suite/sharding/logical_table_remove/broken/column/dependent_force.expected 2016-08-31 19:28:54 +0900 (35a74f0) @@ -52,6 +52,8 @@ logical_table_remove Logs timestamp --min "2015-02-04 00:00:00" --min_border #|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000112> #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) +#|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) +#|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| [object][remove] column is broken: <Logs_20150204.path>: [object][remove] column is broken: <Logs_20150204.path>: [io][open] file size is too small: <8>(required: >= 64): <db/db.000011 #|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000112> #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) Modified: test/command/suite/sharding/logical_table_remove/broken/shard_key_column/dependent_force.expected (+0 -10) =================================================================== --- test/command/suite/sharding/logical_table_remove/broken/shard_key_column/dependent_force.expected 2016-08-31 19:15:36 +0900 (dfdacc8) +++ test/command/suite/sharding/logical_table_remove/broken/shard_key_column/dependent_force.expected 2016-08-31 19:28:54 +0900 (06bf3b5) @@ -76,8 +76,6 @@ table_create Paths_20150203 TABLE_HASH_KEY|KEY_LARGE ShortText table_create Times_20150203 TABLE_PAT_KEY Time -table_create Times_20150204 TABLE_PAT_KEY Time - column_create Logs_20150203 path COLUMN_SCALAR Paths_20150203 load --table Paths_20150203 @@ -94,13 +92,5 @@ load --table Logs_20150203 [2,"/var/",1422975599.0] ] -load --table Times_20150204 -[ -["_key"], -[1422975600.0], -[1423025340.0], -[1423025400.0] -] - column_create PathTerms_20150203 index COLUMN_INDEX|WITH_POSITION Paths_20150203 _key column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp Modified: test/command/suite/sharding/logical_table_remove/broken/table_and_column/dependent_force.expected (+3 -0) =================================================================== --- test/command/suite/sharding/logical_table_remove/broken/table_and_column/dependent_force.expected 2016-08-31 19:15:36 +0900 (0082cda) +++ test/command/suite/sharding/logical_table_remove/broken/table_and_column/dependent_force.expected 2016-08-31 19:28:54 +0900 (363e114) @@ -53,6 +53,9 @@ logical_table_remove Logs timestamp --min "2015-02-04 00:00:00" --min_border #|e| grn_ctx_at: failed to open object: <272>(<Logs_20150204>):<51>(<table:no_key>) #|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000112> #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) +#|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000110> +#|e| grn_ctx_at: failed to open object: <272>(<Logs_20150204>):<51>(<table:no_key>) +#|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000112> #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| grn_ctx_at: failed to open object: <274>(<Logs_20150204.path>):<64>(<column:fix_size>) #|e| [io][open] file size is too small: <8>(required: >= 64): <db/db.0000110> -------------- next part -------------- HTML����������������������������... Download