droonga-engine 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/benchmark/timer-watcher/benchmark.rb +44 -0
  4. data/bin/droonga-engine-absorb-data +246 -187
  5. data/bin/droonga-engine-catalog-generate +12 -12
  6. data/bin/droonga-engine-catalog-modify +4 -4
  7. data/bin/droonga-engine-join +352 -171
  8. data/bin/droonga-engine-set-role +54 -0
  9. data/bin/droonga-engine-unjoin +107 -112
  10. data/droonga-engine.gemspec +3 -3
  11. data/install.sh +55 -36
  12. data/install/centos/functions.sh +2 -2
  13. data/install/debian/functions.sh +2 -2
  14. data/lib/droonga/address.rb +26 -24
  15. data/lib/droonga/buffered_tcp_socket.rb +65 -10
  16. data/lib/droonga/catalog/base.rb +9 -6
  17. data/lib/droonga/catalog/dataset.rb +17 -41
  18. data/lib/droonga/catalog/fetcher.rb +64 -0
  19. data/lib/droonga/catalog/generator.rb +245 -0
  20. data/lib/droonga/catalog/loader.rb +66 -0
  21. data/lib/droonga/{catalog_modifier.rb → catalog/modifier.rb} +11 -18
  22. data/lib/droonga/catalog/replicas_volume.rb +123 -0
  23. data/lib/droonga/catalog/schema.rb +37 -37
  24. data/lib/droonga/catalog/single_volume.rb +11 -3
  25. data/lib/droonga/catalog/slice.rb +10 -6
  26. data/lib/droonga/catalog/{collection_volume.rb → slices_volume.rb} +47 -11
  27. data/lib/droonga/catalog/version1.rb +47 -19
  28. data/lib/droonga/catalog/version2.rb +11 -10
  29. data/lib/droonga/catalog/version2_validator.rb +4 -4
  30. data/lib/droonga/catalog/volume.rb +17 -5
  31. data/lib/droonga/changable.rb +25 -0
  32. data/lib/droonga/cluster.rb +237 -0
  33. data/lib/droonga/collector_runner.rb +4 -0
  34. data/lib/droonga/collectors.rb +2 -1
  35. data/lib/droonga/collectors/recursive_sum.rb +26 -0
  36. data/lib/droonga/command/droonga_engine.rb +404 -127
  37. data/lib/droonga/command/droonga_engine_service.rb +47 -11
  38. data/lib/droonga/command/droonga_engine_worker.rb +21 -1
  39. data/lib/droonga/command/remote_command_base.rb +78 -0
  40. data/lib/droonga/command/serf_event_handler.rb +29 -20
  41. data/lib/droonga/data_absorber_client.rb +222 -0
  42. data/lib/droonga/database_scanner.rb +106 -0
  43. data/lib/droonga/{live_nodes_list_loader.rb → deferrable.rb} +11 -24
  44. data/lib/droonga/differ.rb +58 -0
  45. data/lib/droonga/dispatcher.rb +155 -32
  46. data/lib/droonga/distributed_command_planner.rb +9 -11
  47. data/lib/droonga/engine.rb +83 -78
  48. data/lib/droonga/engine/version.rb +1 -1
  49. data/lib/droonga/engine_node.rb +301 -0
  50. data/lib/droonga/engine_state.rb +62 -40
  51. data/lib/droonga/farm.rb +44 -5
  52. data/lib/droonga/file_observer.rb +16 -12
  53. data/lib/droonga/fluent_message_receiver.rb +98 -29
  54. data/lib/droonga/fluent_message_sender.rb +30 -23
  55. data/lib/droonga/forward_buffer.rb +160 -0
  56. data/lib/droonga/forwarder.rb +73 -40
  57. data/lib/droonga/handler.rb +7 -6
  58. data/lib/droonga/handler_messenger.rb +15 -6
  59. data/lib/droonga/handler_runner.rb +6 -1
  60. data/lib/droonga/internal_fluent_message_receiver.rb +28 -8
  61. data/lib/droonga/job_pusher.rb +10 -7
  62. data/lib/droonga/job_receiver.rb +6 -4
  63. data/lib/droonga/logger.rb +7 -1
  64. data/lib/droonga/node_name.rb +90 -0
  65. data/lib/droonga/node_role.rb +72 -0
  66. data/lib/droonga/path.rb +34 -9
  67. data/lib/droonga/planner.rb +73 -7
  68. data/lib/droonga/plugin/async_command.rb +154 -0
  69. data/lib/droonga/plugins/catalog.rb +1 -0
  70. data/lib/droonga/plugins/crud.rb +22 -6
  71. data/lib/droonga/plugins/dump.rb +66 -135
  72. data/lib/droonga/plugins/groonga/delete.rb +13 -0
  73. data/lib/droonga/plugins/search/distributed_search_planner.rb +4 -4
  74. data/lib/droonga/plugins/system.rb +5 -26
  75. data/lib/droonga/plugins/system/absorb_data.rb +405 -0
  76. data/lib/droonga/plugins/system/statistics.rb +71 -0
  77. data/lib/droonga/plugins/system/status.rb +53 -0
  78. data/lib/droonga/process_control_protocol.rb +3 -1
  79. data/lib/droonga/process_supervisor.rb +32 -15
  80. data/lib/droonga/reducer.rb +69 -0
  81. data/lib/droonga/safe_file_writer.rb +1 -1
  82. data/lib/droonga/serf.rb +207 -276
  83. data/lib/droonga/serf/agent.rb +228 -0
  84. data/lib/droonga/serf/command.rb +94 -0
  85. data/lib/droonga/serf/downloader.rb +120 -0
  86. data/lib/droonga/serf/remote_command.rb +348 -0
  87. data/lib/droonga/serf/tag.rb +56 -0
  88. data/lib/droonga/service_installation.rb +2 -2
  89. data/lib/droonga/session.rb +49 -1
  90. data/lib/droonga/single_step.rb +6 -11
  91. data/lib/droonga/single_step_definition.rb +32 -1
  92. data/lib/droonga/slice.rb +14 -9
  93. data/lib/droonga/supervisor.rb +27 -20
  94. data/lib/droonga/test/stub_handler_messenger.rb +2 -1
  95. data/lib/droonga/timestamp.rb +69 -0
  96. data/lib/droonga/worker_process_agent.rb +33 -15
  97. data/sample/cluster-state.json +8 -0
  98. data/sample/cluster/Rakefile +30 -6
  99. data/test/command/fixture/integer-key-table.jsons +11 -0
  100. data/test/command/fixture/string-key-table.jsons +11 -0
  101. data/test/command/run-test.rb +4 -0
  102. data/test/command/suite/add/error/invalid-integer.expected +3 -3
  103. data/test/command/suite/add/error/invalid-time.expected +3 -3
  104. data/test/command/suite/add/{minimum.expected → key-integer.expected} +0 -0
  105. data/test/command/suite/add/{minimum.test → key-integer.test} +0 -0
  106. data/test/command/suite/add/key-string.expected +6 -0
  107. data/test/command/suite/add/key-string.test +9 -0
  108. data/test/command/suite/add/mismatched-key-type/acceptable/integer-for-string.expected +6 -0
  109. data/test/command/suite/add/mismatched-key-type/acceptable/integer-for-string.test +9 -0
  110. data/test/command/suite/add/mismatched-key-type/acceptable/string-for-integer.expected +6 -0
  111. data/test/command/suite/add/mismatched-key-type/acceptable/string-for-integer.test +9 -0
  112. data/test/command/suite/add/without-values.expected +6 -0
  113. data/test/command/suite/add/without-values.test +11 -0
  114. data/test/command/suite/dump/column/index.expected +33 -1
  115. data/test/command/suite/dump/column/index.test +1 -0
  116. data/test/command/suite/dump/column/scalar.expected +29 -1
  117. data/test/command/suite/dump/column/scalar.test +1 -0
  118. data/test/command/suite/dump/column/vector.expected +29 -1
  119. data/test/command/suite/dump/column/vector.test +1 -0
  120. data/test/command/suite/dump/record/scalar.catalog.json +12 -0
  121. data/test/command/suite/dump/record/scalar.expected +84 -0
  122. data/test/command/suite/dump/record/scalar.test +16 -0
  123. data/test/command/suite/dump/record/vector/reference.expected +83 -1
  124. data/test/command/suite/dump/record/vector/reference.test +1 -0
  125. data/test/command/suite/dump/table/array.expected +27 -1
  126. data/test/command/suite/dump/table/array.test +1 -0
  127. data/test/command/suite/dump/table/double_array_trie.expected +27 -1
  128. data/test/command/suite/dump/table/double_array_trie.test +1 -0
  129. data/test/command/suite/dump/table/hash.expected +27 -1
  130. data/test/command/suite/dump/table/hash.test +1 -0
  131. data/test/command/suite/dump/table/patricia_trie.expected +27 -1
  132. data/test/command/suite/dump/table/patricia_trie.test +1 -0
  133. data/test/command/suite/groonga/delete/{success.expected → key-integer.expected} +0 -0
  134. data/test/command/suite/groonga/delete/key-integer.test +17 -0
  135. data/test/command/suite/groonga/delete/key-string.expected +19 -0
  136. data/test/command/suite/groonga/delete/{success.test → key-string.test} +4 -6
  137. data/test/command/suite/groonga/delete/mismatched-type-key/acceptable/integer-for-string.expected +19 -0
  138. data/test/command/suite/groonga/delete/mismatched-type-key/acceptable/integer-for-string.test +17 -0
  139. data/test/command/suite/groonga/delete/mismatched-type-key/acceptable/string-for-integer.expected +19 -0
  140. data/test/command/suite/groonga/delete/mismatched-type-key/acceptable/string-for-integer.test +17 -0
  141. data/test/command/suite/message/error/missing-dataset.test +1 -0
  142. data/test/command/suite/system/absorb-data/records.catalog.json +58 -0
  143. data/test/command/suite/system/absorb-data/records.expected +32 -0
  144. data/test/command/suite/system/absorb-data/records.test +24 -0
  145. data/test/command/suite/system/statistics/object/count/empty.expected +11 -0
  146. data/test/command/suite/system/statistics/object/count/empty.test +12 -0
  147. data/test/command/suite/system/statistics/object/count/per-volume/empty.catalog.json +36 -0
  148. data/test/command/suite/system/statistics/object/count/per-volume/empty.expected +19 -0
  149. data/test/command/suite/system/statistics/object/count/per-volume/empty.test +12 -0
  150. data/test/command/suite/system/statistics/object/count/per-volume/record.catalog.json +40 -0
  151. data/test/command/suite/system/statistics/object/count/per-volume/record.expected +19 -0
  152. data/test/command/suite/system/statistics/object/count/per-volume/record.test +23 -0
  153. data/test/command/suite/system/statistics/object/count/per-volume/schema.catalog.json +40 -0
  154. data/test/command/suite/system/statistics/object/count/per-volume/schema.expected +19 -0
  155. data/test/command/suite/system/statistics/object/count/per-volume/schema.test +13 -0
  156. data/test/command/suite/system/statistics/object/count/record.catalog.json +12 -0
  157. data/test/command/suite/system/statistics/object/count/record.expected +11 -0
  158. data/test/command/suite/system/statistics/object/count/record.test +23 -0
  159. data/test/command/suite/system/statistics/object/count/schema.catalog.json +12 -0
  160. data/test/command/suite/system/statistics/object/count/schema.expected +11 -0
  161. data/test/command/suite/system/statistics/object/count/schema.test +13 -0
  162. data/test/command/suite/system/status.expected +3 -2
  163. data/test/unit/catalog/test_dataset.rb +4 -1
  164. data/test/unit/{test_catalog_generator.rb → catalog/test_generator.rb} +2 -2
  165. data/test/unit/catalog/test_replicas_volume.rb +79 -0
  166. data/test/unit/catalog/test_single_volume.rb +2 -2
  167. data/test/unit/catalog/test_slice.rb +33 -1
  168. data/test/unit/catalog/{test_collection_volume.rb → test_slices_volume.rb} +72 -11
  169. data/test/unit/catalog/test_version2.rb +3 -0
  170. data/test/unit/helper/distributed_search_planner_helper.rb +2 -2
  171. data/test/unit/plugins/catalog/test_fetch.rb +4 -4
  172. data/test/unit/plugins/crud/test_add.rb +44 -4
  173. data/test/unit/plugins/groonga/test_column_create.rb +4 -4
  174. data/test/unit/plugins/groonga/test_column_list.rb +4 -4
  175. data/test/unit/plugins/groonga/test_column_remove.rb +4 -4
  176. data/test/unit/plugins/groonga/test_column_rename.rb +4 -4
  177. data/test/unit/plugins/groonga/test_delete.rb +73 -10
  178. data/test/unit/plugins/groonga/test_table_create.rb +4 -4
  179. data/test/unit/plugins/groonga/test_table_list.rb +4 -4
  180. data/test/unit/plugins/groonga/test_table_remove.rb +4 -4
  181. data/test/unit/plugins/search/test_handler.rb +4 -4
  182. data/test/unit/plugins/search/test_planner.rb +4 -2
  183. data/test/unit/plugins/system/test_status.rb +31 -15
  184. data/test/unit/plugins/test_watch.rb +16 -16
  185. data/test/unit/test_address.rb +4 -4
  186. metadata +134 -35
  187. data/lib/droonga/catalog/volume_collection.rb +0 -79
  188. data/lib/droonga/catalog_fetcher.rb +0 -53
  189. data/lib/droonga/catalog_generator.rb +0 -243
  190. data/lib/droonga/catalog_loader.rb +0 -56
  191. data/lib/droonga/command/remote.rb +0 -404
  192. data/lib/droonga/data_absorber.rb +0 -264
  193. data/lib/droonga/node_status.rb +0 -71
  194. data/lib/droonga/serf_downloader.rb +0 -115
  195. data/test/unit/catalog/test_volume_collection.rb +0 -78
