[Groonga-commit] groonga/groonga at 8e8c3e8 [master] grndb: fix a bug that index column isn't recovered with --force-lock-clear

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jan 11 09:34:34 JST 2018


Kouhei Sutou	2018-01-11 09:34:34 +0900 (Thu, 11 Jan 2018)

  New Revision: 8e8c3e83fc3a0cd114c248aa3e411ac6725ff44a
  https://github.com/groonga/groonga/commit/8e8c3e83fc3a0cd114c248aa3e411ac6725ff44a

  Message:
    grndb: fix a bug that index column isn't recovered with --force-lock-clear

  Modified files:
    lib/mrb/scripts/command_line/grndb.rb
    test/command_line/helper.rb
    test/command_line/helper/command_runner.rb
    test/command_line/suite/grndb/test_recover.rb

  Modified: lib/mrb/scripts/command_line/grndb.rb (+2 -0)
===================================================================
--- lib/mrb/scripts/command_line/grndb.rb    2018-01-11 09:18:38 +0900 (d72617903)
+++ lib/mrb/scripts/command_line/grndb.rb    2018-01-11 09:34:34 +0900 (5236144a1)
@@ -496,6 +496,8 @@ module Groonga
           end
           @database.each do |object|
             case object
+            when IndexColumn
+              # Ignore. It'll be recovered later.
             when Column, Table
               next unless object.locked?
               object.clear_lock

  Modified: test/command_line/helper.rb (+1 -0)
===================================================================
--- test/command_line/helper.rb    2018-01-11 09:18:38 +0900 (b6e674703)
+++ test/command_line/helper.rb    2018-01-11 09:34:34 +0900 (30622c95d)
@@ -1,5 +1,6 @@
 require "fileutils"
 require "json"
+require "shellwords"
 require "tempfile"
 
 require "test-unit"

  Modified: test/command_line/helper/command_runner.rb (+10 -0)
===================================================================
--- test/command_line/helper/command_runner.rb    2018-01-11 09:18:38 +0900 (a0162573b)
+++ test/command_line/helper/command_runner.rb    2018-01-11 09:34:34 +0900 (61ffd457d)
@@ -60,6 +60,16 @@ module CommandRunner
     run_command(*command_line, &block)
   end
 
+  def groonga_select(*select_arguments)
+    result = groonga("select", *select_arguments)
+    select_result = JSON.parse(result.output)
+    header, body = select_result
+    unless header[0].zero?
+      raise "failed to run select: #{select_arguments.join(" ")}: #{PP.pp(select_result, "")}"
+    end
+    body
+  end
+
   def grndb(command, *arguments)
     command_line = [
       grndb_path,

  Modified: test/command_line/suite/grndb/test_recover.rb (+37 -0)
===================================================================
--- test/command_line/suite/grndb/test_recover.rb    2018-01-11 09:18:38 +0900 (ed2185f34)
+++ test/command_line/suite/grndb/test_recover.rb    2018-01-11 09:34:34 +0900 (faf67094f)
@@ -55,10 +55,22 @@ object corrupt: <[db][recover] column may be broken: <Users.age>: please truncat
     groonga("table_create", "Ages", "TABLE_PAT_KEY", "UInt8")
     groonga("column_create", "Ages", "users_age", "COLUMN_INDEX", "Users", "age")
 
+    groonga("load",
+            "--table", "Users",
+            "--values",
+            Shellwords.escape(JSON.generate([{"_key" => "alice", "age" => 29}])))
+    groonga("truncate", "Ages")
     groonga("lock_acquire", "Ages.users_age")
+    select_result = groonga_select("Users", "--query", "age:29")
+    n_hits, _columns, *_records = select_result[0]
+    assert_equal([0], n_hits)
 
     result = grndb("recover")
     assert_equal("", result.error_output)
+
+    select_result = groonga_select("Users", "--query", "age:29")
+    n_hits, _columns, *_records = select_result[0]
+    assert_equal([1], n_hits)
   end
 
   def test_force_clear_locked_database
@@ -82,6 +94,31 @@ object corrupt: <[db][recover] column may be broken: <Users.age>: please truncat
     assert_equal("", result.error_output)
   end
 
+  def test_force_clear_locked_index_column
+    groonga("table_create", "Users", "TABLE_HASH_KEY", "ShortText")
+    groonga("column_create", "Users", "age", "COLUMN_SCALAR", "UInt8")
+
+    groonga("table_create", "Ages", "TABLE_PAT_KEY", "UInt8")
+    groonga("column_create", "Ages", "users_age", "COLUMN_INDEX", "Users", "age")
+
+    groonga("load",
+            "--table", "Users",
+            "--values",
+            Shellwords.escape(JSON.generate([{"_key" => "alice", "age" => 29}])))
+    groonga("truncate", "Ages")
+    groonga("lock_acquire", "Ages.users_age")
+    select_result = groonga_select("Users", "--query", "age:29")
+    n_hits, _columns, *_records = select_result[0]
+    assert_equal([0], n_hits)
+
+    result = grndb("recover", "--force-lock-clear")
+    assert_equal("", result.error_output)
+
+    select_result = groonga_select("Users", "--query", "age:29")
+    n_hits, _columns, *_records = select_result[0]
+    assert_equal([1], n_hits)
+  end
+
   def test_empty_file
     groonga("table_create", "Users", "TABLE_HASH_KEY", "ShortText")
     _id, _name, path, *_ = JSON.parse(groonga("table_list").output)[1][1]
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180111/98f73c63/attachment-0001.htm 



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