fluent-plugin-droonga 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.dir-locals.el +3 -0
  3. data/.travis.yml +6 -2
  4. data/README.md +6 -7
  5. data/Rakefile +23 -6
  6. data/fluent-plugin-droonga.gemspec +2 -2
  7. data/lib/droonga/adapter.rb +12 -3
  8. data/lib/droonga/adapter_runner.rb +28 -23
  9. data/lib/droonga/catalog/base.rb +7 -111
  10. data/lib/droonga/catalog/dataset.rb +13 -25
  11. data/lib/droonga/catalog/errors.rb +94 -0
  12. data/lib/droonga/catalog/schema.rb +277 -0
  13. data/lib/droonga/catalog/version1.rb +404 -0
  14. data/lib/droonga/catalog/version2.rb +160 -0
  15. data/lib/droonga/catalog_loader.rb +27 -4
  16. data/lib/droonga/catalog_observer.rb +44 -6
  17. data/lib/droonga/collector.rb +12 -10
  18. data/lib/droonga/{handler_plugin.rb → collector_message.rb} +47 -20
  19. data/lib/droonga/collector_runner.rb +64 -0
  20. data/lib/droonga/collectors.rb +18 -0
  21. data/lib/droonga/{catalog.rb → collectors/add.rb} +9 -7
  22. data/lib/droonga/{command_repository.rb → collectors/and.rb} +7 -14
  23. data/lib/droonga/collectors/sum.rb +26 -0
  24. data/lib/droonga/dispatcher.rb +74 -41
  25. data/lib/droonga/distributed_command_planner.rb +2 -2
  26. data/lib/droonga/engine.rb +13 -5
  27. data/lib/droonga/{message_processing_error.rb → error.rb} +33 -12
  28. data/lib/droonga/{plugin/planner/search.rb → error_messages.rb} +12 -10
  29. data/lib/droonga/farm.rb +15 -14
  30. data/lib/droonga/fluent_message_sender.rb +15 -11
  31. data/lib/droonga/forwarder.rb +22 -18
  32. data/lib/droonga/handler.rb +8 -2
  33. data/lib/droonga/handler_runner.rb +47 -26
  34. data/lib/droonga/input_message.rb +6 -6
  35. data/lib/droonga/{command.rb → loggable.rb} +7 -14
  36. data/lib/droonga/logger.rb +56 -15
  37. data/lib/droonga/message_matcher.rb +12 -7
  38. data/lib/droonga/message_pusher.rb +8 -4
  39. data/lib/droonga/message_receiver.rb +11 -9
  40. data/lib/droonga/output_message.rb +2 -0
  41. data/lib/droonga/planner.rb +21 -10
  42. data/lib/droonga/plugin.rb +15 -0
  43. data/lib/droonga/plugin/metadata/{adapter_message.rb → adapter_input_message.rb} +6 -14
  44. data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
  45. data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
  46. data/lib/droonga/plugin/metadata/input_message.rb +15 -0
  47. data/lib/droonga/plugin_loader.rb +33 -25
  48. data/lib/droonga/plugin_registry.rb +9 -1
  49. data/lib/droonga/plugins/basic.rb +54 -0
  50. data/lib/droonga/plugins/crud.rb +36 -15
  51. data/lib/droonga/plugins/error.rb +5 -4
  52. data/lib/droonga/plugins/groonga.rb +9 -6
  53. data/lib/droonga/plugins/groonga/column_create.rb +10 -5
  54. data/lib/droonga/plugins/groonga/generic_command.rb +2 -8
  55. data/lib/droonga/plugins/groonga/generic_response.rb +2 -2
  56. data/lib/droonga/plugins/groonga/select.rb +2 -2
  57. data/lib/droonga/plugins/groonga/table_create.rb +9 -4
  58. data/lib/droonga/plugins/groonga/table_remove.rb +10 -5
  59. data/lib/droonga/plugins/search.rb +106 -5
  60. data/lib/droonga/plugins/search/distributed_search_planner.rb +398 -0
  61. data/lib/droonga/plugins/watch.rb +41 -20
  62. data/lib/droonga/processor.rb +12 -9
  63. data/lib/droonga/{plugin/collector/basic.rb → reducer.rb} +36 -50
  64. data/lib/droonga/replier.rb +7 -4
  65. data/lib/droonga/searcher.rb +40 -37
  66. data/lib/droonga/server.rb +8 -6
  67. data/lib/droonga/session.rb +17 -7
  68. data/lib/droonga/single_step.rb +53 -0
  69. data/lib/droonga/{plugin/planner/watch.rb → single_step_definition.rb} +27 -26
  70. data/lib/droonga/{partition.rb → slice.rb} +23 -12
  71. data/lib/droonga/status_code.rb +25 -0
  72. data/lib/droonga/step_runner.rb +63 -0
  73. data/lib/droonga/watch_schema.rb +7 -3
  74. data/lib/droonga/watcher.rb +4 -4
  75. data/lib/droonga/worker.rb +6 -6
  76. data/lib/fluent/plugin/out_droonga.rb +27 -2
  77. data/sample/cluster/catalog.json +33 -32
  78. data/test/command/config/default/catalog.json +72 -45
  79. data/test/command/config/version1/catalog.json +68 -0
  80. data/test/command/config/version1/fluentd.conf +11 -0
  81. data/test/command/suite/message/error/missing-dataset.expected +1 -1
  82. data/test/command/suite/message/error/unknown-dataset.expected +1 -1
  83. data/test/command/suite/message/error/unknown-type.expected +13 -0
  84. data/test/command/suite/message/error/{unknown-command.test → unknown-type.test} +1 -1
  85. data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
  86. data/test/command/suite/search/error/unknown-source.expected +15 -3
  87. data/test/command/suite/watch/subscribe.expected +1 -3
  88. data/test/command/suite/watch/unsubscribe.expected +1 -3
  89. data/test/performance/watch/catalog.json +1 -0
  90. data/test/unit/catalog/test_dataset.rb +16 -358
  91. data/test/unit/catalog/test_schema.rb +285 -0
  92. data/test/unit/catalog/test_version1.rb +222 -28
  93. data/test/unit/catalog/test_version2.rb +155 -0
  94. data/test/unit/fixtures/catalog/version2.json +62 -0
  95. data/test/unit/helper/distributed_search_planner_helper.rb +2 -2
  96. data/test/unit/plugins/crud/test_add.rb +13 -13
  97. data/test/unit/plugins/groonga/test_column_create.rb +14 -11
  98. data/test/unit/plugins/groonga/test_table_create.rb +4 -9
  99. data/test/unit/plugins/groonga/test_table_remove.rb +4 -9
  100. data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_basic.rb +0 -0
  101. data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_group_by.rb +0 -0
  102. data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_output.rb +0 -0
  103. data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_sort_by.rb +0 -0
  104. data/test/unit/{plugin/collector/test_search.rb → plugins/search/test_collector.rb} +40 -39
  105. data/test/unit/plugins/{test_search.rb → search/test_handler.rb} +6 -5
  106. data/test/unit/{plugin/planner/test_search.rb → plugins/search/test_planner.rb} +3 -3
  107. data/test/unit/{plugin/collector → plugins}/test_basic.rb +68 -50
  108. data/test/unit/plugins/test_groonga.rb +2 -15
  109. data/test/unit/plugins/test_watch.rb +25 -22
  110. data/test/unit/test_message_matcher.rb +29 -6
  111. data/test/unit/test_output.rb +4 -0
  112. metadata +58 -50
  113. data/lib/droonga/collector_plugin.rb +0 -50
  114. data/lib/droonga/legacy_pluggable.rb +0 -66
  115. data/lib/droonga/legacy_plugin.rb +0 -57
  116. data/lib/droonga/legacy_plugin_repository.rb +0 -54
  117. data/lib/droonga/planner_plugin.rb +0 -54
  118. data/lib/droonga/plugin/collector/search.rb +0 -98
  119. data/lib/droonga/plugin/planner/crud.rb +0 -49
  120. data/lib/droonga/plugin/planner/distributed_search_planner.rb +0 -393
  121. data/lib/droonga/plugin/planner/groonga.rb +0 -54
  122. data/lib/droonga/plugin_registerable.rb +0 -75
  123. data/test/command/suite/message/error/unknown-command.expected +0 -13
  124. data/test/unit/test_command_repository.rb +0 -39
  125. data/test/unit/test_legacy_plugin.rb +0 -50
  126. data/test/unit/test_legacy_plugin_repository.rb +0 -89
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24503ddfa77a2b4c19b83b771069a3c91f738ef2
4
- data.tar.gz: 50f89c1a0fed25c58d8d16b5e16c41258cbd4e3a
3
+ metadata.gz: 611f2ebd66b47ba06e51dcba81545e17dc8759fb
4
+ data.tar.gz: 60378c2f9a04272698fbb64bbeb104ab7dd49b76
5
5
  SHA512:
