Kouhei Sutou
null+****@clear*****
Tue Jan 6 19:02:59 JST 2015
Kouhei Sutou 2015-01-06 19:02:59 +0900 (Tue, 06 Jan 2015) New Revision: 90784ff8d1fd23a88d33839e6ee4248b931222d8 https://github.com/ranguba/rroonga/commit/90784ff8d1fd23a88d33839e6ee4248b931222d8 Message: Add Groonga::Database#recover Modified files: ext/groonga/rb-grn-database.c test/test-database.rb Modified: ext/groonga/rb-grn-database.c (+33 -1) =================================================================== --- ext/groonga/rb-grn-database.c 2015-01-06 18:52:51 +0900 (3fcdba7) +++ ext/groonga/rb-grn-database.c 2015-01-06 19:02:59 +0900 (4b157f8) @@ -1,6 +1,6 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2009-2011 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2009-2015 Kouhei Sutou <kou �� clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -562,6 +562,37 @@ rb_grn_database_defrag (int argc, VALUE *argv, VALUE self) return INT2NUM(n_segments); } +/* + * Recovers database. + * + * @overload recover() + * + * If the database is broken, try to recover the database. If the + * database can't be recovered, an {Groonga::Error} family exception + * is raised. + * + * If the database isn't broken, it does nothing. + * + * @return [void] + * + * @since 4.0.8 + */ +static VALUE +rb_grn_database_recover (VALUE self) +{ + grn_rc rc; + grn_ctx *context; + grn_obj *database; + + rb_grn_database_deconstruct(SELF(self), &database, &context, + NULL, NULL, NULL, NULL); + rc = grn_db_recover(context, database); + rb_grn_context_check(context, self); + rb_grn_rc_check(rc, self); + + return Qnil; +} + void rb_grn_init_database (VALUE mGrn) { @@ -593,4 +624,5 @@ rb_grn_init_database (VALUE mGrn) rb_define_method(rb_cGrnDatabase, "touch", rb_grn_database_touch, 0); rb_define_method(rb_cGrnDatabase, "defrag", rb_grn_database_defrag, -1); + rb_define_method(rb_cGrnDatabase, "recover", rb_grn_database_recover, 0); } Modified: test/test-database.rb (+28 -1) =================================================================== --- test/test-database.rb 2015-01-06 18:52:51 +0900 (2d0493d) +++ test/test-database.rb 2015-01-06 19:02:59 +0900 (0ad672c) @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2009-2015 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -171,6 +171,33 @@ class DatabaseTest < Test::Unit::TestCase assert_equal(2, @database.defrag) end + def test_recover + setup_database + Groonga::Schema.define do |schema| + schema.create_table("Users") do |table| + table.short_text("name") + end + + schema.create_table("Terms", + :type => :patricia_trie, + :key_type => :short_text, + :default_tokenizer => "TokenBigram", + :normalizer => "NormalizerAuto") do |table| + table.index("Users.name") + end + end + + index = context["Terms.Users_name"] + index.lock + assert do + index.locked? + end + @database.recover + assert do + not index.locked? + end + end + def test_tables setup_database Groonga::Schema.define do |schema| -------------- next part -------------- HTML����������������������������...ダウンロード