@@ -0,0 +1,56 @@
1
+ # Copyright (C) 2015 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
+ module Droonga
17
+ class Serf
18
+ module Tag
19
+ class << self
20
+ def node_type
21
+ "type"
22
+ end
23
+
24
+ def node_role
25
+ "role"
26
+ end
27
+
28
+ def internal_node_name
29
+ "internal-name"
30
+ end
31
+
32
+ def cluster_id
33
+ "cluster_id"
34
+ end
35
+
36
+ def accept_messages_newer_than
37
+ "accept-newer-than"
38
+ end
39
+
40
+ HAVE_UNPROCESSED_MESSAGES_TAG_PREFIX = "buffered-for-"
41
+
42
+ def have_unprocessed_messages_tag_for(node_name)
43
+ "#{HAVE_UNPROCESSED_MESSAGES_TAG_PREFIX}#{node_name}"
44
+ end
45
+
46
+ def have_unprocessed_messages_tag?(tag)
47
+ tag.start_with?(HAVE_UNPROCESSED_MESSAGES_TAG_PREFIX)
48
+ end
49
+
50
+ def extract_node_name_from_have_unprocessed_messages_tag(tag)
51
+ tag.sub(HAVE_UNPROCESSED_MESSAGES_TAG_PREFIX, "")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -47,7 +47,7 @@ module Droonga
47
47
  test_file = Path.config
