droonga-engine 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/Rakefile +1 -1
- data/benchmark/benchmark.rb +1 -1
- data/benchmark/utils.rb +1 -1
- data/benchmark/watch/benchmark-notify.rb +1 -1
- data/benchmark/watch/benchmark-publish.rb +1 -1
- data/benchmark/watch/benchmark-scan.rb +1 -1
- data/bin/droonga-engine +1 -1
- data/bin/droonga-engine-absorb-data +48 -8
- data/bin/droonga-engine-catalog-generate +1 -1
- data/bin/droonga-engine-catalog-modify +1 -1
- data/bin/droonga-engine-data-publisher +66 -0
- data/bin/droonga-engine-join +72 -17
- data/bin/droonga-engine-serf-event-handler +1 -1
- data/bin/droonga-engine-service +1 -1
- data/bin/droonga-engine-unjoin +11 -4
- data/bin/droonga-engine-worker +20 -0
- data/doc/text/news.md +8 -0
- data/droonga-engine.gemspec +3 -3
- data/lib/droonga/adapter.rb +1 -1
- data/lib/droonga/adapter_runner.rb +1 -1
- data/lib/droonga/address.rb +69 -0
- data/lib/droonga/buffered_tcp_socket.rb +44 -22
- data/lib/droonga/catalog/base.rb +1 -1
- data/lib/droonga/catalog/collection_volume.rb +1 -1
- data/lib/droonga/catalog/dataset.rb +8 -8
- data/lib/droonga/catalog/errors.rb +1 -1
- data/lib/droonga/catalog/schema.rb +1 -1
- data/lib/droonga/catalog/single_volume.rb +6 -8
- data/lib/droonga/catalog/slice.rb +1 -1
- data/lib/droonga/catalog/version1.rb +2 -2
- data/lib/droonga/catalog/version2.rb +6 -6
- data/lib/droonga/catalog/version2_validator.rb +1 -1
- data/lib/droonga/catalog/volume.rb +1 -1
- data/lib/droonga/catalog/volume_collection.rb +2 -2
- data/lib/droonga/catalog_generator.rb +49 -53
- data/lib/droonga/catalog_loader.rb +1 -1
- data/lib/droonga/collector.rb +1 -1
- data/lib/droonga/collector_message.rb +1 -1
- data/lib/droonga/collector_runner.rb +1 -1
- data/lib/droonga/collectors/and.rb +1 -1
- data/lib/droonga/collectors/or.rb +1 -1
- data/lib/droonga/collectors/sum.rb +1 -1
- data/lib/droonga/collectors.rb +1 -1
- data/lib/droonga/command/droonga_engine.rb +103 -55
- data/lib/droonga/command/droonga_engine_service.rb +22 -67
- data/lib/droonga/command/droonga_engine_worker.rb +232 -0
- data/lib/droonga/command/serf_event_handler.rb +126 -46
- data/lib/droonga/data_absorber.rb +32 -14
- data/lib/droonga/dispatcher.rb +15 -11
- data/lib/droonga/distributed_command_planner.rb +1 -1
- data/lib/droonga/distributor.rb +1 -1
- data/lib/droonga/engine/version.rb +2 -2
- data/lib/droonga/engine.rb +8 -3
- data/lib/droonga/engine_state.rb +15 -6
- data/lib/droonga/error.rb +1 -1
- data/lib/droonga/error_messages.rb +1 -1
- data/lib/droonga/event_loop.rb +1 -1
- data/lib/droonga/farm.rb +9 -1
- data/lib/droonga/file_observer.rb +1 -1
- data/lib/droonga/fluent_message_receiver.rb +11 -5
- data/lib/droonga/fluent_message_sender.rb +14 -17
- data/lib/droonga/forwarder.rb +23 -13
- data/lib/droonga/handler.rb +1 -1
- data/lib/droonga/handler_message.rb +1 -1
- data/lib/droonga/handler_messenger.rb +2 -2
- data/lib/droonga/handler_runner.rb +2 -2
- data/lib/droonga/input_message.rb +1 -1
- data/lib/droonga/internal_fluent_message_receiver.rb +3 -2
- data/lib/droonga/job_protocol.rb +1 -1
- data/lib/droonga/job_pusher.rb +1 -1
- data/lib/droonga/job_receiver.rb +1 -1
- data/lib/droonga/line_buffer.rb +1 -1
- data/lib/droonga/live_nodes_list_loader.rb +1 -1
- data/lib/droonga/loggable.rb +1 -1
- data/lib/droonga/logger.rb +3 -3
- data/lib/droonga/message_matcher.rb +1 -1
- data/lib/droonga/output_message.rb +1 -1
- data/lib/droonga/path.rb +5 -1
- data/lib/droonga/planner.rb +1 -1
- data/lib/droonga/pluggable.rb +1 -1
- data/lib/droonga/plugin/metadata/adapter_input_message.rb +1 -1
- data/lib/droonga/plugin/metadata/adapter_output_message.rb +1 -1
- data/lib/droonga/plugin/metadata/collector_message.rb +1 -1
- data/lib/droonga/plugin/metadata/handler_action.rb +1 -1
- data/lib/droonga/plugin/metadata/input_message.rb +1 -1
- data/lib/droonga/plugin.rb +2 -1
- data/lib/droonga/plugin_loader.rb +1 -1
- data/lib/droonga/plugin_registry.rb +3 -1
- data/lib/droonga/plugins/basic.rb +1 -1
- data/lib/droonga/plugins/crud.rb +1 -1
- data/lib/droonga/plugins/dump.rb +13 -2
- data/lib/droonga/plugins/error.rb +1 -1
- data/lib/droonga/plugins/groonga/column_create.rb +1 -1
- data/lib/droonga/plugins/groonga/column_list.rb +1 -1
- data/lib/droonga/plugins/groonga/column_remove.rb +1 -1
- data/lib/droonga/plugins/groonga/column_rename.rb +1 -1
- data/lib/droonga/plugins/groonga/delete.rb +1 -1
- data/lib/droonga/plugins/groonga/generic_command.rb +1 -1
- data/lib/droonga/plugins/groonga/generic_response.rb +1 -1
- data/lib/droonga/plugins/groonga/select.rb +1 -1
- data/lib/droonga/plugins/groonga/table_create.rb +1 -1
- data/lib/droonga/plugins/groonga/table_list.rb +1 -1
- data/lib/droonga/plugins/groonga/table_remove.rb +1 -1
- data/lib/droonga/plugins/groonga.rb +1 -1
- data/lib/droonga/plugins/search/distributed_search_planner.rb +1 -1
- data/lib/droonga/plugins/search.rb +1 -1
- data/lib/droonga/plugins/system.rb +1 -1
- data/lib/droonga/plugins/watch.rb +1 -1
- data/lib/droonga/{service_control_protocol.rb → process_control_protocol.rb} +2 -2
- data/lib/droonga/process_supervisor.rb +91 -0
- data/lib/droonga/processor.rb +1 -1
- data/lib/droonga/reducer.rb +1 -1
- data/lib/droonga/replier.rb +2 -2
- data/lib/droonga/safe_file_writer.rb +1 -1
- data/lib/droonga/schema_applier.rb +1 -1
- data/lib/droonga/searcher/mecab_filter.rb +1 -1
- data/lib/droonga/searcher.rb +31 -19
- data/lib/droonga/serf.rb +81 -14
- data/lib/droonga/serf_downloader.rb +2 -2
- data/lib/droonga/session.rb +1 -1
- data/lib/droonga/single_step.rb +1 -1
- data/lib/droonga/single_step_definition.rb +1 -1
- data/lib/droonga/slice.rb +30 -28
- data/lib/droonga/status_code.rb +1 -1
- data/lib/droonga/step_runner.rb +1 -1
- data/lib/droonga/supervisor.rb +170 -0
- data/lib/droonga/sweeper.rb +1 -1
- data/lib/droonga/test/stub_handler.rb +1 -1
- data/lib/droonga/test/stub_handler_message.rb +1 -1
- data/lib/droonga/test/stub_handler_messenger.rb +1 -1
- data/lib/droonga/test/stub_planner.rb +1 -1
- data/lib/droonga/test.rb +1 -1
- data/lib/droonga/watch_schema.rb +2 -2
- data/lib/droonga/watcher.rb +1 -1
- data/lib/droonga/worker_process_agent.rb +111 -0
- data/sample/cluster/Rakefile +150 -0
- data/test/command/config/default/catalog.json +1 -34
- data/test/command/config/version1/catalog.json +3 -12
- data/test/command/run-test.rb +1 -1
- data/test/command/suite/dump/column/index.expected +19 -82
- data/test/command/suite/dump/column/scalar.expected +5 -36
- data/test/command/suite/dump/column/vector.expected +5 -39
- data/test/command/suite/dump/record/vector/reference.expected +24 -93
- data/test/command/suite/dump/table/array.expected +0 -19
- data/test/command/suite/dump/table/double_array_trie.expected +0 -20
- data/test/command/suite/dump/table/hash.expected +0 -20
- data/test/command/suite/dump/table/patricia_trie.expected +0 -20
- data/test/command/suite/search/condition/query/nonexistent_column.expected +0 -11
- data/test/command/suite/search/condition/query/syntax_error.expected +0 -11
- data/test/command/suite/search/error/unknown-source.expected +0 -12
- data/test/command/suite/search/output/attributes/invalid.expected +0 -10
- data/test/command/suite/search/output/attributes/reference_vector.catalog.json +27 -0
- data/test/command/suite/search/output/attributes/reference_vector.expected +30 -0
- data/test/command/suite/search/output/attributes/reference_vector.test +32 -0
- data/test/command/suite/watch/subscribe.catalog.json +23 -0
- data/test/command/suite/watch/subscribe.test +2 -0
- data/test/command/suite/watch/unsubscribe.catalog.json +23 -0
- data/test/command/suite/watch/unsubscribe.test +2 -0
- data/test/performance/run-test.rb +1 -1
- data/test/unit/catalog/test_collection_volume.rb +1 -1
- data/test/unit/catalog/test_dataset.rb +1 -1
- data/test/unit/catalog/test_schema.rb +1 -1
- data/test/unit/catalog/test_single_volume.rb +27 -19
- data/test/unit/catalog/test_slice.rb +2 -2
- data/test/unit/catalog/test_version1.rb +1 -1
- data/test/unit/catalog/test_version2.rb +1 -1
- data/test/unit/catalog/test_version2_validator.rb +1 -1
- data/test/unit/catalog/test_volume_collection.rb +1 -1
- data/test/unit/helper/distributed_search_planner_helper.rb +1 -1
- data/test/unit/helper/fixture.rb +1 -1
- data/test/unit/helper/plugin_helper.rb +1 -1
- data/test/unit/helper/sandbox.rb +1 -1
- data/test/unit/helper/stub_worker.rb +1 -1
- data/test/unit/helper/watch_helper.rb +1 -1
- data/test/unit/helper.rb +1 -1
- data/test/unit/plugins/crud/test_add.rb +1 -1
- data/test/unit/plugins/groonga/select/test_adapter_input.rb +1 -1
- data/test/unit/plugins/groonga/select/test_adapter_output.rb +1 -1
- data/test/unit/plugins/groonga/test_column_create.rb +1 -1
- data/test/unit/plugins/groonga/test_column_list.rb +1 -1
- data/test/unit/plugins/groonga/test_column_remove.rb +1 -1
- data/test/unit/plugins/groonga/test_column_rename.rb +1 -1
- data/test/unit/plugins/groonga/test_delete.rb +1 -1
- data/test/unit/plugins/groonga/test_table_create.rb +1 -1
- data/test/unit/plugins/groonga/test_table_list.rb +1 -1
- data/test/unit/plugins/groonga/test_table_remove.rb +1 -1
- data/test/unit/plugins/search/planner/test_basic.rb +1 -1
- data/test/unit/plugins/search/planner/test_group_by.rb +1 -1
- data/test/unit/plugins/search/planner/test_output.rb +1 -1
- data/test/unit/plugins/search/planner/test_sort_by.rb +1 -1
- data/test/unit/plugins/search/test_collector.rb +1 -1
- data/test/unit/plugins/search/test_handler.rb +1 -1
- data/test/unit/plugins/search/test_planner.rb +1 -1
- data/test/unit/plugins/system/test_status.rb +1 -1
- data/test/unit/plugins/test_basic.rb +1 -1
- data/test/unit/plugins/test_groonga.rb +1 -1
- data/test/unit/plugins/test_watch.rb +1 -1
- data/test/unit/run-test.rb +1 -1
- data/test/unit/test_address.rb +53 -0
- data/test/unit/test_catalog_generator.rb +59 -1
- data/test/unit/test_line_buffer.rb +1 -1
- data/test/unit/test_message_matcher.rb +1 -1
- data/test/unit/test_schema_applier.rb +1 -1
- data/test/unit/test_sweeper.rb +1 -1
- data/test/unit/test_watch_schema.rb +1 -1
- data/test/unit/test_watcher.rb +1 -1
- metadata +39 -24
- data/lib/droonga/server.rb +0 -45
- data/lib/droonga/worker.rb +0 -66
- data/sample/cluster/catalog.json +0 -42
- data/test/command/config/default/fluentd.conf +0 -11
- data/test/command/config/version1/fluentd.conf +0 -11
data/lib/droonga/slice.rb
CHANGED
@@ -11,13 +11,10 @@
|
|
11
11
|
#
|
12
12
|
# You should have received a copy of the GNU Lesser General Public
|
13
13
|
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc.,
|
15
|
-
|
16
|
-
require "serverengine"
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
15
|
|
18
16
|
require "droonga/loggable"
|
19
|
-
require "droonga/
|
20
|
-
require "droonga/worker"
|
17
|
+
require "droonga/supervisor"
|
21
18
|
require "droonga/event_loop"
|
22
19
|
require "droonga/job_pusher"
|
23
20
|
require "droonga/processor"
|
@@ -27,21 +24,24 @@ module Droonga
|
|
27
24
|
class Slice
|
28
25
|
include Loggable
|
29
26
|
|
27
|
+
attr_accessor :on_ready
|
30
28
|
def initialize(dataset, loop, options={})
|
31
29
|
@dataset = dataset
|
32
30
|
@loop = loop
|
33
31
|
@options = options
|
34
32
|
@n_workers = @options[:n_workers] || 0
|
35
|
-
@
|
33
|
+
@database_path = @options[:database]
|
34
|
+
@job_pusher = JobPusher.new(@loop, @database_path)
|
36
35
|
@processor = Processor.new(@loop, @job_pusher, @options)
|
37
36
|
@supervisor = nil
|
37
|
+
@on_ready = nil
|
38
38
|
end
|
39
39
|
|
40
40
|
def start
|
41
41
|
ensure_database
|
42
42
|
@processor.start
|
43
43
|
@job_pusher.start
|
44
|
-
start_supervisor
|
44
|
+
start_supervisor
|
45
45
|
end
|
46
46
|
|
47
47
|
def shutdown
|
@@ -63,14 +63,13 @@ module Droonga
|
|
63
63
|
enforce_umask
|
64
64
|
context = Groonga::Context.new
|
65
65
|
begin
|
66
|
-
|
67
|
-
|
68
|
-
context.open_database(database_path) do
|
66
|
+
if File.exist?(@database_path)
|
67
|
+
context.open_database(@database_path) do
|
69
68
|
apply_schema(context)
|
70
69
|
end
|
71
70
|
else
|
72
|
-
FileUtils.mkdir_p(File.dirname(database_path))
|
73
|
-
context.create_database(database_path) do
|
71
|
+
FileUtils.mkdir_p(File.dirname(@database_path))
|
72
|
+
context.create_database(@database_path) do
|
74
73
|
apply_schema(context)
|
75
74
|
end
|
76
75
|
end
|
@@ -89,32 +88,35 @@ module Droonga
|
|
89
88
|
end
|
90
89
|
|
91
90
|
def start_supervisor
|
92
|
-
@
|
93
|
-
|
94
|
-
|
95
|
-
:workers => @options[:n_workers],
|
96
|
-
:log_level => logger.level,
|
97
|
-
:server_process_name => "Server[#{@options[:database]}] #$0",
|
98
|
-
:worker_process_name => "Worker[#{@options[:database]}] #$0",
|
99
|
-
:job_receive_socket_path => @job_pusher.socket_path,
|
100
|
-
:job_pusher => @job_pusher,
|
101
|
-
}
|
102
|
-
@options.merge(force_options)
|
91
|
+
if @n_workers.zero?
|
92
|
+
on_ready
|
93
|
+
return
|
103
94
|
end
|
104
|
-
|
105
|
-
|
95
|
+
|
96
|
+
config = Supervisor::WorkerConfiguration.new
|
97
|
+
config.name = @options[:name]
|
98
|
+
config.dataset = @dataset
|
99
|
+
config.database_path = @database_path
|
100
|
+
config.plugins = @options[:plugins]
|
101
|
+
config.job_pusher = @job_pusher
|
102
|
+
@supervisor = Supervisor.new(@loop, @n_workers, config)
|
103
|
+
@supervisor.on_ready = lambda do
|
104
|
+
on_ready
|
106
105
|
end
|
106
|
+
@supervisor.start
|
107
107
|
end
|
108
108
|
|
109
109
|
def shutdown_supervisor
|
110
110
|
logger.trace("supervisor: shutdown: start")
|
111
|
-
@supervisor.
|
112
|
-
logger.trace("supervisor: shutdown: stopped")
|
113
|
-
@supervisor_thread.join
|
111
|
+
@supervisor.stop_gracefully
|
114
112
|
logger.trace("supervisor: shutdown: done")
|
115
113
|
end
|
116
114
|
|
117
115
|
private
|
116
|
+
def on_ready
|
117
|
+
@on_ready.call if @on_ready
|
118
|
+
end
|
119
|
+
|
118
120
|
def log_tag
|
119
121
|
"slice"
|
120
122
|
end
|
data/lib/droonga/status_code.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
module StatusCode
|
data/lib/droonga/step_runner.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# You should have received a copy of the GNU Lesser General Public
|
13
13
|
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc.,
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
15
|
|
16
16
|
require "droonga/loggable"
|
17
17
|
require "droonga/plugin"
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
|
+
|
16
|
+
require "droonga/loggable"
|
17
|
+
require "droonga/process_supervisor"
|
18
|
+
|
19
|
+
module Droonga
|
20
|
+
class Supervisor
|
21
|
+
include Loggable
|
22
|
+
|
23
|
+
attr_writer :on_ready
|
24
|
+
def initialize(loop, n_workers, config)
|
25
|
+
@loop = loop
|
26
|
+
@n_workers = n_workers
|
27
|
+
@config = config
|
28
|
+
@on_ready = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
n_ready_workers = 0
|
33
|
+
@worker_runners = @n_workers.times.collect do |i|
|
34
|
+
worker_runner = WorkerRunner.new(@loop, i, @config)
|
35
|
+
worker_runner.on_ready = lambda do
|
36
|
+
n_ready_workers += 1
|
37
|
+
if n_ready_workers == @n_workers
|
38
|
+
@on_ready.call if @on_ready
|
39
|
+
end
|
40
|
+
end
|
41
|
+
worker_runner.start
|
42
|
+
# TODO: support auto re-run
|
43
|
+
worker_runner
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop_gracefully
|
48
|
+
@worker_runners.each do |worker_runner|
|
49
|
+
worker_runner.stop_gracefully
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def stop_immediately
|
54
|
+
@worker_runners.each do |worker_runner|
|
55
|
+
worker_runner.stop_immediately
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def log_tag
|
61
|
+
"supervisor"
|
62
|
+
end
|
63
|
+
|
64
|
+
class WorkerConfiguration
|
65
|
+
attr_accessor :name
|
66
|
+
attr_accessor :dataset
|
67
|
+
attr_accessor :database_path
|
68
|
+
attr_accessor :plugins
|
69
|
+
attr_accessor :job_pusher
|
70
|
+
def initialize
|
71
|
+
@name = nil
|
72
|
+
@dataset = nil
|
73
|
+
@database_path = nil
|
74
|
+
@plugins = []
|
75
|
+
@job_pusher = nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class WorkerRunner
|
80
|
+
include Loggable
|
81
|
+
|
82
|
+
attr_writer :on_ready
|
83
|
+
attr_writer :on_failure
|
84
|
+
def initialize(loop, id, config)
|
85
|
+
@loop = loop
|
86
|
+
@id = id
|
87
|
+
@config = config
|
88
|
+
@on_ready = nil
|
89
|
+
@on_failure = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def start
|
93
|
+
control_write_in, control_write_out = IO.pipe
|
94
|
+
control_read_in, control_read_out = IO.pipe
|
95
|
+
env = {}
|
96
|
+
command_line = [
|
97
|
+
RbConfig.ruby,
|
98
|
+
"-S",
|
99
|
+
"droonga-engine-worker",
|
100
|
+
"--control-read-fd", control_write_in.fileno.to_s,
|
101
|
+
"--control-write-fd", control_read_out.fileno.to_s,
|
102
|
+
"--job-queue-socket-path", @config.job_pusher.socket_path.to_s,
|
103
|
+
"--pid-file", pid_path.to_s,
|
104
|
+
"--dataset", @config.dataset.name,
|
105
|
+
"--database-path", @config.database_path.to_s,
|
106
|
+
"--plugins", @config.plugins.join(","),
|
107
|
+
]
|
108
|
+
options = {
|
109
|
+
control_write_in => control_write_in,
|
110
|
+
control_read_out => control_read_out,
|
111
|
+
}
|
112
|
+
@pid = spawn(env, *command_line, options)
|
113
|
+
control_write_in.close
|
114
|
+
control_read_out.close
|
115
|
+
@supervisor = create_process_supervisor(control_read_in,
|
116
|
+
control_write_out)
|
117
|
+
@supervisor.start
|
118
|
+
end
|
119
|
+
|
120
|
+
def stop_gracefully
|
121
|
+
@supervisor.stop_gracefully
|
122
|
+
end
|
123
|
+
|
124
|
+
def stop_immediately
|
125
|
+
@supervisor.stop_immediately
|
126
|
+
end
|
127
|
+
|
128
|
+
def success?
|
129
|
+
@success
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
def pid_path
|
134
|
+
@config.database_path + "droonga-worker-#{@id}.pid"
|
135
|
+
end
|
136
|
+
|
137
|
+
def create_process_supervisor(input, output)
|
138
|
+
supervisor = ProcessSupervisor.new(@loop, input, output)
|
139
|
+
supervisor.on_ready = lambda do
|
140
|
+
on_ready
|
141
|
+
end
|
142
|
+
supervisor.on_finish = lambda do
|
143
|
+
on_finish
|
144
|
+
end
|
145
|
+
supervisor
|
146
|
+
end
|
147
|
+
|
148
|
+
def on_ready
|
149
|
+
@on_ready.call if @on_ready
|
150
|
+
end
|
151
|
+
|
152
|
+
def on_failure
|
153
|
+
# TODO: log
|
154
|
+
@on_failure.call if @on_failure
|
155
|
+
end
|
156
|
+
|
157
|
+
def on_finish
|
158
|
+
_, status = Process.waitpid2(@pid)
|
159
|
+
@success = status.success?
|
160
|
+
@supervisor.stop
|
161
|
+
on_failure unless success?
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def log_tag
|
166
|
+
"worker-runner"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/lib/droonga/sweeper.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
class Sweeper
|
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
module Test
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# You should have received a copy of the GNU Lesser General Public
|
13
13
|
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc.,
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
15
|
|
16
16
|
require "droonga/handler_message"
|
17
17
|
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# You should have received a copy of the GNU Lesser General Public
|
13
13
|
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc.,
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
15
|
|
16
16
|
module Droonga
|
17
17
|
module Test
|
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
module Test
|
data/lib/droonga/test.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
require "droonga/test/stub_planner"
|
19
19
|
require "droonga/test/stub_handler"
|
data/lib/droonga/watch_schema.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
require "groonga"
|
19
19
|
|
@@ -86,7 +86,7 @@ module Droonga
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def log_tag
|
89
|
-
"[#{Process.ppid}]
|
89
|
+
"[#{Process.ppid}] watch_schema"
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
data/lib/droonga/watcher.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU Lesser General Public
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
|
-
# Foundation, Inc.,
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
class Watcher
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
15
|
+
|
16
|
+
require "coolio"
|
17
|
+
|
18
|
+
require "droonga/process_control_protocol"
|
19
|
+
require "droonga/line_buffer"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
class WorkerProcessAgent
|
23
|
+
include ProcessControlProtocol
|
24
|
+
|
25
|
+
def initialize(loop, input, output)
|
26
|
+
@loop = loop
|
27
|
+
create_input(input)
|
28
|
+
create_output(output)
|
29
|
+
@on_ready = nil
|
30
|
+
@on_finish = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
@loop.attach(@input)
|
35
|
+
@loop.attach(@output)
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
if @output
|
40
|
+
@output, output = nil, @output
|
41
|
+
output.write(Messages::FINISH)
|
42
|
+
output.close
|
43
|
+
end
|
44
|
+
if @input
|
45
|
+
@input, input = nil, @input
|
46
|
+
input.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def ready
|
51
|
+
@output.write(Messages::READY)
|
52
|
+
end
|
53
|
+
|
54
|
+
def on_stop_gracefully=(callback)
|
55
|
+
@on_stop_gracefully = callback
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_stop_immediately=(callback)
|
59
|
+
@on_stop_immediately = callback
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def create_input(raw_input)
|
64
|
+
@input = Coolio::IO.new(raw_input)
|
65
|
+
on_read = lambda do |data|
|
66
|
+
line_buffer = LineBuffer.new
|
67
|
+
line_buffer.feed(data) do |line|
|
68
|
+
case line
|
69
|
+
when Messages::STOP_GRACEFUL
|
70
|
+
on_stop_gracefully
|
71
|
+
when Messages::STOP_IMMEDIATELY
|
72
|
+
on_stop_immediately
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@input.on_read do |data|
|
77
|
+
on_read.call(data)
|
78
|
+
end
|
79
|
+
on_close = lambda do
|
80
|
+
if @input
|
81
|
+
@input = nil
|
82
|
+
on_stop_immediately
|
83
|
+
end
|
84
|
+
end
|
85
|
+
@input.on_close do
|
86
|
+
on_close.call
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_output(raw_output)
|
91
|
+
@output = Coolio::IO.new(raw_output)
|
92
|
+
on_close = lambda do
|
93
|
+
if @output
|
94
|
+
@output = nil
|
95
|
+
on_stop_immediately
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@output.on_close do
|
99
|
+
on_close.call
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def on_stop_gracefully
|
104
|
+
@on_stop_gracefully.call if @on_stop_gracefully
|
105
|
+
end
|
106
|
+
|
107
|
+
def on_stop_immediately
|
108
|
+
@on_stop_immediately.call if @on_stop_immediately
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
require "pathname"
|
19
|
+
require "json"
|
20
|
+
|
21
|
+
base_dir_path = Pathname.new(__FILE__).dirname
|
22
|
+
top_dir_path = base_dir_path.parent.parent
|
23
|
+
bin_dir_path = top_dir_path + "bin"
|
24
|
+
lib_dir_path = top_dir_path + "lib"
|
25
|
+
|
26
|
+
$LOAD_PATH.unshift(lib_dir_path.to_s)
|
27
|
+
|
28
|
+
class DroongaEngine
|
29
|
+
include Rake::DSL
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def host(node_id)
|
33
|
+
"127.0.#{200 + node_id}.1"
|
34
|
+
end
|
35
|
+
|
36
|
+
def port
|
37
|
+
22000
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(base_dir_path, node_id)
|
42
|
+
@base_dir_path = base_dir_path
|
43
|
+
@node_id = node_id
|
44
|
+
@pid = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup(node_ids)
|
48
|
+
rm_rf(working_dir_path.to_s)
|
49
|
+
mkdir_p(working_dir_path.to_s)
|
50
|
+
generate_catalog(node_ids)
|
51
|
+
end
|
52
|
+
|
53
|
+
def start
|
54
|
+
@pid = spawn("droonga-engine",
|
55
|
+
"--base-dir", working_dir_path.to_s,
|
56
|
+
"--host", host,
|
57
|
+
"--port", self.class.port.to_s,
|
58
|
+
"--pid-file", pid_file_path.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop
|
62
|
+
Process.kill(:TERM, @pid)
|
63
|
+
Process.waitpid(@pid)
|
64
|
+
@pid = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def host
|
68
|
+
self.class.host(@node_id)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def working_dir_path
|
73
|
+
@base_dir_path + @node_id.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def catalog_path
|
77
|
+
working_dir_path + "catalog.json"
|
78
|
+
end
|
79
|
+
|
80
|
+
def pid_file_path
|
81
|
+
working_dir_path + "droonga-engine.pid"
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_catalog(node_ids)
|
85
|
+
hosts = node_ids.collect do |node_id|
|
86
|
+
self.class.host(node_id)
|
87
|
+
end
|
88
|
+
sh("droonga-engine-catalog-generate",
|
89
|
+
"--output", catalog_path.to_s,
|
90
|
+
"--n-workers", "3",
|
91
|
+
"--hosts", hosts.join(","),
|
92
|
+
"--port", self.class.port.to_s)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
namespace :droonga do
|
97
|
+
node_ids = [0, 1, 2]
|
98
|
+
|
99
|
+
namespace :prepare do
|
100
|
+
task :path do
|
101
|
+
paths = [
|
102
|
+
bin_dir_path.to_s,
|
103
|
+
ENV["PATH"],
|
104
|
+
].compact
|
105
|
+
ENV["PATH"] = paths.join(File::PATH_SEPARATOR)
|
106
|
+
end
|
107
|
+
|
108
|
+
task :load_path do
|
109
|
+
load_paths = [
|
110
|
+
lib_dir_path.to_s,
|
111
|
+
ENV["RUBYLIB"],
|
112
|
+
].compact
|
113
|
+
ENV["RUBYLIB"] = load_paths.join(File::PATH_SEPARATOR)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
task :prepare => ["prepare:path", "prepare:load_path"]
|
118
|
+
|
119
|
+
desc "Set up Droonga cluster."
|
120
|
+
task :setup => :prepare do
|
121
|
+
node_ids.each do |node_id|
|
122
|
+
engine = DroongaEngine.new(base_dir_path, node_id)
|
123
|
+
engine.setup(node_ids)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Run Droonga cluster."
|
128
|
+
task :run => :prepare do
|
129
|
+
processes = []
|
130
|
+
begin
|
131
|
+
node_ids.each do |node_id|
|
132
|
+
engine = DroongaEngine.new(base_dir_path, node_id)
|
133
|
+
engine.start
|
134
|
+
processes << engine
|
135
|
+
host = engine.host
|
136
|
+
port = DroongaEngine.port
|
137
|
+
puts("#{host}:#{port}/droonga")
|
138
|
+
end
|
139
|
+
front_node_id = node_ids.first
|
140
|
+
$stdin.gets
|
141
|
+
ensure
|
142
|
+
stop_threads = processes.collect do |process|
|
143
|
+
Thread.new do
|
144
|
+
process.stop
|
145
|
+
end
|
146
|
+
end
|
147
|
+
stop_threads.each(&:join)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|