6
- metadata.gz: d6b1075946a566e9a92703c682a160ece90bfe8e46e7ec2f722617048d25e54b6453aa25ffc91582e12267bd773904d88605b16a20648dc05536f9943bd00e44
7
- data.tar.gz: 4140cc01d656daed66444a853ea585c4aec6fc55b10361e29eac617f924b421d2a3aa2fe17519a5c585ffd8d044b55d01e32e76924bb2ed2ecd441af4ae82ed9
6
+ metadata.gz: 80eb92e66a2114940e77b7668941a2fd25d032d8caf1b3ca9752368b01027ed979049a4a90cfdcbb89a25e8ab85c3e91b7b9441da47fb2571a45b9e5fe271a71
7
+ data.tar.gz: a5dc67e0af98b68713b90ff8d15e8cf3923d86597d19777816a1a74391b5666295cfa74b3a569829b261e5eb629861cca79ecfcff3cbbb7259797f13e678a0e3
@@ -0,0 +1,3 @@
1
+ ((js-mode . ((indent-tabs-mode . nil)
2
+ (js-indent-level . 2)
3
+ (show-trailing-whitespace . t))))
@@ -1,10 +1,14 @@
1
1
  notifications:
2
2
  recipients:
3
3
  - groonga-commit@lists.sourceforge.jp