48
48
  begin
49
49
  test_file.read
50
- rescue Errno::EACCES => error
50
+ rescue Errno::EACCES
51
51
  return false
52
52
  end
53
53
  true
@@ -58,7 +58,7 @@ module Droonga
58
58
  begin
59
59
  FileUtils.mkdir_p(Path.base)
60
60
  FileUtils.touch(test_file.to_s)
61
- rescue Errno::EACCES => error
61
+ rescue Errno::EACCES
62
62
  end
63
63
  unless test_file.exist?
64
64
  return false
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2014 Droonga Project
1
+ # Copyright (C) 2013-2015 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -13,6 +13,8 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
15
 
16
+ require "coolio"
17
+
16
18
  require "droonga/loggable"
17
19
 
18
20
  module Droonga
@@ -26,26 +28,57 @@ module Droonga
26
28
  @tasks = tasks
27
29
  @n_dones = 0
28
30
  @inputs = inputs
31
+ logger.trace("initialized", :tasks => tasks, :inputs => inputs)
29
32
  end
30
33
 
31
34
  def done?
32
35
  @n_dones == @tasks.size
33
36
  end
34
37
 
38
+ #TODO: We don't have to wait results if no collection step is
39
+ # in the list of tasks, because:
40
+ #
41
+ # * Currently the "super step" mecahnism is not
42
+ # implemented yet.
43
+ # * So, results won't be used by other handlers directly.
44
+ # Results will be used only for the "response" for the
45
+ # sender.
46
+ # * So, if there is no collection step, no-one requires
47
+ # results and there is no need to wait for results.
48
+ #
49
+ # However, in the future after the "super step" mechanism
50
+ # is introduced, results can be used by other handlers
51
+ # even if there is no collection step.
52
+ # Then we must update this logic.
53
+ def need_result?
54
+ @tasks.any? do |task|
55
+ @collector_runner.collectable?("task" => task)
56
+ end
57
+ end
58
+
35
59
  def start
