fluent-plugin-droonga 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -4
- data/benchmark/watch/benchmark-notify.rb +2 -2
- data/benchmark/watch/benchmark-scan.rb +3 -0
- data/benchmark/watch/fluentd.conf +0 -1
- data/fluent-plugin-droonga.gemspec +2 -3
- data/lib/droonga/catalog.rb +10 -124
- data/lib/droonga/catalog/base.rb +140 -0
- data/lib/droonga/catalog/version1.rb +23 -0
- data/lib/droonga/catalog_loader.rb +33 -0
- data/lib/droonga/collector.rb +2 -71
- data/lib/droonga/collector_plugin.rb +2 -34
- data/lib/droonga/dispatcher.rb +141 -196
- data/lib/droonga/distribution_planner.rb +76 -0
- data/lib/droonga/distributor.rb +5 -7
- data/lib/droonga/distributor_plugin.rb +23 -15
- data/lib/droonga/engine.rb +2 -2
- data/lib/droonga/event_loop.rb +46 -0
- data/lib/droonga/farm.rb +9 -5
- data/lib/droonga/fluent_message_sender.rb +84 -0
- data/lib/droonga/forwarder.rb +43 -53
- data/lib/droonga/handler.rb +20 -68
- data/lib/droonga/handler_message.rb +61 -0
- data/lib/droonga/handler_messenger.rb +92 -0
- data/lib/droonga/handler_plugin.rb +10 -12
- data/lib/droonga/input_adapter.rb +52 -0
- data/lib/droonga/{adapter.rb → input_adapter_plugin.rb} +7 -13
- data/lib/droonga/input_message.rb +11 -11
- data/lib/droonga/logger.rb +4 -3
- data/lib/droonga/message_pack_packer.rb +62 -0
- data/lib/droonga/message_processing_error.rb +54 -0
- data/lib/droonga/message_pusher.rb +60 -0
- data/lib/droonga/message_receiver.rb +61 -0
- data/lib/droonga/output_adapter.rb +53 -0
- data/lib/droonga/{adapter_plugin.rb → output_adapter_plugin.rb} +3 -21
- data/lib/droonga/output_message.rb +37 -0
- data/lib/droonga/partition.rb +27 -5
- data/lib/droonga/pluggable.rb +9 -4
- data/lib/droonga/plugin.rb +12 -3
- data/lib/droonga/plugin/collector/basic.rb +91 -18
- data/lib/droonga/plugin/distributor/crud.rb +9 -9
- data/lib/droonga/plugin/distributor/distributed_search_planner.rb +401 -0
- data/lib/droonga/plugin/distributor/groonga.rb +5 -5
- data/lib/droonga/plugin/distributor/search.rb +4 -246
- data/lib/droonga/plugin/distributor/watch.rb +11 -6
- data/lib/droonga/plugin/handler/add.rb +69 -7
- data/lib/droonga/plugin/handler/groonga.rb +6 -6
- data/lib/droonga/plugin/handler/search.rb +5 -3
- data/lib/droonga/plugin/handler/watch.rb +19 -13
- data/lib/droonga/plugin/{adapter → input_adapter}/groonga.rb +5 -11
- data/lib/droonga/plugin/{adapter → input_adapter}/groonga/select.rb +2 -36
- data/lib/droonga/plugin/output_adapter/groonga.rb +30 -0
- data/lib/droonga/plugin/output_adapter/groonga/select.rb +54 -0
- data/lib/droonga/plugin_loader.rb +2 -2
- data/lib/droonga/processor.rb +21 -23
- data/lib/droonga/replier.rb +40 -0
- data/lib/droonga/searcher.rb +298 -174
- data/lib/droonga/server.rb +0 -67
- data/lib/droonga/session.rb +85 -0
- data/lib/droonga/test.rb +21 -0
- data/lib/droonga/test/stub_distributor.rb +31 -0
- data/lib/droonga/test/stub_handler.rb +37 -0
- data/lib/droonga/test/stub_handler_message.rb +35 -0
- data/lib/droonga/test/stub_handler_messenger.rb +34 -0
- data/lib/droonga/time_formatter.rb +37 -0
- data/lib/droonga/watcher.rb +1 -0
- data/lib/droonga/worker.rb +16 -19
- data/lib/fluent/plugin/out_droonga.rb +9 -9
- data/lib/groonga_command_converter.rb +5 -5
- data/sample/cluster/catalog.json +1 -1
- data/test/command/config/default/catalog.json +19 -1
- data/test/command/fixture/event.jsons +41 -0
- data/test/command/fixture/user-table.jsons +9 -0
- data/test/command/run-test.rb +2 -2
- data/test/command/suite/add/error/invalid-integer.expected +20 -0
- data/test/command/suite/add/error/invalid-integer.test +12 -0
- data/test/command/suite/add/error/invalid-time.expected +20 -0
- data/test/command/suite/add/error/invalid-time.test +12 -0
- data/test/command/suite/add/error/missing-key.expected +13 -0
- data/test/command/suite/add/error/missing-key.test +16 -0
- data/test/command/suite/add/error/missing-table.expected +13 -0
- data/test/command/suite/add/error/missing-table.test +16 -0
- data/test/command/suite/add/error/unknown-column.expected +20 -0
- data/test/command/suite/add/error/unknown-column.test +12 -0
- data/test/command/suite/add/error/unknown-table.expected +13 -0
- data/test/command/suite/add/error/unknown-table.test +17 -0
- data/test/command/suite/add/minimum.expected +1 -3
- data/test/command/suite/add/with-values.expected +1 -3
- data/test/command/suite/add/without-key.expected +1 -3
- data/test/command/suite/message/error/missing-dataset.expected +13 -0
- data/test/command/suite/message/error/missing-dataset.test +5 -0
- data/test/command/suite/message/error/unknown-command.expected +13 -0
- data/test/command/suite/message/error/unknown-command.test +6 -0
- data/test/command/suite/message/error/unknown-dataset.expected +13 -0
- data/test/command/suite/message/error/unknown-dataset.test +6 -0
- data/test/command/suite/search/{array-attribute-label.expected → attributes/array.expected} +0 -0
- data/test/command/suite/search/{array-attribute-label.test → attributes/array.test} +0 -0
- data/test/command/suite/search/{hash-attribute-label.expected → attributes/hash.expected} +0 -0
- data/test/command/suite/search/{hash-attribute-label.test → attributes/hash.test} +0 -0
- data/test/command/suite/search/{condition-nested.expected → condition/nested.expected} +0 -0
- data/test/command/suite/search/{condition-nested.test → condition/nested.test} +0 -0
- data/test/command/suite/search/{condition-query.expected → condition/query.expected} +0 -0
- data/test/command/suite/search/{condition-query.test → condition/query.test} +0 -0
- data/test/command/suite/search/{condition-script.expected → condition/script.expected} +0 -0
- data/test/command/suite/search/{condition-script.test → condition/script.test} +0 -0
- data/test/command/suite/search/error/cyclic-source.expected +18 -0
- data/test/command/suite/search/error/cyclic-source.test +12 -0
- data/test/command/suite/search/error/deeply-cyclic-source.expected +21 -0
- data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
- data/test/command/suite/search/error/missing-source-parameter.expected +17 -0
- data/test/command/suite/search/error/missing-source-parameter.test +11 -0
- data/test/command/suite/search/error/unknown-source.expected +18 -0
- data/test/command/suite/search/error/unknown-source.test +12 -0
- data/test/command/suite/search/{minimum.expected → group/count.expected} +2 -1
- data/test/command/suite/search/{minimum.test → group/count.test} +5 -3
- data/test/command/suite/search/group/limit.expected +19 -0
- data/test/command/suite/search/group/limit.test +20 -0
- data/test/command/suite/search/group/string.expected +36 -0
- data/test/command/suite/search/group/string.test +44 -0
- data/test/command/suite/search/{chained-queries.expected → multiple/chained.expected} +0 -0
- data/test/command/suite/search/{chained-queries.test → multiple/chained.test} +0 -0
- data/test/command/suite/search/{multiple-queries.expected → multiple/parallel.expected} +0 -0
- data/test/command/suite/search/{multiple-queries.test → multiple/parallel.test} +0 -0
- data/test/command/suite/search/{output-range.expected → range/only-output.expected} +0 -0
- data/test/command/suite/search/{output-range.test → range/only-output.test} +0 -0
- data/test/command/suite/search/{sort-range.expected → range/only-sort.expected} +0 -0
- data/test/command/suite/search/{sort-range.test → range/only-sort.test} +0 -0
- data/test/command/suite/search/{sort-and-output-range.expected → range/sort-and-output.expected} +0 -0
- data/test/command/suite/search/{sort-and-output-range.test → range/sort-and-output.test} +0 -0
- data/test/command/suite/search/range/too-large-output-offset.expected +16 -0
- data/test/command/suite/search/range/too-large-output-offset.test +25 -0
- data/test/command/suite/search/range/too-large-sort-offset.expected +16 -0
- data/test/command/suite/search/range/too-large-sort-offset.test +28 -0
- data/test/command/suite/search/response/records/value/time.expected +24 -0
- data/test/command/suite/search/response/records/value/time.test +24 -0
- data/test/command/suite/search/sort/default-offset-limit.expected +43 -0
- data/test/command/suite/search/sort/default-offset-limit.test +26 -0
- data/test/command/suite/search/{sort-with-invisible-column.expected → sort/invisible-column.expected} +0 -0
- data/test/command/suite/search/{sort-with-invisible-column.test → sort/invisible-column.test} +0 -0
- data/test/command/suite/watch/subscribe.expected +12 -0
- data/test/command/suite/watch/subscribe.test +9 -0
- data/test/command/suite/watch/unsubscribe.expected +12 -0
- data/test/command/suite/watch/unsubscribe.test +9 -0
- data/test/unit/{test_catalog.rb → catalog/test_version1.rb} +12 -4
- data/test/unit/fixtures/{catalog.json → catalog/version1.json} +0 -0
- data/test/unit/helper.rb +2 -0
- data/test/unit/plugin/collector/test_basic.rb +289 -33
- data/test/unit/plugin/distributor/test_search.rb +176 -861
- data/test/unit/plugin/distributor/test_search_planner.rb +1102 -0
- data/test/unit/plugin/handler/groonga/test_column_create.rb +17 -13
- data/test/unit/plugin/handler/groonga/test_table_create.rb +10 -10
- data/test/unit/plugin/handler/test_add.rb +74 -11
- data/test/unit/plugin/handler/test_groonga.rb +15 -1
- data/test/unit/plugin/handler/test_search.rb +33 -17
- data/test/unit/plugin/handler/test_watch.rb +43 -27
- data/test/unit/run-test.rb +2 -0
- data/test/unit/test_message_pack_packer.rb +51 -0
- data/test/unit/test_time_formatter.rb +29 -0
- metadata +208 -110
- data/lib/droonga/job_queue.rb +0 -87
- data/lib/droonga/job_queue_schema.rb +0 -65
- data/test/unit/test_adapter.rb +0 -51
- data/test/unit/test_job_queue_schema.rb +0 -45
data/lib/droonga/logger.rb
CHANGED
@@ -24,10 +24,11 @@ module Droonga
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def error(message, additional_information={})
|
27
|
+
def error(message, exception, additional_information={})
|
28
28
|
if $log
|
29
|
-
$log.error(message
|
30
|
-
|
29
|
+
$log.error("#{message}: #{exception.message}(#{exception.class})",
|
30
|
+
additional_information)
|
31
|
+
$log.error_backtrace(exception.backtrace)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "msgpack"
|
19
|
+
|
20
|
+
require "droonga/time_formatter"
|
21
|
+
|
22
|
+
module Droonga
|
23
|
+
class MessagePackPacker
|
24
|
+
class << self
|
25
|
+
def pack(object)
|
26
|
+
packer = new
|
27
|
+
packer.pack(object)
|
28
|
+
packer.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
MICRO_SECONDS_DECIMAL_PLACE = 6
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@packer = MessagePack::Packer.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def pack(object)
|
39
|
+
case object
|
40
|
+
when Array
|
41
|
+
@packer.write_array_header(object.size)
|
42
|
+
object.each do |element|
|
43
|
+
pack(element)
|
44
|
+
end
|
45
|
+
when Hash
|
46
|
+
@packer.write_map_header(object.size)
|
47
|
+
object.each do |key, value|
|
48
|
+
pack(key)
|
49
|
+
pack(value)
|
50
|
+
end
|
51
|
+
when Time
|
52
|
+
@packer.write(TimeFormatter.format(object))
|
53
|
+
else
|
54
|
+
@packer.write(object)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
@packer.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
module Droonga
|
17
|
+
class MessageProcessingError < StandardError
|
18
|
+
attr_reader :message, :detail
|
19
|
+
|
20
|
+
def initialize(message, detail=nil)
|
21
|
+
@message = message
|
22
|
+
@detail = detail
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
self.class.name.split("::").last
|
27
|
+
end
|
28
|
+
|
29
|
+
def status_code
|
30
|
+
500
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_body
|
34
|
+
body = {
|
35
|
+
"name" => name,
|
36
|
+
"message" => @message,
|
37
|
+
}
|
38
|
+
body["detail"] = @detail unless @detail.nil?
|
39
|
+
body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class BadRequest < MessageProcessingError
|
44
|
+
def status_code
|
45
|
+
400
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class NotFound < MessageProcessingError
|
50
|
+
def status_code
|
51
|
+
404
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "msgpack"
|
19
|
+
|
20
|
+
module Droonga
|
21
|
+
class MessagePusher
|
22
|
+
attr_reader :raw_receiver
|
23
|
+
def initialize(loop)
|
24
|
+
@loop = loop
|
25
|
+
end
|
26
|
+
|
27
|
+
def start(base_path)
|
28
|
+
socket_path = "#{base_path}.sock"
|
29
|
+
FileUtils.rm_f(socket_path)
|
30
|
+
@raw_receiver = UNIXServer.new(socket_path)
|
31
|
+
FileUtils.chmod(0600, socket_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def shutdown
|
35
|
+
$log.trace("#{log_tag}: shutdown: start")
|
36
|
+
socket_path = @raw_receiver.path
|
37
|
+
@raw_receiver.close
|
38
|
+
FileUtils.rm_f(socket_path)
|
39
|
+
$log.trace("#{log_tag}: shutdown: done")
|
40
|
+
end
|
41
|
+
|
42
|
+
def push(message)
|
43
|
+
$log.trace("#{log_tag}: push: start")
|
44
|
+
packed_message = message.to_msgpack
|
45
|
+
path = @raw_receiver.path
|
46
|
+
sender = Coolio::UNIXSocket.connect(path)
|
47
|
+
sender.write(message.to_msgpack)
|
48
|
+
sender.on_write_complete do
|
49
|
+
close
|
50
|
+
end
|
51
|
+
@loop.attach(sender)
|
52
|
+
$log.trace("#{log_tag}: push: done")
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def log_tag
|
57
|
+
"message_pusher"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "msgpack"
|
19
|
+
|
20
|
+
module Droonga
|
21
|
+
class MessageReceiver
|
22
|
+
def initialize(loop, receiver, &callback)
|
23
|
+
@loop = loop
|
24
|
+
@receiver = Coolio::Server.new(receiver, Coolio::Socket) do |connection|
|
25
|
+
setup_receive_handler(connection)
|
26
|
+
end
|
27
|
+
@callback = callback
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
$log.trace("#{log_tag}: start: start")
|
32
|
+
@loop.attach(@receiver)
|
33
|
+
$log.trace("#{log_tag}: start: done")
|
34
|
+
end
|
35
|
+
|
36
|
+
def shutdown
|
37
|
+
$log.trace("#{log_tag}: shutdown: start")
|
38
|
+
@receiver.close
|
39
|
+
$log.trace("#{log_tag}: shutdown: done")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def setup_receive_handler(connection)
|
44
|
+
unpacker = MessagePack::Unpacker.new
|
45
|
+
on_read = lambda do |data|
|
46
|
+
$log.trace("#{log_tag}: on_read: start")
|
47
|
+
unpacker.feed_each(data) do |message|
|
48
|
+
@callback.call(message)
|
49
|
+
end
|
50
|
+
$log.trace("#{log_tag}: on_read: done")
|
51
|
+
end
|
52
|
+
connection.on_read do |data|
|
53
|
+
on_read.call(data)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def log_tag
|
58
|
+
"message_receiver"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "droonga/pluggable"
|
19
|
+
require "droonga/output_adapter_plugin"
|
20
|
+
require "droonga/output_message"
|
21
|
+
|
22
|
+
module Droonga
|
23
|
+
class OutputAdapter
|
24
|
+
include Pluggable
|
25
|
+
|
26
|
+
def initialize(dispatcher, options={})
|
27
|
+
@dispatcher = dispatcher
|
28
|
+
load_plugins(options[:plugins] || [])
|
29
|
+
end
|
30
|
+
|
31
|
+
def adapt(message)
|
32
|
+
adapted_message = message
|
33
|
+
message["via"].reverse_each do |command|
|
34
|
+
@plugins.each do |plugin|
|
35
|
+
next unless plugin.processable?(command)
|
36
|
+
output_message = OutputMessage.new(adapted_message)
|
37
|
+
process(command, output_message)
|
38
|
+
adapted_message = output_message.adapted_message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
adapted_message
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def instantiate_plugin(name)
|
46
|
+
OutputAdapterPlugin.repository.instantiate(name, @dispatcher)
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_tag
|
50
|
+
"output-adapter"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -18,7 +18,7 @@
|
|
18
18
|
require "droonga/plugin"
|
19
19
|
|
20
20
|
module Droonga
|
21
|
-
class
|
21
|
+
class OutputAdapterPlugin < Plugin
|
22
22
|
extend PluginRegisterable
|
23
23
|
|
24
24
|
def initialize(dispatcher)
|
@@ -26,26 +26,8 @@ module Droonga
|
|
26
26
|
@dispatcher = dispatcher
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
@dispatcher.
|
31
|
-
end
|
32
|
-
|
33
|
-
def post(body, destination=nil)
|
34
|
-
@dispatcher.post(body, destination)
|
35
|
-
end
|
36
|
-
|
37
|
-
def emit(value, name=nil)
|
38
|
-
if name
|
39
|
-
@output_values[name] = value
|
40
|
-
else
|
41
|
-
@output_values = value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def process(command, message)
|
46
|
-
@output_values = {}
|
47
|
-
super(command, message)
|
48
|
-
post(@output_values) unless @output_values.empty?
|
29
|
+
def forward(message, destination)
|
30
|
+
@dispatcher.forward(message, destination)
|
49
31
|
end
|
50
32
|
end
|
51
33
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (C) 2013 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
module Droonga
|
17
|
+
class OutputMessage
|
18
|
+
def initialize(raw_message)
|
19
|
+
@raw_message = raw_message
|
20
|
+
end
|
21
|
+
|
22
|
+
def adapted_message
|
23
|
+
# TODO: We can create adapted message non-destructively.
|
24
|
+
# If it is not performance issue, it is better that we don't
|
25
|
+
# change message destructively. Consider about it later.
|
26
|
+
@raw_message
|
27
|
+
end
|
28
|
+
|
29
|
+
def body
|
30
|
+
@raw_message["body"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def body=(body)
|
34
|
+
@raw_message["body"] = body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/droonga/partition.rb
CHANGED
@@ -19,36 +19,57 @@ require "serverengine"
|
|
19
19
|
|
20
20
|
require "droonga/server"
|
21
21
|
require "droonga/worker"
|
22
|
+
require "droonga/event_loop"
|
23
|
+
require "droonga/message_pusher"
|
22
24
|
require "droonga/processor"
|
23
25
|
|
24
26
|
module Droonga
|
25
27
|
class Partition
|
26
|
-
def initialize(options={})
|
28
|
+
def initialize(loop, options={})
|
27
29
|
@options = options
|
28
30
|
@n_workers = @options[:n_workers] || 0
|
29
|
-
@
|
31
|
+
@loop = loop
|
32
|
+
@message_pusher = MessagePusher.new(@loop)
|
33
|
+
@processor = Processor.new(@loop, @message_pusher, @options)
|
30
34
|
@supervisor = nil
|
31
35
|
end
|
32
36
|
|
33
37
|
def start
|
38
|
+
ensure_database
|
34
39
|
@processor.start
|
40
|
+
base_path = @options[:database]
|
41
|
+
@message_pusher.start(base_path)
|
35
42
|
start_supervisor if @n_workers > 0
|
36
43
|
end
|
37
44
|
|
38
45
|
def shutdown
|
39
46
|
$log.trace("partition: shutdown: start")
|
40
47
|
shutdown_supervisor if @supervisor
|
48
|
+
@message_pusher.shutdown
|
41
49
|
@processor.shutdown
|
42
50
|
$log.trace("partition: shutdown: done")
|
43
51
|
end
|
44
52
|
|
45
|
-
def process(
|
53
|
+
def process(message)
|
46
54
|
$log.trace("partition: process: start")
|
47
|
-
@processor.process(
|
55
|
+
@processor.process(message)
|
48
56
|
$log.trace("partition: process: done")
|
49
57
|
end
|
50
58
|
|
51
59
|
private
|
60
|
+
def ensure_database
|
61
|
+
database_path = @options[:database]
|
62
|
+
return if File.exist?(database_path)
|
63
|
+
FileUtils.mkdir_p(File.dirname(database_path))
|
64
|
+
context = Groonga::Context.new
|
65
|
+
begin
|
66
|
+
context.create_database(database_path) do
|
67
|
+
end
|
68
|
+
ensure
|
69
|
+
context.close
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
52
73
|
def start_supervisor
|
53
74
|
@supervisor = ServerEngine::Supervisor.new(Server, Worker) do
|
54
75
|
force_options = {
|
@@ -56,7 +77,8 @@ module Droonga
|
|
56
77
|
:workers => @options[:n_workers],
|
57
78
|
:log_level => $log.level,
|
58
79
|
:server_process_name => "Server[#{@options[:database]}] #$0",
|
59
|
-
:worker_process_name => "Worker[#{@options[:database]}] #$0"
|
80
|
+
:worker_process_name => "Worker[#{@options[:database]}] #$0",
|
81
|
+
:message_receiver => @message_pusher.raw_receiver,
|
60
82
|
}
|
61
83
|
@options.merge(force_options)
|
62
84
|
end
|