Class: Droonga::Catalog::Version2

Inherits:
Base
  • Object
show all
Defined in:
lib/droonga/catalog/version2.rb

Instance Attribute Summary

Attributes inherited from Base

#base_path, #path

Instance Method Summary collapse

Methods inherited from Base

#dataset, #have_dataset?

Constructor Details

#initialize(data, path) ⇒ Version2

Returns a new instance of Version2.



23
24
25
26
27
# File 'lib/droonga/catalog/version2.rb', line 23

def initialize(data, path)
  super
  validate
  prepare_data
end

Instance Method Details

#datasetsObject



29
30
31
# File 'lib/droonga/catalog/version2.rb', line 29

def datasets
  @datasets
end

#get_routes(name, args) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/droonga/catalog/version2.rb', line 60

def get_routes(name, args)
  routes = []
  dataset = dataset(name)
  case args["type"]
  when "broadcast"
    volumes = dataset.replicas.select(args["replica"].to_sym)
    volumes.each do |volume|
      slices = volume.select_slices
      slices.each do |slice|
        routes << slice.volume.address
      end
    end
  when "scatter"
    volumes = dataset.replicas.select(args["replica"].to_sym)
    volumes.each do |volume|
      slice = volume.choose_slice(args["record"])
      routes << slice.volume.address
    end
  end
  routes
end

#slices(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/droonga/catalog/version2.rb', line 33

def slices(name)
  device = "."
  pattern = Regexp.new("^#{name}\.")
  results = {}
  @datasets.each do |dataset_name, dataset|
    n_workers = dataset.n_workers
    plugins = dataset.plugins
    dataset.replicas.each do |volume|
      volume.slices.each do |slice|
        volume_address = slice.volume.address
        if pattern =~ volume_address
          path = File.join([device, $POSTMATCH, "db"])
          path = File.expand_path(path, base_path)
          options = {
            :dataset => dataset_name,
            :database => path,
            :n_workers => n_workers,
            :plugins => plugins
          }
          results[volume_address] = options
        end
      end
    end
  end
  results
end