36
60
  tasks = @inputs[nil] || []
61
+ logger.trace("start: no task!") if tasks.empty?
37
62
  tasks.each do |task|
38
63
  local_message = {
39
64
  "id" => @id,
40
65
  "task" => task,
41
66
  }
67
+ logger.trace("start: dispatching local message", :message => local_message)
42
68
  @dispatcher.process_local_message(local_message)
43
69
  @n_dones += 1
44
70
  end
45
71
  end
46
72
 
73
+ def finish
74
+ @timeout_timer.detach if @timeout_timer
75
+ @timeout_timer = nil
76
+ end
77
+
47
78
  def receive(name, value)
48
79
  tasks = @inputs[name]
80
+ logger.trace("receive: process response",
81
+ :name => name, :value => value, :task => tasks)
49
82
  unless tasks
50
83
  #TODO: result arrived before its query
51
84
  return
@@ -82,6 +115,17 @@ module Droonga
82
115
  end
83
116
  end
84
117
 
118
+ def set_timeout(loop, timeout, &block)
119
+ @timeout_timer = Coolio::TimerWatcher.new(timeout)
120
+ @timeout_timer.on_timer do
121
+ @timeout_timer.detach
122
+ @timeout_timer = nil
123
+ report_timeout_error
124
+ yield
125
+ end
126
+ loop.attach(@timeout_timer)
127
+ end
128
+
85
129
  private
