[Groonga-commit] pgroonga/pgroonga at 54e356a [master] check: support auto recover

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 4 23:15:06 JST 2017


Kouhei Sutou	2017-01-04 23:15:06 +0900 (Wed, 04 Jan 2017)

  New Revision: 54e356a938cf23ae3e57f0429460cfdb6cb978ba
  https://github.com/pgroonga/pgroonga/commit/54e356a938cf23ae3e57f0429460cfdb6cb978ba

  Message:
    check: support auto recover

  Modified files:
    src/pgroonga-check.c
    test/helpers/sandbox.rb
    test/test-pgroonga-check.rb

  Modified: src/pgroonga-check.c (+8 -0)
===================================================================
--- src/pgroonga-check.c    2017-01-04 22:48:44 +0900 (cfd4d65)
+++ src/pgroonga-check.c    2017-01-04 23:15:06 +0900 (94e0c21)
@@ -93,6 +93,14 @@ PGrnCheckDatabaseDirectory(grn_ctx *ctx, const char *databaseDirectoryPath)
 		return;
 	}
 
+	grn_db_recover(ctx, db);
+	if (ctx->rc != GRN_SUCCESS)
+	{
+		grn_obj_close(ctx, db);
+		PGrnRemoveAllRelatedFiles(databaseDirectoryPath);
+		return;
+	}
+
 	grn_obj_close(ctx, db);
 }
 

  Modified: test/helpers/sandbox.rb (+9 -0)
===================================================================
--- test/helpers/sandbox.rb    2017-01-04 22:48:44 +0900 (d35640e)
+++ test/helpers/sandbox.rb    2017-01-04 23:15:06 +0900 (95e430c)
@@ -1,4 +1,5 @@
 require "fileutils"
+require "json"
 require "socket"
 require "stringio"
 
@@ -88,6 +89,14 @@ module Helpers
       psql(@test_db_name, sql)
     end
 
+    def groonga(*command_line)
+      pgrn = Dir.glob("#{@db_dir}/base/*/pgrn").first
+      output, _ = run_command("groonga",
+                              pgrn,
+                              *command_line)
+      JSON.parse(output)
+    end
+
     def start_postgres
       @postgres_is_running = false
       run_command("pg_ctl", "start",

  Modified: test/test-pgroonga-check.rb (+32 -0)
===================================================================
--- test/test-pgroonga-check.rb    2017-01-04 22:48:44 +0900 (9bd080c)
+++ test/test-pgroonga-check.rb    2017-01-04 23:15:06 +0900 (99ef32b)
@@ -28,5 +28,37 @@ SELECT * FROM memos WHERE content %% 'PGroonga';
                              "SELECT * FROM memos WHERE content %% 'PGroonga';"))
       end
     end
+
+    sub_test_case "index" do
+      test "locked" do
+        run_sql("CREATE TABLE memos (content text);")
+        run_sql("CREATE INDEX memos_content ON memos USING pgroonga (content);")
+        run_sql("INSERT INTO memos VALUES ('PGroonga is good!');")
+        stop_postgres
+        lexicon = nil
+        groonga("table_list")[1][2..-1].each do |_, name,|
+          if name.start_with?("Lexicon")
+            lexicon = name
+            break
+          end
+        end
+        groonga("lock_acquire", "#{lexicon}.index")
+        start_postgres
+        run_sql("INSERT INTO memos VALUES ('PGroonga is good!');")
+        output = <<-OUTPUT
+SET enable_seqscan = no;
+SELECT * FROM memos WHERE content %% 'PGroonga';
+      content      
+-------------------
+ PGroonga is good!
+ PGroonga is good!
+(2 rows)
+
+        OUTPUT
+        assert_equal([output, ""],
+                     run_sql("SET enable_seqscan = no;\n" +
+                             "SELECT * FROM memos WHERE content %% 'PGroonga';"))
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Descargar 



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