Class: Droonga::Catalog::Version1::Dataset
- Inherits:
-
Dataset
- Object
- Dataset
- Droonga::Catalog::Version1::Dataset
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
#[], #[]=, #all_nodes, #fact, #initialize, #n_workers, #plugins, #replicas, #schema, #single_slice?
Instance Method Details
#compute_routes(args, live_nodes = nil) ⇒ Object
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
# File 'lib/droonga/catalog/version1.rb', line 392
def compute_routes(args, live_nodes=nil)
routes = []
case args["type"]
when "broadcast"
self["ring"].each do |key, partition|
select_range_and_replicas(partition, args, routes)
end
when "scatter"
name = get_partition(args["record"]["_key"])
partition = self["ring"][name]
select_range_and_replicas(partition, args, routes)
end
return routes
end
|
#get_partition(key) ⇒ Object
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
# File 'lib/droonga/catalog/version1.rb', line 407
def get_partition(key)
continuum = self["continuum"]
return self["ring"].keys[0] unless continuum
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
426
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'lib/droonga/catalog/version1.rb', line 426
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
|