86
130
  def send_to_descendantas(descendantas, result)
87
131
  descendantas.each do |name, routes|
@@ -96,6 +140,10 @@ module Droonga
96
140
  end
97
141
  end
98
142
 
143
+ def report_timeout_error
144
+ #TODO: implement me!
145
+ end
146
+
99
147
  def log_tag
100
148
  "session"
101
149
  end
@@ -32,23 +32,18 @@ module Droonga
32
32
 
33
33
  # XXX: Re-implement me.
34
34
  planner = Planner.new(@dataset)
35
- options = {}
36
- options[:write] = @definition.write?
37
- collector_class = @definition.collector_class
38
- if collector_class
39
- reduce_key = "result"
40
- options[:reduce] = {
41
- reduce_key => collector_class.operator,
42
- }
43
- end
35
+ planner.write = @definition.write?
36
+ planner.single_operation = @definition.single_operation?
37
+ planner.use_all_replicas = @definition.use_all_replicas?
38
+ planner.collector_class = @definition.collector_class
44
39
 
45
40
  body = message["body"]
46
41
  fact_input = find_fact_input(@definition.inputs, @dataset.fact, body)
47
42
  if fact_input
48
43
  record = body[fact_input[:filter]]
49
- planner.send(:scatter, message, record, options)
44
+ planner.plan(message, :record => record)
50
45
  else
51
- planner.send(:broadcast, message, options)
46
+ planner.plan(message)
52
47
  end
53
48
  end
54
49
 
@@ -18,7 +18,9 @@ module Droonga
18
18
  attr_accessor :name
19
19
  attr_accessor :handler
20
20
  attr_accessor :collector
21
- attr_writer :write
21
+ attr_writer :write, :single_operation
22
+ attr_writer :use_all_replicas
23
+ attr_writer :timeout_calculator
22
24
  attr_accessor :inputs
23
25
  attr_accessor :output
24
26
  def initialize(plugin_module)
@@ -27,6 +29,17 @@ module Droonga
27
29
  @handler = nil
28
30
  @collector = nil
29
31
  @write = false
32
+ @single_operation = false
33
+ @use_all_replicas = false
34
+ @timeout_calculator = lambda do |step|
35
+ if step["timeout"]
36
+ return step["timeout"]
37
+ elsif step["body"]
38
+ return step["body"]["timeout"] if step["body"]["timeout"]
39
+ end
40
+ nil
41
+ end
42
+
30
43
  @inputs = []