4
+ env:
5
+ - DEFAULT_TEST_TASK=test:unit
6
+ - DEFAULT_TEST_TASK=test:command:default
7
+ - DEFAULT_TEST_TASK=test:command:version1
4
8
  rvm:
5
9
  - 1.9.3
6
10
  - 2.0.0
7
- - 2.1.0
8
- - ruby-head
11
+ - 2.1
12
+ # - ruby-head
9
13
  before_install:
10
14
  - curl https://raw.github.com/groonga/groonga/master/data/travis/setup.sh | sh
data/README.md CHANGED
@@ -1,18 +1,17 @@
1
1
  # Fluent::Plugin::Droonga
2
2
 
3
- TODO: Write a gem description
3
+ ## What's "Droonga"?
4
4
 
5
- ## What's "droonga"?
6
-
7
- Droonga is a distributed fulltext search engine, named from "distributed-groonga".
8
- This package provides droonga plugin for Fluent event collector.
5
+ Droonga is a scalable data processing engine, named from "Distributed
6
+ Groonga". Droonga can execute distributed fulltext search.
9
7
 
10
8
  ## Usage
11
9
 
12
- TODO: Write usage.
10
+ See [droonga.org](http://droonga.org/). You can find overview, install
11
+ manual, reference manual and tutorial at the site.
13
12
 
14
13
  ## Copyright
15
14
 
16
- * Copyright (c) 2013 Droonga Project
15
+ * Copyright (c) 2013-2014 Droonga Project
17
16
  * License
18
17
  * GNU Lesser General Public License version 2.1
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2013 Droonga Project
3
+ # Copyright (C) 2013-2014 Droonga Project
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -29,19 +29,36 @@ Packnga::DocumentTask.new(spec) do |task|
29
29
  task.translate_languages = ["ja"]
30
30
  end
31
31
 
32
+ def run_command_test(*options)
33
+ ruby(File.join(File.dirname(__FILE__), "test", "command", "run-test.rb",),
34
+ *options)
35
+ end
36
+
32
37
  namespace :test do
33
38
  desc "Run unit test"
34
39
  task :unit do
35
40
  ruby(File.join(File.dirname(__FILE__), "test", "unit", "run-test.rb"))
36
41
  end
37
42
 
38
- desc "Run command test"
39
- task :command do
40
- ruby(File.join(File.dirname(__FILE__), "test", "command", "run-test.rb"))
43
+ namespace :command do
44
+ desc "Run command test: default"
45
+ task :default do
46
+ run_command_test
47
+ end
48
+
49
+ desc "Run command test: version1"
50
+ task :version1 do
51
+ run_command_test("--config", "version1")
52
+ end
41
53
  end
42
54
  end
43
55
 
44
56
  desc "Run test"
45
- task :test => ["test:unit", "test:command"]
57
+ task :test => [
58
+ "test:unit",
59
+ "test:command:default",
60
+ "test:command:version1",
61
+ ]
46
62
 
47
- task :default => :test
63
+ test_task = ENV["DEFAULT_TEST_TASK"] || "test"
64
+ task :default => test_task
@@ -17,10 +17,10 @@
17
17
 
18
18
  Gem::Specification.new do |gem|
19
19
  gem.name = "fluent-plugin-droonga"
20
- gem.version = "0.9.9"
20
+ gem.version = "1.0.0"
21
21
  gem.authors = ["Droonga Project"]
22
22
  gem.email = ["droonga@groonga.org"]
23
- gem.description = "Droonga(distributed Groonga) plugin for Fluent event collector"
23
+ gem.description = "Droonga (distributed Groonga) plugin for Fluent event collector"
24
24
  gem.summary = gem.description
25
25
  gem.homepage = "https://github.com/droonga/fluent-plugin-droonga"
26
26
  gem.files = `git ls-files`.split($/)
@@ -14,15 +14,24 @@
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
16
  require "droonga/pluggable"
17
- require "droonga/plugin/metadata/adapter_message"
17
+ require "droonga/loggable"
18
+ require "droonga/plugin/metadata/adapter_input_message"
19
+ require "droonga/plugin/metadata/adapter_output_message"
20
+ require "droonga/error_messages"
18
21
 
19
22
  module Droonga
20
23
  class Adapter
21
24
  extend Pluggable
25
+ include Loggable
26
+ include ErrorMessages
22
27
 
23
28
  class << self
24
- def message
25
- Plugin::Metadata::AdapterMessage.new(self)
29
+ def input_message
30
+ Plugin::Metadata::AdapterInputMessage.new(self)
31
+ end
32
+
33
+ def output_message
34
+ Plugin::Metadata::AdapterOutputMessage.new(self)
26
35
  end
27
36
 
28
37
  def id
@@ -13,6 +13,7 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
+ require "droonga/loggable"
16
17
  require "droonga/message_matcher"
17
18
  require "droonga/input_message"
18
19
  require "droonga/output_message"
@@ -20,74 +21,78 @@ require "droonga/adapter"
20
21
 
21
22
  module Droonga
22
23
  class AdapterRunner
24
+ include Loggable
25
+
23
26
  def initialize(dispatcher, plugins)
24
27
  @dispatcher = dispatcher
25
28
  default_plugins = ["error"]
26
29
  plugins += (default_plugins - plugins)
30
+ logger.debug("activating plugins: #{plugins.join(", ")}")
27
31
  @adapter_classes = Adapter.find_sub_classes(plugins)
32
+ logger.debug("activated:\n#{@adapter_classes.join("\n")}")
28
33
  end
29
34
 
30
35
  def shutdown
31
36
  end
32
37
 
33
38
  def adapt_input(message)
34
- $log.trace("#{log_tag}: adapt_input: start",
35
- :dataset => message["dataset"],
36
- :type => message["type"])
39
+ logger.trace("adapt_input: start",
40
+ :dataset => message["dataset"],
41
+ :type => message["type"])
37
42
  adapted_message = message
38
43
  adapted_message["appliedAdapters"] = []
39
44
  @adapter_classes.each do |adapter_class|
40
45
  adapter_class_id = adapter_class.id
41
- pattern = adapter_class.message.input_pattern
46
+ pattern = adapter_class.input_message.pattern
42
47
  if pattern
43
48
  matcher = MessageMatcher.new(pattern)
44
- $log.trace("#{log_tag}: adapt_input: skip: #{adapter_class_id}",
45
- :pattern => pattern)
49
+ logger.trace("adapt_input: skip: #{adapter_class_id}",
50
+ :pattern => pattern)
46
51
  next unless matcher.match?(adapted_message)
47
52
  end
48
- $log.trace("#{log_tag}: adapt_input: use: #{adapter_class_id}")
53
+ logger.trace("adapt_input: use: #{adapter_class_id}")
49
54
  input_message = InputMessage.new(adapted_message)
50
55
  adapter = adapter_class.new
51
56
  adapter.adapt_input(input_message)
52
57
  adapted_message = input_message.adapted_message
53
58
  adapted_message["appliedAdapters"] << adapter_class_id
54
59
  end
55
- $log.trace("#{log_tag}: adapt_input: done",
56
- :dataset => adapted_message["dataset"],
57
- :type => adapted_message["type"])
60
+ logger.trace("adapt_input: done",
61
+ :dataset => adapted_message["dataset"],
62
+ :type => adapted_message["type"])
58
63
  adapted_message
59
64
  end
60
65
 
61
66
  def adapt_output(message)
62
- $log.trace("#{log_tag}: adapt_output: start",
63
- :dataset => message["dataset"],
64
- :type => message["type"])
67
+ logger.trace("adapt_output: start",
68
+ :dataset => message["dataset"],
69
+ :type => message["type"])
65
70
  adapted_message = message
66
71
  applied_adapters = adapted_message["appliedAdapters"]
67
72
  @adapter_classes.reverse_each do |adapter_class|
68
73
  adapter_class_id = adapter_class.id
69
74
  if applied_adapters
70
- $log.trace("#{log_tag}: adapt_output: skip: #{adapter_class_id}: " +
71
- "input adapter wasn't applied",
72
- :applied_adapters => applied_adapters)
75
+ logger.trace("adapt_output: skip: #{adapter_class_id}: " +
76
+ "input adapter wasn't applied",
77
+ :applied_adapters => applied_adapters)
73
78
  next unless applied_adapters.include?(adapter_class.id)
74
79
  end
75
- pattern = adapter_class.message.output_pattern
80
+ pattern = adapter_class.output_message.pattern
76
81
  if pattern
77
82
  matcher = MessageMatcher.new(pattern)
78
- $log.trace("#{log_tag}: adapt_output: skip: #{adapter_class_id}",
79
- :pattern => pattern)
83
+ logger.trace("adapt_output: skip: #{adapter_class_id}",
84
+ :pattern => pattern)
80
85
  next unless matcher.match?(adapted_message)
81
86
  end
82
- $log.trace("#{log_tag}: adapt_output: use: #{adapter_class_id}")
87
+ logger.trace("adapt_output: use: #{adapter_class_id}")
83
88
  output_message = OutputMessage.new(adapted_message)
84
89
  adapter = adapter_class.new
85
90
  adapter.adapt_output(output_message)
86
91
  adapted_message = output_message.adapted_message
87
92
  end
88
- $log.trace("#{log_tag}: adapt_output: done",
89
- :dataset => adapted_message["dataset"],
90
- :type => adapted_message["type"])
93
+ logger.trace("adapt_output: done",
94
+ :dataset => adapted_message["dataset"],
95
+ :type => adapted_message["type"])
91
96
  adapted_message
92
97
  end
93
98
 
@@ -15,101 +15,18 @@
15
15
 
16
16
  require "digest/sha1"
17
17
  require "zlib"
18
- require "droonga/message_processing_error"
18
+ require "time"
19
+ require "droonga/error_messages"
20
+ require "droonga/catalog/errors"
19
21
 
20
22
  module Droonga
21
23
  module Catalog
22
24
  class Base
23
- attr_reader :base_path
24
- def initialize(data, base_path)
25
+ attr_reader :path, :base_path
26
+ def initialize(data, path)
25
27
  @data = data
26
- @base_path = base_path
27
-
28
- @data["datasets"].each do |name, dataset|
29
- number_of_partitions = dataset["number_of_partitions"]
30
- next if number_of_partitions < 2
31
- total_weight = compute_total_weight(dataset)
32
- continuum = []
33
- dataset["ring"].each do |key, value|
34
- points = number_of_partitions * 160 * value["weight"] / total_weight
35
- points.times do |point|
36
- hash = Digest::SHA1.hexdigest("#{key}:#{point}")
37
- continuum << [hash[0..7].to_i(16), key]
38
- end
39
- end
40
- dataset["continuum"] = continuum.sort do |a, b| a[0] - b[0]; end
41
- end
42
- @options = @data["options"] || {}
43
- end
44
-
45
- def option(name)
46
- @options[name]
47
- end
48
-
49
- def get_partitions(name)
50
- device = @data["farms"][name]["device"]
51
- pattern = Regexp.new("^#{name}\.")
52
- results = {}
53
- @data["datasets"].each do |key, dataset|
54
- workers = dataset["workers"]
55
- plugins = dataset["plugins"]
56
- dataset["ring"].each do |key, part|
57
- part["partitions"].each do |range, partitions|
58
- partitions.each do |partition|
59
- if partition =~ pattern
60
- path = File.join([device, $POSTMATCH, "db"])
61
- path = File.expand_path(path, base_path)
62
- options = {
63
- :database => path,
64
- :n_workers => workers,
65
- :plugins => plugins
66
- }
67
- results[partition] = options
68
- end
69
- end
70
- end
71
- end
72
- end
73
- return results
74
- end
75
-
76
- def get_routes(name, args)
77
- routes = []
78
- dataset = dataset(name)
79
- case args["type"]
80
- when "broadcast"
81
- dataset["ring"].each do |key, partition|
82
- select_range_and_replicas(partition, args, routes)
83
- end
84
- when "scatter"
85
- name = get_partition(dataset, args["key"])
86
- partition = dataset["ring"][name]
87
- select_range_and_replicas(partition, args, routes)
88
- end
89
- return routes
90
- end
91
-
92
- def get_partition(dataset, key)
93
- continuum = dataset["continuum"]
94
- return dataset["ring"].keys[0] unless continuum
95
- hash = Zlib.crc32(key)
96
- min = 0
97
- max = continuum.size - 1
98
- while (min < max) do
99
- index = (min + max) / 2
100
- value, key = continuum[index]
101
- return key if value == hash
102
- if value > hash
103
- max = index
104
- else
105
- min = index + 1
106
- end
107
- end
108
- return continuum[max][1]
109
- end
110
-
111
- def datasets
112
- @data["datasets"] || {}
28
+ @path = path
29
+ @base_path = File.dirname(path)
113
30
  end
114
31
 
115
32
  def have_dataset?(name)
@@ -119,27 +36,6 @@ module Droonga
119
36
  def dataset(name)
120
37
  datasets[name]
121
38
  end
122
-
123
- def select_range_and_replicas(partition, args, routes)
124
- date_range = args["date_range"] || 0..-1
125
- partition["partitions"].sort[date_range].each do |time, replicas|
126
- case args["replica"]
127
- when "top"
128
- routes << replicas[0]
129
- when "random"
130
- routes << replicas[rand(replicas.size)]
131
- when "all"
132
- routes.concat(replicas)
133
- end
134
- end
135
- end
136
-
137
- private
138
- def compute_total_weight(dataset)
139
- dataset["ring"].reduce(0) do |result, zone|
140
- result + zone[1]["weight"]
141
- end
142
- end
143
39
  end
144
40
  end
145
41
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013-2014 Droonga Project
1
+ # Copyright (C) 2014 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,41 +13,29 @@
13
13
  # License along with this library; if not, write to the Free Software
14
14
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
15
 
16
- require "digest/sha1"
16
+ require "droonga/catalog/schema"
17
17
 
18
18
  module Droonga
19
19
  module Catalog
20
20
  class Dataset
21
- def initialize(data)
21
+ def initialize(name, data)
22
+ @name = name
22
23
  @data = data
24
+ @schema = nil
23
25
  end
24
26
 
25
- def continuum
26
- @continuum ||= compute_continuum
27
+ # provided for compatibility
28
+ def [](key)
29
+ @data[key]
27
30
  end
28
31
 
29
- private
30
- def compute_continuum
31
- number_of_partitions = @data["number_of_partitions"]
32
- return [] if number_of_partitions < 2
33
- total_weight = compute_total_weight
34
- continuum = []
35
- @data["ring"].each do |key, value|
36
- points = number_of_partitions * 160 * value["weight"] / total_weight
37
- points.times do |point|
38
- hash = Digest::SHA1.hexdigest("#{key}:#{point}")
39
- continuum << [hash[0..7].to_i(16), key]
40
- end
41
- end
42
- continuum.sort do |a, b|
43
- a[0] - b[0]
44
- end
32
+ # provided for compatibility
33
+ def []=(key, value)
34
+ @data[key] = value
45
35
  end
46
36
 
47
- def compute_total_weight
48
- @data["ring"].reduce(0) do |result, zone|
49
- result + zone[1]["weight"]
50
- end
37
+ def schema
38
+ @schema ||= Droonga::Catalog::Schema.new(@name, @data["schema"])
51
39
  end
52
40
  end
53
41
  end