Class: Droonga::Catalog::Version1::Dataset

Inherits:
Dataset
  • Object
show all
Defined in:
lib/droonga/catalog/version1.rb

Constant Summary

Constants inherited from Dataset

Dataset::DEFAULT_NAME

Instance Attribute Summary

Attributes inherited from Dataset

#name

Instance Method Summary collapse

Methods inherited from Dataset

#[], #[]=, #fact, #initialize, #n_workers, #plugins, #replicas, #schema

Constructor Details

This class inherits a constructor from Droonga::Catalog::Dataset

Instance Method Details

#all_nodesObject



448
449
450
# File 'lib/droonga/catalog/version1.rb', line 448

def all_nodes
  @all_nodes ||= collect_all_nodes
end

#compute_routes(args, active_nodes = nil) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/droonga/catalog/version1.rb', line 392

def compute_routes(args, active_nodes=nil)
  routes = []
  case args["type"]
  when "broadcast"
    self["ring"].each do |key, partition|
      select_range_and_replicas(partition, args, routes)
    end
  when "scatter"
    record = args["record"]
    if record
      key = record["_key"]
    else
      key = nil
    end
    name = get_partition(key)
    partition = self["ring"][name]
    select_range_and_replicas(partition, args, routes)
  end
  return routes
end

#get_partition(key) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/droonga/catalog/version1.rb', line 413

def get_partition(key)
  continuum = self["continuum"]
  return self["ring"].keys[0] unless continuum
  return continuum.sample[1] unless key
  key = key.to_s unless key.is_a?(String)
  hash = Zlib.crc32(key)
  min = 0
  max = continuum.size - 1
  while (min < max) do
    index = (min + max) / 2
    value, key = continuum[index]
    return key if value == hash
    if value > hash
      max = index
    else
      min = index + 1
    end
  end
  return continuum[max][1]
end

#select_range_and_replicas(partition, args, routes) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/droonga/catalog/version1.rb', line 434

def select_range_and_replicas(partition, args, routes)
  date_range = args["date_range"] || 0..-1
  partition["partitions"].sort[date_range].each do |time, replicas|
    case args["replica"]
    when "top"
      routes << replicas[0]
    when "random"
      routes << replicas[rand(replicas.size)]
    when "all"
      routes.concat(replicas)
    end
  end
end

#sliced?Boolean

Returns:

  • (Boolean)


452
453
454
# File 'lib/droonga/catalog/version1.rb', line 452

def sliced?
  self["ring"].keys.size > 1
end