31
44
  @output = {}
32
45
  yield(self)
@@ -36,6 +49,24 @@ module Droonga
36
49
  @write
37
50
  end
38
51
 
52
+ def single_operation?
53
+ return false if @write
54
+ @single_operation
55
+ end
56
+
57
+ def use_all_replicas?
58
+ return true if @write
59
+ @use_all_replicas
60
+ end
61
+
62
+ def timeout_for_step(step)
63
+ if @timeout_calculator
64
+ @timeout_calculator.call(step)
65
+ else
66
+ nil
67
+ end
68
+ end
69
+
39
70
  def handler_class
40
71
  resolve_class(@handler)
41
72
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2014 Droonga Project
1
+ # Copyright (C) 2013-2015 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,7 @@
14
14
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
15
 
16
16
  require "droonga/loggable"
17
+ require "droonga/deferrable"
17
18
  require "droonga/supervisor"
18
19
  require "droonga/event_loop"
19
20
  require "droonga/job_pusher"
@@ -23,9 +24,10 @@ require "droonga/schema_applier"
23
24
  module Droonga
24
25
  class Slice
25
26
  include Loggable
27
+ include Deferrable
26
28
 
27
- attr_writer :on_ready
28
- def initialize(dataset, loop, options={})
29
+ def initialize(label, dataset, loop, options={})
30
+ @label = label
29
31
  @dataset = dataset
30
32
  @loop = loop
31
33
  @options = options
@@ -34,7 +36,6 @@ module Droonga
34
36
  @job_pusher = JobPusher.new(@loop, @database_path)
35
37
  @processor = Processor.new(@loop, @job_pusher, @options)
36
38
  @supervisor = nil
37
- @on_ready = nil
38
39
  end
39
40
 
40
41
  def start
@@ -50,6 +51,7 @@ module Droonga
50
51
  @job_pusher.shutdown
51
52
  @processor.shutdown
52
53
  yield if block_given?
54
+ logger.trace("stop_gracefully: done")
53
55
  end
54
56
  if @supervisor
55
57
  @supervisor.stop_gracefully do
@@ -58,7 +60,6 @@ module Droonga
58
60
  else
59
61
  on_stop.call
60
62
  end
61
- logger.trace("stop_gracefully: done")
62
63
  end
63
64
 
64
65
  def stop_immediately
@@ -69,6 +70,12 @@ module Droonga
69
70
  logger.trace("stop_immediately: done")
70
71
  end
71
72
 
73
+ def refresh_node_reference
74
+ logger.trace("refresh_node_reference: start")
75
+ @supervisor.refresh_node_reference if @supervisor
76
+ logger.trace("refresh_node_reference: done")
77
+ end
78
+
72
79
  def process(message)
73
80
  logger.trace("process: start")
74
81
  @processor.process(message)
@@ -112,10 +119,12 @@ module Droonga
112
119
 
113
120
  config = Supervisor::WorkerConfiguration.new
114
121
  config.name = @options[:name]
122
+ config.label = @label
115
123
  config.dataset = @dataset
116
124
  config.database_path = @database_path
117
125
  config.plugins = @options[:plugins]
118
126
  config.job_pusher = @job_pusher
127
+ config.internal_connection_lifetime = @options[:internal_connection_lifetime]
119
128
  @supervisor = Supervisor.new(@loop, @n_workers, config)
120
129
  @supervisor.on_ready = lambda do
121
130
  on_ready
@@ -123,10 +132,6 @@ module Droonga
123
132
  @supervisor.start
124
133
  end
125
134
 
126
- def on_ready
127
- @on_ready.call if @on_ready
128
- end
129
-
130
135
  def log_tag
131
136
  "slice"
132
137
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Droonga Project
1
+ # Copyright (C) 2014-2015 Droonga Project
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,18 +14,18 @@
14
14
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
15
 
16
16
  require "droonga/loggable"
17
+ require "droonga/deferrable"
17
18
  require "droonga/process_supervisor"
18
19
 
19
20
  module Droonga
20
21
  class Supervisor
21
22
  include Loggable
23
+ include Deferrable
22
24
 
23
- attr_writer :on_ready
24
25
  def initialize(loop, n_workers, config)
25
26
  @loop = loop
