Kouhei Sutou
null+****@clear*****
Mon Nov 13 17:00:40 JST 2017
Kouhei Sutou 2017-11-13 17:00:40 +0900 (Mon, 13 Nov 2017) New Revision: 8560e44ba4b474e1bd1f8fdeb4003e4ae9e7bbef https://github.com/groonga/groonga/commit/8560e44ba4b474e1bd1f8fdeb4003e4ae9e7bbef Message: grndb: bundle groonga-log TODO: * Test CMake case * Implement check based on Groonga log Added files: vendor/groonga-log-source vendor/groonga-log/CMakeLists.txt vendor/groonga-log/Makefile.am vendor/groonga-log/ruby_scripts_groonga_log_sources.am vendor/groonga-log/ruby_scripts_sources.am Modified files: .gitmodules configure.ac lib/mrb/scripts/command_line/grndb.rb test/command_line/helper.rb test/command_line/run-test.rb test/command_line/suite/grndb/test_check.rb vendor/Makefile.am Modified: .gitmodules (+3 -0) =================================================================== --- .gitmodules 2017-11-13 16:40:37 +0900 (5eedc5724) +++ .gitmodules 2017-11-13 17:00:40 +0900 (486ffba35) @@ -10,3 +10,6 @@ [submodule "vendor/ngx_mruby-source"] path = vendor/ngx_mruby-source url = https://github.com/matsumoto-r/ngx_mruby.git +[submodule "vendor/groonga-log-source"] + path = vendor/groonga-log-source + url = https://github.com/groonga/groonga-log.git Modified: configure.ac (+1 -0) =================================================================== --- configure.ac 2017-11-13 16:40:37 +0900 (25f8a6eff) +++ configure.ac 2017-11-13 17:00:40 +0900 (09c694a93) @@ -310,6 +310,7 @@ AC_CONFIG_FILES([ vendor/mecab/Makefile vendor/message_pack/Makefile vendor/mruby/Makefile + vendor/groonga-log/Makefile ]) if test "$GCC" = "yes"; then Modified: lib/mrb/scripts/command_line/grndb.rb (+33 -0) =================================================================== --- lib/mrb/scripts/command_line/grndb.rb 2017-11-13 16:40:37 +0900 (edd16d588) +++ lib/mrb/scripts/command_line/grndb.rb 2017-11-13 17:00:40 +0900 (3ecbc4c70) @@ -1,3 +1,5 @@ +require "groonga-log" + module Groonga module CommandLine class Grndb @@ -32,6 +34,9 @@ module Groonga options = command.options options.banner += " DB_PATH" options.string("--target", "Check only the target object.") + options.array("--groonga-log-path", + "Path to Groonga log file to be checked.", + "You can specify multiple times to specify multiple log files.") command.add_action do |options| open_database(command, options) do |database, rest_arguments| @@ -109,10 +114,13 @@ module Groonga checker.program_path = @program_path checker.database_path = @database_path checker.database = database + checker.log_paths = options[:groonga_log_path] checker.on_failure = lambda do |message| failed(message) end + checker.check_log_paths + checker.check_database target_name = options[:target] @@ -127,6 +135,7 @@ module Groonga attr_writer :program_path attr_writer :database_path attr_writer :database + attr_writer :log_paths attr_writer :on_failure def initialize @@ -134,6 +143,23 @@ module Groonga @checked = {} end + def check_log_paths + @log_paths.each do |log_path| + begin + log_file = open(log_path) + rescue + failed("[#{log_path}] Can't open Groonga log path.") + next + end + + begin + check_log_file(log_file) + ensure + log_file.close + end + end + end + def check_database check_database_orphan_inspect check_database_locked @@ -177,6 +203,13 @@ module Groonga end private + def check_log_file(log_file) + parser = GroongaLog::Parser.new + parser.parse(log_file) do |statistic| + p statistic.to_h + end + end + def check_database_orphan_inspect open_database_cursor do |cursor| cursor.each do |id| Modified: test/command_line/helper.rb (+1 -0) =================================================================== --- test/command_line/helper.rb 2017-11-13 16:40:37 +0900 (3dd78dc20) +++ test/command_line/helper.rb 2017-11-13 17:00:40 +0900 (b6e674703) @@ -1,5 +1,6 @@ require "fileutils" require "json" +require "tempfile" require "test-unit" Modified: test/command_line/run-test.rb (+4 -0) =================================================================== --- test/command_line/run-test.rb 2017-11-13 16:40:37 +0900 (bc54ce6f3) +++ test/command_line/run-test.rb 2017-11-13 17:00:40 +0900 (a75bca55e) @@ -30,6 +30,10 @@ else ].join(File::PATH_SEPARATOR) ENV["GRN_PLUGINS_DIR"] = (build_top_dir_path + "plugins").to_s ENV["GRN_RUBY_SCRIPTS_DIR"] = (build_top_dir_path + "lib/mrb/scripts").to_s + ENV["GRN_RUBY_LOAD_PATH"] = [ + (build_top_dir_path + "vendor/groonga-log-source/lib").to_s, + ENV["GRN_RUBY_LOAD_PATH"], + ].compact.join(File::PATH_SEPARATOR) end $VERBOSE = true Modified: test/command_line/suite/grndb/test_check.rb (+30 -0) =================================================================== --- test/command_line/suite/grndb/test_check.rb 2017-11-13 16:40:37 +0900 (4b286f43a) +++ test/command_line/suite/grndb/test_check.rb 2017-11-13 17:00:40 +0900 (70385f1e1) @@ -2,6 +2,36 @@ class TestGrnDBCheck < GroongaTestCase def setup end + sub_test_case "Groonga log" do + def test_failed_to_open + groonga("status") + error = assert_raise(CommandRunner::Error) do + grndb("check", + "--groonga-log-path", "/nonexistent1", + "--groonga-log-path", "/nonexistent2") + end + assert_equal(<<-MESSAGE, error.error_output) +[/nonexistent1] Can't open Groonga log path. +[/nonexistent2] Can't open Groonga log path. + MESSAGE + end + + def test_normal + # TODO: This test should be removed when we put check cases. + groonga("status") + log_file = Tempfile.new(["grndb-check-log-path", ".log"]) + log_file.puts(<<-GROONGA_LOG) +2017-11-13 15:58:27.712199|n| grn_init: <7.0.8-14-g16082c4> + GROONGA_LOG + log_file.close + result = grndb("check", + "--groonga-log-path", log_file.path) + assert_equal(<<-MESSAGE, result.output) +{:timestamp=>Mon Nov 13 15:58:27 2017, :log_level=>:notice, :pid=>nil, :message=>"grn_init: <7.0.8-14-g16082c4>"} + MESSAGE + end + end + def test_orphan_inspect groonga("table_create", "inspect", "TABLE_NO_KEY") _id, _name, path, *_ = JSON.parse(groonga("table_list").output)[1][1] Modified: vendor/Makefile.am (+20 -1) =================================================================== --- vendor/Makefile.am 2017-11-13 16:40:37 +0900 (d66aac556) +++ vendor/Makefile.am 2017-11-13 17:00:40 +0900 (85484a20e) @@ -1,3 +1,18 @@ +# Copyright(C) 2017 Brazil +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + NGINX_DIR = nginx-$(NGINX_VERSION) SUBDIRS = \ @@ -5,7 +20,8 @@ SUBDIRS = \ onigmo \ mecab \ message_pack \ - mruby + mruby \ + groonga-log EXTRA_DIST = \ $(NGINX_DIR) \ @@ -27,3 +43,6 @@ dist-hook: $(MKDIR_P) $(distdir)/ngx_mruby-source GIT_DIR=$(srcdir)/ngx_mruby-source/.git git archive --format=tar HEAD | \ tar xf - -C $(distdir)/ngx_mruby-source + $(MKDIR_P) $(distdir)/groonga-log + GIT_DIR=$(srcdir)/groonga-log/.git git archive --format=tar HEAD | \ + tar xf - -C $(distdir)/groonga-log Added: vendor/groonga-log-source (+1 -0) 160000 =================================================================== --- /dev/null +++ vendor/groonga-log-source 2017-11-13 17:00:40 +0900 (7b7bc76b8) @@ -0,0 +1 @@ +Subproject commit 7b7bc76b887df08a15a7c368560a572b5f230cab Added: vendor/groonga-log/CMakeLists.txt (+34 -0) 100644 =================================================================== --- /dev/null +++ vendor/groonga-log/CMakeLists.txt 2017-11-13 17:00:40 +0900 (e59074aa7) @@ -0,0 +1,34 @@ +# Copyright(C) 2017 Brazil +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +set(GROONGA_LOG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../groonga-log-source") + +if(GRN_WITH_MRUBY) + read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/ruby_scripts_sources.am + RUBY_SCRIPTS_SOURCES) + read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/ruby_scripts_groonga_log_sources.am + RUBY_SCRIPTS_GROONGA_LOG_SOURCES) + install( + FILES ${RUBY_SCRIPTS} + DESTINATION "${GRN_RELATIVE_RUBY_SCRIPTS_DIR}") + install( + FILES ${RUBY_SCRIPTS_GROONGA_LOG_SOURCES} + DESTINATION "${GRN_RELATIVE_RUBY_SCRIPTS_DIR}/groonga-log") + install( + FILES + "${GROONGA_LOG_SOURCE_DIR}/README.md" + "${GROONGA_LOG_SOURCE_DIR}/doc/text/lgpl-2.1.txt" + DESTINATION "${GRN_DATA_DIR}/groonga-log" +endif() Added: vendor/groonga-log/Makefile.am (+27 -0) 100644 =================================================================== --- /dev/null +++ vendor/groonga-log/Makefile.am 2017-11-13 17:00:40 +0900 (31d73a9f4) @@ -0,0 +1,27 @@ +# Copyright(C) 2017 Brazil +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +EXTRA_DIST = \ + CMakeLists.txt + +ruby_scripts_groonga_logdir = $(ruby_scriptsdir)/groonga-log + +include ruby_scripts_sources.am +include ruby_scripts_groonga_log_sources.am + +groonga_log_datadir = $(pkgdatadir)/groonga-log +groonga_log_data_DATA = \ + ../groonga-log-source/README.md \ + ../groonga-log-source/doc/text/lgpl-2.1.txt Added: vendor/groonga-log/ruby_scripts_groonga_log_sources.am (+4 -0) 100644 =================================================================== --- /dev/null +++ vendor/groonga-log/ruby_scripts_groonga_log_sources.am 2017-11-13 17:00:40 +0900 (d2418dc75) @@ -0,0 +1,4 @@ +ruby_scripts_groonga_log_DATA = \ + ../groonga-log-source/lib/groonga-log/parser.rb \ + ../groonga-log-source/lib/groonga-log/statistic.rb \ + ../groonga-log-source/lib/groonga-log/version.rb Added: vendor/groonga-log/ruby_scripts_sources.am (+2 -0) 100644 =================================================================== --- /dev/null +++ vendor/groonga-log/ruby_scripts_sources.am 2017-11-13 17:00:40 +0900 (84a459747) @@ -0,0 +1,2 @@ +ruby_scripts_DATA = \ + ../groonga-log-source/lib/groonga-log.rb -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171113/c73f3915/attachment-0001.htm