26
27
  @n_workers = n_workers
27
28
  @config = config
28
- @on_ready = nil
29
29
  end
30
30
 
31
31
  def start
@@ -35,7 +35,7 @@ module Droonga
35
35
  worker_runner.on_ready = lambda do
36
36
  n_ready_workers += 1
37
37
  if n_ready_workers == @n_workers
38
- @on_ready.call if @on_ready
38
+ on_ready
39
39
  end
40
40
  end
41
41
  worker_runner.start
@@ -53,10 +53,10 @@ module Droonga
53
53
  n_done_worker_runners += 1
54
54
  if n_done_worker_runners == n_worker_runners
55
55
  yield if block_given?
56
+ logger.trace("stop_gracefully: done")
56
57
  end
57
58
  end
58
59
  end
59
- logger.trace("stop_gracefully: done")
60
60
  end
61
61
 
62
62
  def stop_immediately
@@ -65,6 +65,12 @@ module Droonga
65
65
  end
66
66
  end
67
67
 
68
+ def refresh_node_reference
69
+ @worker_runners.each do |worker_runner|
70
+ worker_runner.refresh_node_reference
71
+ end
72
+ end
73
+
68
74
  private
69
75
  def log_tag
70
76
  "supervisor"
@@ -72,30 +78,31 @@ module Droonga
72
78
 
73
79
  class WorkerConfiguration
74
80
  attr_accessor :name
81
+ attr_accessor :label
75
82
  attr_accessor :dataset
76
83
  attr_accessor :database_path
77
84
  attr_accessor :plugins
78
85
  attr_accessor :job_pusher
86
+ attr_accessor :internal_connection_lifetime
79
87
  def initialize
80
88
  @name = nil
89
+ @label = nil
81
90
  @dataset = nil
82
91
  @database_path = nil
83
92
  @plugins = []
84
93
  @job_pusher = nil
94
+ @internal_connection_lifetime = nil
85
95
  end
86
96
  end
87
97
 
88
98
  class WorkerRunner
89
99
  include Loggable
100
+ include Deferrable
90
101
 
91
- attr_writer :on_ready
92
- attr_writer :on_failure
93
102
  def initialize(loop, id, config)
94
103
  @loop = loop
95
104
  @id = id
96
105
  @config = config
97
- @on_ready = nil
98
- @on_failure = nil
99
106
  @stop_gracefully_callback = nil
100
107
  end
101
108
 
@@ -111,9 +118,12 @@ module Droonga
111
118
  "--control-write-fd", control_read_out.fileno.to_s,
112
119
  "--job-queue-socket-path", @config.job_pusher.socket_path.to_s,
113
120
  "--pid-file", pid_path.to_s,
121
+ "--label", @config.label,
114
122
  "--dataset", @config.dataset.name,
115
123
  "--database-path", @config.database_path.to_s,
116
124
  "--plugins", @config.plugins.join(","),
125
+ "--internal-connection-lifetime",
126
+ @config.internal_connection_lifetime.to_s,
117
127
  ]
118
128
  options = {
119
129
  control_write_in => control_write_in,
@@ -130,14 +140,20 @@ module Droonga
130
140
  def stop_gracefully(&block)
131
141
  logger.trace("stop_gracefully: start")
132
142
  @supervisor.stop_gracefully
133
- @stop_gracefully_callback = block
134
- logger.trace("stop_gracefully: done")
143
+ @stop_gracefully_callback = lambda do
144
+ yield if block_given?
145
+ logger.trace("stop_gracefully: done")
146
+ end
135
147
  end
136
148
 
137
149
  def stop_immediately
138
150
  @supervisor.stop_immediately
139
151
  end
140
152
 
153
+ def refresh_node_reference
154
+ @supervisor.refresh_node_reference
155
+ end
156
+
141
157
  def success?
142
158
  @success
143
159
  end
@@ -158,15 +174,6 @@ module Droonga
158
174
  supervisor
159
175
  end
160
176
 
161
- def on_ready
162
- @on_ready.call if @on_ready
163
- end
164
-
165
- def on_failure
166
- # TODO: log
167
- @on_failure.call if @on_failure
168
- end
169
-
170
177
  def on_finish
171
178
  _, status = Process.waitpid2(@pid)
172
179
  @success = status.success?